Skip to content

Commit

Permalink
Add an .is_nick() function to the Nick class
Browse files Browse the repository at this point in the history
Enables easier checking for whether an identifier is a nick or a
channel. Closes sopel-irc#281.
  • Loading branch information
embolalia committed Mar 29, 2014
1 parent 3c1828a commit e8071ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
25 changes: 13 additions & 12 deletions adminchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import re
from willie.module import commands, priority, OP
from willie.tools import Nick


def setup(bot):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chanlogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion meetbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e8071ee

Please sign in to comment.