2017-10-17 11:08:09 +00:00
|
|
|
package telegram
|
|
|
|
|
2017-11-29 22:08:29 +00:00
|
|
|
import "time"
|
2017-10-17 11:08:09 +00:00
|
|
|
|
|
|
|
func (msg *Message) IsCommand() bool {
|
|
|
|
if len(msg.Entities) <= 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:10:20 +00:00
|
|
|
if msg.Entities[0].Type != EntityBotCommand {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.Entities[0].Offset == 0 {
|
2017-10-17 11:08:09 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *Message) Command() string {
|
|
|
|
if !msg.IsCommand() {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return string([]rune(msg.Text)[1:msg.Entities[0].Length])
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *Message) CommandArgument() string {
|
|
|
|
if !msg.IsCommand() {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:08:29 +00:00
|
|
|
argument := string([]rune(msg.Text)[msg.Entities[0].Length:])
|
|
|
|
|
|
|
|
if argument != "" {
|
|
|
|
return argument[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
2017-10-17 11:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *Message) HasArgument() bool {
|
|
|
|
if !msg.IsCommand() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.CommandArgument() != "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *Message) Time() time.Time {
|
|
|
|
return time.Unix(msg.Date, 0)
|
|
|
|
}
|