1
0
telegram/messages_helpers.go
2017-11-21 19:40:36 +05:00

55 lines
795 B
Go

package telegram
import (
"strings"
"time"
)
func (msg *Message) IsCommand() bool {
if len(msg.Entities) <= 0 {
return false
}
if msg.Entities[0].Type == EntityBotCommand &&
msg.Entities[0].Offset == 0 {
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 ""
}
return strings.TrimLeft(
string([]rune(msg.Text)[(msg.Entities[0].Length):]),
" ",
)
}
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)
}