mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +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 utils
|
||||||
import plugins
|
import plugins
|
||||||
import privmsgs
|
import privmsgs
|
||||||
|
import registry
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite
|
import sqlite
|
||||||
@ -52,41 +52,29 @@ except ImportError:
|
|||||||
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
|
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
|
||||||
'plugin. Download it at <http://pysqlite.sf.net/>'
|
'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
|
conf.registerPlugin('Karma')
|
||||||
# afterConnect are both lists. Append to onStart the commands you would
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'simpleOutput',
|
||||||
# like to be run when the bot is started; append to afterConnect the
|
registry.Boolean(False, """Determines whether the bot will output shorter
|
||||||
# commands you would like to be run when the bot has finished connecting.
|
versions of the karma output when requesting a single thing's karma."""))
|
||||||
from questions import expect, anything, something, yn
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaResponse',
|
||||||
onStart.append('load Karma')
|
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,
|
class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||||
configurable.Mixin,
|
|
||||||
plugins.ChannelDBHandler):
|
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):
|
def __init__(self):
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
plugins.ChannelDBHandler.__init__(self)
|
plugins.ChannelDBHandler.__init__(self)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
configurable.Mixin.die(self)
|
|
||||||
plugins.ChannelDBHandler.die(self)
|
plugins.ChannelDBHandler.die(self)
|
||||||
|
|
||||||
def makeDb(self, filename):
|
def makeDb(self, filename):
|
||||||
@ -131,7 +119,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
|||||||
else:
|
else:
|
||||||
(added, subtracted) = imap(int, cursor.fetchone())
|
(added, subtracted) = imap(int, cursor.fetchone())
|
||||||
total = added - subtracted
|
total = added - subtracted
|
||||||
if self.configurables.get('simple-output', channel):
|
if self.registryValue('simpleOutput', channel):
|
||||||
s = '%s: %s' % (name, total)
|
s = '%s: %s' % (name, total)
|
||||||
else:
|
else:
|
||||||
s = 'Karma for %r has been increased %s ' \
|
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 '
|
irc.reply('I didn\'t know the karma for any '
|
||||||
'of those things.')
|
'of those things.')
|
||||||
else: # No name was given. Return the top/bottom N karmas.
|
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
|
cursor.execute("""SELECT name, added-subtracted
|
||||||
FROM karma
|
FROM karma
|
||||||
ORDER BY added-subtracted DESC
|
ORDER BY added-subtracted DESC
|
||||||
@ -204,7 +192,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
|||||||
orderby = 'added+subtracted'
|
orderby = 'added+subtracted'
|
||||||
sql = "SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s" % \
|
sql = "SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s" % \
|
||||||
(orderby, orderby,
|
(orderby, orderby,
|
||||||
self.configurables.get('karma-most-display', channel))
|
self.registryValue('karmaMostDisplay', channel))
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
@ -227,7 +215,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
|||||||
cursor.execute("""UPDATE karma
|
cursor.execute("""UPDATE karma
|
||||||
SET added=added+1
|
SET added=added+1
|
||||||
WHERE normalized=%s""", normalized)
|
WHERE normalized=%s""", normalized)
|
||||||
if self.configurables.get('karma-response', msg.args[0]):
|
if self.registryValue('karmaResponse', msg.args[0])
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
|
||||||
def decreaseKarma(self, irc, msg, match):
|
def decreaseKarma(self, irc, msg, match):
|
||||||
@ -241,7 +229,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
|||||||
cursor.execute("""UPDATE karma
|
cursor.execute("""UPDATE karma
|
||||||
SET subtracted=subtracted+1
|
SET subtracted=subtracted+1
|
||||||
WHERE normalized=%s""", normalized)
|
WHERE normalized=%s""", normalized)
|
||||||
if self.configurables.get('karma-response', msg.args[0]):
|
if self.registryValue('karmaResponse', msg.args[0]):
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,44 +56,31 @@ import utils
|
|||||||
import webutils
|
import webutils
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
|
import registry
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
L = [os.__file__]
|
L = [os.__file__]
|
||||||
if hasattr(math, '__file__'):
|
if hasattr(math, '__file__'):
|
||||||
L.append(math.__file__)
|
L.append(math.__file__)
|
||||||
pythonPath = map(os.path.dirname, L)
|
pythonPath = map(os.path.dirname, L)
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
def configure(onStart):
|
||||||
# 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
|
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;
|
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.
|
it will output the name of the Recipe when it sees such a URL.
|
||||||
Would you like to enable this snarfer?""") == 'y':
|
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, '_.')
|
modulechars = '%s%s%s' % (string.ascii_letters, string.digits, '_.')
|
||||||
regexps = ['aspnRecipes']
|
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):
|
def pydoc(self, irc, msg, args):
|
||||||
"""<python function>
|
"""<python function>
|
||||||
|
|
||||||
@ -188,7 +175,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
_bold = lambda self, g: (ircutils.bold(g[0]),) + g[1:]
|
_bold = lambda self, g: (ircutils.bold(g[0]),) + g[1:]
|
||||||
def aspnRecipes(self, irc, msg, match):
|
def aspnRecipes(self, irc, msg, match):
|
||||||
r"http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/\d+"
|
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
|
return
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
s = webutils.getUrl(url)
|
s = webutils.getUrl(url)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user