From 20eda29542a2b6d495f601d3af88b9848121888b Mon Sep 17 00:00:00 2001 From: Thomas Tan Date: Thu, 26 May 2016 00:03:41 +0800 Subject: [PATCH] coretasks: prevent KeyError when untracked user leaves Fixes #1005 --- sopel/coretasks.py | 1 + sopel/tools/target.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sopel/coretasks.py b/sopel/coretasks.py index 1cdf245009..f10666cd8e 100644 --- a/sopel/coretasks.py +++ b/sopel/coretasks.py @@ -357,6 +357,7 @@ def track_join(bot, trigger): user = bot.users.get(trigger.nick) if user is None: user = User(trigger.nick, trigger.user, trigger.host) + bot.users[trigger.nick] = user bot.channels[trigger.sender].add_user(user) if len(trigger.args) > 1 and trigger.args[1] != '*' and ( diff --git a/sopel/tools/target.py b/sopel/tools/target.py index 2ff0a91090..0757bb7eba 100644 --- a/sopel/tools/target.py +++ b/sopel/tools/target.py @@ -62,10 +62,10 @@ def __init__(self, name): """The topic of the channel.""" def clear_user(self, nick): - user = self.users[nick] - user.channels.pop(self.name, None) - del self.users[nick] - del self.privileges[nick] + user = self.users.pop(nick, None) + self.privileges.pop(nick, None) + if user != None: + user.channels.pop(self.name, None) def add_user(self, user): assert isinstance(user, User)