package main import ( "context" "regexp" "strings" neco "git.nefrace.ru/nefrace/nechotron" ) func karmaTriggers(u *neco.Update) bool { triggers := GetTriggers() text := u.Text() for t, v := range triggers { 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) return true } } return false } func offtopTrigger(u *neco.Update) bool { text := strings.ToLower(u.Text()) return strings.Contains(text, "оффтоп") } var docRegex = regexp.MustCompile(`(?i)док(ументац[а-я]+|[а-я])? ((п)?о )?(?P@?[\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 } func isFile(u *neco.Update) bool { if u.Message == nil { return false } if u.Message.Document == nil { return false } return true }