2005-01-19 14:14:38 +01:00
|
|
|
###
|
2005-01-19 14:33:05 +01:00
|
|
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
2012-09-01 16:16:48 +02:00
|
|
|
# Copyright (c) 2008-2009, James McCoy
|
2005-01-19 14:14:38 +01: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.
|
|
|
|
###
|
|
|
|
|
|
|
|
import gc
|
|
|
|
import os
|
|
|
|
import sys
|
2008-11-14 10:11:58 +01:00
|
|
|
import time
|
2005-01-19 14:14:38 +01:00
|
|
|
import socket
|
2017-01-22 12:34:54 +01:00
|
|
|
import string
|
2005-01-19 14:14:38 +01:00
|
|
|
import linecache
|
|
|
|
|
2013-05-13 15:27:26 +02:00
|
|
|
import re
|
2007-04-25 18:12:21 +02:00
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.log as log
|
|
|
|
import supybot.conf as conf
|
2010-11-19 17:10:47 +01:00
|
|
|
import supybot.i18n as i18n
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.world as world
|
|
|
|
import supybot.ircdb as ircdb
|
|
|
|
from supybot.commands import *
|
|
|
|
import supybot.irclib as irclib
|
2005-01-20 00:22:35 +01:00
|
|
|
import supybot.plugin as plugin
|
2005-05-18 19:44:28 +02:00
|
|
|
import supybot.plugins as plugins
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.drivers as drivers
|
2015-08-11 16:50:23 +02:00
|
|
|
import supybot.utils.minisix as minisix
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.registry as registry
|
|
|
|
import supybot.callbacks as callbacks
|
2010-10-31 11:29:01 +01:00
|
|
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
|
|
|
_ = PluginInternationalization('Owner')
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
###
|
|
|
|
# supybot.commands.
|
|
|
|
###
|
|
|
|
|
|
|
|
def registerDefaultPlugin(command, plugin):
|
|
|
|
command = callbacks.canonicalName(command)
|
|
|
|
conf.registerGlobalValue(conf.supybot.commands.defaultPlugins,
|
|
|
|
command, registry.String(plugin, ''))
|
|
|
|
# This must be set, or the quotes won't be removed.
|
|
|
|
conf.supybot.commands.defaultPlugins.get(command).set(plugin)
|
|
|
|
|
|
|
|
|
|
|
|
registerDefaultPlugin('list', 'Misc')
|
|
|
|
registerDefaultPlugin('help', 'Misc')
|
|
|
|
registerDefaultPlugin('ignore', 'Admin')
|
|
|
|
registerDefaultPlugin('reload', 'Owner')
|
|
|
|
registerDefaultPlugin('enable', 'Owner')
|
|
|
|
registerDefaultPlugin('disable', 'Owner')
|
|
|
|
registerDefaultPlugin('unignore', 'Admin')
|
|
|
|
registerDefaultPlugin('capabilities', 'User')
|
|
|
|
registerDefaultPlugin('addcapability', 'Admin')
|
|
|
|
registerDefaultPlugin('removecapability', 'Admin')
|
|
|
|
|
2005-02-09 08:04:04 +01:00
|
|
|
class Owner(callbacks.Plugin):
|
2014-11-30 21:07:41 +01:00
|
|
|
"""Owner-only commands for core Supybot. This is a core Supybot module
|
|
|
|
that should not be removed!"""
|
2005-01-19 14:14:38 +01:00
|
|
|
# This plugin must be first; its priority must be lowest; otherwise odd
|
|
|
|
# things will happen when adding callbacks.
|
2005-01-29 22:43:23 +01:00
|
|
|
def __init__(self, irc=None):
|
2005-08-15 07:36:23 +02:00
|
|
|
if irc is not None:
|
|
|
|
assert not irc.getCallback(self.name())
|
2005-01-19 14:14:38 +01:00
|
|
|
self.__parent = super(Owner, self)
|
2005-01-29 20:16:29 +01:00
|
|
|
self.__parent.__init__(irc)
|
2005-01-19 14:14:38 +01:00
|
|
|
# Setup command flood detection.
|
2013-05-09 09:40:55 +02:00
|
|
|
self.commands = ircutils.FloodQueue(conf.supybot.abuse.flood.interval())
|
|
|
|
conf.supybot.abuse.flood.interval.addCallback(self.setFloodQueueTimeout)
|
2005-01-19 14:14:38 +01:00
|
|
|
# Setup plugins and default plugins for commands.
|
2005-09-02 00:18:30 +02:00
|
|
|
#
|
|
|
|
# This needs to be done before we connect to any networks so that the
|
|
|
|
# children of supybot.plugins (the actual plugins) exist and can be
|
|
|
|
# loaded.
|
2015-08-08 22:20:14 +02:00
|
|
|
for (name, s) in registry._cache.items():
|
2005-01-19 14:14:38 +01:00
|
|
|
if 'alwaysLoadDefault' in name or 'alwaysLoadImportant' in name:
|
|
|
|
continue
|
|
|
|
if name.startswith('supybot.plugins'):
|
|
|
|
try:
|
|
|
|
(_, _, name) = registry.split(name)
|
|
|
|
except ValueError: # unpack list of wrong size.
|
|
|
|
continue
|
|
|
|
# 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():
|
|
|
|
name = name.capitalize()
|
|
|
|
conf.registerPlugin(name)
|
|
|
|
if name.startswith('supybot.commands.defaultPlugins'):
|
|
|
|
try:
|
|
|
|
(_, _, _, name) = registry.split(name)
|
|
|
|
except ValueError: # unpack list of wrong size.
|
|
|
|
continue
|
|
|
|
registerDefaultPlugin(name, s)
|
2005-09-02 00:18:30 +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)
|
2014-01-20 15:49:15 +01:00
|
|
|
except socket.error as e:
|
2005-09-02 00:18:30 +02:00
|
|
|
self.log.error('Could not connect to %s: %s.', network, e)
|
2014-01-20 15:49:15 +01:00
|
|
|
except Exception as e:
|
2005-09-02 00:18:30 +02:00
|
|
|
self.log.exception('Exception connecting to %s:', network)
|
|
|
|
self.log.error('Could not connect to %s: %s.', network, e)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def callPrecedence(self, irc):
|
|
|
|
return ([], [cb for cb in irc.callbacks if cb is not self])
|
|
|
|
|
|
|
|
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
|
|
|
|
return msg
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
# This has to be done somewhere, I figure here is as good place as any.
|
2005-02-07 07:28:52 +01:00
|
|
|
callbacks.IrcObjectProxy._mores.clear()
|
2005-01-19 14:14:38 +01:00
|
|
|
self.__parent.reset()
|
|
|
|
|
2005-12-14 05:20:04 +01:00
|
|
|
def _connect(self, network, serverPort=None, password='', ssl=False):
|
2005-01-19 14:14:38 +01:00
|
|
|
try:
|
|
|
|
group = conf.supybot.networks.get(network)
|
|
|
|
(server, port) = group.servers()[0]
|
|
|
|
except (registry.NonExistentRegistryEntry, IndexError):
|
|
|
|
if serverPort is None:
|
2014-01-20 15:43:55 +01:00
|
|
|
raise ValueError('connect requires a (server, port) ' \
|
|
|
|
'if the network is not registered.')
|
2005-12-14 05:20:04 +01:00
|
|
|
conf.registerNetwork(network, password, ssl)
|
2005-01-19 14:14:38 +01:00
|
|
|
serverS = '%s:%s' % serverPort
|
|
|
|
conf.supybot.networks.get(network).servers.append(serverS)
|
2005-03-22 20:03:02 +01:00
|
|
|
assert conf.supybot.networks.get(network).servers(), \
|
|
|
|
'No servers are set for the %s network.' % network
|
2016-02-21 11:01:31 +01:00
|
|
|
self.log.debug('Creating new Irc for %s.', network)
|
2005-01-19 14:14:38 +01:00
|
|
|
newIrc = irclib.Irc(network)
|
|
|
|
driver = drivers.newDriver(newIrc)
|
2005-08-15 07:37:05 +02:00
|
|
|
self._loadPlugins(newIrc)
|
2005-01-19 14:14:38 +01:00
|
|
|
return newIrc
|
|
|
|
|
2005-08-15 07:37:05 +02:00
|
|
|
def _loadPlugins(self, irc):
|
2016-02-21 11:01:31 +01:00
|
|
|
self.log.debug('Loading plugins (connecting to %s).', irc.network)
|
2005-01-19 14:14:38 +01:00
|
|
|
alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
|
|
|
|
important = conf.supybot.commands.defaultPlugins.importantPlugins()
|
|
|
|
for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
|
|
|
|
if irc.getCallback(name) is None:
|
|
|
|
load = value()
|
|
|
|
if not load and name in important:
|
|
|
|
if alwaysLoadImportant:
|
|
|
|
s = '%s is configured not to be loaded, but is being '\
|
|
|
|
'loaded anyway because ' \
|
|
|
|
'supybot.plugins.alwaysLoadImportant is True.'
|
|
|
|
self.log.warning(s, name)
|
|
|
|
load = True
|
|
|
|
if load:
|
2005-02-09 01:32:00 +01:00
|
|
|
# We don't load plugins that don't start with a capital
|
|
|
|
# letter.
|
|
|
|
if name[0].isupper() and not irc.getCallback(name):
|
2005-01-19 14:14:38 +01:00
|
|
|
# This is debug because each log logs its beginning.
|
2005-05-18 06:18:35 +02:00
|
|
|
self.log.debug('Loading %s.', name)
|
2005-01-19 14:14:38 +01:00
|
|
|
try:
|
2005-01-20 00:22:35 +01:00
|
|
|
m = plugin.loadPluginModule(name,
|
|
|
|
ignoreDeprecation=True)
|
|
|
|
plugin.loadPluginClass(irc, m)
|
2014-01-20 15:49:15 +01:00
|
|
|
except callbacks.Error as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
# This is just an error message.
|
|
|
|
log.warning(str(e))
|
2014-09-14 13:08:28 +02:00
|
|
|
except plugins.NoSuitableDatabase as e:
|
|
|
|
s = 'Failed to load %s: no suitable database(%s).' % (name, e)
|
|
|
|
log.warning(s)
|
|
|
|
except ImportError as e:
|
2014-11-01 18:57:01 +01:00
|
|
|
e = str(e)
|
|
|
|
if e.endswith(name):
|
2014-11-01 19:08:36 +01:00
|
|
|
s = 'Failed to load {0}: No plugin named {0} exists.'.format(
|
|
|
|
utils.str.dqrepr(name))
|
2014-11-01 18:57:01 +01:00
|
|
|
elif "No module named 'config'" in e:
|
2014-11-01 19:20:05 +01:00
|
|
|
s = ("Failed to load %s: This plugin may be incompatible "
|
2014-11-01 18:57:01 +01:00
|
|
|
"with your current Python version. If this error is appearing "
|
|
|
|
"with stock Supybot plugins, remove the stock plugins directory "
|
|
|
|
"(usually ~/Limnoria/plugins) from 'config directories.plugins'." % name)
|
|
|
|
else:
|
|
|
|
s = 'Failed to load %s: import error (%s).' % (name, e)
|
2005-05-18 19:44:28 +02:00
|
|
|
log.warning(s)
|
2014-01-20 15:49:15 +01:00
|
|
|
except Exception as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
log.exception('Failed to load %s:', name)
|
|
|
|
else:
|
|
|
|
# Let's import the module so configuration is preserved.
|
|
|
|
try:
|
2005-01-20 00:22:35 +01:00
|
|
|
_ = plugin.loadPluginModule(name)
|
2014-01-20 15:49:15 +01:00
|
|
|
except Exception as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
log.debug('Attempted to load %s to preserve its '
|
|
|
|
'configuration, but load failed: %s',
|
|
|
|
name, e)
|
|
|
|
world.starting = False
|
|
|
|
|
|
|
|
def do376(self, irc, msg):
|
2014-05-09 14:39:57 +02:00
|
|
|
msgs = conf.supybot.networks.get(irc.network).channels.joins()
|
|
|
|
if msgs:
|
|
|
|
for msg in msgs:
|
|
|
|
irc.queueMsg(msg)
|
2005-01-19 14:14:38 +01:00
|
|
|
do422 = do377 = do376
|
|
|
|
|
2013-05-09 09:40:55 +02:00
|
|
|
def setFloodQueueTimeout(self, *args, **kwargs):
|
|
|
|
self.commands.timeout = conf.supybot.abuse.flood.interval()
|
2005-01-19 14:14:38 +01:00
|
|
|
def doPrivmsg(self, irc, msg):
|
2005-08-15 07:36:23 +02:00
|
|
|
assert self is irc.callbacks[0], \
|
|
|
|
'Owner isn\'t first callback: %r' % irc.callbacks
|
2005-01-19 14:14:38 +01:00
|
|
|
if ircmsgs.isCtcp(msg):
|
|
|
|
return
|
|
|
|
s = callbacks.addressed(irc.nick, msg)
|
|
|
|
if s:
|
|
|
|
ignored = ircdb.checkIgnored(msg.prefix)
|
|
|
|
if ignored:
|
2005-05-18 06:18:35 +02:00
|
|
|
self.log.info('Ignoring command from %s.', msg.prefix)
|
2005-01-19 14:14:38 +01:00
|
|
|
return
|
2008-11-14 10:11:58 +01:00
|
|
|
maximum = conf.supybot.abuse.flood.command.maximum()
|
|
|
|
self.commands.enqueue(msg)
|
|
|
|
if conf.supybot.abuse.flood.command() \
|
|
|
|
and self.commands.len(msg) > maximum \
|
2011-06-22 20:02:43 +02:00
|
|
|
and not ircdb.checkCapability(msg.prefix, 'trusted'):
|
2008-11-14 10:11:58 +01:00
|
|
|
punishment = conf.supybot.abuse.flood.command.punishment()
|
2015-09-01 20:40:32 +02:00
|
|
|
banmask = conf.supybot.protocols.irc.banmask \
|
|
|
|
.makeBanmask(msg.prefix)
|
2008-11-14 10:11:58 +01:00
|
|
|
self.log.info('Ignoring %s for %s seconds due to an apparent '
|
|
|
|
'command flood.', banmask, punishment)
|
|
|
|
ircdb.ignores.add(banmask, time.time() + punishment)
|
2015-09-16 21:32:25 +02:00
|
|
|
if conf.supybot.abuse.flood.command.notify():
|
|
|
|
irc.reply('You\'ve given me %s commands within the last '
|
|
|
|
'%i seconds; I\'m now ignoring you for %s.' %
|
|
|
|
(maximum,
|
|
|
|
conf.supybot.abuse.flood.interval(),
|
|
|
|
utils.timeElapsed(punishment, seconds=False)))
|
2008-11-14 10:11:58 +01:00
|
|
|
return
|
2005-01-19 14:14:38 +01:00
|
|
|
try:
|
|
|
|
tokens = callbacks.tokenize(s, channel=msg.args[0])
|
|
|
|
self.Proxy(irc, msg, tokens)
|
2014-01-20 15:49:15 +01:00
|
|
|
except SyntaxError as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.queueMsg(callbacks.error(msg, str(e)))
|
|
|
|
|
2009-10-31 23:22:14 +01:00
|
|
|
def logmark(self, irc, msg, args, text):
|
|
|
|
"""<text>
|
|
|
|
|
|
|
|
Logs <text> to the global Supybot log at critical priority. Useful for
|
|
|
|
marking logfiles for later searching.
|
|
|
|
"""
|
|
|
|
self.log.critical(text)
|
|
|
|
irc.replySuccess()
|
|
|
|
logmark = wrap(logmark, ['text'])
|
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
def announce(self, irc, msg, args, text):
|
|
|
|
"""<text>
|
|
|
|
|
|
|
|
Sends <text> to all channels the bot is currently on and not
|
|
|
|
lobotomized in.
|
|
|
|
"""
|
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
2017-01-22 12:34:54 +01:00
|
|
|
|
|
|
|
template = self.registryValue('announceFormat')
|
|
|
|
|
|
|
|
text = ircutils.standardSubstitute(
|
2017-01-22 12:50:00 +01:00
|
|
|
irc, msg, template, env={'owner': u.name, 'text': text})
|
2017-01-22 12:34:54 +01:00
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
for channel in irc.state.channels:
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
if not c.lobotomized:
|
|
|
|
irc.queueMsg(ircmsgs.privmsg(channel, text))
|
2017-01-22 12:34:54 +01:00
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.noReply()
|
|
|
|
announce = wrap(announce, ['text'])
|
|
|
|
|
|
|
|
def defaultplugin(self, irc, msg, args, optlist, command, plugin):
|
|
|
|
"""[--remove] <command> [<plugin>]
|
|
|
|
|
|
|
|
Sets the default plugin for <command> to <plugin>. If --remove is
|
|
|
|
given, removes the current default plugin for <command>. If no plugin
|
2008-07-30 00:44:11 +02:00
|
|
|
is given, returns the current default plugin set for <command>. See
|
|
|
|
also, supybot.commands.defaultPlugins.importantPlugins.
|
2005-01-19 14:14:38 +01:00
|
|
|
"""
|
|
|
|
remove = False
|
|
|
|
for (option, arg) in optlist:
|
|
|
|
if option == 'remove':
|
|
|
|
remove = True
|
2005-02-18 14:40:05 +01:00
|
|
|
(_, cbs) = irc.findCallbacksForArgs([command])
|
2005-01-19 14:14:38 +01:00
|
|
|
if remove:
|
|
|
|
try:
|
|
|
|
conf.supybot.commands.defaultPlugins.unregister(command)
|
|
|
|
irc.replySuccess()
|
|
|
|
except registry.NonExistentRegistryEntry:
|
|
|
|
s = 'I don\'t have a default plugin set for that command.'
|
|
|
|
irc.error(s)
|
|
|
|
elif not cbs:
|
|
|
|
irc.errorInvalid('command', command)
|
|
|
|
elif plugin:
|
|
|
|
if not plugin.isCommand(command):
|
2010-09-21 00:20:52 +02:00
|
|
|
irc.errorInvalid('command in the %s plugin' % plugin.name(),
|
|
|
|
command)
|
2005-01-19 14:14:38 +01:00
|
|
|
registerDefaultPlugin(command, plugin.name())
|
|
|
|
irc.replySuccess()
|
|
|
|
else:
|
|
|
|
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)
|
|
|
|
defaultplugin = wrap(defaultplugin, [getopts({'remove': ''}),
|
|
|
|
'commandName',
|
|
|
|
additional('plugin')])
|
|
|
|
|
|
|
|
def ircquote(self, irc, msg, args, s):
|
|
|
|
"""<string to be sent to the server>
|
|
|
|
|
|
|
|
Sends the raw string given to the server.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
m = ircmsgs.IrcMsg(s)
|
2014-01-20 15:49:15 +01:00
|
|
|
except Exception as e:
|
2005-02-15 14:57:57 +01:00
|
|
|
irc.error(utils.exnToString(e))
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
irc.queueMsg(m)
|
|
|
|
irc.noReply()
|
|
|
|
ircquote = wrap(ircquote, ['text'])
|
|
|
|
|
|
|
|
def quit(self, irc, msg, args, text):
|
|
|
|
"""[<text>]
|
|
|
|
|
|
|
|
Exits the bot with the QUIT message <text>. If <text> is not given,
|
|
|
|
the default quit message (supybot.plugins.Owner.quitMsg) will be used.
|
2015-02-06 05:26:14 +01:00
|
|
|
If there is no default quitMsg set, your nick will be used. The standard
|
|
|
|
substitutions ($version, $nick, etc.) are all handled appropriately.
|
2005-01-19 14:14:38 +01:00
|
|
|
"""
|
|
|
|
text = text or self.registryValue('quitMsg') or msg.nick
|
2015-02-06 05:26:14 +01:00
|
|
|
text = ircutils.standardSubstitute(irc, msg, text)
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.noReply()
|
|
|
|
m = ircmsgs.quit(text)
|
|
|
|
world.upkeep()
|
|
|
|
for irc in world.ircs[:]:
|
|
|
|
irc.queueMsg(m)
|
|
|
|
irc.die()
|
|
|
|
quit = wrap(quit, [additional('text')])
|
|
|
|
|
|
|
|
def flush(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Runs all the periodic flushers in world.flushers. This includes
|
|
|
|
flushing all logs and all configuration changes to disk.
|
|
|
|
"""
|
|
|
|
world.flush()
|
|
|
|
irc.replySuccess()
|
|
|
|
flush = wrap(flush)
|
|
|
|
|
|
|
|
def upkeep(self, irc, msg, args, level):
|
|
|
|
"""[<level>]
|
|
|
|
|
|
|
|
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
|
2011-08-10 11:26:47 +02:00
|
|
|
as do normal upkeep stuff).
|
2005-01-19 14:14:38 +01:00
|
|
|
"""
|
|
|
|
L = []
|
|
|
|
if level == 'high':
|
2005-01-29 22:24:17 +01:00
|
|
|
L.append(format('Regexp cache flushed: %n cleared.',
|
2013-05-13 15:27:26 +02:00
|
|
|
(len(re._cache), 'regexp')))
|
|
|
|
re.purge()
|
2005-01-29 22:24:17 +01:00
|
|
|
L.append(format('Pattern cache flushed: %n cleared.',
|
|
|
|
(len(ircutils._patternCache), 'compiled pattern')))
|
2005-01-19 14:14:38 +01:00
|
|
|
ircutils._patternCache.clear()
|
2005-01-29 22:24:17 +01:00
|
|
|
L.append(format('hostmaskPatternEqual cache flushed: %n cleared.',
|
|
|
|
(len(ircutils._hostmaskPatternEqualCache),
|
|
|
|
'result')))
|
2005-01-19 14:14:38 +01:00
|
|
|
ircutils._hostmaskPatternEqualCache.clear()
|
2005-01-29 22:24:17 +01:00
|
|
|
L.append(format('ircdb username cache flushed: %n cleared.',
|
|
|
|
(len(ircdb.users._nameCache),
|
|
|
|
'username to id mapping')))
|
2005-01-19 14:14:38 +01:00
|
|
|
ircdb.users._nameCache.clear()
|
2005-01-29 22:24:17 +01:00
|
|
|
L.append(format('ircdb hostmask cache flushed: %n cleared.',
|
|
|
|
(len(ircdb.users._hostmaskCache),
|
|
|
|
'hostmask to id mapping')))
|
2005-01-19 14:14:38 +01:00
|
|
|
ircdb.users._hostmaskCache.clear()
|
2005-03-25 19:48:49 +01:00
|
|
|
L.append(format('linecache line cache flushed: %n cleared.',
|
|
|
|
(len(linecache.cache), 'line')))
|
2005-01-19 14:14:38 +01:00
|
|
|
linecache.clearcache()
|
2015-08-09 09:21:12 +02:00
|
|
|
if minisix.PY2:
|
2015-05-19 19:10:00 +02:00
|
|
|
sys.exc_clear()
|
2005-01-19 14:14:38 +01:00
|
|
|
collected = world.upkeep()
|
|
|
|
if gc.garbage:
|
|
|
|
L.append('Garbage! %r.' % gc.garbage)
|
2005-01-29 22:24:17 +01:00
|
|
|
L.append(format('%n collected.', (collected, 'object')))
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.reply(' '.join(L))
|
|
|
|
upkeep = wrap(upkeep, [additional(('literal', ['high']))])
|
|
|
|
|
|
|
|
def load(self, irc, msg, args, optlist, name):
|
|
|
|
"""[--deprecated] <plugin>
|
|
|
|
|
|
|
|
Loads the plugin <plugin> from any of the directories in
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
ignoreDeprecation = False
|
|
|
|
for (option, argument) in optlist:
|
|
|
|
if option == 'deprecated':
|
|
|
|
ignoreDeprecation = True
|
|
|
|
if name.endswith('.py'):
|
|
|
|
name = name[:-3]
|
|
|
|
if irc.getCallback(name):
|
|
|
|
irc.error('%s is already loaded.' % name.capitalize())
|
|
|
|
return
|
|
|
|
try:
|
2005-01-20 00:22:35 +01:00
|
|
|
module = plugin.loadPluginModule(name, ignoreDeprecation)
|
|
|
|
except plugin.Deprecated:
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.error('%s is deprecated. Use --deprecated '
|
|
|
|
'to force it to load.' % name.capitalize())
|
|
|
|
return
|
2014-01-20 15:49:15 +01:00
|
|
|
except ImportError as e:
|
2014-02-07 03:52:33 +01:00
|
|
|
if str(e).endswith(name):
|
2005-01-27 07:59:08 +01:00
|
|
|
irc.error('No plugin named %s exists.' % utils.str.dqrepr(name))
|
2014-11-01 18:57:01 +01:00
|
|
|
elif "No module named 'config'" in str(e):
|
2014-11-01 19:20:05 +01:00
|
|
|
irc.error('This plugin may be incompatible with your current Python '
|
2014-11-01 18:57:01 +01:00
|
|
|
'version. Try running 2to3 on it.')
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
irc.error(str(e))
|
|
|
|
return
|
2005-01-20 00:22:35 +01:00
|
|
|
cb = plugin.loadPluginClass(irc, module)
|
2005-01-19 14:14:38 +01:00
|
|
|
name = cb.name() # Let's normalize this.
|
|
|
|
conf.registerPlugin(name, True)
|
|
|
|
irc.replySuccess()
|
|
|
|
load = wrap(load, [getopts({'deprecated': ''}), 'something'])
|
|
|
|
|
|
|
|
def reload(self, irc, msg, args, name):
|
|
|
|
"""<plugin>
|
|
|
|
|
|
|
|
Unloads and subsequently reloads the plugin by name; use the 'list'
|
|
|
|
command to see a list of the currently loaded plugins.
|
|
|
|
"""
|
2014-11-03 16:45:32 +01:00
|
|
|
if ircutils.strEqual(name, self.name()):
|
|
|
|
irc.error('You can\'t reload the %s plugin.' % name)
|
|
|
|
return
|
2005-01-19 14:14:38 +01:00
|
|
|
callbacks = irc.removeCallback(name)
|
|
|
|
if callbacks:
|
|
|
|
module = sys.modules[callbacks[0].__module__]
|
|
|
|
if hasattr(module, 'reload'):
|
|
|
|
x = module.reload()
|
|
|
|
try:
|
2005-01-20 00:22:35 +01:00
|
|
|
module = plugin.loadPluginModule(name)
|
2012-08-05 18:28:17 +02:00
|
|
|
if hasattr(module, 'reload') and 'x' in locals():
|
2005-01-19 14:14:38 +01:00
|
|
|
module.reload(x)
|
2012-09-17 17:49:13 +02:00
|
|
|
if hasattr(module, 'config'):
|
2015-08-11 16:50:23 +02:00
|
|
|
from imp import reload
|
2012-09-17 17:49:13 +02:00
|
|
|
reload(module.config)
|
2005-01-19 14:14:38 +01:00
|
|
|
for callback in callbacks:
|
|
|
|
callback.die()
|
|
|
|
del callback
|
|
|
|
gc.collect() # This makes sure the callback is collected.
|
2005-01-20 00:22:35 +01:00
|
|
|
callback = plugin.loadPluginClass(irc, module)
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
except ImportError:
|
|
|
|
for callback in callbacks:
|
|
|
|
irc.addCallback(callback)
|
2014-11-11 03:34:49 +01:00
|
|
|
irc.error('No plugin named %s exists.' % name)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
irc.error('There was no plugin %s.' % name)
|
|
|
|
reload = wrap(reload, ['something'])
|
|
|
|
|
|
|
|
def unload(self, irc, msg, args, name):
|
|
|
|
"""<plugin>
|
|
|
|
|
|
|
|
Unloads the callback by name; use the 'list' command to see a list
|
2012-02-11 15:19:14 +01:00
|
|
|
of the currently loaded plugins. Obviously, the Owner plugin can't
|
2005-01-19 14:14:38 +01:00
|
|
|
be unloaded.
|
|
|
|
"""
|
|
|
|
if ircutils.strEqual(name, self.name()):
|
|
|
|
irc.error('You can\'t unload the %s plugin.' % name)
|
|
|
|
return
|
|
|
|
# Let's do this so even if the plugin isn't currently loaded, it doesn't
|
|
|
|
# stay attempting to load.
|
2017-10-28 08:34:08 +02:00
|
|
|
old_callback = irc.getCallback(name)
|
|
|
|
if old_callback:
|
|
|
|
# Normalize the plugin case to prevent duplicate registration
|
|
|
|
# entries, https://github.com/ProgVal/Limnoria/issues/1295
|
|
|
|
name = old_callback.name()
|
|
|
|
conf.registerPlugin(name, False)
|
|
|
|
callbacks = irc.removeCallback(name)
|
|
|
|
if callbacks:
|
|
|
|
for callback in callbacks:
|
|
|
|
callback.die()
|
|
|
|
del callback
|
|
|
|
gc.collect()
|
|
|
|
irc.replySuccess()
|
|
|
|
return
|
|
|
|
irc.error('There was no plugin %s.' % name)
|
2005-01-19 14:14:38 +01:00
|
|
|
unload = wrap(unload, ['something'])
|
|
|
|
|
|
|
|
def defaultcapability(self, irc, msg, args, action, capability):
|
|
|
|
"""{add|remove} <capability>
|
|
|
|
|
|
|
|
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()
|
|
|
|
defaultcapability = wrap(defaultcapability,
|
|
|
|
[('literal', ['add','remove']), 'capability'])
|
|
|
|
|
|
|
|
def disable(self, irc, msg, args, plugin, command):
|
|
|
|
"""[<plugin>] <command>
|
|
|
|
|
|
|
|
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).
|
|
|
|
"""
|
|
|
|
if command in ('enable', 'identify'):
|
|
|
|
irc.error('You can\'t disable %s.' % command)
|
|
|
|
return
|
|
|
|
if plugin:
|
|
|
|
if plugin.isCommand(command):
|
|
|
|
pluginCommand = '%s.%s' % (plugin.name(), command)
|
|
|
|
conf.supybot.commands.disabled().add(pluginCommand)
|
2016-11-03 14:28:41 +01:00
|
|
|
plugin._disabled.add(command, plugin.name())
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
irc.error('%s is not a command in the %s plugin.' %
|
|
|
|
(command, plugin.name()))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
conf.supybot.commands.disabled().add(command)
|
|
|
|
self._disabled.add(command)
|
|
|
|
irc.replySuccess()
|
|
|
|
disable = wrap(disable, [optional('plugin'), 'commandName'])
|
|
|
|
|
|
|
|
def enable(self, irc, msg, args, plugin, command):
|
|
|
|
"""[<plugin>] <command>
|
|
|
|
|
|
|
|
Enables the command <command> for all users. If <plugin>
|
|
|
|
if given, only enables the <command> from <plugin>. This command is
|
|
|
|
the inverse of disable.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
if plugin:
|
2011-06-29 13:56:22 +02:00
|
|
|
plugin._disabled.remove(command, plugin.name())
|
2005-04-21 05:27:03 +02:00
|
|
|
command = '%s.%s' % (plugin.name(), command)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
self._disabled.remove(command)
|
|
|
|
conf.supybot.commands.disabled().remove(command)
|
|
|
|
irc.replySuccess()
|
|
|
|
except KeyError:
|
|
|
|
irc.error('That command wasn\'t disabled.')
|
|
|
|
enable = wrap(enable, [optional('plugin'), 'commandName'])
|
|
|
|
|
2014-07-18 20:43:24 +02:00
|
|
|
def rename(self, irc, msg, args, command_plugin, command, newName):
|
2005-01-19 14:14:38 +01:00
|
|
|
"""<plugin> <command> <new name>
|
|
|
|
|
|
|
|
Renames <command> in <plugin> to the <new name>.
|
|
|
|
"""
|
2014-07-18 20:43:24 +02:00
|
|
|
if not command_plugin.isCommand(command):
|
|
|
|
what = 'command in the %s plugin' % command_plugin.name()
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.errorInvalid(what, command)
|
2014-07-18 20:43:24 +02:00
|
|
|
if hasattr(command_plugin, newName):
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.error('The %s plugin already has an attribute named %s.' %
|
2014-07-18 20:43:24 +02:00
|
|
|
(command_plugin, newName))
|
2005-01-19 14:14:38 +01:00
|
|
|
return
|
2014-07-18 20:43:24 +02:00
|
|
|
plugin.registerRename(command_plugin.name(), command, newName)
|
|
|
|
plugin.renameCommand(command_plugin, command, newName)
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
rename = wrap(rename, ['plugin', 'commandName', 'commandName'])
|
|
|
|
|
|
|
|
def unrename(self, irc, msg, args, plugin):
|
|
|
|
"""<plugin>
|
|
|
|
|
|
|
|
Removes all renames in <plugin>. The plugin will be reloaded after
|
|
|
|
this command is run.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
conf.supybot.commands.renames.unregister(plugin.name())
|
|
|
|
except registry.NonExistentRegistryEntry:
|
|
|
|
irc.errorInvalid('plugin', plugin.name())
|
|
|
|
self.reload(irc, msg, [plugin.name()]) # This makes the replySuccess.
|
|
|
|
unrename = wrap(unrename, ['plugin'])
|
|
|
|
|
2010-11-19 17:10:47 +01:00
|
|
|
def reloadlocale(self, irc, msg, args):
|
|
|
|
"""takes no argument
|
|
|
|
|
|
|
|
Reloads the locale of the bot."""
|
|
|
|
i18n.reloadLocales()
|
|
|
|
irc.replySuccess()
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
Class = Owner
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|