commands: Consolidate state.channel checks into getChannel

Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
James McCoy 2013-10-10 18:54:50 -04:00
parent 6361b1e856
commit 56a6799deb

View File

@ -303,8 +303,7 @@ def getNetworkIrc(irc, msg, args, state, errorIfNoMatch=False):
state.args.append(irc)
def getHaveOp(irc, msg, args, state, action='do that'):
if not state.channel:
getChannel(irc, msg, args, state)
getChannel(irc, msg, args, state)
if state.channel not in irc.state.channels:
state.error('I\'m not even in %s.' % state.channel, Raise=True)
if not irc.state.channels[state.channel].isOp(irc.nick):
@ -329,8 +328,7 @@ def getHostmask(irc, msg, args, state):
def getBanmask(irc, msg, args, state):
getHostmask(irc, msg, args, state)
if not state.channel:
getChannel(irc, msg, args, state)
getChannel(irc, msg, args, state)
channel = state.channel
banmaskstyle = conf.supybot.protocols.irc.banmask
state.args[-1] = banmaskstyle.makeBanmask(state.args[-1])
@ -406,6 +404,8 @@ def getSeenNick(irc, msg, args, state, errmsg=None):
state.error(errmsg, Raise=True)
def getChannel(irc, msg, args, state):
if state.channel:
return
if args and irc.isChannel(args[0]):
channel = args.pop(0)
elif irc.isChannel(msg.args[0]):
@ -437,8 +437,7 @@ def getChannelDb(irc, msg, args, state, **kwargs):
state.args.append(channel)
def inChannel(irc, msg, args, state):
if not state.channel:
getChannel(irc, msg, args, state)
getChannel(irc, msg, args, state)
if state.channel not in irc.state.channels:
state.error('I\'m not in %s.' % state.channel, Raise=True)
@ -478,8 +477,7 @@ def getChannelOrNone(irc, msg, args, state):
state.args.append(None)
def checkChannelCapability(irc, msg, args, state, cap):
if not state.channel:
getChannel(irc, msg, args, state)
getChannel(irc, msg, args, state)
cap = ircdb.canonicalCapability(cap)
cap = ircdb.makeChannelCapability(state.channel, cap)
if not ircdb.checkCapability(msg.prefix, cap):