From a20491d084c28d82e0965b9f06d77a0edf0f60ed Mon Sep 17 00:00:00 2001 From: Tony Young Date: Tue, 4 Feb 2014 02:50:24 -0500 Subject: [PATCH 1/3] Don't throw KeyError if we can't format a hostmask for a nickname. Some IRCds send weird commands at odd times (e.g. PING before NICK), and sometimes user information isn't always available (e.g. out of channel messages). --- pydle/client.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pydle/client.py b/pydle/client.py index 16a0705..4ff78d2 100644 --- a/pydle/client.py +++ b/pydle/client.py @@ -272,10 +272,7 @@ class BasicClient: del self.users[nickname] def _format_hostmask(self, nickname): - if nickname not in self.users: - raise KeyError('Unknown user "{usr}".'.format(usr=nickname)) - - user = self.users[nickname] + user = self.users.get(nickname, {"username": "*", "hostname": "*"}) return '{n}!{u}@{h}'.format(n=nickname, u=user['username'] or '*', h=user['hostname'] or '*') From 38ca472ff15297e374b14ff5f129853e23b96177 Mon Sep 17 00:00:00 2001 From: Tony Young Date: Tue, 4 Feb 2014 02:52:14 -0500 Subject: [PATCH 2/3] Run on_connect tasks when code 422 is received. Code 422 is sent if there is no MOTD set on the server but the connection completes. --- pydle/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pydle/client.py b/pydle/client.py index 4ff78d2..92ffecf 100644 --- a/pydle/client.py +++ b/pydle/client.py @@ -911,6 +911,11 @@ class BasicClient: # MOTD is done, let's tell our bot the connection is ready. self.on_connect() + def on_raw_422(self, message): + """ MOTD is missing. """ + self.motd = None + self.on_connect() + def on_raw_421(self, message): """ Server responded with 'unknown command'. """ self.logger.warn('Server responded with "Unknown command: {}"'.format(message.params[0])) From e92a981f1a650bd2a49225aad3234c3be3f6cc56 Mon Sep 17 00:00:00 2001 From: Tony Young Date: Tue, 4 Feb 2014 02:53:03 -0500 Subject: [PATCH 3/3] Fix typo (_construct_message -> _create_message). --- pydle/features/ircv3_1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydle/features/ircv3_1.py b/pydle/features/ircv3_1.py index b73e712..43c0606 100644 --- a/pydle/features/ircv3_1.py +++ b/pydle/features/ircv3_1.py @@ -83,7 +83,7 @@ class IRCv3_1Support(sasl.SASLSupport, tls.TLSSupport): self._sync_user(nick, user, host) # Emit a fake join message. - fakemsg = self._construct_message('JOIN', channels, source=message.source) + fakemsg = self._create_message('JOIN', channels, source=message.source) super().on_raw_join(fakemsg) if account == NO_ACCOUNT: