2023-01-22 23:54:54 +03:00
|
|
|
package nechotron
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
type FilterFn func(u *Update) bool
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|