From 89857d9bd862b038af09af9d7bb17c3ed7ccfa84 Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Wed, 26 Nov 2003 17:07:20 +0000 Subject: [PATCH] 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. --- plugins/Karma.py | 29 +++++++++++++++++++++++------ test/test_Karma.py | 7 +++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/plugins/Karma.py b/plugins/Karma.py index babacf5cf..6d8295315 100644 --- a/plugins/Karma.py +++ b/plugins/Karma.py @@ -55,11 +55,24 @@ def configure(onStart, afterConnect, advanced): from questions import expect, anything, something, yn onStart.append('load Karma') -class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler): +class Karma(callbacks.PrivmsgCommandAndRegexp, + plugins.Configurable, + plugins.ChannelDBHandler): 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): - plugins.ChannelDBHandler.__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): if os.path.exists(filename): @@ -103,10 +116,14 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler): else: (added, subtracted) = imap(int, cursor.fetchone()) total = added - subtracted - 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) + if self.configurables.get('simple-output', channel): + s = '%s: %s' % (name, total) + else: + 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) elif len(args) > 1: normalizedArgs = sets.Set(imap(str.lower, args)) diff --git a/test/test_Karma.py b/test/test_Karma.py index 4632640d0..a32975a34 100644 --- a/test/test_Karma.py +++ b/test/test_Karma.py @@ -68,6 +68,13 @@ if sqlite is not None: self.assertRegexp('karma MoO', '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: