ircbot: guess at nickmask in __init__()

some ircds don't lead to a welcome signal, so our attempts to set the
nickmask there may never happen. guess at one first, in the event that
_on_welcome() never fires
This commit is contained in:
Brian S. Stephan 2015-05-21 18:45:01 -05:00
parent c9542c1617
commit ed5f164092
1 changed files with 9 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import collections
import copy
import logging
import re
import socket
import ssl
import sys
@ -304,6 +305,14 @@ class IRCBot(irc.client.SimpleIRCClient):
self._nickname = settings.IRCBOT_NICKNAME
self._realname = settings.IRCBOT_REALNAME
# guess at nickmask. hopefully _on_welcome() will set this, but this should be
# a pretty good guess if not
nick = self._nickname
user = self._nickname
host = socket.getfqdn()
self.nickmask = "{0:s}!~{1:s}@{2:s}".format(nick, user, host)
log.debug("guessing at nickmask '{0:s}'".format(self.nickmask))
# handlers
for i in ['disconnect', 'join', 'kick', 'mode', 'namreply', 'nick', 'part', 'quit', 'welcome']:
self.connection.add_global_handler(i, getattr(self, '_on_' + i), -20)