Added defaultplugin.

This commit is contained in:
Jeremy Fincher 2003-10-30 03:08:52 +00:00
parent f4e4233704
commit 51c5d53259
2 changed files with 43 additions and 13 deletions

View File

@ -85,12 +85,23 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
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)
self.defaultPlugins = {}
def _disambiguate(self, tokens):
if tokens:
command = callbacks.canonicalName(tokens[0])
if command in self.defaultPlugins:
tokens.insert(0, self.defaultPlugins[command])
for elt in tokens:
if isinstance(elt, list):
self._disambiguate(elt)
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
callbacks.Privmsg.handled = False callbacks.Privmsg.handled = False
s = callbacks.addressed(irc.nick, msg) s = callbacks.addressed(irc.nick, msg)
if s: if s:
tokens = callbacks.tokenize(s) tokens = callbacks.tokenize(s)
self._disambiguate(tokens)
ambiguousCommands = {} ambiguousCommands = {}
commands = callbacks.getCommands(tokens) commands = callbacks.getCommands(tokens)
for command in commands: for command in commands:
@ -119,6 +130,29 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
irc.queueMsg(callbacks.error(msg, s)) irc.queueMsg(callbacks.error(msg, s))
else: else:
callbacks.IrcObjectProxy(irc, msg, tokens) callbacks.IrcObjectProxy(irc, msg, tokens)
def defaultplugin(self, irc, msg, args):
"""<command> [<plugin>]
Calls <command> from <plugin> by default, rather than complaining about
multiple plugins providing it. If <plugin> is not provided, remove the
currently used default plugin.
"""
(command, plugin) = privmsgs.getArgs(args, optional=1)
command = callbacks.canonicalName(command)
cbs = callbacks.findCallbackForCommand(irc, command)
if not cbs:
irc.error(msg, 'That\'t not a valid command.')
return
if plugin:
self.defaultPlugins[command] = plugin
else:
try:
del self.defaultPlugins[command]
except KeyError:
irc.error(msg, 'I have no default for that command.')
return
irc.reply(msg, conf.replySuccess)
def eval(self, irc, msg, args): def eval(self, irc, msg, args):
"""<expression> """<expression>
@ -330,18 +364,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
loadPluginClass(irc, module) loadPluginClass(irc, module)
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
'''
def superreload(self, irc, msg, args):
"""<module name>
Reloads a module, hopefully such that all vestiges of the old module
are gone.
"""
name = privmsgs.getArgs(args)
world.superReload(__import__(name))
irc.reply(msg, conf.replySuccess)
'''
def reload(self, irc, msg, args): def reload(self, irc, msg, args):
"""<plugin> """<plugin>

View File

@ -35,7 +35,15 @@ import conf
import Owner import Owner
class OwnerTestCase(PluginTestCase, PluginDocumentation): class OwnerTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Utilities',) plugins = ('Utilities', 'Relay', 'Network')
def testDefaultPlugin(self):
self.assertError('whois osu.edu')
self.assertNotError('defaultplugin whois network')
self.assertNotError('whois osu.edu')
self.assertNotError('defaultplugin whois')
self.assertError('whois osu.edu')
self.assertError('defaultplugin asdlfkjasdflkjsad Owner')
def testEval(self): def testEval(self):
try: try:
originalConfAllowEval = conf.allowEval originalConfAllowEval = conf.allowEval