mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Added ability for commands to raise callbacks.CannotNest if they are not nestable.
This commit is contained in:
parent
fff995221e
commit
9550971042
@ -159,12 +159,12 @@ class FunDB(callbacks.Privmsg):
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'There are currently no available insults.')
|
||||
return
|
||||
else:
|
||||
(id, insult) = cursor.fetchone()
|
||||
sql = """UPDATE insults SET use_count=use_count+1, requested_by=%s
|
||||
WHERE id=%s"""
|
||||
cursor.execute(sql, msg.prefix, id)
|
||||
if nick.strip() in (irc.nick, 'himself', 'me'):
|
||||
nick = nick.strip()
|
||||
if nick in (irc.nick, 'yourself', 'me'):
|
||||
insultee = msg.nick
|
||||
else:
|
||||
insultee = nick
|
||||
@ -380,6 +380,7 @@ class FunDB(callbacks.Privmsg):
|
||||
lartee = nick
|
||||
lart = lart.replace("$who", lartee)
|
||||
irc.queueMsg(ircmsgs.action(channel, '%s (#%s)' % (lart, id)))
|
||||
raise callbacks.CannotNest
|
||||
|
||||
def praise(self, irc, msg, args):
|
||||
"""[<channel>] <nick>
|
||||
@ -408,6 +409,7 @@ class FunDB(callbacks.Privmsg):
|
||||
praisee = nick
|
||||
praise = praise.replace("$who", praisee)
|
||||
irc.queueMsg(ircmsgs.action(channel, '%s (#%s)' % (praise, id)))
|
||||
raise callbacks.CannotNest
|
||||
|
||||
def addword(self, irc, msg, args):
|
||||
"""<word>
|
||||
|
@ -179,6 +179,10 @@ class ArgumentError(Error):
|
||||
"""The bot replies with a help message when this is raised."""
|
||||
pass
|
||||
|
||||
class CannotNest(Error):
|
||||
"""Exception to be raised by commands that cannot be nested."""
|
||||
pass
|
||||
|
||||
class Tokenizer:
|
||||
# This will be used as a global environment to evaluate strings in.
|
||||
# Evaluation is, of course, necessary in order to allowed escaped
|
||||
@ -310,6 +314,9 @@ class IrcObjectProxy:
|
||||
else:
|
||||
s = 'Invalid arguments for %s.' % name
|
||||
self.reply(self.msg, s)
|
||||
except CannotNest, e:
|
||||
if not isinstance(self.irc, irclib.Irc):
|
||||
self.error(self.msg, 'Command %r cannot be nested.' % name)
|
||||
except (SyntaxError, Error), e:
|
||||
self.reply(self.msg, debug.exnToString(e))
|
||||
except Exception, e:
|
||||
@ -330,7 +337,10 @@ class IrcObjectProxy:
|
||||
self.evalArgs()
|
||||
|
||||
def error(self, msg, s):
|
||||
self.reply(msg, 'Error: ' + s)
|
||||
if isinstance(self.irc, self.__class__):
|
||||
self.irc.error(msg, s)
|
||||
else:
|
||||
self.irc.queueMsg(reply(msg, 'Error: ' + s))
|
||||
|
||||
def killProxy(self):
|
||||
if not isinstance(self.irc, irclib.Irc):
|
||||
@ -385,6 +395,10 @@ class CommandThread(threading.Thread):
|
||||
else:
|
||||
s = 'Invalid arguments for %s.' % self.commandName
|
||||
self.irc.reply(self.msg, s)
|
||||
except CannotNest:
|
||||
if not isinstance(self.irc.irc, irclib.Irc):
|
||||
s = 'Command %r cannot be nested.' % self.commandName
|
||||
self.irc.error(self.msg, s)
|
||||
except (SyntaxError, Error), e:
|
||||
self.irc.reply(self.msg, debug.exnToString(e))
|
||||
except Exception, e:
|
||||
@ -453,7 +467,7 @@ class Privmsg(irclib.IrcCallback):
|
||||
args = tokenize(s)
|
||||
self.Proxy(irc, msg, args)
|
||||
except SyntaxError, e:
|
||||
irc.queueMsg(reply(msg, debug.exnToString(e)))
|
||||
irc.queueMsg(reply(msg, str(e)))
|
||||
|
||||
def isCommand(self, methodName):
|
||||
# This function is ugly, but I don't want users to call methods like
|
||||
|
Loading…
Reference in New Issue
Block a user