Skip to content

Commit 8252e1f

Browse files
committed
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.
1 parent a8dcb76 commit 8252e1f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sopel/coretasks.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,29 @@ def startup(bot, trigger):
252252
if bot.connection_registered:
253253
return
254254

255+
# nick shenanigans are serious business, but fortunately RPL_WELCOME
256+
# includes the actual nick used by the server after truncation, removal
257+
# of invalid characters, etc. so we can check for such shenanigans
258+
if trigger.event == events.RPL_WELCOME:
259+
if bot.nick != trigger.args[0]:
260+
# setting modes below is just one of the things that won't work
261+
# as expected if the conditions for running this block are met
262+
privmsg = (
263+
"Hi, I'm your bot, %s. The IRC server didn't assign me the "
264+
"nick you configured. This can cause problems for me, and "
265+
"make me do weird things. You'll probably want to stop me, "
266+
"figure out why my nick isn't acceptable, and fix that before "
267+
"starting me again." % bot.nick
268+
)
269+
debug_msg = (
270+
"RPL_WELCOME indicated the server did not accept the bot's "
271+
"configured nickname. Requested '%s'; got '%s'. This can "
272+
"cause unexpected behavior. Please modify the configuration "
273+
"and restart the bot." % (bot.nick, trigger.args[0])
274+
)
275+
LOGGER.critical(debug_msg)
276+
bot.say(privmsg, bot.config.core.owner)
277+
255278
# set flag
256279
bot.connection_registered = True
257280

0 commit comments

Comments
 (0)