mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Made Karma a configurable, added the 'simple-output' option to forego all the
'increased/decreased' output when requesting something's karma and to just return the name and the total karma.
This commit is contained in:
parent
8dc24b2d50
commit
89857d9bd8
@ -55,11 +55,24 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
from questions import expect, anything, something, yn
|
from questions import expect, anything, something, yn
|
||||||
onStart.append('load Karma')
|
onStart.append('load Karma')
|
||||||
|
|
||||||
class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||||
|
plugins.Configurable,
|
||||||
|
plugins.ChannelDBHandler):
|
||||||
addressedRegexps = ['increaseKarma', 'decreaseKarma']
|
addressedRegexps = ['increaseKarma', 'decreaseKarma']
|
||||||
|
configurables = plugins.ConfigurableDictionary(
|
||||||
|
[('simple-output', plugins.ConfigurableBoolType, False,
|
||||||
|
"""Determines whether the bot will output shorter versions of URLs
|
||||||
|
longer than the tinyurl-minimum-length config variable.""")]
|
||||||
|
)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
plugins.ChannelDBHandler.__init__(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
|
plugins.Configurable.__init__(self)
|
||||||
|
plugins.ChannelDBHandler.__init__(self)
|
||||||
|
|
||||||
|
def die(self):
|
||||||
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
|
plugins.Configurable.die(self)
|
||||||
|
plugins.ChannelDBHandler.die(self)
|
||||||
|
|
||||||
def makeDb(self, filename):
|
def makeDb(self, filename):
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
@ -103,10 +116,14 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
|||||||
else:
|
else:
|
||||||
(added, subtracted) = imap(int, cursor.fetchone())
|
(added, subtracted) = imap(int, cursor.fetchone())
|
||||||
total = added - subtracted
|
total = added - subtracted
|
||||||
s = 'Karma for %r has been increased %s %s ' \
|
if self.configurables.get('simple-output', channel):
|
||||||
'and decreased %s %s for a total karma of %s.' % \
|
s = '%s: %s' % (name, total)
|
||||||
(name, added, utils.pluralize(added, 'time'),
|
else:
|
||||||
subtracted, utils.pluralize(subtracted, 'time'), total)
|
s = 'Karma for %r has been increased %s %s ' \
|
||||||
|
'and decreased %s %s for a total karma of %s.' % \
|
||||||
|
(name, added, utils.pluralize(added, 'time'),
|
||||||
|
subtracted, utils.pluralize(subtracted, 'time'),
|
||||||
|
total)
|
||||||
irc.reply(msg, s)
|
irc.reply(msg, s)
|
||||||
elif len(args) > 1:
|
elif len(args) > 1:
|
||||||
normalizedArgs = sets.Set(imap(str.lower, args))
|
normalizedArgs = sets.Set(imap(str.lower, args))
|
||||||
|
@ -68,6 +68,13 @@ if sqlite is not None:
|
|||||||
self.assertRegexp('karma MoO',
|
self.assertRegexp('karma MoO',
|
||||||
'Karma for \'MoO\'.*increased 1.*total.*1')
|
'Karma for \'MoO\'.*increased 1.*total.*1')
|
||||||
|
|
||||||
|
def testSimpleOutput(self):
|
||||||
|
self.assertNotError('karma config simple-output on')
|
||||||
|
self.assertNoResponse('foo++', 2)
|
||||||
|
self.assertResponse('karma foo', 'foo: 1')
|
||||||
|
self.assertNoResponse('bar--', 2)
|
||||||
|
self.assertResponse('karma bar', 'bar: -1')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user