26 lines
514 B
Go
26 lines
514 B
Go
|
package nechotron
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type CallbackFilter func(u *Update) bool
|
||
|
|
||
|
func CallbackExact(text string) CallbackFilter {
|
||
|
return func(u *Update) bool {
|
||
|
data := u.Callback()
|
||
|
return text == data
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func CallbackPrefix(text string) CallbackFilter {
|
||
|
return func(u *Update) bool {
|
||
|
data := u.Callback()
|
||
|
if strings.HasPrefix(data, text) {
|
||
|
u.Ctx = context.WithValue(u.Ctx, FilteredValue("cb_"+text), strings.TrimPrefix(data, text+":"))
|
||
|
}
|
||
|
return strings.HasPrefix(data, text)
|
||
|
}
|
||
|
}
|