2017-11-03 21:33:02 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
2017-11-28 20:37:14 +04:00
|
|
|
|
"math/rand"
|
2017-11-14 03:44:21 +04:00
|
|
|
|
"regexp"
|
2018-03-31 16:45:09 +04:00
|
|
|
|
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2018-02-17 16:01:05 +04:00
|
|
|
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
2017-11-03 21:33:02 +04:00
|
|
|
|
)
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
func (r *Router) routeGroupRequest(update tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
|
2017-11-03 21:33:02 +04:00
|
|
|
|
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|^)(Б|б)(Л|л)((Я|я)(Т|т|Д|д))")
|
2017-11-03 21:33:02 +04:00
|
|
|
|
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
|
|
|
|
|
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
restrictionStatus := c.Chatter.ProtectChat(&update, playerRaw, chatRaw)
|
2018-03-31 17:46:13 +04:00
|
|
|
|
if restrictionStatus != "ok" {
|
2017-12-23 17:03:26 +04:00
|
|
|
|
return restrictionStatus
|
2017-11-29 19:11:52 +04:00
|
|
|
|
}
|
2017-11-26 06:48:13 +04:00
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
// Welcomes
|
2017-11-14 03:44:21 +04:00
|
|
|
|
if update.Message.NewChatMembers != nil {
|
|
|
|
|
newUsers := *update.Message.NewChatMembers
|
|
|
|
|
if len(newUsers) > 0 {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Welcomer.GroupWelcomeMessage(&update)
|
2017-11-14 03:44:21 +04:00
|
|
|
|
}
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
|
|
|
|
// New chat names
|
|
|
|
|
if update.Message.NewChatTitle != "" {
|
2018-02-17 16:01:05 +04:00
|
|
|
|
_, err := c.DataCache.UpdateChatTitle(chatRaw.ID, update.Message.NewChatTitle)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
|
|
|
|
return "fail"
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 16:01:05 +04:00
|
|
|
|
return "ok"
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-28 20:37:14 +04:00
|
|
|
|
// easter eggs
|
|
|
|
|
trigger := rand.Intn(5)
|
|
|
|
|
if trigger == 4 {
|
|
|
|
|
switch {
|
|
|
|
|
case huMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.MatMessage(&update)
|
2017-11-28 20:37:14 +04:00
|
|
|
|
case blMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.MatMessage(&update)
|
2017-11-28 20:37:14 +04:00
|
|
|
|
case ebMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.MatMessage(&update)
|
2017-11-28 20:37:14 +04:00
|
|
|
|
case piMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.MatMessage(&update)
|
2017-11-28 20:37:14 +04:00
|
|
|
|
case durakMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.DurakMessage(&update)
|
2017-11-28 20:37:14 +04:00
|
|
|
|
}
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 13:45:24 +04:00
|
|
|
|
switch {
|
|
|
|
|
case update.Message.Command() == "long":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.LongMessage(&update)
|
2018-05-06 05:57:52 +04:00
|
|
|
|
default:
|
|
|
|
|
if update.Message.IsCommand() {
|
|
|
|
|
return c.Talkers.RulesMessage(&update)
|
|
|
|
|
}
|
2017-12-02 13:45:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-03 00:40:30 +04:00
|
|
|
|
// Ah, we're still here
|
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|