2003-03-27 07:34:48 +01:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-03-27 07:34:48 +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.
|
|
|
|
###
|
|
|
|
|
|
|
|
"""
|
|
|
|
Miscellaneous commands.
|
|
|
|
"""
|
|
|
|
|
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
|
2004-09-10 10:31:59 +02:00
|
|
|
__contributors__ = {
|
|
|
|
supybot.authors.skorobeus: ['contributors'],
|
|
|
|
}
|
2003-11-25 09:38:19 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.fix as fix
|
2003-09-07 07:26:18 +02:00
|
|
|
|
2003-03-27 07:34:48 +01:00
|
|
|
import os
|
2003-09-25 10:14:46 +02:00
|
|
|
import sys
|
2004-09-10 09:40:24 +02:00
|
|
|
import time
|
2003-09-07 07:26:18 +02:00
|
|
|
import getopt
|
2003-11-15 04:21:34 +01:00
|
|
|
from itertools import imap, ifilter
|
2003-03-27 07:34:48 +01:00
|
|
|
|
2004-09-10 09:40:24 +02:00
|
|
|
import supybot.log as log
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
2004-08-25 19:05:27 +02:00
|
|
|
import supybot.world as world
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.ircdb as ircdb
|
|
|
|
import supybot.irclib as irclib
|
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.privmsgs as privmsgs
|
|
|
|
import supybot.webutils as webutils
|
2004-08-06 08:57:54 +02:00
|
|
|
import supybot.registry as registry
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.callbacks as callbacks
|
2003-03-27 07:34:48 +01:00
|
|
|
|
2004-08-06 08:57:54 +02:00
|
|
|
conf.registerPlugin('Misc')
|
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Misc, 'listPrivatePlugins',
|
|
|
|
registry.Boolean(True, """Determines whether the bot will list private
|
|
|
|
plugins with the list command if given the --private switch. If this is
|
|
|
|
disabled, non-owner users should be unable to see what private plugins
|
|
|
|
are loaded."""))
|
2004-09-10 08:45:27 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Misc, 'timestampFormat',
|
|
|
|
registry.String('[%H:%M:%S]', """Determines the format string for
|
|
|
|
timestamps in the Misc.last command. Refer to the Python documentation
|
|
|
|
for the time module to see what formats are accepted. If you set this
|
|
|
|
variable to the empty string, the timestamp will not be shown."""))
|
2004-08-06 08:57:54 +02:00
|
|
|
|
2003-10-21 08:03:57 +02:00
|
|
|
class Misc(callbacks.Privmsg):
|
2004-09-09 01:34:48 +02:00
|
|
|
def __init__(self):
|
|
|
|
super(Misc, self).__init__()
|
2004-09-10 09:40:24 +02:00
|
|
|
self.invalidCommands = ircutils.FloodQueue(60)
|
2004-09-09 01:34:48 +02: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], [])
|
|
|
|
|
2003-10-28 01:22:15 +01:00
|
|
|
def invalidCommand(self, irc, msg, tokens):
|
2004-09-16 12:28:59 +02:00
|
|
|
assert not msg.repliedTo, 'repliedTo msg in Misc.invalidCommand.'
|
|
|
|
assert self is irc.callbacks[-1], 'Misc isn\'t last callback.'
|
2004-01-01 21:18:13 +01:00
|
|
|
self.log.debug('Misc.invalidCommand called (tokens %s)', tokens)
|
2004-09-09 01:34:48 +02:00
|
|
|
# First, we check for invalidCommand floods. This is rightfully done
|
|
|
|
# here since this will be the last invalidCommand called, and thus it
|
|
|
|
# will only be called if this is *truly* an invalid command.
|
|
|
|
maximum = conf.supybot.abuse.flood.command.invalid.maximum()
|
|
|
|
self.invalidCommands.enqueue(msg)
|
|
|
|
if self.invalidCommands.len(msg) > maximum and \
|
|
|
|
not ircdb.checkCapability(msg.prefix, 'owner'):
|
|
|
|
punishment = conf.supybot.abuse.flood.command.invalid.punishment()
|
|
|
|
banmask = '*!%s@%s' % (msg.user, msg.host)
|
|
|
|
self.log.info('Ignoring %s for %s seconds due to an apparent '
|
|
|
|
'invalid command flood.', banmask, punishment)
|
|
|
|
if tokens and tokens[0] == 'Error:':
|
|
|
|
self.log.warning('Apparent error loop with another Supybot '
|
|
|
|
'observed at %s. Consider ignoring this bot '
|
|
|
|
'permanently.', log.timestamp())
|
|
|
|
ircdb.ignores.add(banmask, time.time() + punishment)
|
|
|
|
irc.reply('You\'ve given me %s invalid commands within the last '
|
|
|
|
'minute; I\'m now ignoring you for %s.' %
|
2004-09-10 09:40:24 +02:00
|
|
|
(maximum, utils.timeElapsed(punishment, seconds=False)))
|
2004-09-09 01:34:48 +02:00
|
|
|
return
|
|
|
|
# Now, for normal handling.
|
|
|
|
channel = msg.args[0]
|
|
|
|
if conf.get(conf.supybot.reply.whenNotCommand, channel):
|
2003-10-30 00:02:27 +01:00
|
|
|
command = tokens and tokens[0] or ''
|
2004-09-23 00:41:58 +02:00
|
|
|
irc.errorInvalid('command', command, repr=False)
|
2003-10-28 01:22:15 +01:00
|
|
|
else:
|
2004-04-27 19:14:31 +02:00
|
|
|
if tokens:
|
|
|
|
# echo [] will get us an empty token set, but there's no need
|
|
|
|
# to log this in that case anyway, it being a nested command.
|
|
|
|
self.log.info('Not replying to %s, not a command.' % tokens[0])
|
2003-10-28 01:22:15 +01:00
|
|
|
if not isinstance(irc.irc, irclib.Irc):
|
2004-09-09 01:34:48 +02:00
|
|
|
brackets = conf.get(conf.supybot.reply.brackets, channel)
|
|
|
|
if brackets:
|
|
|
|
(left, right) = brackets
|
|
|
|
irc.reply(left + ' '.join(tokens) + right)
|
|
|
|
else:
|
|
|
|
pass # Let's just do nothing, I can't think of better.
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-03-27 07:34:48 +01:00
|
|
|
def list(self, irc, msg, args):
|
2003-09-22 12:22:06 +02:00
|
|
|
"""[--private] [<module name>]
|
2003-03-27 07:34:48 +01:00
|
|
|
|
2003-09-07 06:05:34 +02:00
|
|
|
Lists the commands available in the given plugin. If no plugin is
|
2003-09-22 12:22:06 +02:00
|
|
|
given, lists the public plugins available. If --private is given,
|
2004-07-28 06:27:51 +02:00
|
|
|
lists the private plugins.
|
2003-03-27 07:34:48 +01:00
|
|
|
"""
|
2003-09-22 12:22:06 +02:00
|
|
|
(optlist, rest) = getopt.getopt(args, '', ['private'])
|
2004-07-28 06:27:51 +02:00
|
|
|
private = False
|
2003-09-22 12:22:06 +02:00
|
|
|
for (option, argument) in optlist:
|
|
|
|
if option == '--private':
|
2004-07-28 06:27:51 +02:00
|
|
|
private = True
|
2004-08-06 08:57:54 +02:00
|
|
|
if not self.registryValue('listPrivatePlugins') and \
|
|
|
|
not ircdb.checkCapability(msg.prefix, 'owner'):
|
|
|
|
irc.errorNoCapability('owner')
|
|
|
|
return
|
2003-11-11 14:20:06 +01:00
|
|
|
name = privmsgs.getArgs(rest, required=0, optional=1)
|
2003-12-07 01:13:56 +01:00
|
|
|
name = callbacks.canonicalName(name)
|
2003-03-27 07:34:48 +01:00
|
|
|
if not name:
|
2004-04-28 10:42:01 +02:00
|
|
|
def isPublic(cb):
|
|
|
|
name = cb.name()
|
2004-07-28 06:27:51 +02:00
|
|
|
return conf.supybot.plugins.get(name).public()
|
|
|
|
names = [cb.name() for cb in irc.callbacks
|
|
|
|
if (private and not isPublic(cb)) or
|
|
|
|
(not private and isPublic(cb))]
|
2003-03-28 08:23:12 +01:00
|
|
|
names.sort()
|
2004-08-05 05:57:48 +02:00
|
|
|
if names:
|
|
|
|
irc.reply(utils.commaAndify(names))
|
|
|
|
else:
|
|
|
|
if private:
|
|
|
|
irc.reply('There are no private plugins.')
|
|
|
|
else:
|
|
|
|
irc.reply('There are no public plugins.')
|
2003-03-27 07:34:48 +01:00
|
|
|
else:
|
2003-12-07 01:13:56 +01:00
|
|
|
cb = irc.getCallback(name)
|
|
|
|
if cb is None:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('No such plugin %r exists.' % name)
|
2003-12-07 01:13:56 +01:00
|
|
|
elif isinstance(cb, callbacks.PrivmsgRegexp) or \
|
|
|
|
not isinstance(cb, callbacks.Privmsg):
|
2004-02-13 12:02:42 +01:00
|
|
|
irc.error('That plugin exists, but it has no commands. '
|
|
|
|
'You may wish to check if it has any useful '
|
|
|
|
'configuration variables with the command '
|
|
|
|
'"config list supybot.plugins.%s".' % name)
|
2003-12-07 01:13:56 +01:00
|
|
|
else:
|
|
|
|
commands = []
|
|
|
|
for s in dir(cb):
|
|
|
|
if cb.isCommand(s) and \
|
2003-12-09 22:32:55 +01:00
|
|
|
(s != name or cb._original) and \
|
2003-12-07 01:13:56 +01:00
|
|
|
s == callbacks.canonicalName(s):
|
|
|
|
method = getattr(cb, s)
|
|
|
|
if hasattr(method, '__doc__') and method.__doc__:
|
|
|
|
commands.append(s)
|
|
|
|
if commands:
|
2003-03-28 08:23:12 +01:00
|
|
|
commands.sort()
|
2004-02-12 05:17:20 +01:00
|
|
|
irc.reply(utils.commaAndify(commands))
|
2003-12-07 01:13:56 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That plugin exists, but it has no '
|
2004-08-05 05:57:48 +02:00
|
|
|
'commands with help.')
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-10-22 06:32:29 +02:00
|
|
|
def apropos(self, irc, msg, args):
|
|
|
|
"""<string>
|
|
|
|
|
|
|
|
Searches for <string> in the commands currently offered by the bot,
|
|
|
|
returning a list of the commands containing that string.
|
|
|
|
"""
|
|
|
|
s = privmsgs.getArgs(args)
|
2003-10-26 18:39:01 +01:00
|
|
|
commands = {}
|
2003-10-22 06:32:29 +02:00
|
|
|
L = []
|
|
|
|
for cb in irc.callbacks:
|
|
|
|
if isinstance(cb, callbacks.Privmsg) and \
|
|
|
|
not isinstance(cb, callbacks.PrivmsgRegexp):
|
|
|
|
for attr in dir(cb):
|
|
|
|
if s in attr and cb.isCommand(attr):
|
2003-11-26 19:21:12 +01:00
|
|
|
if attr == callbacks.canonicalName(attr):
|
|
|
|
commands.setdefault(attr, []).append(cb.name())
|
2003-10-26 18:39:01 +01:00
|
|
|
for (key, names) in commands.iteritems():
|
|
|
|
if len(names) == 1:
|
|
|
|
L.append(key)
|
|
|
|
else:
|
|
|
|
for name in names:
|
|
|
|
L.append('%s %s' % (name, key))
|
2003-10-27 05:59:54 +01:00
|
|
|
if L:
|
|
|
|
L.sort()
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(utils.commaAndify(L))
|
2003-10-27 05:59:54 +01:00
|
|
|
else:
|
2004-08-10 09:51:14 +02:00
|
|
|
irc.reply('No appropriate commands were found.')
|
2003-10-22 06:32:29 +02:00
|
|
|
|
2003-10-20 12:25:13 +02:00
|
|
|
def help(self, irc, msg, args):
|
|
|
|
"""[<plugin>] <command>
|
2003-03-27 07:34:48 +01:00
|
|
|
|
2003-10-22 20:49:51 +02:00
|
|
|
This command gives a useful description of what <command> does.
|
|
|
|
<plugin> is only necessary if the command is in more than one plugin.
|
2003-03-27 07:34:48 +01:00
|
|
|
"""
|
2003-12-12 18:53:16 +01:00
|
|
|
def getHelp(method, name=None):
|
|
|
|
if hasattr(method, '__doc__') and method.__doc__:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(callbacks.getHelp(method, name=name))
|
2003-12-12 18:53:16 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('%s has no help.' % name)
|
2003-10-20 12:25:13 +02:00
|
|
|
if len(args) > 1:
|
2004-07-20 07:26:35 +02:00
|
|
|
cb = irc.getCallback(args[0]) # No pop, we'll use this later.
|
2003-10-20 12:25:13 +02:00
|
|
|
if cb is not None:
|
|
|
|
command = callbacks.canonicalName(privmsgs.getArgs(args[1:]))
|
2004-08-26 01:03:42 +02:00
|
|
|
prefixChars = conf.supybot.reply.whenAddressedBy.chars()
|
|
|
|
command = command.lstrip(prefixChars)
|
2003-10-24 23:35:59 +02:00
|
|
|
name = ' '.join(args)
|
2003-10-20 12:25:13 +02:00
|
|
|
if hasattr(cb, 'isCommand') and cb.isCommand(command):
|
|
|
|
method = getattr(cb, command)
|
2003-12-12 18:53:16 +01:00
|
|
|
getHelp(method, name)
|
2003-09-25 10:14:46 +02:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('There is no such command %s.' % name)
|
2003-03-27 07:34:48 +01:00
|
|
|
else:
|
2004-04-30 06:23:51 +02:00
|
|
|
irc.error('There is no such plugin %s.' % args[0])
|
2003-10-20 12:25:13 +02:00
|
|
|
return
|
2004-07-20 07:26:35 +02:00
|
|
|
name = privmsgs.getArgs(args)
|
|
|
|
cb = irc.getCallback(name)
|
2004-09-16 18:36:12 +02:00
|
|
|
if cb is not None and cb.__doc__ and not getattr(cb,'_original',None):
|
2004-07-20 07:26:35 +02:00
|
|
|
irc.reply(utils.normalizeWhitespace(cb.__doc__))
|
|
|
|
return
|
|
|
|
command = callbacks.canonicalName(name)
|
2003-10-19 21:19:47 +02:00
|
|
|
# Users might expect "@help @list" to work.
|
2004-08-26 01:03:42 +02:00
|
|
|
# command = command.lstrip(conf.supybot.reply.whenAddressedBy.chars())
|
2004-09-22 23:38:20 +02:00
|
|
|
cbs = irc.findCallbackForCommand(command)
|
|
|
|
if not cbs:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('There is no such command %s.' % command)
|
2004-09-22 23:38:20 +02:00
|
|
|
elif len(cbs) > 1:
|
|
|
|
names = sorted([cb.name() for cb in cbs])
|
|
|
|
irc.error('That command exists in the %s plugins. '
|
|
|
|
'Please specify exactly which plugin command '
|
|
|
|
'you want help with.'% utils.commaAndify(names))
|
2003-10-20 12:25:13 +02:00
|
|
|
else:
|
|
|
|
cb = cbs[0]
|
2003-03-27 07:34:48 +01:00
|
|
|
method = getattr(cb, command)
|
2003-12-12 18:53:16 +01:00
|
|
|
getHelp(method)
|
2003-08-20 18:26:23 +02:00
|
|
|
|
2003-09-12 23:16:59 +02:00
|
|
|
def hostmask(self, irc, msg, args):
|
2003-10-21 23:33:27 +02:00
|
|
|
"""[<nick>]
|
2003-09-12 23:16:59 +02:00
|
|
|
|
2003-10-21 23:33:27 +02:00
|
|
|
Returns the hostmask of <nick>. If <nick> isn't given, return the
|
|
|
|
hostmask of the person giving the command.
|
2003-09-12 23:16:59 +02:00
|
|
|
"""
|
2003-11-11 14:20:06 +01:00
|
|
|
nick = privmsgs.getArgs(args, required=0, optional=1)
|
2003-11-15 04:21:34 +01:00
|
|
|
if nick:
|
|
|
|
try:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(irc.state.nickToHostmask(nick))
|
2003-11-15 04:21:34 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('I haven\'t seen anyone named %r' % nick)
|
2003-11-15 04:21:34 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(msg.prefix)
|
2003-09-12 23:16:59 +02:00
|
|
|
|
2003-03-27 07:34:48 +01:00
|
|
|
def version(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Returns the version of the current bot.
|
|
|
|
"""
|
2004-02-07 13:19:15 +01:00
|
|
|
try:
|
|
|
|
newest = webutils.getUrl('http://supybot.sf.net/version.txt')
|
2004-02-07 13:35:58 +01:00
|
|
|
newest ='The newest version available online is %s.'%newest.strip()
|
2004-02-07 13:19:15 +01:00
|
|
|
except webutils.WebError, e:
|
|
|
|
self.log.warning('Couldn\'t get website version: %r', e)
|
2004-08-19 15:33:34 +02:00
|
|
|
newest = 'I couldn\'t fetch the newest version ' \
|
2004-02-07 13:19:15 +01:00
|
|
|
'from the Supybot website.'
|
|
|
|
s = 'The current (running) version of this Supybot is %s. %s' % \
|
|
|
|
(conf.version, newest)
|
|
|
|
irc.reply(s)
|
|
|
|
version = privmsgs.thread(version)
|
2003-03-27 07:34:48 +01:00
|
|
|
|
2003-11-25 10:32:18 +01:00
|
|
|
def revision(self, irc, msg, args):
|
|
|
|
"""[<module>]
|
|
|
|
|
|
|
|
Gives the latest revision of <module>. If <module> isn't given, gives
|
2004-01-21 21:19:38 +01:00
|
|
|
the revision of all Supybot modules.
|
2003-11-25 10:32:18 +01:00
|
|
|
"""
|
2004-08-22 17:22:17 +02:00
|
|
|
def normalize(name):
|
2004-01-14 16:50:45 +01:00
|
|
|
if name.endswith('.py'):
|
|
|
|
name = name[:-3]
|
2004-08-22 17:22:17 +02:00
|
|
|
return name
|
2004-08-23 06:41:07 +02:00
|
|
|
def getRevisionNumber(module, name):
|
|
|
|
def getVersion(s, n):
|
2004-08-22 17:22:17 +02:00
|
|
|
try:
|
|
|
|
return s.split(None, 3)[2]
|
|
|
|
except:
|
2004-08-23 07:33:59 +02:00
|
|
|
self.log.exception('Getting %s module\'s revision number '
|
2004-08-23 15:30:35 +02:00
|
|
|
'from __revision__ string: %s', n, s)
|
2004-08-22 17:22:17 +02:00
|
|
|
if hasattr(module, '__revision__'):
|
|
|
|
if 'supybot' in module.__file__:
|
2004-08-23 06:41:07 +02:00
|
|
|
return getVersion(module.__revision__, name)
|
2004-08-22 17:22:17 +02:00
|
|
|
else:
|
|
|
|
for dir in conf.supybot.directories.plugins():
|
|
|
|
if module.__file__.startswith(dir):
|
2004-08-23 06:41:07 +02:00
|
|
|
return getVersion(module.__revision__, name)
|
2004-08-22 17:22:17 +02:00
|
|
|
if len(args) == 1 and '*' not in args[0] and '?' not in args[0]:
|
|
|
|
# wildcards are handled below.
|
|
|
|
name = normalize(args[0])
|
2003-11-25 10:32:18 +01:00
|
|
|
try:
|
2004-02-17 19:54:35 +01:00
|
|
|
def startsWithPluginsDir(filename):
|
|
|
|
for dir in conf.supybot.directories.plugins():
|
|
|
|
if filename.startswith(dir):
|
|
|
|
return True
|
|
|
|
return False
|
2003-12-02 12:06:39 +01:00
|
|
|
modules = {}
|
2004-02-16 04:01:20 +01:00
|
|
|
for (moduleName, module) in sys.modules.iteritems():
|
|
|
|
if hasattr(module, '__file__'):
|
2004-02-17 19:54:35 +01:00
|
|
|
if startsWithPluginsDir(module.__file__):
|
2004-02-16 04:01:20 +01:00
|
|
|
modules[moduleName.lower()] = moduleName
|
|
|
|
try:
|
|
|
|
module = sys.modules[name]
|
2004-02-17 19:54:35 +01:00
|
|
|
if not startsWithPluginsDir(module.__file__):
|
2004-02-16 04:01:20 +01:00
|
|
|
raise KeyError
|
|
|
|
except KeyError:
|
|
|
|
try:
|
|
|
|
module = sys.modules[modules[name.lower()]]
|
2004-02-17 19:54:35 +01:00
|
|
|
if not startsWithPluginsDir(module.__file__):
|
2004-02-16 04:01:20 +01:00
|
|
|
raise KeyError
|
|
|
|
except KeyError:
|
|
|
|
module = sys.modules[name.lower()]
|
2004-02-17 19:54:35 +01:00
|
|
|
if not startsWithPluginsDir(module.__file__):
|
2004-02-16 04:01:20 +01:00
|
|
|
raise KeyError
|
2003-11-25 10:32:18 +01:00
|
|
|
except KeyError:
|
2004-04-14 20:50:38 +02:00
|
|
|
irc.error('I couldn\'t find a Supybot module named %s.' % name)
|
2003-11-25 10:32:18 +01:00
|
|
|
return
|
|
|
|
if hasattr(module, '__revision__'):
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(module.__revision__)
|
2003-11-25 10:32:18 +01:00
|
|
|
else:
|
2004-02-17 19:54:35 +01:00
|
|
|
irc.error('Module %s has no __revision__ string.' % name)
|
2003-11-25 10:32:18 +01:00
|
|
|
else:
|
2004-08-22 17:22:17 +02:00
|
|
|
names = []
|
|
|
|
if not args:
|
|
|
|
# I shouldn't use iteritems here for some reason.
|
|
|
|
for (name, module) in sys.modules.items():
|
2004-08-23 06:41:07 +02:00
|
|
|
names.append((name, getRevisionNumber(module, name)))
|
2004-08-22 17:22:17 +02:00
|
|
|
elif len(args) == 1: # wildcards
|
|
|
|
pattern = args[0]
|
|
|
|
for (name, module) in sys.modules.items():
|
|
|
|
if ircutils.hostmaskPatternEqual(pattern, name):
|
2004-08-23 06:41:07 +02:00
|
|
|
names.append((name, getRevisionNumber(module, name)))
|
2004-08-22 17:22:17 +02:00
|
|
|
else:
|
|
|
|
for name in args:
|
|
|
|
name = normalize(name)
|
|
|
|
if name not in sys.modules:
|
|
|
|
irc.error('I couldn\'t find a Supybot named %s.'%name)
|
|
|
|
return
|
|
|
|
module = sys.modules[name]
|
2004-08-23 06:41:07 +02:00
|
|
|
names.append((name, getRevisionNumber(module, name)))
|
2004-08-22 17:22:17 +02:00
|
|
|
names.sort()
|
|
|
|
L = ['%s: %s' % (k, v) for (k, v) in names if v]
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(utils.commaAndify(L))
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-03-28 09:41:11 +01:00
|
|
|
def source(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
2004-08-19 01:15:27 +02:00
|
|
|
Returns a URL saying where to get Supybot.
|
2003-03-28 09:41:11 +01:00
|
|
|
"""
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('My source is at http://supybot.sf.net/')
|
2003-03-28 09:41:11 +01:00
|
|
|
|
2003-09-07 06:05:34 +02:00
|
|
|
def plugin(self, irc, msg, args):
|
2003-04-14 07:54:33 +02:00
|
|
|
"""<command>
|
|
|
|
|
2004-09-23 17:30:43 +02:00
|
|
|
Returns the plugin (or plugins) <command> is in. If this command is
|
|
|
|
nested, it returns only the plugin name(s). If given as a normal
|
|
|
|
command, it returns a more verbose, user-friendly response.
|
2003-04-14 07:54:33 +02:00
|
|
|
"""
|
2003-06-18 08:05:33 +02:00
|
|
|
command = callbacks.canonicalName(privmsgs.getArgs(args))
|
2003-10-20 12:25:13 +02:00
|
|
|
cbs = callbacks.findCallbackForCommand(irc, command)
|
|
|
|
if cbs:
|
2004-02-12 14:31:52 +01:00
|
|
|
names = [cb.name() for cb in cbs]
|
|
|
|
names.sort()
|
2004-09-16 16:51:40 +02:00
|
|
|
plugin = utils.commaAndify(names)
|
|
|
|
if irc.nested:
|
|
|
|
irc.reply(utils.commaAndify(names))
|
|
|
|
else:
|
2004-09-16 20:49:29 +02:00
|
|
|
irc.reply('The %r command is available in the %s %s.' %
|
|
|
|
(command, plugin,
|
|
|
|
utils.pluralize('plugin', len(names))))
|
2003-04-14 07:54:33 +02:00
|
|
|
else:
|
2004-08-06 07:19:11 +02:00
|
|
|
irc.error('There is no such command %s.' % command)
|
2003-04-14 07:54:33 +02:00
|
|
|
|
2004-04-28 08:30:55 +02:00
|
|
|
def author(self, irc, msg, args):
|
|
|
|
"""<plugin>
|
|
|
|
|
|
|
|
Returns the author of <plugin>. This is the person you should talk to
|
|
|
|
if you have ideas, suggestions, or other comments about a given plugin.
|
|
|
|
"""
|
|
|
|
plugin = privmsgs.getArgs(args)
|
|
|
|
cb = irc.getCallback(plugin)
|
|
|
|
if cb is None:
|
|
|
|
irc.error('That plugin does not seem to be loaded.')
|
|
|
|
return
|
|
|
|
module = sys.modules[cb.__class__.__module__]
|
|
|
|
if hasattr(module, '__author__') and module.__author__:
|
2004-04-30 20:24:35 +02:00
|
|
|
irc.reply(utils.mungeEmailForWeb(module.__author__))
|
2004-04-28 08:30:55 +02:00
|
|
|
else:
|
|
|
|
irc.reply('That plugin doesn\'t have an author that claims it.')
|
|
|
|
|
2003-09-07 06:05:34 +02:00
|
|
|
def more(self, irc, msg, args):
|
2003-09-07 08:42:17 +02:00
|
|
|
"""[<nick>]
|
2003-09-07 06:05:34 +02:00
|
|
|
|
|
|
|
If the last command was truncated due to IRC message length
|
|
|
|
limitations, returns the next chunk of the result of the last command.
|
2003-09-12 00:21:56 +02:00
|
|
|
If <nick> is given, it takes the continuation of the last command from
|
2003-09-07 08:42:17 +02:00
|
|
|
<nick> instead of the person sending this message.
|
2003-09-07 06:05:34 +02:00
|
|
|
"""
|
2003-11-11 14:20:06 +01:00
|
|
|
nick = privmsgs.getArgs(args, required=0, optional=1)
|
2003-09-07 08:48:42 +02:00
|
|
|
userHostmask = msg.prefix.split('!', 1)[1]
|
2003-09-07 08:42:17 +02:00
|
|
|
if nick:
|
|
|
|
try:
|
2003-09-22 15:07:20 +02:00
|
|
|
(private, L) = self._mores[nick]
|
|
|
|
if not private:
|
2003-09-08 21:43:33 +02:00
|
|
|
self._mores[userHostmask] = L[:]
|
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('%s has no public mores.' % nick)
|
2003-09-08 21:43:33 +02:00
|
|
|
return
|
2003-09-07 08:42:17 +02:00
|
|
|
except KeyError:
|
2004-07-08 02:22:35 +02:00
|
|
|
irc.error('Sorry, I can\'t find any mores for %s' % nick)
|
2003-09-07 08:42:17 +02:00
|
|
|
return
|
2003-09-07 06:05:34 +02:00
|
|
|
try:
|
2003-09-07 07:13:58 +02:00
|
|
|
L = self._mores[userHostmask]
|
|
|
|
chunk = L.pop()
|
|
|
|
if L:
|
|
|
|
chunk += ' \x02(%s)\x0F' % \
|
2003-12-12 16:41:33 +01:00
|
|
|
utils.nItems('message', len(L), 'more')
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(chunk, True)
|
2003-09-07 06:05:34 +02:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('You haven\'t asked me a command!')
|
2003-09-07 06:05:34 +02:00
|
|
|
except IndexError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That\'s all, there is no more.')
|
2003-09-07 06:05:34 +02:00
|
|
|
|
2003-09-17 10:07:24 +02:00
|
|
|
def _validLastMsg(self, msg):
|
|
|
|
return msg.prefix and \
|
|
|
|
msg.command == 'PRIVMSG' and \
|
|
|
|
ircutils.isChannel(msg.args[0])
|
|
|
|
|
2003-09-07 07:26:18 +02:00
|
|
|
def last(self, irc, msg, args):
|
2004-09-10 08:45:27 +02:00
|
|
|
"""[--{from,in,on,with,without,regexp,nolimit}] <args>
|
2003-09-07 07:26:18 +02:00
|
|
|
|
|
|
|
Returns the last message matching the given criteria. --from requires
|
2004-09-10 08:45:27 +02:00
|
|
|
a nick from whom the message came; --in requires a channel the message
|
2004-09-23 18:28:53 +02:00
|
|
|
was sent to; --on requires a network the message was sent on; --with
|
2004-09-10 08:45:27 +02:00
|
|
|
requires some string that had to be in the message; --regexp requires
|
|
|
|
a regular expression the message must i match; --nolimit returns all
|
|
|
|
the messages that can be found. By default, the current channel is
|
|
|
|
searched.
|
2003-09-07 07:26:18 +02:00
|
|
|
"""
|
2004-09-10 08:45:27 +02:00
|
|
|
(optlist, rest) = getopt.getopt(args, '', ['from=', 'in=', 'on=',
|
2004-06-28 21:09:25 +02:00
|
|
|
'with=', 'regexp=',
|
2004-08-24 22:22:12 +02:00
|
|
|
'without=', 'nolimit'])
|
2003-12-02 11:55:22 +01:00
|
|
|
predicates = {}
|
2004-06-28 21:09:25 +02:00
|
|
|
nolimit = False
|
2003-12-02 11:55:22 +01:00
|
|
|
if ircutils.isChannel(msg.args[0]):
|
2004-09-10 08:45:27 +02:00
|
|
|
predicates['in'] = lambda m: ircutils.strEqual(m.args[0],
|
|
|
|
msg.args[0])
|
2003-09-07 07:26:18 +02:00
|
|
|
for (option, arg) in optlist:
|
2003-11-15 04:21:34 +01:00
|
|
|
if option == '--from':
|
2003-12-02 11:55:22 +01:00
|
|
|
def f(m, arg=arg):
|
|
|
|
return ircutils.hostmaskPatternEqual(arg, m.nick)
|
|
|
|
predicates['from'] = f
|
2004-09-10 08:45:27 +02:00
|
|
|
elif option == '--in':
|
2003-12-02 11:55:22 +01:00
|
|
|
def f(m, arg=arg):
|
2004-09-10 08:45:27 +02:00
|
|
|
return ircutils.strEqual(m.args[0], arg)
|
2003-12-02 11:55:22 +01:00
|
|
|
predicates['in'] = f
|
2004-09-10 08:45:27 +02:00
|
|
|
elif option == '--on':
|
|
|
|
def f(m, arg=arg):
|
|
|
|
return m.receivedOn == arg
|
|
|
|
predicates['on'] = f
|
2003-11-15 04:21:34 +01:00
|
|
|
elif option == '--with':
|
2003-12-02 11:55:22 +01:00
|
|
|
def f(m, arg=arg):
|
2004-08-16 19:34:16 +02:00
|
|
|
return arg.lower() in m.args[1].lower()
|
2003-12-02 11:55:22 +01:00
|
|
|
predicates.setdefault('with', []).append(f)
|
2004-08-24 22:22:12 +02:00
|
|
|
elif option == '--without':
|
|
|
|
def f(m, arg=arg):
|
|
|
|
return arg.lower() not in m.args[1].lower()
|
|
|
|
predicates.setdefault('without', []).append(f)
|
2003-11-15 04:21:34 +01:00
|
|
|
elif option == '--regexp':
|
2003-09-07 07:26:18 +02:00
|
|
|
try:
|
|
|
|
r = utils.perlReToPythonRe(arg)
|
2003-12-02 11:55:22 +01:00
|
|
|
def f(m, r=r):
|
2004-03-25 13:08:01 +01:00
|
|
|
if ircmsgs.isAction(m):
|
|
|
|
return r.search(ircmsgs.unAction(m))
|
|
|
|
else:
|
|
|
|
return r.search(m.args[1])
|
2003-12-02 11:55:22 +01:00
|
|
|
predicates.setdefault('regexp', []).append(f)
|
2003-09-07 07:26:18 +02:00
|
|
|
except ValueError, e:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(str(e))
|
2003-09-07 07:26:18 +02:00
|
|
|
return
|
2004-06-28 21:09:25 +02:00
|
|
|
elif option == '--nolimit':
|
|
|
|
nolimit = True
|
2004-04-20 11:51:20 +02:00
|
|
|
iterable = ifilter(self._validLastMsg, reversed(irc.state.history))
|
2003-11-15 04:21:34 +01:00
|
|
|
iterable.next() # Drop the first message.
|
2003-12-02 11:55:22 +01:00
|
|
|
predicates = list(utils.flatten(predicates.itervalues()))
|
2004-06-28 21:09:25 +02:00
|
|
|
resp = []
|
2004-09-10 08:45:27 +02:00
|
|
|
tsf = self.registryValue('timestampFormat')
|
2003-11-15 04:21:34 +01:00
|
|
|
for m in iterable:
|
2003-09-07 07:26:18 +02:00
|
|
|
for predicate in predicates:
|
|
|
|
if not predicate(m):
|
|
|
|
break
|
|
|
|
else:
|
2004-06-28 21:09:25 +02:00
|
|
|
if nolimit:
|
2004-09-10 08:45:27 +02:00
|
|
|
resp.append(ircmsgs.prettyPrint(m, timestampFormat=tsf))
|
2004-06-28 21:09:25 +02:00
|
|
|
else:
|
2004-09-10 08:45:27 +02:00
|
|
|
irc.reply(ircmsgs.prettyPrint(m, timestampFormat=tsf))
|
2004-06-28 21:09:25 +02:00
|
|
|
return
|
|
|
|
if not resp:
|
|
|
|
irc.error('I couldn\'t find a message matching that criteria in '
|
|
|
|
'my history of %s messages.' % len(irc.state.history))
|
|
|
|
else:
|
|
|
|
irc.reply(utils.commaAndify(resp))
|
2003-09-07 07:26:18 +02:00
|
|
|
|
|
|
|
def tell(self, irc, msg, args):
|
2004-09-09 01:34:48 +02:00
|
|
|
"""<nick> <text>
|
2003-09-07 07:26:18 +02:00
|
|
|
|
2004-09-09 01:34:48 +02:00
|
|
|
Tells the <nick> whatever <text> is. Use nested commands to your
|
|
|
|
benefit here.
|
2003-09-07 07:26:18 +02:00
|
|
|
"""
|
2003-11-11 14:20:06 +01:00
|
|
|
(target, text) = privmsgs.getArgs(args, required=2)
|
2004-01-15 18:21:06 +01:00
|
|
|
if target.lower() == 'me':
|
|
|
|
target = msg.nick
|
2004-07-27 01:51:00 +02:00
|
|
|
elif ircutils.isChannel(target):
|
2004-04-30 04:21:17 +02:00
|
|
|
irc.error('Dude, just give the command. No need for the tell.')
|
|
|
|
return
|
2004-07-27 01:51:00 +02:00
|
|
|
elif not ircutils.isNick(target):
|
2004-09-09 01:34:48 +02:00
|
|
|
irc.errorInvalid('nick', target, Raise=True)
|
2004-07-27 01:51:00 +02:00
|
|
|
elif ircutils.nickEqual(target, irc.nick):
|
2004-09-09 01:34:48 +02:00
|
|
|
irc.error('You just told me, why should I tell myself?',Raise=True)
|
2004-08-16 23:36:48 +02:00
|
|
|
elif target not in irc.state.nicksToHostmasks and \
|
|
|
|
not ircdb.checkCapability(msg.prefix, 'owner'):
|
|
|
|
# We'll let owners do this.
|
2004-07-29 09:39:59 +02:00
|
|
|
s = 'I haven\'t seen %s, I\'ll let you do the telling.' % target
|
|
|
|
irc.error(s)
|
2004-07-27 01:51:00 +02:00
|
|
|
return
|
2004-02-02 00:04:19 +01:00
|
|
|
if irc.action:
|
|
|
|
irc.action = False
|
|
|
|
text = '* %s %s' % (irc.nick, text)
|
2003-09-07 07:26:18 +02:00
|
|
|
s = '%s wants me to tell you: %s' % (msg.nick, text)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(s, to=target, private=True)
|
2003-09-07 07:26:18 +02:00
|
|
|
|
2003-10-03 17:42:11 +02:00
|
|
|
def private(self, irc, msg, args):
|
|
|
|
"""<text>
|
|
|
|
|
|
|
|
Replies with <text> in private. Use nested commands to your benefit
|
|
|
|
here.
|
|
|
|
"""
|
|
|
|
text = privmsgs.getArgs(args)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(text, private=True)
|
2003-10-03 17:42:11 +02:00
|
|
|
|
2003-11-11 12:32:09 +01:00
|
|
|
def action(self, irc, msg, args):
|
2003-12-10 05:38:44 +01:00
|
|
|
"""<text>
|
2003-11-11 12:32:09 +01:00
|
|
|
|
2004-08-16 23:36:48 +02:00
|
|
|
Replies with <text> as an action. use nested commands to your benefit
|
|
|
|
here.
|
2003-11-11 12:32:09 +01:00
|
|
|
"""
|
2003-12-10 05:38:44 +01:00
|
|
|
text = privmsgs.getArgs(args)
|
|
|
|
if text:
|
2004-02-02 00:04:19 +01:00
|
|
|
irc.reply(text, action=True)
|
2003-12-10 05:38:44 +01:00
|
|
|
else:
|
2004-02-02 00:04:19 +01:00
|
|
|
raise callbacks.ArgumentError
|
2003-11-11 12:32:09 +01:00
|
|
|
|
2003-10-20 12:10:46 +02:00
|
|
|
def notice(self, irc, msg, args):
|
|
|
|
"""<text>
|
|
|
|
|
2004-04-09 17:30:55 +02:00
|
|
|
Replies with <text> in a notice. Use nested commands to your benefit
|
|
|
|
here. If you want a private notice, nest the private command.
|
2003-10-20 12:10:46 +02:00
|
|
|
"""
|
|
|
|
text = privmsgs.getArgs(args)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(text, notice=True)
|
2003-09-07 07:26:18 +02:00
|
|
|
|
2004-09-10 10:31:59 +02:00
|
|
|
def contributors(self, irc, msg, args):
|
2004-09-12 07:46:18 +02:00
|
|
|
"""<plugin> [<nick>]
|
2004-09-10 10:31:59 +02:00
|
|
|
|
|
|
|
Replies with a list of people who made contributions to a given plugin.
|
2004-09-12 07:46:18 +02:00
|
|
|
If <nick> is specified, that person's specific contributions will
|
|
|
|
be listed. Note: The <nick> is the part inside of the parentheses
|
|
|
|
in the people listing.
|
2004-09-10 10:31:59 +02:00
|
|
|
"""
|
2004-09-12 07:46:18 +02:00
|
|
|
(plugin, nick) = privmsgs.getArgs(args, required=1, optional=1)
|
|
|
|
nick = nick.lower()
|
2004-09-10 10:31:59 +02:00
|
|
|
def getShortName(authorInfo):
|
|
|
|
"""
|
|
|
|
Take an Authors object, and return only the name and nick values
|
2004-09-12 07:46:18 +02:00
|
|
|
in the format 'First Last (nick)'.
|
2004-09-10 10:31:59 +02:00
|
|
|
"""
|
|
|
|
return '%(name)s (%(nick)s)' % authorInfo.__dict__
|
|
|
|
def buildContributorsString(longList):
|
|
|
|
"""
|
|
|
|
Take a list of long names and turn it into :
|
2004-09-12 07:46:18 +02:00
|
|
|
shortname[, shortname and shortname].
|
2004-09-10 10:31:59 +02:00
|
|
|
"""
|
2004-09-12 07:46:18 +02:00
|
|
|
L = [getShortName(n) for n in longList]
|
|
|
|
return utils.commaAndify(L)
|
2004-09-10 10:31:59 +02:00
|
|
|
def sortAuthors():
|
|
|
|
"""
|
|
|
|
Sort the list of 'long names' based on the number of contributions
|
2004-09-12 07:46:18 +02:00
|
|
|
associated with each.
|
2004-09-10 10:31:59 +02:00
|
|
|
"""
|
|
|
|
L = module.__contributors__.items()
|
2004-09-12 07:46:18 +02:00
|
|
|
def negativeSecondElement(x):
|
2004-09-13 03:14:38 +02:00
|
|
|
return -len(x[1])
|
2004-09-12 07:46:18 +02:00
|
|
|
utils.sortBy(negativeSecondElement, L)
|
|
|
|
return [t[0] for t in L]
|
2004-09-10 10:31:59 +02:00
|
|
|
def buildPeopleString(module):
|
|
|
|
"""
|
|
|
|
Build the list of author + contributors (if any) for the requested
|
2004-09-12 07:46:18 +02:00
|
|
|
plugin.
|
2004-09-10 10:31:59 +02:00
|
|
|
"""
|
|
|
|
head = 'The %s plugin' % plugin
|
|
|
|
author = 'has not been claimed by an author'
|
|
|
|
conjunction = 'and'
|
|
|
|
contrib = 'has no contributors listed'
|
|
|
|
hasAuthor = False
|
|
|
|
hasContribs = False
|
2004-09-12 07:46:18 +02:00
|
|
|
if getattr(module, '__author__', None):
|
2004-09-10 10:31:59 +02:00
|
|
|
author = 'was written by %s' % \
|
|
|
|
utils.mungeEmailForWeb(str(module.__author__))
|
|
|
|
hasAuthor = True
|
2004-09-12 07:46:18 +02:00
|
|
|
if getattr(module, '__contributors__', None):
|
2004-09-10 10:31:59 +02:00
|
|
|
contribs = sortAuthors()
|
|
|
|
if hasAuthor:
|
|
|
|
try:
|
|
|
|
contribs.remove(module.__author__)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2004-09-10 10:52:03 +02:00
|
|
|
if contribs:
|
|
|
|
contrib = '%s %s contributed to it.' % \
|
|
|
|
(buildContributorsString(contribs),
|
|
|
|
utils.has(len(contribs)))
|
|
|
|
hasContribs = True
|
|
|
|
elif hasAuthor:
|
|
|
|
contrib = 'has no additional contributors listed'
|
2004-09-10 10:31:59 +02:00
|
|
|
if hasContribs and not hasAuthor:
|
2004-09-10 10:52:03 +02:00
|
|
|
conjunction = 'but'
|
2004-09-12 07:46:18 +02:00
|
|
|
return ' '.join([head, author, conjunction, contrib])
|
2004-09-10 10:31:59 +02:00
|
|
|
def buildPersonString(module):
|
|
|
|
"""
|
|
|
|
Build the list of contributions (if any) for the requested person
|
|
|
|
for the requested plugin
|
|
|
|
"""
|
|
|
|
isAuthor = False
|
2004-09-12 07:46:18 +02:00
|
|
|
authorInfo = getattr(supybot.authors, nick, None)
|
2004-09-10 10:31:59 +02:00
|
|
|
if not authorInfo:
|
2004-09-12 07:46:18 +02:00
|
|
|
return 'The nick specified (%s) is not a registered ' \
|
|
|
|
'contributor' % nick
|
2004-09-10 10:31:59 +02:00
|
|
|
fullName = utils.mungeEmailForWeb(str(authorInfo))
|
|
|
|
contributions = []
|
|
|
|
if hasattr(module, '__contributors__'):
|
|
|
|
if authorInfo not in module.__contributors__:
|
|
|
|
return 'The %s plugin does not have \'%s\' listed as a ' \
|
2004-09-12 07:46:18 +02:00
|
|
|
'contributor' % (plugin, nick)
|
2004-09-10 10:31:59 +02:00
|
|
|
contributions = module.__contributors__[authorInfo]
|
|
|
|
if getattr(module, '__author__', False) == authorInfo:
|
|
|
|
isAuthor = True
|
2004-09-12 07:46:18 +02:00
|
|
|
# XXX Partition needs moved to utils.
|
2004-09-13 09:11:54 +02:00
|
|
|
(nonCommands, commands) = fix.partition(lambda s: ' ' in s,
|
|
|
|
contributions)
|
2004-09-10 10:31:59 +02:00
|
|
|
results = []
|
2004-09-13 09:11:54 +02:00
|
|
|
if commands:
|
2004-09-10 10:31:59 +02:00
|
|
|
results.append(
|
2004-09-13 09:11:54 +02:00
|
|
|
'the %s %s' %(utils.commaAndify(commands),
|
|
|
|
utils.pluralize('command',len(commands))))
|
|
|
|
if nonCommands:
|
|
|
|
results.append('the %s' % utils.commaAndify(nonCommands))
|
2004-09-10 10:31:59 +02:00
|
|
|
if results and isAuthor:
|
2004-09-10 10:52:03 +02:00
|
|
|
return '%s wrote the %s plugin and also contributed %s' % \
|
2004-09-10 10:31:59 +02:00
|
|
|
(fullName, plugin, utils.commaAndify(results))
|
|
|
|
elif results and not isAuthor:
|
2004-09-10 10:52:03 +02:00
|
|
|
return '%s contributed %s to the %s plugin' % \
|
2004-09-10 10:31:59 +02:00
|
|
|
(fullName, utils.commaAndify(results), plugin)
|
|
|
|
elif isAuthor and not results:
|
2004-09-10 10:52:03 +02:00
|
|
|
return '%s wrote the %s plugin' % (fullName, plugin)
|
2004-09-10 10:31:59 +02:00
|
|
|
else:
|
2004-09-10 10:52:03 +02:00
|
|
|
return '%s has no listed contributions for the %s plugin %s' %\
|
2004-09-10 10:31:59 +02:00
|
|
|
(fullName, plugin)
|
|
|
|
# First we need to check and see if the requested plugin is loaded
|
|
|
|
cb = irc.getCallback(plugin)
|
|
|
|
if cb is None:
|
|
|
|
irc.error('No such plugin %r exists.' % plugin)
|
|
|
|
return
|
|
|
|
module = sys.modules[cb.__class__.__module__]
|
2004-09-12 07:46:18 +02:00
|
|
|
if not nick:
|
2004-09-10 10:31:59 +02:00
|
|
|
irc.reply(buildPeopleString(module))
|
|
|
|
else:
|
|
|
|
irc.reply(buildPersonString(module))
|
2003-03-27 07:34:48 +01:00
|
|
|
|
2003-10-21 08:03:57 +02:00
|
|
|
Class = Misc
|
2003-03-27 07:34:48 +01:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|