2003-11-04 09:42:11 +01:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-11-04 09:42:11 +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.
|
|
|
|
###
|
|
|
|
|
|
|
|
"""
|
2003-12-02 00:47:37 +01:00
|
|
|
Plugin for handling Karma stuff for a channel.
|
2003-11-04 09:42:11 +01:00
|
|
|
"""
|
|
|
|
|
2004-09-11 22:25:07 +02:00
|
|
|
import supybot
|
|
|
|
|
2003-12-02 00:47:37 +01:00
|
|
|
__revision__ = "$Id$"
|
2004-09-10 17:59:38 +02:00
|
|
|
__contributors__ = {
|
2004-09-13 02:40:25 +02:00
|
|
|
supybot.authors.jamessan: ['allowUnaddressedKarma configuration variable'],
|
2004-09-10 17:59:38 +02:00
|
|
|
}
|
2003-12-02 00:47:37 +01:00
|
|
|
|
2003-11-04 09:42:11 +01:00
|
|
|
import os
|
2004-12-06 08:23:56 +01:00
|
|
|
import csv
|
2003-11-21 13:31:51 +01:00
|
|
|
import sets
|
2003-11-15 05:37:04 +01:00
|
|
|
from itertools import imap
|
2003-11-04 09:42:11 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
2004-10-27 01:22:02 +02:00
|
|
|
from supybot.commands import *
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.plugins as plugins
|
2004-09-10 17:59:38 +02:00
|
|
|
import supybot.ircmsgs as ircmsgs
|
2004-08-12 01:31:18 +02:00
|
|
|
import supybot.ircutils as ircutils
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.registry as registry
|
|
|
|
import supybot.callbacks as callbacks
|
2003-11-04 09:42:11 +01:00
|
|
|
|
2004-01-27 16:28:00 +01:00
|
|
|
conf.registerPlugin('Karma')
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'simpleOutput',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will output shorter
|
|
|
|
versions of the karma output when requesting a single thing's karma."""))
|
2004-01-31 22:56:39 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'response',
|
2004-01-27 16:28:00 +01:00
|
|
|
registry.Boolean(False, """Determines whether the bot will reply with a
|
2004-08-19 01:15:27 +02:00
|
|
|
success message when something's karma is increased or decreased."""))
|
2004-01-31 22:56:39 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'rankingDisplay',
|
2004-01-27 16:28:00 +01:00
|
|
|
registry.Integer(3, """Determines how many highest/lowest karma things are
|
|
|
|
shown when karma is called with no arguments."""))
|
2004-01-31 22:56:39 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'mostDisplay',
|
2004-01-27 16:28:00 +01:00
|
|
|
registry.Integer(25, """Determines how many karma things are shown when
|
|
|
|
the most command is called.'"""))
|
2004-07-07 20:10:00 +02:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'allowSelfRating',
|
|
|
|
registry.Boolean(False, """Determines whether users can adjust the karma
|
|
|
|
of their nick."""))
|
2004-09-10 17:59:38 +02:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'allowUnaddressedKarma',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will
|
|
|
|
increase/decrease karma without being addressed."""))
|
2003-11-04 09:42:11 +01:00
|
|
|
|
2004-08-12 01:28:45 +02:00
|
|
|
class SqliteKarmaDB(object):
|
2004-09-17 05:01:21 +02:00
|
|
|
def __init__(self, filename):
|
|
|
|
self.dbs = ircutils.IrcDict()
|
|
|
|
self.filename = filename
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
for db in self.dbs.itervalues():
|
|
|
|
db.close()
|
|
|
|
|
2004-08-12 01:28:45 +02:00
|
|
|
def _getDb(self, channel):
|
2004-09-17 05:01:21 +02:00
|
|
|
try:
|
|
|
|
import sqlite
|
|
|
|
except ImportError:
|
|
|
|
raise callbacks.Error, 'You need to have PySQLite installed to ' \
|
|
|
|
'use this plugin. Download it at ' \
|
|
|
|
'<http://pysqlite.sf.net/>'
|
|
|
|
filename = plugins.makeChannelFilename(self.filename, channel)
|
|
|
|
if filename in self.dbs:
|
|
|
|
return self.dbs[filename]
|
2003-11-04 09:42:11 +01:00
|
|
|
if os.path.exists(filename):
|
2004-09-17 05:01:21 +02:00
|
|
|
self.dbs[filename] = sqlite.connect(filename)
|
|
|
|
return self.dbs[filename]
|
|
|
|
db = sqlite.connect(filename)
|
|
|
|
self.dbs[filename] = db
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""CREATE TABLE karma (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT,
|
|
|
|
normalized TEXT UNIQUE ON CONFLICT IGNORE,
|
|
|
|
added INTEGER,
|
|
|
|
subtracted INTEGER
|
|
|
|
)""")
|
|
|
|
db.commit()
|
2003-11-04 09:42:11 +01:00
|
|
|
def p(s1, s2):
|
|
|
|
return int(ircutils.nickEqual(s1, s2))
|
|
|
|
db.create_function('nickeq', 2, p)
|
|
|
|
return db
|
|
|
|
|
2004-08-12 01:28:45 +02:00
|
|
|
def get(self, channel, thing):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
thing = thing.lower()
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT added, subtracted FROM karma
|
|
|
|
WHERE normalized=%s""", thing)
|
|
|
|
if cursor.rowcount == 0:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return map(int, cursor.fetchone())
|
|
|
|
|
|
|
|
def gets(self, channel, things):
|
|
|
|
db = self._getDb(channel)
|
2004-08-12 01:40:56 +02:00
|
|
|
cursor = db.cursor()
|
2004-08-12 01:28:45 +02:00
|
|
|
normalizedThings = dict(zip(map(str.lower, things), things))
|
|
|
|
criteria = ' OR '.join(['normalized=%s'] * len(normalizedThings))
|
|
|
|
sql = """SELECT name, added-subtracted FROM karma
|
|
|
|
WHERE %s ORDER BY added-subtracted DESC""" % criteria
|
|
|
|
cursor.execute(sql, *normalizedThings)
|
|
|
|
L = [(name, int(karma)) for (name, karma) in cursor.fetchall()]
|
|
|
|
for (name, _) in L:
|
|
|
|
del normalizedThings[name.lower()]
|
|
|
|
neutrals = normalizedThings.values()
|
|
|
|
neutrals.sort()
|
|
|
|
return (L, neutrals)
|
|
|
|
|
|
|
|
def top(self, channel, limit):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT name, added-subtracted FROM karma
|
|
|
|
ORDER BY added-subtracted DESC LIMIT %s""", limit)
|
|
|
|
return [(t[0], int(t[1])) for t in cursor.fetchall()]
|
|
|
|
|
|
|
|
def bottom(self, channel, limit):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT name, added-subtracted FROM karma
|
|
|
|
ORDER BY added-subtracted ASC LIMIT %s""", limit)
|
|
|
|
return [(t[0], int(t[1])) for t in cursor.fetchall()]
|
2004-09-07 22:28:24 +02:00
|
|
|
|
2004-08-12 01:28:45 +02:00
|
|
|
def rank(self, channel, thing):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT added-subtracted FROM karma
|
|
|
|
WHERE name=%s""", thing)
|
|
|
|
if cursor.rowcount == 0:
|
|
|
|
return None
|
|
|
|
karma = int(cursor.fetchone()[0])
|
|
|
|
cursor.execute("""SELECT COUNT(*) FROM karma
|
|
|
|
WHERE added-subtracted > %s""", karma)
|
|
|
|
rank = int(cursor.fetchone()[0])
|
|
|
|
return rank
|
|
|
|
|
|
|
|
def size(self, channel):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT COUNT(*) FROM karma""")
|
|
|
|
return int(cursor.fetchone()[0])
|
2004-09-07 22:28:24 +02:00
|
|
|
|
2004-08-12 01:28:45 +02:00
|
|
|
def increment(self, channel, name):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
normalized = name.lower()
|
|
|
|
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
|
|
|
|
name, normalized)
|
|
|
|
cursor.execute("""UPDATE karma SET added=added+1
|
|
|
|
WHERE normalized=%s""", normalized)
|
|
|
|
db.commit()
|
2004-09-07 22:28:24 +02:00
|
|
|
|
2004-08-12 01:35:11 +02:00
|
|
|
def decrement(self, channel, name):
|
2004-08-12 01:28:45 +02:00
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
normalized = name.lower()
|
|
|
|
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
|
|
|
|
name, normalized)
|
|
|
|
cursor.execute("""UPDATE karma SET subtracted=subtracted+1
|
|
|
|
WHERE normalized=%s""", normalized)
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
def most(self, channel, kind, limit):
|
|
|
|
if kind == 'increased':
|
|
|
|
orderby = 'added'
|
|
|
|
elif kind == 'decreased':
|
|
|
|
orderby = 'subtracted'
|
|
|
|
elif kind == 'active':
|
|
|
|
orderby = 'added+subtracted'
|
|
|
|
else:
|
|
|
|
raise ValueError, 'invalid kind'
|
|
|
|
sql = """SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s""" % \
|
|
|
|
(orderby, orderby, limit)
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute(sql)
|
|
|
|
return [(name, int(i)) for (name, i) in cursor.fetchall()]
|
2004-08-27 17:26:52 +02:00
|
|
|
|
|
|
|
def clear(self, channel, name):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
normalized = name.lower()
|
|
|
|
cursor.execute("""UPDATE karma SET subtracted=0, added=0
|
|
|
|
WHERE normalized=%s""", normalized)
|
|
|
|
db.commit()
|
2004-09-07 22:28:24 +02:00
|
|
|
|
2004-12-06 08:23:56 +01:00
|
|
|
def dump(self, channel, filename):
|
|
|
|
filename = conf.supybot.directories.data.dirize(filename)
|
|
|
|
fd = utils.transactionalFile(filename)
|
|
|
|
out = csv.writer(fd)
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT name, added, subtracted FROM karma""")
|
|
|
|
for (name, added, subtracted) in cursor.fetchall():
|
|
|
|
out.writerow([name, added, subtracted])
|
|
|
|
fd.close()
|
|
|
|
|
|
|
|
def load(self, channel, filename):
|
|
|
|
filename = conf.supybot.directories.data.dirize(filename)
|
|
|
|
fd = file(filename)
|
|
|
|
reader = csv.reader(fd)
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""DELETE FROM karma""")
|
|
|
|
for (name, added, subtracted) in reader:
|
|
|
|
normalized = name.lower()
|
|
|
|
cursor.execute("""INSERT INTO karma
|
|
|
|
VALUES (NULL, %s, %s, %s, %s)""",
|
|
|
|
name, normalized, added, subtracted)
|
|
|
|
db.commit()
|
|
|
|
fd.close()
|
|
|
|
|
2004-09-17 05:01:21 +02:00
|
|
|
KarmaDB = plugins.DB('Karma',
|
|
|
|
{'sqlite': SqliteKarmaDB})
|
2004-09-07 22:28:24 +02:00
|
|
|
|
2004-09-16 13:36:24 +02:00
|
|
|
class Karma(callbacks.Privmsg):
|
2004-09-16 23:01:38 +02:00
|
|
|
callBefore = ('Factoids', 'MoobotFactoids', 'Infobot')
|
2004-08-12 01:28:45 +02:00
|
|
|
def __init__(self):
|
2004-09-20 01:51:21 +02:00
|
|
|
self.__parent = super(Karma, self)
|
|
|
|
self.__parent.__init__()
|
2004-09-17 06:21:32 +02:00
|
|
|
self.db = KarmaDB()
|
2004-08-12 01:28:45 +02:00
|
|
|
|
2004-09-17 05:01:21 +02:00
|
|
|
def die(self):
|
2004-09-20 01:51:21 +02:00
|
|
|
self.__parent.die()
|
2004-09-17 05:01:21 +02:00
|
|
|
self.db.close()
|
|
|
|
|
2004-09-16 13:36:24 +02:00
|
|
|
def _normalizeThing(self, thing):
|
|
|
|
assert thing
|
|
|
|
if thing[0] == '(' and thing[-1] == ')':
|
|
|
|
thing = thing[1:-1]
|
|
|
|
return thing
|
2004-09-17 05:01:21 +02:00
|
|
|
|
2004-09-16 13:36:24 +02:00
|
|
|
def _respond(self, irc, channel):
|
|
|
|
if self.registryValue('response', channel):
|
|
|
|
irc.replySuccess()
|
|
|
|
else:
|
|
|
|
irc.noReply()
|
2004-09-16 16:37:08 +02:00
|
|
|
assert irc.msg.repliedTo
|
2004-09-17 05:01:21 +02:00
|
|
|
|
2004-09-16 13:36:24 +02:00
|
|
|
def _doKarma(self, irc, channel, thing):
|
|
|
|
assert thing[-2:] in ('++', '--')
|
|
|
|
if thing.endswith('++'):
|
|
|
|
thing = thing[:-2]
|
|
|
|
if ircutils.strEqual(thing, irc.msg.nick) and \
|
|
|
|
not self.registryValue('allowSelfRating', channel):
|
|
|
|
irc.error('You\'re not allowed to adjust your own karma.')
|
|
|
|
elif thing:
|
|
|
|
self.db.increment(channel, self._normalizeThing(thing))
|
|
|
|
self._respond(irc, channel)
|
|
|
|
else:
|
|
|
|
thing = thing[:-2]
|
|
|
|
if ircutils.strEqual(thing, irc.msg.nick) and \
|
|
|
|
not self.registryValue('allowSelfRating', channel):
|
|
|
|
irc.error('You\'re not allowed to adjust your own karma.')
|
|
|
|
elif thing:
|
|
|
|
self.db.decrement(channel, self._normalizeThing(thing))
|
|
|
|
self._respond(irc, channel)
|
2004-09-17 05:01:21 +02:00
|
|
|
|
2004-09-16 13:36:24 +02:00
|
|
|
def tokenizedCommand(self, irc, msg, tokens):
|
|
|
|
channel = msg.args[0]
|
|
|
|
if not ircutils.isChannel(channel):
|
|
|
|
return
|
|
|
|
if tokens[-1][-2:] in ('++', '--'):
|
|
|
|
thing = ' '.join(tokens)
|
|
|
|
self._doKarma(irc, channel, thing)
|
|
|
|
|
|
|
|
def doPrivmsg(self, irc, msg):
|
|
|
|
if not msg.repliedTo:
|
|
|
|
channel = msg.args[0]
|
|
|
|
if ircutils.isChannel(channel) and \
|
|
|
|
self.registryValue('allowUnaddressedKarma', channel):
|
|
|
|
irc = callbacks.SimpleProxy(irc, msg)
|
|
|
|
thing = msg.args[1].rstrip()
|
|
|
|
if thing[-2:] in ('++', '--'):
|
|
|
|
self._doKarma(irc, channel, thing)
|
2004-09-17 05:01:21 +02:00
|
|
|
|
2004-10-27 01:22:02 +02:00
|
|
|
def karma(self, irc, msg, args, channel, things):
|
2004-11-04 02:24:31 +01:00
|
|
|
"""[<channel>] [<thing> ...]
|
2003-11-04 09:42:11 +01:00
|
|
|
|
2003-11-21 13:31:51 +01:00
|
|
|
Returns the karma of <text>. If <thing> is not given, returns the top
|
|
|
|
three and bottom three karmas. If one <thing> is given, returns the
|
|
|
|
details of its karma; if more than one <thing> is given, returns the
|
|
|
|
total karma of each of the the things. <channel> is only necessary if
|
|
|
|
the message isn't sent on the channel itself.
|
2003-11-04 09:42:11 +01:00
|
|
|
"""
|
2004-10-27 01:22:02 +02:00
|
|
|
if len(things) == 1:
|
|
|
|
name = things[0]
|
2004-08-12 01:28:45 +02:00
|
|
|
t = self.db.get(channel, name)
|
|
|
|
if t is None:
|
2004-08-01 16:38:37 +02:00
|
|
|
irc.reply('%s has neutral karma.' % name)
|
2003-11-04 09:42:11 +01:00
|
|
|
else:
|
2004-08-12 01:28:45 +02:00
|
|
|
(added, subtracted) = t
|
2003-11-04 09:42:11 +01:00
|
|
|
total = added - subtracted
|
2004-01-27 16:28:00 +01:00
|
|
|
if self.registryValue('simpleOutput', channel):
|
2003-11-26 18:07:20 +01:00
|
|
|
s = '%s: %s' % (name, total)
|
|
|
|
else:
|
2004-10-24 00:07:50 +02:00
|
|
|
s = 'Karma for %s has been increased %s ' \
|
2003-12-12 16:41:33 +01:00
|
|
|
'and decreased %s for a total karma of %s.' % \
|
2004-10-24 00:07:50 +02:00
|
|
|
(utils.quoted(name), utils.nItems('time', added),
|
2003-12-12 16:41:33 +01:00
|
|
|
utils.nItems('time', subtracted), total)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(s)
|
2004-10-27 01:22:02 +02:00
|
|
|
elif len(things) > 1:
|
|
|
|
(L, neutrals) = self.db.gets(channel, things)
|
2004-08-12 01:28:45 +02:00
|
|
|
if L:
|
|
|
|
s = utils.commaAndify(['%s: %s' % t for t in L])
|
|
|
|
if neutrals:
|
|
|
|
neutral = '. %s %s neutral karma' % \
|
|
|
|
(utils.commaAndify(neutrals),
|
|
|
|
utils.has(len(neutrals)))
|
|
|
|
s += neutral
|
|
|
|
irc.reply(s + '.')
|
2003-11-04 09:42:11 +01:00
|
|
|
else:
|
2004-08-12 01:28:45 +02:00
|
|
|
irc.reply('I didn\'t know the karma for any of those things.')
|
2003-12-29 04:12:47 +01:00
|
|
|
else: # No name was given. Return the top/bottom N karmas.
|
2004-01-31 22:56:39 +01:00
|
|
|
limit = self.registryValue('rankingDisplay', channel)
|
2004-08-12 01:28:45 +02:00
|
|
|
top = self.db.top(channel, limit)
|
2004-10-24 00:07:50 +02:00
|
|
|
highest = ['%s (%s)' % (utils.quoted(s), t)
|
|
|
|
for (s, t) in self.db.top(channel, limit)]
|
|
|
|
lowest = ['%s (%s)' % (utils.quoted(s), t)
|
|
|
|
for (s, t) in self.db.bottom(channel, limit)]
|
2003-11-04 10:09:53 +01:00
|
|
|
if not (highest and lowest):
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('I have no karma for this channel.')
|
2004-02-07 12:23:02 +01:00
|
|
|
return
|
2004-08-12 01:28:45 +02:00
|
|
|
rank = self.db.rank(channel, msg.nick)
|
|
|
|
if rank is not None:
|
|
|
|
total = self.db.size(channel)
|
2004-02-07 12:23:02 +01:00
|
|
|
rankS = ' You (%s) are ranked %s out of %s.' % \
|
|
|
|
(msg.nick, rank, total)
|
2004-08-12 01:28:45 +02:00
|
|
|
else:
|
|
|
|
rankS = ''
|
2004-02-07 12:23:02 +01:00
|
|
|
s = 'Highest karma: %s. Lowest karma: %s.%s' % \
|
|
|
|
(utils.commaAndify(highest), utils.commaAndify(lowest), rankS)
|
|
|
|
irc.reply(s)
|
2004-11-04 02:24:31 +01:00
|
|
|
karma = wrap(karma, ['channel', any('something')])
|
2003-12-02 00:47:37 +01:00
|
|
|
|
|
|
|
_mostAbbrev = utils.abbrev(['increased', 'decreased', 'active'])
|
2004-10-27 01:22:02 +02:00
|
|
|
def most(self, irc, msg, args, channel, kind):
|
2003-12-02 00:47:37 +01:00
|
|
|
"""[<channel>] {increased,decreased,active}
|
|
|
|
|
|
|
|
Returns the most increased, the most decreased, or the most active
|
|
|
|
(the sum of increased and decreased) karma things. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
2004-10-27 01:22:02 +02:00
|
|
|
L = self.db.most(channel, kind,
|
|
|
|
self.registryValue('mostDisplay', channel))
|
|
|
|
if L:
|
|
|
|
L = ['%s: %s' % (utils.quoted(name), i) for (name, i) in L]
|
|
|
|
irc.reply(utils.commaAndify(L))
|
|
|
|
else:
|
|
|
|
irc.error('I have no karma for this channel.')
|
|
|
|
most = wrap(most, ['channel',
|
|
|
|
('literal', ['increased', 'decreased', 'active'])])
|
2004-07-07 20:10:00 +02:00
|
|
|
|
2004-10-27 01:22:02 +02:00
|
|
|
def clear(self, irc, msg, args, channel, name):
|
2004-08-27 17:26:52 +02:00
|
|
|
"""[<channel>] <name>
|
|
|
|
|
|
|
|
Resets the karma of <name> to 0.
|
|
|
|
"""
|
|
|
|
self.db.clear(channel, name)
|
2004-08-27 18:05:07 +02:00
|
|
|
irc.replySuccess()
|
2004-10-27 01:22:02 +02:00
|
|
|
clear = wrap(clear, [('checkChannelCapability', 'op'), 'text'])
|
2004-08-27 17:26:52 +02:00
|
|
|
|
2004-09-10 17:59:38 +02:00
|
|
|
def getName(self, nick, msg, match):
|
|
|
|
addressed = callbacks.addressed(nick, msg)
|
|
|
|
name = callbacks.addressed(nick,
|
|
|
|
ircmsgs.IrcMsg(prefix='',
|
|
|
|
args=(msg.args[0], match.group(1)),
|
|
|
|
msg=msg))
|
|
|
|
if not name:
|
|
|
|
name = match.group(1)
|
|
|
|
if not addressed:
|
|
|
|
if not self.registryValue('allowUnaddressedKarma'):
|
|
|
|
return ''
|
|
|
|
if not msg.args[1].startswith(match.group(1)):
|
|
|
|
return ''
|
|
|
|
name = match.group(1)
|
|
|
|
elif addressed:
|
|
|
|
if not addressed.startswith(name):
|
|
|
|
return ''
|
|
|
|
name = name.strip('()')
|
|
|
|
return name
|
|
|
|
|
2004-12-06 08:23:56 +01:00
|
|
|
def dump(self, irc, msg, args, channel, filename):
|
|
|
|
"""[<channel>] <filename>
|
|
|
|
|
|
|
|
Dumps the Karma database for <channel> to <filename> in the bot's
|
|
|
|
data directory. <channel> is only necessary if the message isn't sent
|
|
|
|
in the channel itself.
|
|
|
|
"""
|
|
|
|
self.db.dump(channel, filename)
|
|
|
|
irc.replySuccess()
|
|
|
|
dump = wrap(dump, [('checkCapability', 'owner'), 'channeldb', 'filename'])
|
|
|
|
|
|
|
|
def load(self, irc, msg, args, channel, filename):
|
|
|
|
"""[<channel>] <filename>
|
|
|
|
|
|
|
|
Loads the Karma database for <channel> from <filename> in the bot's
|
|
|
|
data directory. <channel> is only necessary if the message isn't sent
|
|
|
|
in the channel itself.
|
|
|
|
"""
|
|
|
|
self.db.load(channel, filename)
|
|
|
|
irc.replySuccess()
|
|
|
|
load = wrap(load, [('checkCapability', 'owner'), 'channeldb', 'filename'])
|
2003-11-04 09:42:11 +01:00
|
|
|
|
|
|
|
Class = Karma
|
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|