Skip to content
Snippets Groups Projects
Commit 36ff6dfc authored by Bruce Cowan's avatar Bruce Cowan
Browse files

Added postfix operators

Such as government-- and A350++
parent b16ed391
No related branches found
No related tags found
No related merge requests found
# Copyright © 2016 Bruce Cowan <bruce@bcowan.eu>
# Copyright © 2016, 2018 Bruce Cowan <bruce@bcowan.eu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from collections import defaultdict
import re
from errbot import BotPlugin, botcmd
......@@ -26,11 +27,35 @@ class Karma(BotPlugin):
self.karma = self.get('karma', defaultdict(int))
self.inc = re.compile(r'(.+)\+\+')
self.dec = re.compile(r'(.+)--')
def deactivate(self):
self['karma'] = self.karma
super().deactivate()
def _inc_karma(self, target, message):
self.karma[target] += 1
text = "Karma for '{}' is now {}".format(target, self.karma[target])
self.send(message.to, text, message, True)
def _dec_karma(self, target, message):
self.karma[target] -= 1
text = "Karma for '{}' is now {}".format(target, self.karma[target])
self.send(message.to, text, message, True)
def callback_message(self, message):
# Increment?
match = self.inc.search(message.body)
if match:
self._inc_karma(match.group(1), message)
# Decrement?
match = self.dec.search(message.body)
if match:
self._dec_karma(match.group(1), message)
@botcmd
def karma_list(self, message, args):
"""Prints a list of karmaed things"""
......@@ -46,8 +71,7 @@ class Karma(BotPlugin):
if not args:
return "**Usage**: !karma add <target>"
self.karma[args] += 1
return "Karma for '{}' is now {}".format(args, self.karma[args])
self._inc_karma(args, message)
@botcmd
def karma_remove(self, message, args):
......@@ -55,8 +79,7 @@ class Karma(BotPlugin):
if not args:
return "**Usage**: !karma remove <target>"
self.karma[args] -= 1
return "Karma for '{}' is now {}".format(args, self.karma[args])
self._dec_karma(args, message)
@botcmd
def karma(self, message, args):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment