Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/router/group_request.go
Vladimir Hodakov 4abfc457ce Add return constants package, and common message sender functions
Trying to resolve as much as possible ``gometalinter`` issues.
2018-03-31 16:45:09 +04:00

72 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package router
import (
"math/rand"
"regexp"
"github.com/go-telegram-bot-api/telegram-bot-api"
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
)
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("(Х|х)(У|у)(Й|й|Я|я|Ю|ю|Е|е)")
var blMsg = regexp.MustCompile("(\\s|^)(Б|б)(Л|л)((Я|я)(Т|т|Д|д))")
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
restrictionStatus := c.Chatter.ProtectChat(&update, playerRaw, chatRaw)
if restrictionStatus != "protection_passed" {
return restrictionStatus
}
// Welcomes
if update.Message.NewChatMembers != nil {
newUsers := *update.Message.NewChatMembers
if len(newUsers) > 0 {
return c.Welcomer.GroupWelcomeMessage(&update)
}
}
// New chat names
if update.Message.NewChatTitle != "" {
_, err := c.DataCache.UpdateChatTitle(chatRaw.ID, update.Message.NewChatTitle)
if err != nil {
c.Log.Error(err.Error())
return "fail"
}
return "ok"
}
// easter eggs
trigger := rand.Intn(5)
if trigger == 4 {
switch {
case huMsg.MatchString(text):
return c.Talkers.MatMessage(&update)
case blMsg.MatchString(text):
return c.Talkers.MatMessage(&update)
case ebMsg.MatchString(text):
return c.Talkers.MatMessage(&update)
case piMsg.MatchString(text):
return c.Talkers.MatMessage(&update)
case durakMsg.MatchString(text):
return c.Talkers.DurakMessage(&update)
}
}
switch {
case update.Message.Command() == "long":
return c.Talkers.LongMessage(&update)
}
// Ah, we're still here
return "ok"
}