1
0
Fork 0

🏗️ Improve IsCommand helper for checking commands

This commit is contained in:
Maxim Lebedev 2018-01-29 13:01:46 +05:00
parent ddf7ed711f
commit 845bf04e75
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
2 changed files with 11 additions and 6 deletions

View File

@ -45,7 +45,7 @@ func (bot *Bot) IsReplyToMe(msg *Message) bool {
}
func (bot *Bot) IsCommandToMe(msg *Message) bool {
if !msg.IsCommand() {
if !msg.IsCommand("") {
return false
}

View File

@ -5,7 +5,7 @@ import (
"time"
)
func (msg *Message) IsCommand() bool {
func (msg *Message) IsCommand(command string) bool {
if !msg.IsText() {
return false
}
@ -15,11 +15,16 @@ func (msg *Message) IsCommand() bool {
}
entity := msg.Entities[0]
return entity.IsBotCommand() && entity.Offset == 0
isBotCommand := entity.IsBotCommand() && entity.Offset == 0
if command != "" {
return isBotCommand && strings.EqualFold(msg.Command(), command)
}
return isBotCommand
}
func (msg *Message) Command() string {
if !msg.IsCommand() {
if !msg.IsCommand("") {
return ""
}
@ -27,7 +32,7 @@ func (msg *Message) Command() string {
}
func (msg *Message) RawCommand() string {
if !msg.IsCommand() {
if !msg.IsCommand("") {
return ""
}
@ -35,7 +40,7 @@ func (msg *Message) RawCommand() string {
}
func (msg *Message) HasCommandArgument() bool {
if !msg.IsCommand() {
if !msg.IsCommand("") {
return false
}