This commit is contained in:
Jeremy Fincher 2004-10-22 05:35:05 +00:00
parent e817b2379e
commit 6389256dc2
2 changed files with 33 additions and 28 deletions

View File

@ -54,6 +54,7 @@ import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.world as world import supybot.world as world
import supybot.ircdb as ircdb import supybot.ircdb as ircdb
from supybot.commands import *
import supybot.irclib as irclib import supybot.irclib as irclib
import supybot.drivers as drivers import supybot.drivers as drivers
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
@ -200,10 +201,10 @@ class LogProxy(object):
self.im_func = holder() self.im_func = holder()
self.im_func.func_name = 'log' self.im_func.func_name = 'log'
def __call__(self, irc, msg, args): def __call__(self, irc, msg, args, text):
text = privmsgs.getArgs(args)
log.critical(text) log.critical(text)
irc.replySuccess() irc.replySuccess()
__call__ = wrap(__call__, ['text'])
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.log, attr) return getattr(self.log, attr)
@ -379,7 +380,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
'___': None, '___': None,
} }
_evalEnv.update(globals()) _evalEnv.update(globals())
def eval(self, irc, msg, args): def eval(self, irc, msg, args, s):
"""<expression> """<expression>
Evaluates <expression> (which should be a Python expression) and Evaluates <expression> (which should be a Python expression) and
@ -387,7 +388,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
exception (and logs the traceback to the bot's logfile). exception (and logs the traceback to the bot's logfile).
""" """
if conf.allowEval: if conf.allowEval:
s = privmsgs.getArgs(args)
try: try:
self._evalEnv.update(locals()) self._evalEnv.update(locals())
x = eval(s, self._evalEnv, self._evalEnv) x = eval(s, self._evalEnv, self._evalEnv)
@ -407,14 +407,14 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
# loaded. Let's be extra-special-safe. # loaded. Let's be extra-special-safe.
irc.error('You must run Supybot with the --allow-eval ' irc.error('You must run Supybot with the --allow-eval '
'option for this command to be enabled.') 'option for this command to be enabled.')
eval = wrap(eval, ['text'])
def _exec(self, irc, msg, args): def _exec(self, irc, msg, args, s):
"""<statement> """<statement>
Execs <code>. Returns success if it didn't raise any exceptions. Execs <code>. Returns success if it didn't raise any exceptions.
""" """
if conf.allowEval: if conf.allowEval:
s = privmsgs.getArgs(args)
try: try:
exec s exec s
irc.replySuccess() irc.replySuccess()
@ -425,6 +425,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
# loaded. Let's be extra-special-safe. # loaded. Let's be extra-special-safe.
irc.error('You must run Supybot with the --allow-eval ' irc.error('You must run Supybot with the --allow-eval '
'option for this command to be enabled.') 'option for this command to be enabled.')
_exec = wrap(_exec, ['text'])
else: else:
def eval(self, irc, msg, args): def eval(self, irc, msg, args):
"""Run your bot with --allow-eval if you want this to work.""" """Run your bot with --allow-eval if you want this to work."""
@ -432,19 +433,19 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
'this command to be enabled.') 'this command to be enabled.')
_exec = eval _exec = eval
def announce(self, irc, msg, args): def announce(self, irc, msg, args, text):
"""<text> """<text>
Sends <text> to all channels the bot is currently on and not Sends <text> to all channels the bot is currently on and not
lobotomized in. lobotomized in.
""" """
text = privmsgs.getArgs(args)
u = ircdb.users.getUser(msg.prefix) u = ircdb.users.getUser(msg.prefix)
text = 'Announcement from my owner (%s): %s' % (u.name, text) text = 'Announcement from my owner (%s): %s' % (u.name, text)
for channel in irc.state.channels: for channel in irc.state.channels:
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
if not c.lobotomized: if not c.lobotomized:
irc.queueMsg(ircmsgs.privmsg(channel, text)) irc.queueMsg(ircmsgs.privmsg(channel, text))
announce = wrap(announce, ['text'])
def defaultplugin(self, irc, msg, args): def defaultplugin(self, irc, msg, args):
"""[--remove] <command> [<plugin>] """[--remove] <command> [<plugin>]
@ -469,11 +470,13 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
s = 'I don\'t have a default plugin set for that command.' s = 'I don\'t have a default plugin set for that command.'
irc.error(s) irc.error(s)
elif not cbs: elif not cbs:
irc.errorInvalid('command', command, Raise=True) irc.errorInvalid('command', command)
elif plugin: elif plugin:
cb = irc.getCallback(plugin) cb = irc.getCallback(plugin)
if cb is None: if cb is None:
irc.errorInvalid('plugin', plugin, Raise=True) irc.errorInvalid('plugin', plugin)
if not cb.isCommand(command):
irc.errorInvalid('command in the %s plugin' % plugin, command)
registerDefaultPlugin(command, plugin) registerDefaultPlugin(command, plugin)
irc.replySuccess() irc.replySuccess()
else: else:
@ -483,7 +486,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
s = 'I don\'t have a default plugin set for that command.' s = 'I don\'t have a default plugin set for that command.'
irc.error(s) irc.error(s)
def ircquote(self, irc, msg, args): def ircquote(self, irc, msg, args, s):
"""<string to be sent to the server> """<string to be sent to the server>
Sends the raw string given to the server. Sends the raw string given to the server.
@ -495,14 +498,14 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
irc.error(utils.exnToString(e)) irc.error(utils.exnToString(e))
else: else:
irc.queueMsg(m) irc.queueMsg(m)
ircquote = wrap(ircquote, ['text'])
def quit(self, irc, msg, args): def quit(self, irc, msg, args, text):
"""[<text>] """[<text>]
Exits the bot with the QUIT message <text>. If <text> is not given, Exits the bot with the QUIT message <text>. If <text> is not given,
your nick will be substituted. your nick will be substituted.
""" """
text = privmsgs.getArgs(args, required=0, optional=1)
if not text: if not text:
text = msg.nick text = msg.nick
irc.noReply() irc.noReply()
@ -511,6 +514,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
for irc in world.ircs[:]: for irc in world.ircs[:]:
irc.queueMsg(m) irc.queueMsg(m)
irc.die() irc.die()
quit = wrap(quit, [additional('text')])
def flush(self, irc, msg, args): def flush(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -520,8 +524,9 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
""" """
world.flush() world.flush()
irc.replySuccess() irc.replySuccess()
flush = wrap(flush)
def upkeep(self, irc, msg, args): def upkeep(self, irc, msg, args, level):
"""[<level>] """[<level>]
Runs the standard upkeep stuff (flushes and gc.collects()). If given Runs the standard upkeep stuff (flushes and gc.collects()). If given
@ -529,7 +534,6 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
level is "high", which causes the bot to flush a lot of caches as well level is "high", which causes the bot to flush a lot of caches as well
as do normal upkeep stuff. as do normal upkeep stuff.
""" """
level = privmsgs.getArgs(args, required=0, optional=1)
L = [] L = []
if level == 'high': if level == 'high':
L.append('Regexp cache flushed: %s cleared.' % L.append('Regexp cache flushed: %s cleared.' %
@ -560,8 +564,9 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
L.append('Garbage! %r.' % gc.garbage) L.append('Garbage! %r.' % gc.garbage)
L.append('%s collected.' % utils.nItems('object', collected)) L.append('%s collected.' % utils.nItems('object', collected))
irc.reply(' '.join(L)) irc.reply(' '.join(L))
upkeep = wrap(upkeep, [additional(('literal', ['high']))])
def load(self, irc, msg, args): def load(self, irc, msg, args, optlist, name):
"""[--deprecated] <plugin> """[--deprecated] <plugin>
Loads the plugin <plugin> from any of the directories in Loads the plugin <plugin> from any of the directories in
@ -569,12 +574,10 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
installed directory and 'plugins' in the current directory. installed directory and 'plugins' in the current directory.
--deprecated is necessary if you wish to load deprecated plugins. --deprecated is necessary if you wish to load deprecated plugins.
""" """
(optlist, args) = getopt.getopt(args, '', ['deprecated'])
ignoreDeprecation = False ignoreDeprecation = False
for (option, argument) in optlist: for (option, argument) in optlist:
if option == '--deprecated': if option == 'deprecated':
ignoreDeprecation = True ignoreDeprecation = True
name = privmsgs.getArgs(args)
if name.endswith('.py'): if name.endswith('.py'):
name = name[:-3] name = name[:-3]
if irc.getCallback(name): if irc.getCallback(name):
@ -596,14 +599,14 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
name = cb.name() # Let's normalize this. name = cb.name() # Let's normalize this.
conf.registerPlugin(name, True) conf.registerPlugin(name, True)
irc.replySuccess() irc.replySuccess()
load = wrap(load, [getopts({'deprecated': ''}), 'something'])
def reload(self, irc, msg, args): def reload(self, irc, msg, args, name):
"""<plugin> """<plugin>
Unloads and subsequently reloads the plugin by name; use the 'list' Unloads and subsequently reloads the plugin by name; use the 'list'
command to see a list of the currently loaded plugins. command to see a list of the currently loaded plugins.
""" """
name = privmsgs.getArgs(args)
callbacks = irc.removeCallback(name) callbacks = irc.removeCallback(name)
if callbacks: if callbacks:
module = sys.modules[callbacks[0].__module__] module = sys.modules[callbacks[0].__module__]
@ -625,15 +628,15 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
irc.error('No plugin %s exists.' % name) irc.error('No plugin %s exists.' % name)
else: else:
irc.error('There was no plugin %s.' % name) irc.error('There was no plugin %s.' % name)
reload = wrap(reload, ['something'])
def unload(self, irc, msg, args): def unload(self, irc, msg, args, name):
"""<plugin> """<plugin>
Unloads the callback by name; use the 'list' command to see a list Unloads the callback by name; use the 'list' command to see a list
of the currently loaded callbacks. Obviously, the Owner plugin can't of the currently loaded callbacks. Obviously, the Owner plugin can't
be unloaded. be unloaded.
""" """
name = privmsgs.getArgs(args)
if ircutils.strEqual(name, self.name()): if ircutils.strEqual(name, self.name()):
irc.error('You can\'t unload the %s plugin.' % name) irc.error('You can\'t unload the %s plugin.' % name)
return return
@ -649,15 +652,15 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
irc.replySuccess() irc.replySuccess()
else: else:
irc.error('There was no plugin %s.' % name) irc.error('There was no plugin %s.' % name)
unload = wrap(unload, ['something'])
def defaultcapability(self, irc, msg, args): def defaultcapability(self, irc, msg, args, action, capability):
"""{add|remove} <capability> """{add|remove} <capability>
Adds or removes (according to the first argument) <capability> from the Adds or removes (according to the first argument) <capability> from the
default capabilities given to users (the configuration variable default capabilities given to users (the configuration variable
supybot.capabilities stores these). supybot.capabilities stores these).
""" """
(action, capability) = privmsgs.getArgs(args, required=2)
if action == 'add': if action == 'add':
conf.supybot.capabilities().add(capability) conf.supybot.capabilities().add(capability)
irc.replySuccess() irc.replySuccess()
@ -673,9 +676,8 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
anticap = ircdb.makeAntiCapability(capability) anticap = ircdb.makeAntiCapability(capability)
conf.supybot.capabilities().add(anticap) conf.supybot.capabilities().add(anticap)
irc.replySuccess() irc.replySuccess()
else: defaultcapability = wrap(defaultcapability,
irc.errorInvalid('action to take', action, [('literal', ['add','remove']), 'capability'])
'Valid actions include "add" and "remove".')
def disable(self, irc, msg, args): def disable(self, irc, msg, args):
"""[<plugin>] <command> """[<plugin>] <command>

View File

@ -118,6 +118,9 @@ class OwnerTestCase(PluginTestCase, PluginDocumentation):
self.assertRegexp('list admin', 'removecapability') self.assertRegexp('list admin', 'removecapability')
self.assertNotRegexp('list admin', 'rmcap') self.assertNotRegexp('list admin', 'rmcap')
def testDefaultPluginErrorsWhenCommandNotInPlugin(self):
self.assertError('defaultplugin foobar owner')
class FunctionsTestCase(SupyTestCase): class FunctionsTestCase(SupyTestCase):