diff --git a/willie/bot.py b/willie/bot.py index afaf5ebf52..97016792ef 100644 --- a/willie/bot.py +++ b/willie/bot.py @@ -601,10 +601,7 @@ def __new__(cls, text, origin, bytes, match, event, args, self): s = unicode.__new__(cls, text) """Is trigger from a channel or in PM""" - s.is_privmsg = False - if (origin.sender is not None - and not origin.sender.startswith(('#', '&', '+', '!'))): - s.is_privmsg = True + s.is_privmsg = origin.sender.is_nick() s.sender = origin.sender """ @@ -753,7 +750,7 @@ def call(self, func, origin, willie, trigger): self.times[nick][func] = time.time() def limit(self, origin, func): - if origin.sender and origin.sender.startswith('#'): + if origin.sender and not origin.sender.is_nick(): if self.config.has_section('limit'): limits = self.config.limit.get(origin.sender) if limits and (func.__module__ not in limits): diff --git a/willie/coretasks.py b/willie/coretasks.py index 32b8913f1e..f63a7d7701 100644 --- a/willie/coretasks.py +++ b/willie/coretasks.py @@ -162,7 +162,7 @@ def track_modes(bot, trigger): # If the first character of where the mode is being set isn't a # # then it's a user mode, not a channel mode, so we'll ignore it. - if channel[0] != '#': + if channel.is_nick(): return def handle_old_modes(nick, mode): diff --git a/willie/modules/adminchannel.py b/willie/modules/adminchannel.py index 269987d08a..ec4b206705 100644 --- a/willie/modules/adminchannel.py +++ b/willie/modules/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/willie/modules/chanlogs.py b/willie/modules/chanlogs.py index 44cabddc91..521f2f08ee 100644 --- a/willie/modules/chanlogs.py +++ b/willie/modules/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/willie/modules/meetbot.py b/willie/modules/meetbot.py index 025ff51e0f..f1e330c7ca 100644 --- a/willie/modules/meetbot.py +++ b/willie/modules/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/willie/modules/wikipedia.py b/willie/modules/wikipedia.py index 30110e352d..94699e3528 100644 --- a/willie/modules/wikipedia.py +++ b/willie/modules/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( diff --git a/willie/tools.py b/willie/tools.py index 50cf93f300..40f93c7a7e 100644 --- a/willie/tools.py +++ b/willie/tools.py @@ -43,6 +43,7 @@ itervalues = dict.itervalues iterkeys = dict.iterkeys +_channel_prefixes = ('#', '&', '+', '!') class ExpressionEvaluator: @@ -228,8 +229,7 @@ def __getitem__(self, key): class Nick(unicode): - - """A `unicode` subclass which acts appropriately for an IRC nickname. + """A `unicode` subclass which acts appropriately for IRC identifiers. When used as normal `unicode` objects, case will be preserved. However, when comparing two Nick objects, or comparing a Nick object with a @@ -299,6 +299,11 @@ def __eq__(self, other): def __ne__(self, other): return not (self == other) + def is_nick(self): + """Returns True if the Identifier is a nickname (as opposed to channel) + """ + return self and not self.startswith(_channel_prefixes) + class OutputRedirect: