package nechotron import ( "strings" ) type FilterFn func(u *Update) bool type FilteredValue interface{} func TextStartsWith(text string) FilterFn { return func(u *Update) bool { return strings.HasPrefix(u.Text(), text) } } 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 } } func TextHas(text string) FilterFn { return func(u *Update) bool { return strings.Contains(u.Text(), text) } } 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 } } 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() } 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" }