54 lines
963 B
Go
54 lines
963 B
Go
package telegram
|
|
|
|
import "time"
|
|
|
|
func (msg *Message) IsCommand() bool {
|
|
if msg.Entities == nil ||
|
|
len(msg.Entities) <= 0 {
|
|
return false
|
|
}
|
|
|
|
return msg.Entities[0].Offset == 0 &&
|
|
msg.Entities[0].Type == EntityBotCommand
|
|
}
|
|
|
|
func (msg *Message) Command() string {
|
|
if !msg.IsCommand() {
|
|
return ""
|
|
}
|
|
|
|
return string([]rune(msg.Text)[1:msg.Entities[0].Length])
|
|
}
|
|
|
|
func (msg *Message) HasArgument() bool {
|
|
switch {
|
|
case msg.IsCommand(),
|
|
len(msg.CommandArgument()) > 0:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func (msg *Message) CommandArgument() string {
|
|
switch {
|
|
case !msg.IsCommand(),
|
|
len([]rune(msg.Text)) == msg.Entities[0].Length:
|
|
return ""
|
|
default:
|
|
return string([]rune(msg.Text)[msg.Entities[0].Length+1:])
|
|
}
|
|
}
|
|
|
|
func (msg *Message) IsReply() bool {
|
|
return msg.ReplyToMessage != nil
|
|
}
|
|
|
|
func (msg *Message) IsForward() bool {
|
|
return msg.ForwardFrom != nil
|
|
}
|
|
|
|
func (msg *Message) Time() time.Time {
|
|
return time.Unix(msg.Date, 0)
|
|
}
|