2003-08-28 18:33:45 +02:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-08-28 18:33:45 +02:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
2003-09-03 11:50:04 +02:00
|
|
|
"""
|
|
|
|
Provides commands useful to the owner of the bot; the commands here require
|
|
|
|
their caller to have the 'owner' capability. This plugin is loaded by default.
|
|
|
|
"""
|
|
|
|
|
2004-09-01 08:06:54 +02:00
|
|
|
import supybot
|
|
|
|
|
2003-11-25 09:38:19 +01:00
|
|
|
__revision__ = "$Id$"
|
2004-09-01 08:06:54 +02:00
|
|
|
__author__ = supybot.authors.jemfinch
|
2003-11-25 09:38:19 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.fix as fix
|
2003-09-12 20:07:04 +02:00
|
|
|
|
2003-08-28 18:33:45 +02:00
|
|
|
import gc
|
2003-10-14 05:34:47 +02:00
|
|
|
import os
|
2003-08-28 18:33:45 +02:00
|
|
|
import imp
|
2004-08-21 09:01:45 +02:00
|
|
|
import sre
|
2003-08-28 18:33:45 +02:00
|
|
|
import sys
|
2004-01-15 15:08:14 +01:00
|
|
|
import getopt
|
2004-08-25 07:08:27 +02:00
|
|
|
import socket
|
2004-03-28 14:11:09 +02:00
|
|
|
import logging
|
2003-08-28 18:33:45 +02:00
|
|
|
import linecache
|
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.log as log
|
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.world as world
|
|
|
|
import supybot.ircdb as ircdb
|
2004-10-22 07:35:05 +02:00
|
|
|
from supybot.commands import *
|
2004-08-23 14:34:16 +02:00
|
|
|
import supybot.irclib as irclib
|
|
|
|
import supybot.drivers as drivers
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.ircmsgs as ircmsgs
|
2004-08-01 21:05:06 +02:00
|
|
|
import supybot.ircutils as ircutils
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.privmsgs as privmsgs
|
|
|
|
import supybot.registry as registry
|
|
|
|
import supybot.callbacks as callbacks
|
2004-09-09 01:34:48 +02:00
|
|
|
import supybot.structures as structures
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-01-15 15:08:14 +01:00
|
|
|
class Deprecated(ImportError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def loadPluginModule(name, ignoreDeprecation=False):
|
2003-10-04 15:24:51 +02:00
|
|
|
"""Loads (and returns) the module for the plugin with the given name."""
|
2003-10-14 05:34:47 +02:00
|
|
|
files = []
|
2004-01-18 08:58:26 +01:00
|
|
|
pluginDirs = conf.supybot.directories.plugins()
|
|
|
|
for dir in pluginDirs:
|
2003-11-22 18:06:23 +01:00
|
|
|
try:
|
|
|
|
files.extend(os.listdir(dir))
|
2004-01-15 15:08:14 +01:00
|
|
|
except EnvironmentError: # OSError, IOError superclass.
|
2004-10-26 00:59:03 +02:00
|
|
|
log.warning('Invalid plugin directory: %s; removing.',
|
|
|
|
utils.quoted(dir))
|
2004-07-28 04:58:10 +02:00
|
|
|
conf.supybot.directories.plugins().remove(dir)
|
2003-10-14 05:34:47 +02:00
|
|
|
loweredFiles = map(str.lower, files)
|
|
|
|
try:
|
2003-11-15 05:37:04 +01:00
|
|
|
index = loweredFiles.index(name.lower()+'.py')
|
2003-10-14 05:34:47 +02:00
|
|
|
name = os.path.splitext(files[index])[0]
|
2004-02-04 19:01:00 +01:00
|
|
|
if name in sys.modules:
|
|
|
|
m = sys.modules[name]
|
|
|
|
if not hasattr(m, 'Class'):
|
|
|
|
raise ImportError, 'Module is not a plugin.'
|
2003-10-14 05:34:47 +02:00
|
|
|
except ValueError: # We'd rather raise the ImportError, so we'll let go...
|
|
|
|
pass
|
2004-01-18 08:58:26 +01:00
|
|
|
moduleInfo = imp.find_module(name, pluginDirs)
|
2004-02-06 10:19:21 +01:00
|
|
|
try:
|
|
|
|
module = imp.load_module(name, *moduleInfo)
|
|
|
|
except:
|
2004-02-16 17:16:13 +01:00
|
|
|
if name in sys.modules:
|
|
|
|
del sys.modules[name]
|
2004-02-06 10:19:21 +01:00
|
|
|
raise
|
2004-01-15 15:08:14 +01:00
|
|
|
if 'deprecated' in module.__dict__ and module.deprecated:
|
|
|
|
if ignoreDeprecation:
|
|
|
|
log.warning('Deprecated plugin loaded: %s', name)
|
|
|
|
else:
|
2004-10-26 00:59:03 +02:00
|
|
|
raise Deprecated, 'Attempted to load deprecated plugin %s' % \
|
2004-10-28 19:09:03 +02:00
|
|
|
utils.quoted(name)
|
2003-12-09 22:33:13 +01:00
|
|
|
if module.__name__ in sys.modules:
|
|
|
|
sys.modules[module.__name__] = module
|
2003-09-18 07:47:42 +02:00
|
|
|
linecache.checkcache()
|
|
|
|
return module
|
|
|
|
|
2004-04-28 10:42:01 +02:00
|
|
|
def loadPluginClass(irc, module, register=None):
|
2004-08-19 15:33:34 +02:00
|
|
|
"""Loads the plugin Class from the given module into the given Irc."""
|
2004-08-02 01:19:59 +02:00
|
|
|
try:
|
|
|
|
cb = module.Class()
|
2004-09-07 21:14:57 +02:00
|
|
|
except AttributeError, e:
|
2004-10-26 23:12:49 +02:00
|
|
|
if 'Class' in str(e):
|
|
|
|
raise callbacks.Error, \
|
|
|
|
'This plugin module doesn\'t have a "Class" ' \
|
|
|
|
'attribute to specify which plugin should be ' \
|
|
|
|
'instantiated. If you didn\'t write this ' \
|
|
|
|
'plugin, but received it with Supybot, file ' \
|
|
|
|
'a bug with us about this error.'
|
|
|
|
else:
|
|
|
|
raise
|
2004-09-22 23:38:20 +02:00
|
|
|
plugin = cb.name()
|
2004-04-28 10:42:01 +02:00
|
|
|
public = True
|
|
|
|
if hasattr(cb, 'public'):
|
|
|
|
public = cb.public
|
2004-09-22 23:38:20 +02:00
|
|
|
conf.registerPlugin(plugin, register, public)
|
|
|
|
assert not irc.getCallback(plugin)
|
2004-09-11 18:16:16 +02:00
|
|
|
try:
|
2004-09-22 23:38:20 +02:00
|
|
|
renames = registerRename(plugin)()
|
|
|
|
if renames:
|
|
|
|
for command in renames:
|
|
|
|
v = registerRename(plugin, command)
|
|
|
|
newName = v()
|
|
|
|
assert newName
|
|
|
|
renameCommand(cb, command, newName)
|
|
|
|
else:
|
|
|
|
conf.supybot.commands.renames.unregister(plugin)
|
2004-09-11 18:16:16 +02:00
|
|
|
except registry.NonExistentRegistryEntry, e:
|
|
|
|
pass # The plugin isn't there.
|
2004-04-28 10:42:01 +02:00
|
|
|
irc.addCallback(cb)
|
|
|
|
return cb
|
|
|
|
|
|
|
|
conf.registerPlugin('Owner', True)
|
|
|
|
conf.supybot.plugins.Owner.register('public', registry.Boolean(True,
|
2004-08-19 01:15:27 +02:00
|
|
|
"""Determines whether this plugin is publicly visible."""))
|
2004-07-29 11:46:22 +02:00
|
|
|
|
|
|
|
###
|
|
|
|
# supybot.commands.
|
|
|
|
###
|
2004-08-11 14:57:52 +02:00
|
|
|
|
2004-09-11 18:16:16 +02:00
|
|
|
conf.registerGroup(conf.supybot.commands, 'renames', orderAlphabetically=True)
|
2003-09-18 07:47:42 +02:00
|
|
|
|
2004-02-08 00:22:47 +01:00
|
|
|
def registerDefaultPlugin(command, plugin):
|
|
|
|
command = callbacks.canonicalName(command)
|
|
|
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
|
|
|
command, registry.String(plugin, ''))
|
2004-04-29 13:38:02 +02:00
|
|
|
# This must be set, or the quotes won't be removed.
|
|
|
|
conf.supybot.commands.defaultPlugins.get(command).set(plugin)
|
2004-02-08 00:22:47 +01:00
|
|
|
|
2004-09-22 23:38:20 +02:00
|
|
|
def registerRename(plugin, command=None, newName=None):
|
|
|
|
g = conf.registerGlobalValue(conf.supybot.commands.renames, plugin,
|
|
|
|
registry.SpaceSeparatedSetOfStrings([], """Determines what commands
|
|
|
|
in this plugin are to be renamed."""))
|
|
|
|
if command is not None:
|
|
|
|
g().add(command)
|
|
|
|
v = conf.registerGlobalValue(g, command, registry.String('', ''))
|
|
|
|
if newName is not None:
|
|
|
|
v.setValue(newName) # In case it was already registered.
|
|
|
|
return v
|
|
|
|
else:
|
|
|
|
return g
|
2004-09-11 18:16:16 +02:00
|
|
|
|
|
|
|
def renameCommand(cb, name, newName):
|
|
|
|
assert not hasattr(cb, newName), 'Cannot rename over existing attributes.'
|
|
|
|
assert newName == callbacks.canonicalName(newName), \
|
|
|
|
'newName must already be canonicalized.'
|
|
|
|
if name != newName:
|
|
|
|
method = getattr(cb.__class__, name)
|
|
|
|
setattr(cb.__class__, newName, method)
|
|
|
|
delattr(cb.__class__, name)
|
2004-10-26 00:59:03 +02:00
|
|
|
|
|
|
|
|
2004-02-08 00:22:47 +01:00
|
|
|
registerDefaultPlugin('list', 'Misc')
|
|
|
|
registerDefaultPlugin('help', 'Misc')
|
2004-09-11 18:16:16 +02:00
|
|
|
registerDefaultPlugin('ignore', 'Admin')
|
2004-02-08 00:22:47 +01:00
|
|
|
registerDefaultPlugin('reload', 'Owner')
|
2004-11-06 20:01:05 +01:00
|
|
|
registerDefaultPlugin('enable', 'Owner')
|
|
|
|
registerDefaultPlugin('disable', 'Owner')
|
2004-09-11 18:16:16 +02:00
|
|
|
registerDefaultPlugin('unignore', 'Admin')
|
2004-02-08 00:22:47 +01:00
|
|
|
registerDefaultPlugin('capabilities', 'User')
|
2004-09-11 18:16:16 +02:00
|
|
|
registerDefaultPlugin('addcapability', 'Admin')
|
|
|
|
registerDefaultPlugin('removecapability', 'Admin')
|
2004-02-07 12:48:03 +01:00
|
|
|
|
|
|
|
class holder(object):
|
|
|
|
pass
|
|
|
|
|
2004-03-28 14:11:09 +02:00
|
|
|
# This is used so we can support a "log" command as well as a "self.log"
|
|
|
|
# Logger.
|
2004-02-07 12:48:03 +01:00
|
|
|
class LogProxy(object):
|
|
|
|
"""<text>
|
|
|
|
|
2004-08-19 15:33:34 +02:00
|
|
|
Logs <text> to the global Supybot log at critical priority. Useful for
|
2004-02-07 12:48:03 +01:00
|
|
|
marking logfiles for later searching.
|
|
|
|
"""
|
2004-04-20 12:59:20 +02:00
|
|
|
__name__ = 'log' # Necessary for help.
|
2004-02-07 12:48:03 +01:00
|
|
|
def __init__(self, log):
|
|
|
|
self.log = log
|
|
|
|
self.im_func = holder()
|
|
|
|
self.im_func.func_name = 'log'
|
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def __call__(self, irc, msg, args, text):
|
2004-02-07 12:48:03 +01:00
|
|
|
log.critical(text)
|
|
|
|
irc.replySuccess()
|
2004-10-22 07:35:05 +02:00
|
|
|
__call__ = wrap(__call__, ['text'])
|
2004-02-07 12:48:03 +01:00
|
|
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
return getattr(self.log, attr)
|
|
|
|
|
2004-10-27 02:50:41 +02:00
|
|
|
conf.registerPlugin('Owner')
|
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Owner, 'quitMsg',
|
|
|
|
registry.String('', """Determines what quit message will be used by default.
|
|
|
|
If the quit command is called without a quit message, this will be used. If
|
|
|
|
this value is empty, the nick of the person giving the quit command will be
|
|
|
|
used."""))
|
|
|
|
|
2003-10-21 08:03:57 +02:00
|
|
|
class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
2003-10-21 23:01:43 +02:00
|
|
|
# This plugin must be first; its priority must be lowest; otherwise odd
|
|
|
|
# things will happen when adding callbacks.
|
2003-08-28 18:33:45 +02:00
|
|
|
capability = 'owner'
|
2004-08-01 21:05:06 +02:00
|
|
|
_srcPlugins = ircutils.IrcSet(('Admin', 'Channel', 'Config',
|
|
|
|
'Misc', 'Owner', 'User'))
|
2004-09-09 01:34:48 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.__parent = super(Owner, self)
|
|
|
|
self.__parent.__init__()
|
2004-08-23 14:34:16 +02:00
|
|
|
# Setup log object/command.
|
2004-02-07 12:48:03 +01:00
|
|
|
self.log = LogProxy(self.log)
|
2004-09-09 01:34:48 +02:00
|
|
|
# Setup command flood detection.
|
|
|
|
self.commands = ircutils.FloodQueue(60)
|
2004-08-23 14:34:16 +02:00
|
|
|
# Setup exec command.
|
2004-01-20 17:16:25 +01:00
|
|
|
setattr(self.__class__, 'exec', self.__class__._exec)
|
2004-08-23 14:34:16 +02:00
|
|
|
# Setup Irc objects, connected to networks. If world.ircs is already
|
|
|
|
# populated, chances are that we're being reloaded, so don't do this.
|
|
|
|
if not world.ircs:
|
|
|
|
for network in conf.supybot.networks():
|
|
|
|
try:
|
|
|
|
self._connect(network)
|
2004-08-25 07:08:27 +02:00
|
|
|
except socket.error, e:
|
|
|
|
self.log.error('Could not connect to %s: %s.', network, e)
|
2004-08-23 14:34:16 +02:00
|
|
|
except Exception, e:
|
2004-08-25 07:08:27 +02:00
|
|
|
self.log.exception('Exception connecting to %s:', network)
|
2004-08-23 14:34:16 +02:00
|
|
|
self.log.error('Could not connect to %s: %s.', network, e)
|
|
|
|
# Setup plugins and default plugins for commands.
|
2004-01-20 13:09:54 +01:00
|
|
|
for (name, s) in registry._cache.iteritems():
|
2004-10-22 22:14:43 +02:00
|
|
|
if 'alwaysLoadDefault' in name or 'alwaysLoadImportant' in name:
|
|
|
|
continue
|
2004-01-18 08:58:26 +01:00
|
|
|
if name.startswith('supybot.plugins'):
|
|
|
|
try:
|
2004-07-24 23:40:47 +02:00
|
|
|
(_, _, name) = registry.split(name)
|
2004-02-08 10:58:45 +01:00
|
|
|
except ValueError: # unpack list of wrong size.
|
2004-01-18 08:58:26 +01:00
|
|
|
continue
|
2004-08-23 14:34:16 +02:00
|
|
|
# This is just for the prettiness of the configuration file.
|
|
|
|
# There are no plugins that are all-lowercase, so we'll at
|
|
|
|
# least attempt to capitalize them.
|
|
|
|
if name == name.lower():
|
2004-10-26 00:59:03 +02:00
|
|
|
name = name.capitalize()
|
2004-01-19 23:38:09 +01:00
|
|
|
conf.registerPlugin(name)
|
2004-02-08 10:58:45 +01:00
|
|
|
if name.startswith('supybot.commands.defaultPlugins'):
|
|
|
|
try:
|
2004-07-24 23:40:47 +02:00
|
|
|
(_, _, _, name) = registry.split(name)
|
2004-02-08 10:58:45 +01:00
|
|
|
except ValueError: # unpack list of wrong size.
|
|
|
|
continue
|
|
|
|
registerDefaultPlugin(name, s)
|
2004-01-18 08:58:26 +01:00
|
|
|
|
2004-09-16 12:28:59 +02:00
|
|
|
def callPrecedence(self, irc):
|
|
|
|
return ([], [cb for cb in irc.callbacks if cb is not self])
|
|
|
|
|
2004-08-22 09:07:47 +02:00
|
|
|
def outFilter(self, irc, msg):
|
|
|
|
if msg.command == 'PRIVMSG' and not world.testing:
|
|
|
|
if ircutils.strEqual(msg.args[0], irc.nick):
|
|
|
|
self.log.warning('Tried to send a message to myself: %r.', msg)
|
|
|
|
return None
|
2004-08-21 22:34:29 +02:00
|
|
|
return msg
|
2004-10-26 00:59:03 +02:00
|
|
|
|
2004-09-09 01:34:48 +02:00
|
|
|
def isCommand(self, name):
|
|
|
|
return name == 'log' or \
|
|
|
|
self.__parent.isCommand(name)
|
2004-02-07 12:48:03 +01:00
|
|
|
|
2004-02-13 08:24:30 +01:00
|
|
|
def reset(self):
|
|
|
|
# This has to be done somewhere, I figure here is as good place as any.
|
|
|
|
callbacks.Privmsg._mores.clear()
|
2004-09-09 01:34:48 +02:00
|
|
|
self.__parent.reset()
|
2004-02-13 08:24:30 +01:00
|
|
|
|
2004-09-12 07:46:18 +02:00
|
|
|
def _connect(self, network, serverPort=None):
|
|
|
|
try:
|
|
|
|
group = conf.supybot.networks.get(network)
|
|
|
|
(server, port) = group.servers()[0]
|
|
|
|
except (registry.NonExistentRegistryEntry, IndexError):
|
|
|
|
if serverPort is None:
|
|
|
|
raise ValueError, 'connect requires a (server, port) ' \
|
|
|
|
'if the network is not registered.'
|
|
|
|
conf.registerNetwork(network)
|
|
|
|
serverS = '%s:%s' % serverPort
|
|
|
|
conf.supybot.networks.get(network).servers.append(serverS)
|
|
|
|
assert conf.supybot.networks.get(network).servers()
|
|
|
|
self.log.info('Creating new Irc for %s.', network)
|
|
|
|
newIrc = irclib.Irc(network)
|
|
|
|
for irc in world.ircs:
|
|
|
|
if irc != newIrc:
|
|
|
|
newIrc.state.history = irc.state.history
|
|
|
|
driver = drivers.newDriver(newIrc)
|
|
|
|
return newIrc
|
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
def do001(self, irc, msg):
|
2004-11-04 08:15:02 +01:00
|
|
|
self.log.info('Loading plugins (connected to %s).', irc.network)
|
2004-10-20 17:08:04 +02:00
|
|
|
alwaysLoadSrcPlugins = conf.supybot.plugins.alwaysLoadImportant()
|
2004-01-27 12:29:54 +01:00
|
|
|
for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
|
2004-02-04 06:56:51 +01:00
|
|
|
if irc.getCallback(name) is None:
|
2004-08-22 08:41:22 +02:00
|
|
|
load = value()
|
2004-10-22 22:14:43 +02:00
|
|
|
# XXX This (_srcPlugins) should be changed to the configurable
|
|
|
|
# importantPlugins.
|
2004-08-22 08:41:22 +02:00
|
|
|
if not load and name in self._srcPlugins:
|
|
|
|
if alwaysLoadSrcPlugins:
|
|
|
|
s = '%s is configured not to be loaded, but is being '\
|
|
|
|
'loaded anyway because ' \
|
2004-10-20 17:08:04 +02:00
|
|
|
'supybot.plugins.alwaysLoadImportant is True.'
|
2004-08-22 08:41:22 +02:00
|
|
|
self.log.warning(s, name)
|
|
|
|
load = True
|
|
|
|
if load:
|
2004-02-04 06:56:51 +01:00
|
|
|
if not irc.getCallback(name):
|
2004-08-17 17:36:42 +02:00
|
|
|
# This is debug because each log logs its beginning.
|
|
|
|
self.log.debug('Loading %s.' % name)
|
2004-02-04 06:56:51 +01:00
|
|
|
try:
|
2004-10-28 19:09:03 +02:00
|
|
|
m = loadPluginModule(name, ignoreDeprecation=True)
|
2004-02-04 06:56:51 +01:00
|
|
|
loadPluginClass(irc, m)
|
2004-08-24 00:15:54 +02:00
|
|
|
except callbacks.Error, e:
|
|
|
|
# This is just an error message.
|
|
|
|
log.warning(str(e))
|
2004-04-01 13:47:02 +02:00
|
|
|
except ImportError, e:
|
2004-10-24 07:43:02 +02:00
|
|
|
log.warning('Failed to load %s: %s.', name, e)
|
2004-08-01 21:05:06 +02:00
|
|
|
if name in self._srcPlugins:
|
|
|
|
self.log.exception('Error loading %s:', name)
|
|
|
|
self.log.error('Error loading src/ plugin %s. '
|
|
|
|
'This is usually rather '
|
|
|
|
'serious; these plugins are '
|
2004-08-11 15:51:15 +02:00
|
|
|
'almost always be loaded.',name)
|
2004-02-04 06:56:51 +01:00
|
|
|
except Exception, e:
|
2004-02-12 01:49:41 +01:00
|
|
|
log.exception('Failed to load %s:', name)
|
2004-02-04 06:56:51 +01:00
|
|
|
else:
|
|
|
|
# Let's import the module so configuration is preserved.
|
2004-02-12 01:49:41 +01:00
|
|
|
try:
|
|
|
|
_ = loadPluginModule(name)
|
|
|
|
except Exception, e:
|
2004-10-27 09:29:30 +02:00
|
|
|
log.debug('Attempted to load %s to preserve its '
|
|
|
|
'configuration, but load failed: %s',
|
|
|
|
name, e)
|
2004-02-12 01:49:41 +01:00
|
|
|
world.starting = False
|
2003-10-30 04:08:52 +01:00
|
|
|
|
2004-08-01 21:05:06 +02:00
|
|
|
def do376(self, irc, msg):
|
2004-12-07 01:29:20 +01:00
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
|
|
|
for channel in networkGroup.channels():
|
|
|
|
irc.queueMsg(networkGroup.channels.join(channel))
|
2004-08-01 21:05:06 +02:00
|
|
|
do422 = do377 = do376
|
|
|
|
|
2003-10-21 23:01:43 +02:00
|
|
|
def doPrivmsg(self, irc, msg):
|
2004-09-16 12:28:59 +02:00
|
|
|
assert self is irc.callbacks[0], 'Owner isn\'t first callback.'
|
|
|
|
if ircmsgs.isCtcp(msg):
|
|
|
|
return
|
2003-10-28 01:22:15 +01:00
|
|
|
s = callbacks.addressed(irc.nick, msg)
|
|
|
|
if s:
|
2004-09-16 12:28:59 +02:00
|
|
|
ignored = ircdb.checkIgnored(msg.prefix)
|
2004-09-10 08:30:21 +02:00
|
|
|
if ignored:
|
|
|
|
self.log.info('Ignoring command from %s.' % msg.prefix)
|
|
|
|
return
|
2003-10-31 19:18:04 +01:00
|
|
|
try:
|
2004-09-24 01:15:27 +02:00
|
|
|
tokens = callbacks.tokenize(s, channel=msg.args[0])
|
|
|
|
self.Proxy(irc, msg, tokens)
|
2003-10-31 19:18:04 +01:00
|
|
|
except SyntaxError, e:
|
|
|
|
irc.queueMsg(callbacks.error(msg, str(e)))
|
2003-10-30 04:08:52 +01:00
|
|
|
|
2004-01-18 20:35:36 +01:00
|
|
|
if conf.allowEval:
|
2004-08-20 07:30:37 +02:00
|
|
|
_evalEnv = {'_': None,
|
|
|
|
'__': None,
|
|
|
|
'___': None,
|
|
|
|
}
|
|
|
|
_evalEnv.update(globals())
|
2004-10-22 07:35:05 +02:00
|
|
|
def eval(self, irc, msg, args, s):
|
2004-01-18 20:35:36 +01:00
|
|
|
"""<expression>
|
2003-09-02 21:55:53 +02:00
|
|
|
|
2004-04-15 08:22:01 +02:00
|
|
|
Evaluates <expression> (which should be a Python expression) and
|
|
|
|
returns its value. If an exception is raised, reports the
|
2004-10-10 05:17:18 +02:00
|
|
|
exception (and logs the traceback to the bot's logfile).
|
2004-01-18 20:35:36 +01:00
|
|
|
"""
|
|
|
|
if conf.allowEval:
|
|
|
|
try:
|
2004-08-20 07:30:37 +02:00
|
|
|
self._evalEnv.update(locals())
|
|
|
|
x = eval(s, self._evalEnv, self._evalEnv)
|
|
|
|
self._evalEnv['___'] = self._evalEnv['__']
|
|
|
|
self._evalEnv['__'] = self._evalEnv['_']
|
|
|
|
self._evalEnv['_'] = x
|
|
|
|
irc.reply(repr(x))
|
2004-01-18 20:35:36 +01:00
|
|
|
except SyntaxError, e:
|
2004-10-26 00:59:03 +02:00
|
|
|
irc.reply('%s: %s' % (utils.exnToString(e),
|
|
|
|
utils.quoted(s)))
|
2004-01-18 20:35:36 +01:00
|
|
|
except Exception, e:
|
2004-12-01 05:42:52 +01:00
|
|
|
self.log.exception('Uncaught exception in Owner.eval.\n'
|
2004-10-10 05:17:18 +02:00
|
|
|
'This is not a bug. Please do not '
|
|
|
|
'report it.')
|
2004-10-10 05:48:33 +02:00
|
|
|
irc.reply(utils.exnToString(e))
|
2004-01-18 20:35:36 +01:00
|
|
|
else:
|
2004-09-09 01:34:48 +02:00
|
|
|
# There's a potential that allowEval got changed after we were
|
|
|
|
# loaded. Let's be extra-special-safe.
|
2004-08-19 15:33:34 +02:00
|
|
|
irc.error('You must run Supybot with the --allow-eval '
|
2004-02-05 08:53:00 +01:00
|
|
|
'option for this command to be enabled.')
|
2004-10-22 07:35:05 +02:00
|
|
|
eval = wrap(eval, ['text'])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def _exec(self, irc, msg, args, s):
|
2004-01-18 20:35:36 +01:00
|
|
|
"""<statement>
|
2003-09-02 21:55:53 +02:00
|
|
|
|
2004-01-18 20:35:36 +01:00
|
|
|
Execs <code>. Returns success if it didn't raise any exceptions.
|
|
|
|
"""
|
|
|
|
if conf.allowEval:
|
|
|
|
try:
|
|
|
|
exec s
|
|
|
|
irc.replySuccess()
|
|
|
|
except Exception, e:
|
|
|
|
irc.reply(utils.exnToString(e))
|
|
|
|
else:
|
2004-09-09 01:34:48 +02:00
|
|
|
# There's a potential that allowEval got changed after we were
|
|
|
|
# loaded. Let's be extra-special-safe.
|
2004-08-19 15:33:34 +02:00
|
|
|
irc.error('You must run Supybot with the --allow-eval '
|
2004-02-05 08:53:00 +01:00
|
|
|
'option for this command to be enabled.')
|
2004-10-22 07:35:05 +02:00
|
|
|
_exec = wrap(_exec, ['text'])
|
2004-01-20 17:16:25 +01:00
|
|
|
else:
|
|
|
|
def eval(self, irc, msg, args):
|
2004-02-05 08:53:00 +01:00
|
|
|
"""Run your bot with --allow-eval if you want this to work."""
|
|
|
|
irc.error('You must give your bot the --allow-eval option for '
|
2004-01-20 17:16:25 +01:00
|
|
|
'this command to be enabled.')
|
|
|
|
_exec = eval
|
2004-06-18 22:18:14 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def announce(self, irc, msg, args, text):
|
2004-04-18 02:38:20 +02:00
|
|
|
"""<text>
|
|
|
|
|
|
|
|
Sends <text> to all channels the bot is currently on and not
|
|
|
|
lobotomized in.
|
|
|
|
"""
|
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
|
|
|
text = 'Announcement from my owner (%s): %s' % (u.name, text)
|
|
|
|
for channel in irc.state.channels:
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
if not c.lobotomized:
|
|
|
|
irc.queueMsg(ircmsgs.privmsg(channel, text))
|
2004-10-22 07:35:05 +02:00
|
|
|
announce = wrap(announce, ['text'])
|
2004-06-18 22:18:14 +02:00
|
|
|
|
2004-12-01 05:42:52 +01:00
|
|
|
def defaultplugin(self, irc, msg, args, optlist, command, plugin):
|
2004-02-08 00:22:47 +01:00
|
|
|
"""[--remove] <command> [<plugin>]
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-02-08 00:22:47 +01:00
|
|
|
Sets the default plugin for <command> to <plugin>. If --remove is
|
|
|
|
given, removes the current default plugin for <command>. If no plugin
|
|
|
|
is given, returns the current default plugin set for <command>.
|
|
|
|
"""
|
|
|
|
remove = False
|
|
|
|
for (option, arg) in optlist:
|
2004-12-01 05:42:52 +01:00
|
|
|
if option == 'remove':
|
2004-02-08 00:22:47 +01:00
|
|
|
remove = True
|
|
|
|
cbs = callbacks.findCallbackForCommand(irc, command)
|
|
|
|
if remove:
|
2004-06-18 22:18:14 +02:00
|
|
|
try:
|
|
|
|
conf.supybot.commands.defaultPlugins.unregister(command)
|
|
|
|
irc.replySuccess()
|
|
|
|
except registry.NonExistentRegistryEntry:
|
2004-07-31 08:15:19 +02:00
|
|
|
s = 'I don\'t have a default plugin set for that command.'
|
|
|
|
irc.error(s)
|
2004-02-08 00:22:47 +01:00
|
|
|
elif not cbs:
|
2004-10-22 07:35:05 +02:00
|
|
|
irc.errorInvalid('command', command)
|
2004-02-08 00:22:47 +01:00
|
|
|
elif plugin:
|
2004-12-01 05:42:52 +01:00
|
|
|
if not plugin.isCommand(command):
|
2004-10-22 07:35:05 +02:00
|
|
|
irc.errorInvalid('command in the %s plugin' % plugin, command)
|
2004-12-01 05:42:52 +01:00
|
|
|
registerDefaultPlugin(command, plugin.name())
|
2004-02-08 00:22:47 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
else:
|
2004-04-28 12:31:15 +02:00
|
|
|
try:
|
|
|
|
irc.reply(conf.supybot.commands.defaultPlugins.get(command)())
|
|
|
|
except registry.NonExistentRegistryEntry:
|
|
|
|
s = 'I don\'t have a default plugin set for that command.'
|
|
|
|
irc.error(s)
|
2004-12-01 05:42:52 +01:00
|
|
|
defaultplugin = wrap(defaultplugin, [getopts({'remove': ''}),
|
|
|
|
'commandName',
|
|
|
|
additional('plugin')])
|
2004-04-19 07:06:36 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def ircquote(self, irc, msg, args, s):
|
2003-08-28 18:33:45 +02:00
|
|
|
"""<string to be sent to the server>
|
|
|
|
|
|
|
|
Sends the raw string given to the server.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
m = ircmsgs.IrcMsg(s)
|
2003-11-26 19:21:12 +01:00
|
|
|
except Exception, e:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(utils.exnToString(e))
|
2003-11-26 19:21:12 +01:00
|
|
|
else:
|
2003-08-28 18:33:45 +02:00
|
|
|
irc.queueMsg(m)
|
2004-10-22 07:35:05 +02:00
|
|
|
ircquote = wrap(ircquote, ['text'])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def quit(self, irc, msg, args, text):
|
2004-08-19 22:32:07 +02:00
|
|
|
"""[<text>]
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-08-19 22:32:07 +02:00
|
|
|
Exits the bot with the QUIT message <text>. If <text> is not given,
|
2004-10-27 02:50:41 +02:00
|
|
|
the default quit message (supybot.plugins.Owner.quitMsg) will be used.
|
|
|
|
If there is no default quitMsg set, your nick will be used.
|
2003-08-28 18:33:45 +02:00
|
|
|
"""
|
2004-12-07 07:44:34 +01:00
|
|
|
text = text or self.registryValue('quitMsg') or msg.nick
|
2004-10-01 00:48:54 +02:00
|
|
|
irc.noReply()
|
2004-08-19 22:32:07 +02:00
|
|
|
m = ircmsgs.quit(text)
|
2004-08-05 08:01:35 +02:00
|
|
|
world.upkeep()
|
2004-08-29 09:29:43 +02:00
|
|
|
for irc in world.ircs[:]:
|
2004-08-19 22:32:07 +02:00
|
|
|
irc.queueMsg(m)
|
|
|
|
irc.die()
|
2004-10-22 07:35:05 +02:00
|
|
|
quit = wrap(quit, [additional('text')])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
|
|
|
def flush(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
2004-03-28 14:11:09 +02:00
|
|
|
Runs all the periodic flushers in world.flushers. This includes
|
|
|
|
flushing all logs and all configuration changes to disk.
|
2003-08-28 18:33:45 +02:00
|
|
|
"""
|
|
|
|
world.flush()
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2004-10-22 07:35:05 +02:00
|
|
|
flush = wrap(flush)
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def upkeep(self, irc, msg, args, level):
|
2004-08-21 09:01:45 +02:00
|
|
|
"""[<level>]
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-08-21 09:01:45 +02:00
|
|
|
Runs the standard upkeep stuff (flushes and gc.collects()). If given
|
|
|
|
a level, runs that level of upkeep (currently, the only supported
|
|
|
|
level is "high", which causes the bot to flush a lot of caches as well
|
|
|
|
as do normal upkeep stuff.
|
2003-08-28 18:33:45 +02:00
|
|
|
"""
|
2004-08-21 09:01:45 +02:00
|
|
|
L = []
|
|
|
|
if level == 'high':
|
|
|
|
L.append('Regexp cache flushed: %s cleared.' %
|
|
|
|
utils.nItems('regexp', len(sre._cache)))
|
|
|
|
sre.purge()
|
|
|
|
L.append('Pattern cache flushed: %s cleared.' %
|
|
|
|
utils.nItems('compiled pattern',
|
|
|
|
len(ircutils._patternCache)))
|
|
|
|
ircutils._patternCache.clear()
|
|
|
|
L.append('hostmaskPatternEqual cache flushed: %s cleared.' %
|
2004-08-21 10:53:29 +02:00
|
|
|
utils.nItems('result',
|
2004-08-21 09:01:45 +02:00
|
|
|
len(ircutils._hostmaskPatternEqualCache)))
|
|
|
|
ircutils._hostmaskPatternEqualCache.clear()
|
|
|
|
L.append('ircdb username cache flushed: %s cleared.' %
|
|
|
|
utils.nItems('username to id mapping',
|
|
|
|
len(ircdb.users._nameCache)))
|
|
|
|
ircdb.users._nameCache.clear()
|
|
|
|
L.append('ircdb hostmask cache flushed: %s cleared.' %
|
|
|
|
utils.nItems('hostmask to id mapping',
|
|
|
|
len(ircdb.users._hostmaskCache)))
|
|
|
|
ircdb.users._hostmaskCache.clear()
|
|
|
|
L.append('linecache line cache flushed: %s cleared.' %
|
|
|
|
utils.nItems('line', len(linecache.cache)))
|
|
|
|
linecache.clearcache()
|
|
|
|
sys.exc_clear()
|
2004-09-09 01:34:48 +02:00
|
|
|
collected = world.upkeep()
|
2003-08-28 18:33:45 +02:00
|
|
|
if gc.garbage:
|
2004-08-21 09:01:45 +02:00
|
|
|
L.append('Garbage! %r.' % gc.garbage)
|
|
|
|
L.append('%s collected.' % utils.nItems('object', collected))
|
|
|
|
irc.reply(' '.join(L))
|
2004-10-22 07:35:05 +02:00
|
|
|
upkeep = wrap(upkeep, [additional(('literal', ['high']))])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def load(self, irc, msg, args, optlist, name):
|
2004-01-15 15:08:14 +01:00
|
|
|
"""[--deprecated] <plugin>
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2003-10-14 05:06:47 +02:00
|
|
|
Loads the plugin <plugin> from any of the directories in
|
2004-01-18 08:58:26 +01:00
|
|
|
conf.supybot.directories.plugins; usually this includes the main
|
|
|
|
installed directory and 'plugins' in the current directory.
|
|
|
|
--deprecated is necessary if you wish to load deprecated plugins.
|
2003-08-28 18:33:45 +02:00
|
|
|
"""
|
2004-01-15 15:08:14 +01:00
|
|
|
ignoreDeprecation = False
|
|
|
|
for (option, argument) in optlist:
|
2004-10-22 07:35:05 +02:00
|
|
|
if option == 'deprecated':
|
2004-01-15 15:08:14 +01:00
|
|
|
ignoreDeprecation = True
|
|
|
|
if name.endswith('.py'):
|
|
|
|
name = name[:-3]
|
2003-10-24 11:03:34 +02:00
|
|
|
if irc.getCallback(name):
|
2004-09-10 08:30:21 +02:00
|
|
|
irc.error('%s is already loaded.' % name.capitalize())
|
2003-10-24 11:03:34 +02:00
|
|
|
return
|
2003-08-28 18:33:45 +02:00
|
|
|
try:
|
2004-01-15 15:08:14 +01:00
|
|
|
module = loadPluginModule(name, ignoreDeprecation)
|
|
|
|
except Deprecated:
|
2004-09-10 08:30:21 +02:00
|
|
|
irc.error('%s is deprecated. Use --deprecated '
|
|
|
|
'to force it to load.' % name.capitalize())
|
2004-01-15 15:08:14 +01:00
|
|
|
return
|
2003-10-04 00:28:05 +02:00
|
|
|
except ImportError, e:
|
|
|
|
if name in str(e):
|
2004-09-10 08:30:21 +02:00
|
|
|
irc.error('No plugin named %s exists.' % utils.dqrepr(name))
|
2003-10-04 00:28:05 +02:00
|
|
|
else:
|
2004-02-04 19:01:00 +01:00
|
|
|
irc.error(str(e))
|
2003-08-28 18:33:45 +02:00
|
|
|
return
|
2004-04-30 20:24:35 +02:00
|
|
|
cb = loadPluginClass(irc, module)
|
|
|
|
name = cb.name() # Let's normalize this.
|
2004-01-19 23:38:09 +01:00
|
|
|
conf.registerPlugin(name, True)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2004-10-22 07:35:05 +02:00
|
|
|
load = wrap(load, [getopts({'deprecated': ''}), 'something'])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def reload(self, irc, msg, args, name):
|
2003-09-05 20:47:58 +02:00
|
|
|
"""<plugin>
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2003-12-16 20:57:18 +01:00
|
|
|
Unloads and subsequently reloads the plugin by name; use the 'list'
|
|
|
|
command to see a list of the currently loaded plugins.
|
2003-08-28 18:33:45 +02:00
|
|
|
"""
|
|
|
|
callbacks = irc.removeCallback(name)
|
|
|
|
if callbacks:
|
2003-10-22 00:24:13 +02:00
|
|
|
module = sys.modules[callbacks[0].__module__]
|
|
|
|
if hasattr(module, 'reload'):
|
|
|
|
x = module.reload()
|
2003-08-28 18:33:45 +02:00
|
|
|
try:
|
2003-09-18 07:52:55 +02:00
|
|
|
module = loadPluginModule(name)
|
2003-10-22 00:24:13 +02:00
|
|
|
if hasattr(module, 'reload'):
|
|
|
|
module.reload(x)
|
2003-09-06 03:13:43 +02:00
|
|
|
for callback in callbacks:
|
|
|
|
callback.die()
|
|
|
|
del callback
|
2004-08-01 21:05:06 +02:00
|
|
|
gc.collect() # This makes sure the callback is collected.
|
2003-09-18 07:52:55 +02:00
|
|
|
callback = loadPluginClass(irc, module)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-08-28 18:33:45 +02:00
|
|
|
except ImportError:
|
|
|
|
for callback in callbacks:
|
|
|
|
irc.addCallback(callback)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('No plugin %s exists.' % name)
|
2003-08-28 18:33:45 +02:00
|
|
|
else:
|
2004-08-03 05:27:49 +02:00
|
|
|
irc.error('There was no plugin %s.' % name)
|
2004-10-22 07:35:05 +02:00
|
|
|
reload = wrap(reload, ['something'])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def unload(self, irc, msg, args, name):
|
2003-09-05 20:47:58 +02:00
|
|
|
"""<plugin>
|
2003-08-28 18:33:45 +02:00
|
|
|
|
|
|
|
Unloads the callback by name; use the 'list' command to see a list
|
2004-08-01 20:46:56 +02:00
|
|
|
of the currently loaded callbacks. Obviously, the Owner plugin can't
|
|
|
|
be unloaded.
|
2003-08-28 18:33:45 +02:00
|
|
|
"""
|
2004-08-01 20:46:56 +02:00
|
|
|
if ircutils.strEqual(name, self.name()):
|
2004-08-01 21:05:06 +02:00
|
|
|
irc.error('You can\'t unload the %s plugin.' % name)
|
2004-08-01 20:46:56 +02:00
|
|
|
return
|
2004-08-19 18:51:57 +02:00
|
|
|
# Let's do this so even if the plugin isn't currently loaded, it doesn't
|
|
|
|
# stay attempting to load.
|
|
|
|
conf.registerPlugin(name, False)
|
2003-08-28 18:33:45 +02:00
|
|
|
callbacks = irc.removeCallback(name)
|
|
|
|
if callbacks:
|
|
|
|
for callback in callbacks:
|
|
|
|
callback.die()
|
|
|
|
del callback
|
|
|
|
gc.collect()
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-08-28 18:33:45 +02:00
|
|
|
else:
|
2004-08-03 05:27:49 +02:00
|
|
|
irc.error('There was no plugin %s.' % name)
|
2004-10-22 07:35:05 +02:00
|
|
|
unload = wrap(unload, ['something'])
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2004-10-22 07:35:05 +02:00
|
|
|
def defaultcapability(self, irc, msg, args, action, capability):
|
2004-09-09 01:34:48 +02:00
|
|
|
"""{add|remove} <capability>
|
2004-08-27 07:00:40 +02:00
|
|
|
|
|
|
|
Adds or removes (according to the first argument) <capability> from the
|
|
|
|
default capabilities given to users (the configuration variable
|
|
|
|
supybot.capabilities stores these).
|
|
|
|
"""
|
|
|
|
if action == 'add':
|
|
|
|
conf.supybot.capabilities().add(capability)
|
|
|
|
irc.replySuccess()
|
|
|
|
elif action == 'remove':
|
|
|
|
try:
|
|
|
|
conf.supybot.capabilities().remove(capability)
|
|
|
|
irc.replySuccess()
|
|
|
|
except KeyError:
|
|
|
|
if ircdb.isAntiCapability(capability):
|
|
|
|
irc.error('That capability wasn\'t in '
|
|
|
|
'supybot.capabilities.')
|
|
|
|
else:
|
|
|
|
anticap = ircdb.makeAntiCapability(capability)
|
|
|
|
conf.supybot.capabilities().add(anticap)
|
|
|
|
irc.replySuccess()
|
2004-10-22 07:35:05 +02:00
|
|
|
defaultcapability = wrap(defaultcapability,
|
|
|
|
[('literal', ['add','remove']), 'capability'])
|
2004-10-26 00:59:03 +02:00
|
|
|
|
2004-12-01 05:42:52 +01:00
|
|
|
def disable(self, irc, msg, args, plugin, command):
|
2004-07-29 11:46:22 +02:00
|
|
|
"""[<plugin>] <command>
|
|
|
|
|
2004-08-27 06:31:53 +02:00
|
|
|
Disables the command <command> for all users (including the owners).
|
|
|
|
If <plugin> is given, only disables the <command> from <plugin>. If
|
|
|
|
you want to disable a command for most users but not for yourself, set
|
|
|
|
a default capability of -plugin.command or -command (if you want to
|
|
|
|
disable the command in all plugins).
|
2004-07-29 11:46:22 +02:00
|
|
|
"""
|
|
|
|
if command in ('enable', 'identify'):
|
|
|
|
irc.error('You can\'t disable %s.' % command)
|
2004-12-01 05:42:52 +01:00
|
|
|
return
|
|
|
|
if plugin:
|
|
|
|
if plugin.isCommand(command):
|
|
|
|
pluginCommand = '%s.%s' % (plugin.name(), command)
|
|
|
|
conf.supybot.commands.disabled().add(pluginCommand)
|
|
|
|
else:
|
|
|
|
irc.error('%s is not a command in the %s plugin.' %
|
|
|
|
(command, plugin.name()))
|
|
|
|
return
|
2004-12-02 05:51:16 +01:00
|
|
|
self._disabled.add(command, plugin.name())
|
2004-07-29 11:46:22 +02:00
|
|
|
else:
|
2004-12-01 05:42:52 +01:00
|
|
|
conf.supybot.commands.disabled().add(command)
|
2004-12-02 05:51:16 +01:00
|
|
|
self._disabled.add(command)
|
2004-12-01 05:42:52 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
disable = wrap(disable, [optional('plugin'), 'commandName'])
|
2004-07-29 11:46:22 +02:00
|
|
|
|
2004-12-02 06:08:53 +01:00
|
|
|
def enable(self, irc, msg, args, plugin, command):
|
2004-07-29 11:46:22 +02:00
|
|
|
"""[<plugin>] <command>
|
|
|
|
|
2004-08-27 06:31:53 +02:00
|
|
|
Enables the command <command> for all users. If <plugin>
|
|
|
|
if given, only enables the <command> from <plugin>. This command is
|
|
|
|
the inverse of disable.
|
2004-07-29 11:46:22 +02:00
|
|
|
"""
|
|
|
|
try:
|
2004-12-02 06:08:53 +01:00
|
|
|
if plugin:
|
|
|
|
command = '%s.%s' % (plugin.name(), command)
|
|
|
|
self._disabled.remove(command, plugin.name())
|
2004-07-29 11:46:22 +02:00
|
|
|
else:
|
2004-12-02 06:08:53 +01:00
|
|
|
self._disabled.remove(command)
|
|
|
|
conf.supybot.commands.disabled().remove(command)
|
2004-07-29 11:46:22 +02:00
|
|
|
irc.replySuccess()
|
|
|
|
except KeyError:
|
|
|
|
irc.error('That command wasn\'t disabled.')
|
2004-12-02 06:08:53 +01:00
|
|
|
enable = wrap(enable, [optional('plugin'), 'commandName'])
|
2004-07-29 11:46:22 +02:00
|
|
|
|
2004-12-02 06:08:53 +01:00
|
|
|
def rename(self, irc, msg, args, plugin, command, newName):
|
2004-08-03 09:20:53 +02:00
|
|
|
"""<plugin> <command> <new name>
|
|
|
|
|
|
|
|
Renames <command> in <plugin> to the <new name>.
|
|
|
|
"""
|
2004-12-02 06:08:53 +01:00
|
|
|
if not plugin.isCommand(command):
|
|
|
|
what = 'command in the %s plugin' % plugin.name()
|
|
|
|
irc.errorInvalid(what, command)
|
|
|
|
if hasattr(plugin, newName):
|
2004-08-03 16:01:54 +02:00
|
|
|
irc.error('The %s plugin already has an attribute named %s.' %
|
2004-12-02 06:08:53 +01:00
|
|
|
(plugin, newName))
|
2004-08-03 16:01:54 +02:00
|
|
|
return
|
2004-12-02 06:08:53 +01:00
|
|
|
registerRename(plugin.name(), command, newName)
|
|
|
|
renameCommand(plugin, command, newName)
|
2004-08-03 09:20:53 +02:00
|
|
|
irc.replySuccess()
|
2004-12-02 06:08:53 +01:00
|
|
|
rename = wrap(rename, ['plugin', 'commandName', 'commandName'])
|
2004-08-11 14:57:52 +02:00
|
|
|
|
2004-12-02 06:08:53 +01:00
|
|
|
def unrename(self, irc, msg, args, plugin):
|
2004-09-11 18:16:16 +02:00
|
|
|
"""<plugin>
|
|
|
|
|
|
|
|
Removes all renames in <plugin>. The plugin will be reloaded after
|
|
|
|
this command is run.
|
|
|
|
"""
|
|
|
|
try:
|
2004-12-02 06:08:53 +01:00
|
|
|
conf.supybot.commands.renames.unregister(plugin.name())
|
2004-09-11 18:16:16 +02:00
|
|
|
except registry.NonExistentRegistryEntry:
|
2004-12-02 06:08:53 +01:00
|
|
|
irc.errorInvalid('plugin', plugin.name())
|
|
|
|
self.reload(irc, msg, [plugin.name()]) # This makes the replySuccess.
|
|
|
|
unrename = wrap(unrename, ['plugin'])
|
2004-09-11 18:16:16 +02:00
|
|
|
|
2003-08-28 18:33:45 +02:00
|
|
|
|
2003-10-21 08:03:57 +02:00
|
|
|
Class = Owner
|
2003-08-28 18:33:45 +02:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
|
|
|
|