From e8071ee9b920a9d466b30a673031bb5cdf45293d Mon Sep 17 00:00:00 2001 From: Edward Powell Date: Sat, 29 Mar 2014 14:59:01 -0400 Subject: [PATCH] Add an `.is_nick()` function to the Nick class Enables easier checking for whether an identifier is a nick or a channel. Closes #281. --- adminchannel.py | 25 +++++++++++++------------ chanlogs.py | 2 +- meetbot.py | 2 +- wikipedia.py | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/adminchannel.py b/adminchannel.py index 269987d08a..ec4b206705 100644 --- a/adminchannel.py +++ b/adminchannel.py @@ -11,6 +11,7 @@ import re from willie.module import commands, priority, OP +from willie.tools import Nick def setup(bot): @@ -87,11 +88,11 @@ def kick(bot, trigger): argc = len(text) if argc < 2: return - opt = text[1] + opt = Nick(text[1]) nick = opt channel = trigger.sender reasonidx = 2 - if opt.startswith('#'): + if not opt.is_nick(): if argc < 3: return nick = text[2] @@ -137,10 +138,10 @@ def ban(bot, trigger): argc = len(text) if argc < 2: return - opt = text[1] + opt = Nick(text[1]) banmask = opt channel = trigger.sender - if opt.startswith('#'): + if not opt.is_nick(): if argc < 3: return channel = opt @@ -163,10 +164,10 @@ def unban(bot, trigger): argc = len(text) if argc < 2: return - opt = text[1] + opt = Nick(text[1]) banmask = opt channel = trigger.sender - if opt.startswith('#'): + if not opt.is_nick(): if argc < 3: return channel = opt @@ -189,10 +190,10 @@ def quiet(bot, trigger): argc = len(text) if argc < 2: return - opt = text[1] + opt = Nick(text[1]) quietmask = opt channel = trigger.sender - if opt.startswith('#'): + if not opt.is_nick(): if argc < 3: return quietmask = text[2] @@ -215,10 +216,10 @@ def unquiet(bot, trigger): argc = len(text) if argc < 2: return - opt = text[1] + opt = Nick(text[1]) quietmask = opt channel = trigger.sender - if opt.startswith('#'): + if not opt.is_nick(): if argc < 3: return quietmask = text[2] @@ -243,11 +244,11 @@ def kickban(bot, trigger): argc = len(text) if argc < 4: return - opt = text[1] + opt = Nick(text[1]) nick = opt mask = text[2] reasonidx = 3 - if opt.startswith('#'): + if not opt.is_nick(): if argc < 5: return channel = opt diff --git a/chanlogs.py b/chanlogs.py index 44cabddc91..521f2f08ee 100644 --- a/chanlogs.py +++ b/chanlogs.py @@ -91,7 +91,7 @@ def setup(bot): def log_message(bot, message): "Log every message in a channel" # if this is a private message and we're not logging those, return early - if not bot.origin.sender.startswith("#") and not bot.config.chanlogs.privmsg: + if message.sender.is_nick() and not bot.config.chanlogs.privmsg: return # determine which template we want, message or action diff --git a/meetbot.py b/meetbot.py index 025ff51e0f..f1e330c7ca 100644 --- a/meetbot.py +++ b/meetbot.py @@ -377,7 +377,7 @@ def take_comment(bot, trigger): """ target, message = trigger.group(2).split(None, 1) target = Nick(target) - if trigger.sender[0] in '#&+!': + if not trigger.sender.is_nick(): return if not ismeetingrunning(target): bot.say("There's not currently a meeting in that channel.") diff --git a/wikipedia.py b/wikipedia.py index 30110e352d..94699e3528 100644 --- a/wikipedia.py +++ b/wikipedia.py @@ -74,7 +74,7 @@ def wikipedia(bot, trigger): #change lang if channel has custom language set if ( trigger.sender and - trigger.sender.startswith('#') and + not trigger.sender.is_nick() and bot.config.has_option('wikipedia', 'lang_per_channel') ): customlang = re.search(