mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-19 07:00:57 +01:00
Added docstring to disambiguate, fixed some bugs.
This commit is contained in:
parent
4b3b245834
commit
5502794a23
14
src/Owner.py
14
src/Owner.py
@ -99,6 +99,10 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
'removecapability': 'Admin'}
|
'removecapability': 'Admin'}
|
||||||
|
|
||||||
def disambiguate(self, irc, tokens, ambiguousCommands=None):
|
def disambiguate(self, irc, tokens, ambiguousCommands=None):
|
||||||
|
"""Disambiguates the given tokens based on the plugins loaded and
|
||||||
|
commands available in the given irc. Returns a dictionary of
|
||||||
|
ambiguous commands, mapping the command to the plugins it's
|
||||||
|
available in."""
|
||||||
if ambiguousCommands is None:
|
if ambiguousCommands is None:
|
||||||
ambiguousCommands = {}
|
ambiguousCommands = {}
|
||||||
if tokens:
|
if tokens:
|
||||||
@ -117,9 +121,11 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
for elt in tokens:
|
for elt in tokens:
|
||||||
if isinstance(elt, list):
|
if isinstance(elt, list):
|
||||||
self.disambiguate(irc, elt, ambiguousCommands)
|
self.disambiguate(irc, elt, ambiguousCommands)
|
||||||
|
return ambiguousCommands
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
callbacks.Privmsg.handled = False
|
callbacks.Privmsg.handled = False
|
||||||
|
callbacks.Privmsg.errored = False
|
||||||
if ircdb.checkIgnored(msg.prefix):
|
if ircdb.checkIgnored(msg.prefix):
|
||||||
return
|
return
|
||||||
s = callbacks.addressed(irc.nick, msg)
|
s = callbacks.addressed(irc.nick, msg)
|
||||||
@ -132,6 +138,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
irc.queueMsg(callbacks.error(msg, s))
|
irc.queueMsg(callbacks.error(msg, s))
|
||||||
return
|
return
|
||||||
except SyntaxError, e:
|
except SyntaxError, e:
|
||||||
|
callbacks.Privmsg.errored = True
|
||||||
irc.queueMsg(callbacks.error(msg, str(e)))
|
irc.queueMsg(callbacks.error(msg, str(e)))
|
||||||
return
|
return
|
||||||
ambiguousCommands = {}
|
ambiguousCommands = {}
|
||||||
@ -185,7 +192,12 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
if remove:
|
if remove:
|
||||||
del self.defaultPlugins[command]
|
del self.defaultPlugins[command]
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, self.defaultPlugins[command])
|
L = [command]
|
||||||
|
d = self.disambiguate(irc, L)
|
||||||
|
if d:
|
||||||
|
raise KeyError
|
||||||
|
assert len(L) == 2, 'Not disambiguated!'
|
||||||
|
irc.reply(msg, L[0])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error(msg,'I have no default plugin for that command.')
|
irc.error(msg,'I have no default plugin for that command.')
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user