Skip to content
Snippets Groups Projects
Commit f0b59c71 authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Add karma delete thingy

parent 5f598c11
No related branches found
No related tags found
1 merge request!4Complete rewrite
Pipeline #3018 passed
......@@ -2,9 +2,10 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import annotations
import collections
import re
from typing import Optional
import errbot
......@@ -30,7 +31,7 @@ class Karma(errbot.BotPlugin):
return f"Karma for '{target}' is now {self['karma'][target]}"
@errbot.re_botcmd(pattern=r"(.+)\+\+", prefixed=False, flags=re.IGNORECASE)
def on_karma_inc(self, message: errbot.Message, match: re.Match) -> Optional[str]:
def on_karma_inc(self, message: errbot.Message, match: re.Match) -> str | None:
"""Adds karma"""
if message.frm == self.bot_identifier:
return
......@@ -40,7 +41,7 @@ class Karma(errbot.BotPlugin):
return self._change_karma(match.group(1), 1)
@errbot.re_botcmd(pattern=r"(.+)--", prefixed=False, flags=re.IGNORECASE)
def on_karma_dec(self, message: errbot.Message, match: re.Match) -> Optional[str]:
def on_karma_dec(self, message: errbot.Message, match: re.Match) -> str | None:
"""Removes karma"""
if message.frm == self.bot_identifier:
return
......@@ -48,7 +49,7 @@ class Karma(errbot.BotPlugin):
return self._change_karma(match.group(1), -1)
@errbot.botcmd
def karma(self, message: errbot.Message, args: Optional[str]) -> str:
def karma(self, message: errbot.Message, args: str | None) -> str:
"""Gets karma"""
if not args:
return "**Usage**: !karma <target>"
......@@ -56,7 +57,7 @@ class Karma(errbot.BotPlugin):
return f"Karma for '{args}' is {self['karma'][args]}"
@errbot.botcmd
def karma_top(self, message: errbot.Message, args: Optional[str]) -> str:
def karma_top(self, message: errbot.Message, args: str | None) -> str:
"""Gets the top n items"""
if len(self["karma"]) == 0:
return "There are no items with karma"
......@@ -70,7 +71,7 @@ class Karma(errbot.BotPlugin):
return ", ".join([f"{k}: {v}" for k, v in top])
@errbot.botcmd
def karma_bottom(self, message: errbot.Message, args: Optional[str]) -> str:
def karma_bottom(self, message: errbot.Message, args: str | None) -> str:
"""Gets the bottom n items"""
if len(self["karma"]) == 0:
return "There are no items with karma"
......@@ -82,3 +83,14 @@ class Karma(errbot.BotPlugin):
bottom = self["karma"].most_common()[: -num - 1 : -1]
return ", ".join([f"{k}: {v}" for k, v in bottom])
@errbot.botcmd
def karma_reset(self, message: errbot.Message, args: str | None) -> str:
args = args.strip()
if args not in self["karma"]:
return "**Error**: no such item"
with self.mutable("karma") as k:
del k[args]
return f"Deleted {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