From 2bbd43fd8587f034a6e41dfeb57d88c6eb68bdc4 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 7 Apr 2020 21:17:52 +0200 Subject: [PATCH] ChannelStats: Skip checks of nick in irc.state.channels[channel] when channel databases are linked. It crashes with KeyError because databases.plugins.channelspecific sets channel='#', which is a non-existent channel. And it doesn't make sense to check for presence in channel if the DB is shared between all channels anyway. --- plugins/ChannelStats/plugin.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/ChannelStats/plugin.py b/plugins/ChannelStats/plugin.py index e8c186b0f..5662c3ed2 100644 --- a/plugins/ChannelStats/plugin.py +++ b/plugins/ChannelStats/plugin.py @@ -242,9 +242,11 @@ class ChannelStats(callbacks.Plugin): necessary if the message isn't sent on the channel itself. If isn't given, it defaults to the user sending the command. """ - if msg.nick not in irc.state.channels[channel].users: - irc.error(format('You must be in %s to use this command.', channel)) - return + if channel != '#': + # Skip this check if databases.plugins.channelspecific is False. + if msg.nick not in irc.state.channels[channel].users: + irc.error(format('You must be in %s to use this command.', channel)) + return if name and ircutils.strEqual(name, irc.nick): id = 0 elif not name: @@ -303,9 +305,11 @@ class ChannelStats(callbacks.Plugin): 'kicks', 'kicked', 'topics', and 'modes'. Any simple mathematical expression involving those variables is permitted. """ - if msg.nick not in irc.state.channels[channel].users: - irc.error(format('You must be in %s to use this command.', channel)) - return + if channel != '#': + # Skip this check if databases.plugins.channelspecific is False. + if msg.nick not in irc.state.channels[channel].users: + irc.error(format('You must be in %s to use this command.', channel)) + return expr = expr.lower() users = [] for ((c, id), stats) in self.db.items():