Explorar el Código

Top scorers subcommand added

Kirk Trombley hace 6 años
padre
commit
3f9e399ea7
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      src/plugins/curse.py

+ 17 - 0
src/plugins/curse.py

@@ -42,6 +42,8 @@ def curse_agg(db, msg, args):
 
 def curse_clear(db, msg, args):
     name, _ = pop_arg(args)
+    if name is None:
+        return RollbotResponse(msg, txt=f"Sorry! I need to know who's records you're trying to clear!")
     person_id = name.strip().lower()
     if not msg.from_admin:
         return RollbotResponse(msg, failure=RollbotFailure.PERMISSIONS)
@@ -57,6 +59,8 @@ def curse_clear(db, msg, args):
 
 def curse_clearall(db, msg, args):
     name, _ = pop_arg(args)
+    if name is None:
+        return RollbotResponse(msg, txt=f"Sorry! I need to know who's records you're trying to clear!")
     person_id = name.strip().lower()
     if not msg.from_admin:
         return RollbotResponse(msg, failure=RollbotFailure.PERMISSIONS)
@@ -74,10 +78,23 @@ def curse_clearall(db, msg, args):
     return RollbotResponse(msg, txt=f"Done! I have cleared all records of {name} in all chats, who was previously cursed {fmt_times(oc)} and blessed {fmt_times(ob)} in total!")
 
 
+def curse_top(db, msg, args):
+    rankings = "\n".join(f"{i + 1}. {cbs.person_id.capitalize()} was cursed {fmt_times(cbs.curses)}"
+        for i, cbs in enumerate(db.query(CurseBlessScore
+            ).filter(CurseBlessScore.group_id == msg.group_id
+            ).filter(CurseBlessScore.curses != 0
+            ).order_by(CurseBlessScore.curses.desc()
+            ).limit(10)))
+    if len(rankings) == 0:
+        return RollbotResponse(msg, txt="Sorry! I don't have enough curse history in this chat to give statistics.")
+    return RollbotResponse(msg, txt=f"The worst offenders of this chat:\n{rankings}")
+
+
 SUBC_MAP = {
     "aggregate": curse_agg,
     "clear": curse_clear,
     "clearall": curse_clearall,
+    "top": curse_top,
 }