🐛 Fixed commands helpers and added new methods
This commit is contained in:
parent
454ab91b8c
commit
7ec684ec3c
31
toolbox.go
31
toolbox.go
|
@ -1,8 +1,10 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
router "github.com/buaazp/fasthttprouter"
|
router "github.com/buaazp/fasthttprouter"
|
||||||
|
@ -199,6 +201,7 @@ func (bot *Bot) NewWebhookChannel(endpoint string, params *GetUpdatesParameters)
|
||||||
func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChannel {
|
func (bot *Bot) NewLongPollingChannel(params *GetUpdatesParameters) UpdatesChannel {
|
||||||
if params == nil {
|
if params == nil {
|
||||||
params = &GetUpdatesParameters{
|
params = &GetUpdatesParameters{
|
||||||
|
Offset: 0,
|
||||||
Limit: 100,
|
Limit: 100,
|
||||||
Timeout: 60,
|
Timeout: 60,
|
||||||
}
|
}
|
||||||
|
@ -243,16 +246,36 @@ func (msg *Message) IsCommand() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *Message) Command() string {
|
func (msg *Message) Command() string {
|
||||||
if len(msg.Entities) <= 0 {
|
if !msg.IsCommand() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Entities[0].Type != EntityBotCommand &&
|
return string([]rune(msg.Text)[1:msg.Entities[0].Length])
|
||||||
msg.Entities[0].Offset != 0 {
|
}
|
||||||
|
|
||||||
|
func (msg *Message) CommandArgument() string {
|
||||||
|
if !msg.IsCommand() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return string([]rune(msg.Text)[:msg.Entities[0].Length])
|
arg := strings.TrimPrefix(
|
||||||
|
msg.Text,
|
||||||
|
fmt.Sprint("/", msg.Command()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return strings.TrimPrefix(arg, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *Message) HasArgument() bool {
|
||||||
|
if !msg.IsCommand() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.CommandArgument() == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chat *Chat) IsPrivate() bool {
|
func (chat *Chat) IsPrivate() bool {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user