2023-01-22 23:54:54 +03:00
|
|
|
package nechotron
|
|
|
|
|
2023-02-13 01:39:57 +03:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
2023-01-22 23:54:54 +03:00
|
|
|
|
|
|
|
type FilterFn func(u *Update) bool
|
2023-02-13 01:39:57 +03:00
|
|
|
type FilteredValue interface{}
|
2023-01-22 23:54:54 +03:00
|
|
|
|
|
|
|
func TextStartsWith(text string) FilterFn {
|
|
|
|
return func(u *Update) bool {
|
|
|
|
return strings.HasPrefix(u.Text(), text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-24 01:08:24 +03:00
|
|
|
func TextStartsWithAny(subs ...string) FilterFn {
|
|
|
|
return func(u *Update) bool {
|
|
|
|
text := u.Text()
|
|
|
|
for _, sub := range subs {
|
|
|
|
if strings.HasPrefix(text, sub) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 23:54:54 +03:00
|
|
|
func TextHas(text string) FilterFn {
|
|
|
|
return func(u *Update) bool {
|
|
|
|
return strings.Contains(u.Text(), text)
|
|
|
|
}
|
|
|
|
}
|
2023-01-24 01:08:24 +03:00
|
|
|
|
|
|
|
func TextHasAny(subs ...string) FilterFn {
|
|
|
|
return func(u *Update) bool {
|
|
|
|
text := u.Text()
|
|
|
|
for _, sub := range subs {
|
|
|
|
if strings.Contains(text, sub) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2023-01-24 23:16:58 +03:00
|
|
|
|
|
|
|
func IsPrivate(u *Update) bool {
|
|
|
|
return u.ChatID() > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsForum(u *Update) bool {
|
|
|
|
return u.Chat().IsForum
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsReply(u *Update) bool {
|
|
|
|
return u.IsReply()
|
|
|
|
}
|
|
|
|
|
2023-06-13 02:23:09 +03:00
|
|
|
func IsCallback(u *Update) bool {
|
|
|
|
return u.IsCallback()
|
|
|
|
}
|
|
|
|
|
2023-01-24 23:16:58 +03:00
|
|
|
func IsUserAdmin(u *Update) bool {
|
|
|
|
if IsPrivate(u) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
member, err := u.Bot.GetChatMember(u.ChatID(), u.From().ID)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return member.Result.Status == "administrator" || member.Result.Status == "creator"
|
|
|
|
}
|