Pārlūkot izejas kodu

Clearing system for admins

Kirk Trombley 6 gadi atpakaļ
vecāks
revīzija
0d005738bf
1 mainītis faili ar 26 papildinājumiem un 0 dzēšanām
  1. 26 0
      src/plugins/curse.py

+ 26 - 0
src/plugins/curse.py

@@ -55,6 +55,32 @@ def curse(db, msg):
             curses += cbs.curses
             blessings += cbs.blessings
         return RollbotResponse(msg, txt=f"From my records, {name} has been cursed {fmt_times(curses)} and blessed {fmt_times(blessings)} across all chats.")
+    elif subc == "clear":
+        if not msg.from_admin:
+            return RollbotResponse(msg, failure=RollbotFailure.PERMISSIONS)
+        cbs = db.query(CurseBlessScore).get((msg.group_id, person_id))
+        if cbs:
+            oc = cbs.curses
+            ob = cbs.blessings
+            cbs.curses = 0
+            cbs.blessings = 0
+            return RollbotResponse(msg, txt=f"Done! I have cleared all records of {name} in this chat, who was previously cursed {fmt_times(oc)} and blessed {fmt_times(ob)}!")
+        return RollbotResponse(msg, txt=f"Sorry! I don't know who {name} is!")
+    elif subc == "clearall":
+        if not msg.from_admin:
+            return RollbotResponse(msg, failure=RollbotFailure.PERMISSIONS)
+        cnt = 0
+        oc = 0
+        ob = 0
+        for cbs in db.query(CurseBlessScore).filter(CurseBlessScore.person_id == person_id):
+            oc += cbs.curses
+            ob += cbs.blessings
+            cbs.curses = 0
+            cbs.blessings = 0
+            cnt += 1
+        if cnt == 0:
+            return RollbotResponse(msg, txt=f"Sorry! I don't know who {name} is!")
+        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!")
     else:
         return RollbotResponse(msg, failure=RollbotFailure.INVALID_SUBCOMMAND)