mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Updated to use the registry.
This commit is contained in:
parent
ca094203f5
commit
0627cb9c1c
@ -43,8 +43,8 @@ import conf
|
||||
import utils
|
||||
import plugins
|
||||
import privmsgs
|
||||
import registry
|
||||
import callbacks
|
||||
import configurable
|
||||
|
||||
try:
|
||||
import sqlite
|
||||
@ -52,41 +52,29 @@ except ImportError:
|
||||
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
|
||||
'plugin. Download it at <http://pysqlite.sf.net/>'
|
||||
|
||||
def configure(onStart, afterConnect, advanced):
|
||||
# This will be called by setup.py to configure this module. onStart and
|
||||
# afterConnect are both lists. Append to onStart the commands you would
|
||||
# like to be run when the bot is started; append to afterConnect the
|
||||
# commands you would like to be run when the bot has finished connecting.
|
||||
from questions import expect, anything, something, yn
|
||||
onStart.append('load Karma')
|
||||
|
||||
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."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaResponse',
|
||||
registry.Boolean(False, """Determines whether the bot will reply with a
|
||||
success message when something's karma is incrneased or decreased."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaRankingDisplay',
|
||||
registry.Integer(3, """Determines how many highest/lowest karma things are
|
||||
shown when karma is called with no arguments."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaMostDisplay',
|
||||
registry.Integer(25, """Determines how many karma things are shown when
|
||||
the most command is called.'"""))
|
||||
|
||||
class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
configurable.Mixin,
|
||||
plugins.ChannelDBHandler):
|
||||
addressedRegexps = ['increaseKarma', 'decreaseKarma']
|
||||
configurables = configurable.Dictionary(
|
||||
[('simple-output', configurable.BoolType, False,
|
||||
"""Determines whether the bot will output shorter versions of the
|
||||
karma output when requesting a single thing's karma. (example: 'foo:
|
||||
1')"""),
|
||||
('karma-response', configurable.BoolType, False,
|
||||
"""Determines whether the bot will reply with a success message when
|
||||
something's karma is increased or decreased."""),
|
||||
('karma-ranking-display', configurable.IntType, 3,
|
||||
"""Determines how many highest/lowest karma things are shown when
|
||||
karma is called with no arguments."""),
|
||||
('karma-most-display', configurable.IntType, 25,
|
||||
"""Determines how many karma things are shown when karma most is
|
||||
called."""),]
|
||||
)
|
||||
def __init__(self):
|
||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||
configurable.Mixin.__init__(self)
|
||||
plugins.ChannelDBHandler.__init__(self)
|
||||
|
||||
def die(self):
|
||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||
configurable.Mixin.die(self)
|
||||
plugins.ChannelDBHandler.die(self)
|
||||
|
||||
def makeDb(self, filename):
|
||||
@ -131,7 +119,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
else:
|
||||
(added, subtracted) = imap(int, cursor.fetchone())
|
||||
total = added - subtracted
|
||||
if self.configurables.get('simple-output', channel):
|
||||
if self.registryValue('simpleOutput', channel):
|
||||
s = '%s: %s' % (name, total)
|
||||
else:
|
||||
s = 'Karma for %r has been increased %s ' \
|
||||
@ -166,7 +154,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
irc.reply('I didn\'t know the karma for any '
|
||||
'of those things.')
|
||||
else: # No name was given. Return the top/bottom N karmas.
|
||||
limit = self.configurables.get('karma-ranking-display', channel)
|
||||
limit = self.registryValue('karmaRankingDisplay', channel)
|
||||
cursor.execute("""SELECT name, added-subtracted
|
||||
FROM karma
|
||||
ORDER BY added-subtracted DESC
|
||||
@ -204,7 +192,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
orderby = 'added+subtracted'
|
||||
sql = "SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s" % \
|
||||
(orderby, orderby,
|
||||
self.configurables.get('karma-most-display', channel))
|
||||
self.registryValue('karmaMostDisplay', channel))
|
||||
db = self.getDb(channel)
|
||||
cursor = db.cursor()
|
||||
cursor.execute(sql)
|
||||
@ -227,7 +215,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
cursor.execute("""UPDATE karma
|
||||
SET added=added+1
|
||||
WHERE normalized=%s""", normalized)
|
||||
if self.configurables.get('karma-response', msg.args[0]):
|
||||
if self.registryValue('karmaResponse', msg.args[0])
|
||||
irc.replySuccess()
|
||||
|
||||
def decreaseKarma(self, irc, msg, match):
|
||||
@ -241,7 +229,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
cursor.execute("""UPDATE karma
|
||||
SET subtracted=subtracted+1
|
||||
WHERE normalized=%s""", normalized)
|
||||
if self.configurables.get('karma-response', msg.args[0]):
|
||||
if self.registryValue('karmaResponse', msg.args[0]):
|
||||
irc.replySuccess()
|
||||
|
||||
|
||||
|
@ -56,44 +56,31 @@ import utils
|
||||
import webutils
|
||||
import ircutils
|
||||
import privmsgs
|
||||
import registry
|
||||
import callbacks
|
||||
import configurable
|
||||
|
||||
L = [os.__file__]
|
||||
if hasattr(math, '__file__'):
|
||||
L.append(math.__file__)
|
||||
pythonPath = map(os.path.dirname, L)
|
||||
|
||||
def configure(onStart, afterConnect, advanced):
|
||||
# This will be called by setup.py to configure this module. onStart and
|
||||
# afterConnect are both lists. Append to onStart the commands you would
|
||||
# like to be run when the bot is started; append to afterConnect the
|
||||
# commands you would like to be run when the bot has finished connecting.
|
||||
def configure(onStart):
|
||||
from questions import expect, anything, something, yn
|
||||
onStart.append('load Python')
|
||||
conf.registerPlugin('Python', True)
|
||||
if yn("""This plugin provides a snarfer for ASPN Python Recipe URLs;
|
||||
it will output the name of the Recipe when it sees such a URL.
|
||||
Would you like to enable this snarfer?""") == 'y':
|
||||
onStart.append('python config aspn-snarfer on')
|
||||
conf.supybot.plugins.Python.aspnSnarfer.setValue(True)
|
||||
|
||||
class Python(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||
conf.registerPlugin('Python')
|
||||
conf.registerChannelValue(conf.supybot.plugins.Python, 'aspnSnarfer',
|
||||
registry.Boolean(False, """Determines whether the ASPN Python recipe
|
||||
snarfer is enabled. If so, it will message the channel with the name of
|
||||
the recipe when it see an ASPN Python recipe link on the channel."""))
|
||||
|
||||
class Python(callbacks.PrivmsgCommandAndRegexp):
|
||||
modulechars = '%s%s%s' % (string.ascii_letters, string.digits, '_.')
|
||||
regexps = ['aspnRecipes']
|
||||
configurables = configurable.Dictionary(
|
||||
[('aspn-snarfer', configurable.BoolType, False,
|
||||
"""Determines whether the ASPN Python recipe snarfer is enabled. If
|
||||
so, it will message the channel with the name of the recipe when it
|
||||
sees an ASPN Python recipe link on the channel.""")]
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
configurable.Mixin.__init__(self)
|
||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||
|
||||
def die(self):
|
||||
configurable.Mixin.die(self)
|
||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||
|
||||
def pydoc(self, irc, msg, args):
|
||||
"""<python function>
|
||||
|
||||
@ -188,7 +175,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||
_bold = lambda self, g: (ircutils.bold(g[0]),) + g[1:]
|
||||
def aspnRecipes(self, irc, msg, match):
|
||||
r"http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/\d+"
|
||||
if not self.configurables.get('aspn-snarfer', channel=msg.args[0]):
|
||||
if not self.registryValue('aspnSnarfer', msg.args[0]):
|
||||
return
|
||||
url = match.group(0)
|
||||
s = webutils.getUrl(url)
|
||||
|
Loading…
Reference in New Issue
Block a user