Compare commits

..

1 Commits

Author SHA1 Message Date
82534a9030
Refactor integrations
Move to a separate file for better code structure and to avoid huge
branching inside Msg().

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-09-29 14:45:03 +02:00
2 changed files with 11 additions and 10 deletions

View File

@ -128,11 +128,8 @@ func (w *WatBot) Msg(m *irc.Message) {
}
// integration with games in other bots
isBot, games := w.integration.Bot(m)
if isBot {
if w.integration.HandleIntegration(m, args, games) {
return
}
if w.integration.HandleIntegration(m, args) {
return
}
// check if command char (or something weird) is present

View File

@ -39,14 +39,18 @@ func (w *WatIntegration) Bot(m *irc.Message) (bool, []string) {
return isBot, games
}
func (w *WatIntegration) HandleIntegration(m *irc.Message, msgargs []string, games []string) bool {
func (w *WatIntegration) HandleIntegration(m *irc.Message, msgargs []string) bool {
// handles a message "Top finishers: (nick1: 1300) (nick2: 1200)" from an authorized Jeopardy game bot
if msgargs[0] == "Top" && msgargs[1] == "finishers:" && w.bot.Allowed("jeopardy", games) {
w.Jeopardy(m, msgargs)
return true
isBot, games := w.Bot(m)
if isBot {
// handles a message "Top finishers: (nick1: 1300) (nick2: 1200)" from an authorized Jeopardy game bot
if msgargs[0] == "Top" && msgargs[1] == "finishers:" && w.bot.Allowed("jeopardy", games) {
w.Jeopardy(m, msgargs)
return true
}
}
// not an authorized bot or no integration matched the given message
return false
}