2023-01-24 23:17:30 +03:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2023-02-13 01:40:20 +03:00
|
|
|
|
"context"
|
|
|
|
|
"regexp"
|
2023-01-24 23:17:30 +03:00
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
neco "git.nefrace.ru/nefrace/nechotron"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func karmaTriggers(u *neco.Update) bool {
|
2023-02-13 01:40:20 +03:00
|
|
|
|
triggers := GetTriggers()
|
|
|
|
|
|
2023-01-24 23:17:30 +03:00
|
|
|
|
text := u.Text()
|
2023-02-13 01:40:20 +03:00
|
|
|
|
for t, v := range triggers {
|
2023-01-24 23:17:30 +03:00
|
|
|
|
if strings.HasPrefix(text, t) {
|
2023-02-13 01:40:20 +03:00
|
|
|
|
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
|
|
|
|
|
}
|
2023-02-13 01:40:20 +03:00
|
|
|
|
|
2023-04-13 11:13:24 +03:00
|
|
|
|
func offtopTrigger(u *neco.Update) bool {
|
|
|
|
|
text := strings.ToLower(u.Text())
|
|
|
|
|
return strings.Contains(text, "оффтоп")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var docRegex = regexp.MustCompile(`(?i)док(ументац[а-я]+|[а-я])? ((п)?о )?(?P<topic>@?[\w\d\s]{1,32})`)
|
2023-02-13 01:40:20 +03:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2023-06-13 02:22:44 +03:00
|
|
|
|
|
|
|
|
|
func isFile(u *neco.Update) bool {
|
|
|
|
|
if u.Message == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if u.Message.Document == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|