go-dette/filters.go

42 lines
945 B
Go
Raw Normal View History

2023-01-24 23:17:30 +03:00
package main
import (
"context"
"regexp"
2023-01-24 23:17:30 +03:00
"strings"
neco "git.nefrace.ru/nefrace/nechotron"
)
func karmaTriggers(u *neco.Update) bool {
triggers := GetTriggers()
2023-01-24 23:17:30 +03:00
text := u.Text()
for t, v := range triggers {
2023-01-24 23:17:30 +03:00
if strings.HasPrefix(text, t) {
u.Ctx = context.WithValue(u.Ctx, neco.FilteredValue("karmaTrigger"), t)
u.Ctx = context.WithValue(u.Ctx, neco.FilteredValue("karmaValue"), v)
2023-01-24 23:17:30 +03:00
return true
}
}
return false
}
var docRegex = regexp.MustCompile(`док(ументац[а-я]+|[а-я])? ((п)?о )?(?P<topic>@?[\w\d\s]{1,32})`)
func docRequest(u *neco.Update) bool {
text := u.Text()
matches := docRegex.FindStringSubmatch(text)
if len(matches) == 0 {
return false
}
result := make(map[string]string)
for i, name := range docRegex.SubexpNames() {
if i != 0 && name != "" {
result[name] = matches[i]
}
}
u.Ctx = context.WithValue(u.Ctx, neco.FilteredValue("docTopic"), result["topic"])
return true
}