From 51c5d53259a73445508ddebbe40b7ebafc88620b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 30 Oct 2003 03:08:52 +0000 Subject: [PATCH] Added defaultplugin. --- src/Owner.py | 46 ++++++++++++++++++++++++++++++++++------------ test/test_Owner.py | 10 +++++++++- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/Owner.py b/src/Owner.py index c05b2acea..157b4e399 100644 --- a/src/Owner.py +++ b/src/Owner.py @@ -85,12 +85,23 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): def __init__(self): callbacks.Privmsg.__init__(self) 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): callbacks.Privmsg.handled = False s = callbacks.addressed(irc.nick, msg) if s: tokens = callbacks.tokenize(s) + self._disambiguate(tokens) ambiguousCommands = {} commands = callbacks.getCommands(tokens) for command in commands: @@ -119,6 +130,29 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): irc.queueMsg(callbacks.error(msg, s)) else: callbacks.IrcObjectProxy(irc, msg, tokens) + + def defaultplugin(self, irc, msg, args): + """ [] + + Calls from by default, rather than complaining about + multiple plugins providing it. If 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): """ @@ -330,18 +364,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): loadPluginClass(irc, module) irc.reply(msg, conf.replySuccess) - ''' - def superreload(self, irc, msg, args): - """ - - 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): """ diff --git a/test/test_Owner.py b/test/test_Owner.py index dc1c9eafd..6c8cfce7a 100644 --- a/test/test_Owner.py +++ b/test/test_Owner.py @@ -35,7 +35,15 @@ import conf import Owner 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): try: originalConfAllowEval = conf.allowEval