From 8252e1f8630e6ee8abdd1cbdc32a053e9cf1f855 Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 27 Nov 2021 20:44:57 -0600 Subject: [PATCH] coretasks: alert owner if nick in RPL_WELCOME does not match config Inspired by a recent PR to the "horse docs" site, which adds a paragraph about this. --- sopel/coretasks.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sopel/coretasks.py b/sopel/coretasks.py index 747c5208a2..e25d50d085 100644 --- a/sopel/coretasks.py +++ b/sopel/coretasks.py @@ -252,6 +252,29 @@ def startup(bot, trigger): if bot.connection_registered: return + # nick shenanigans are serious business, but fortunately RPL_WELCOME + # includes the actual nick used by the server after truncation, removal + # of invalid characters, etc. so we can check for such shenanigans + if trigger.event == events.RPL_WELCOME: + if bot.nick != trigger.args[0]: + # setting modes below is just one of the things that won't work + # as expected if the conditions for running this block are met + privmsg = ( + "Hi, I'm your bot, %s. The IRC server didn't assign me the " + "nick you configured. This can cause problems for me, and " + "make me do weird things. You'll probably want to stop me, " + "figure out why my nick isn't acceptable, and fix that before " + "starting me again." % bot.nick + ) + debug_msg = ( + "RPL_WELCOME indicated the server did not accept the bot's " + "configured nickname. Requested '%s'; got '%s'. This can " + "cause unexpected behavior. Please modify the configuration " + "and restart the bot." % (bot.nick, trigger.args[0]) + ) + LOGGER.critical(debug_msg) + bot.say(privmsg, bot.config.core.owner) + # set flag bot.connection_registered = True