hdkv
/
i2_bot
Archived
1
Fork 0
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues/pull-requests.
i2_bot/lib/router/group_request.go

79 lines
2.1 KiB
Go
Raw Normal View History

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package router
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
"math/rand"
2017-11-14 03:44:21 +04:00
"regexp"
2017-11-29 19:11:52 +04:00
"strconv"
)
2017-11-14 03:44:21 +04:00
func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
text := update.Message.Text
// Regular expressions
var durakMsg = regexp.MustCompile("(Д|д)(У|у)(Р|р)(А|а|Е|е|О|о)")
var huMsg = regexp.MustCompile("(Х|х)(У|у)(Й|й|Я|я|Ю|ю|Е|е)")
2017-11-29 18:54:13 +04:00
var blMsg = regexp.MustCompile("(\\s|^)(Б|б)(Л|л)((Я|я)(Т|т|Д|д))")
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
squadHandled := c.Squader.ProcessMessage(update, chatRaw)
if squadHandled != "ok" {
return squadHandled
}
2017-11-29 19:11:52 +04:00
bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64)
if update.Message.Chat.ID == bastionChatID {
c.Squader.FilterBastion(update)
}
// Welcomes
2017-11-14 03:44:21 +04:00
if update.Message.NewChatMembers != nil {
newUsers := *update.Message.NewChatMembers
if len(newUsers) > 0 {
return c.Welcomer.GroupWelcomeMessage(update)
2017-11-14 03:44:21 +04:00
}
}
// New chat names
if update.Message.NewChatTitle != "" {
_, ok := c.Chatter.UpdateChatTitle(chatRaw, update.Message.NewChatTitle)
if ok {
return "ok"
}
return "fail"
}
// New chat IDs (usually on supergroup creation)
if (update.Message.MigrateToChatID != 0) && (update.Message.MigrateFromChatID != 0) {
_, ok := c.Chatter.UpdateChatTelegramID(update)
if ok {
return "ok"
}
return "fail"
}
// easter eggs
trigger := rand.Intn(5)
if trigger == 4 {
switch {
case huMsg.MatchString(text):
c.Talkers.MatMessage(update)
case blMsg.MatchString(text):
c.Talkers.MatMessage(update)
case ebMsg.MatchString(text):
c.Talkers.MatMessage(update)
case piMsg.MatchString(text):
c.Talkers.MatMessage(update)
case durakMsg.MatchString(text):
c.Talkers.DurakMessage(update)
}
}
return "ok"
}