mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Made it so only one method will be called, unless a plugin specifically declares a command to be alwaysCalled.
This commit is contained in:
parent
e298f33d7e
commit
7a1130cc28
@ -77,12 +77,18 @@ def loadPluginClass(irc, module):
|
|||||||
callback.configure(irc)
|
callback.configure(irc)
|
||||||
|
|
||||||
class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
||||||
priority = ~sys.maxint # This must be first!
|
# This plugin must be first; its priority must be lowest; otherwise odd
|
||||||
|
# things will happen when adding callbacks.
|
||||||
|
priority = ~sys.maxint-1 # This must be first!
|
||||||
capability = 'owner'
|
capability = 'owner'
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
setattr(self.__class__, 'exec', self.__class__._exec)
|
setattr(self.__class__, 'exec', self.__class__._exec)
|
||||||
|
|
||||||
|
def doPrivmsg(self, irc, msg):
|
||||||
|
callbacks.Privmsg.handled = False
|
||||||
|
super(self.__class__, self).doPrivmsg(irc, msg)
|
||||||
|
|
||||||
def eval(self, irc, msg, args):
|
def eval(self, irc, msg, args):
|
||||||
"""<expression>
|
"""<expression>
|
||||||
|
|
||||||
|
@ -571,6 +571,8 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
"""Base class for all Privmsg handlers."""
|
"""Base class for all Privmsg handlers."""
|
||||||
threaded = False
|
threaded = False
|
||||||
public = True
|
public = True
|
||||||
|
handled = False
|
||||||
|
alwaysCall = ()
|
||||||
commandArgs = ['self', 'irc', 'msg', 'args']
|
commandArgs = ['self', 'irc', 'msg', 'args']
|
||||||
_mores = {} # This must be class-scope, so all subclasses use the same one.
|
_mores = {} # This must be class-scope, so all subclasses use the same one.
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -656,6 +658,7 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
def callCommand(self, f, irc, msg, *L):
|
def callCommand(self, f, irc, msg, *L):
|
||||||
# Exceptions aren't caught here because IrcObjectProxy.finalEval
|
# Exceptions aren't caught here because IrcObjectProxy.finalEval
|
||||||
# catches them and does The Right Thing.
|
# catches them and does The Right Thing.
|
||||||
|
Privmsg.handled = True
|
||||||
start = time.time()
|
start = time.time()
|
||||||
f(irc, msg, *L)
|
f(irc, msg, *L)
|
||||||
elapsed = time.time() - start
|
elapsed = time.time() - start
|
||||||
@ -678,6 +681,8 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
if args and isinstance(args[0], str):
|
if args and isinstance(args[0], str):
|
||||||
args[0] = canonicalName(args[0])
|
args[0] = canonicalName(args[0])
|
||||||
if self.isCommand(args[0]):
|
if self.isCommand(args[0]):
|
||||||
|
if self.handled and args[0] not in self.alwaysCall:
|
||||||
|
return
|
||||||
if rateLimit:
|
if rateLimit:
|
||||||
self.rateLimiter.put(msg)
|
self.rateLimiter.put(msg)
|
||||||
msg = self.rateLimiter.get()
|
msg = self.rateLimiter.get()
|
||||||
@ -732,7 +737,6 @@ class PrivmsgRegexp(Privmsg):
|
|||||||
"""
|
"""
|
||||||
threaded = False # Again, like Privmsg...
|
threaded = False # Again, like Privmsg...
|
||||||
flags = re.I
|
flags = re.I
|
||||||
onlyFirstMatch = False
|
|
||||||
commandArgs = ['self', 'irc', 'msg', 'match']
|
commandArgs = ['self', 'irc', 'msg', 'match']
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Privmsg.__init__(self)
|
Privmsg.__init__(self)
|
||||||
@ -778,8 +782,6 @@ class PrivmsgRegexp(Privmsg):
|
|||||||
msg = self.rateLimiter.get()
|
msg = self.rateLimiter.get()
|
||||||
if msg:
|
if msg:
|
||||||
self.callCommand(method, irc, msg, m)
|
self.callCommand(method, irc, msg, m)
|
||||||
if self.onlyFirstMatch:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class PrivmsgCommandAndRegexp(Privmsg):
|
class PrivmsgCommandAndRegexp(Privmsg):
|
||||||
@ -821,7 +823,11 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
|||||||
return
|
return
|
||||||
fed = False
|
fed = False
|
||||||
for (r, method) in self.res:
|
for (r, method) in self.res:
|
||||||
|
originalHandled = self.handled
|
||||||
|
name = method.__name__
|
||||||
for m in r.finditer(msg.args[1]):
|
for m in r.finditer(msg.args[1]):
|
||||||
|
if originalHandled and name not in self.alwaysCall:
|
||||||
|
continue
|
||||||
if not fed:
|
if not fed:
|
||||||
fed = True
|
fed = True
|
||||||
self.rateLimiter.put(msg)
|
self.rateLimiter.put(msg)
|
||||||
@ -832,7 +838,11 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
|||||||
s = addressed(irc.nick, msg)
|
s = addressed(irc.nick, msg)
|
||||||
if s:
|
if s:
|
||||||
for (r, method) in self.addressedRes:
|
for (r, method) in self.addressedRes:
|
||||||
|
originalHandled = self.handled
|
||||||
|
name = method.__name__
|
||||||
for m in r.finditer(s):
|
for m in r.finditer(s):
|
||||||
|
if originalHandled and name not in self.alwaysCall:
|
||||||
|
continue
|
||||||
if not fed:
|
if not fed:
|
||||||
fed = True
|
fed = True
|
||||||
self.rateLimiter.put(msg)
|
self.rateLimiter.put(msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user