Compare commits

..

1 Commits

Author SHA1 Message Date
984e86a123
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:38:50 +02:00
2 changed files with 10 additions and 11 deletions

View File

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

View File

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