Ver código fonte

Curse command (new version)

Kirk Trombley 4 anos atrás
pai
commit
fba944876e
3 arquivos alterados com 53 adições e 5 exclusões
  1. 0 1
      README.md
  2. 0 4
      src/commands/__init__.py
  3. 53 0
      src/commands/curse.py

+ 0 - 1
README.md

@@ -9,7 +9,6 @@ TODO as always
 ## Missing Commands
 
 Needs the following ported from rollbot3 for feature parity:
-- curse
 - hangguy
 - watchlist
 - rollcoin

+ 0 - 4
src/commands/__init__.py

@@ -34,10 +34,6 @@ config = get_command_config().extend(
             "hg": "hangguy",
             "cookie": "fortune",
             "wl": "watchlist",
-            "bless": "curse",
-            "blurse": "curse",
-            "uncurse": "curse",
-            "unbless": "curse",
         },
     )
 )

+ 53 - 0
src/commands/curse.py

@@ -0,0 +1,53 @@
+from rollbot import as_command, initialize_data, RollbotFailure, Message, Context
+from rollbot.injection import Data, Args, Lazy, Injector
+
+
+@initialize_data
+class CurseScore:
+    score: int = 0
+    zero_passes: int = 0
+
+
+class Target(Injector[str]):
+    async def inject(self, message: Message, context: Context) -> str:
+        args = await Args.inject(message, context)
+        key = args.rsplit("for", maxsplit=1)[0].strip().replace(" ", "_").lower()
+        if key == "":
+            RollbotFailure.INVALID_ARGUMENTS.raise_exc(
+                detail="I need to know who or what you're trying to curse!"
+            )
+        return key
+
+
+@as_command
+def karma(target: Target(), score: Data(CurseScore).For(Target())):
+    return f"{target.capitalize()} = {score.score}{'!' * score.zero_passes}"
+
+
+@as_command
+async def curse(target: Target(), store: Data(CurseScore)):
+    score = await store.load_or(target)
+    score.score -= 1
+    if score.score == 0:
+        score.zero_passes += 1
+    await store.save(target, score)
+    return f"{target.capitalize()} = {score.score}{'!' * score.zero_passes}"
+
+
+@as_command
+async def bless(target: Target(), store: Data(CurseScore)):
+    score = await store.load_or(target)
+    score.score += 1
+    if score.score == 0:
+        score.zero_passes += 1
+    await store.save(target, score)
+    return f"{target.capitalize()} = {score.score}{'!' * score.zero_passes}"
+
+
+@as_command
+async def blurse(target: Target(), store: Data(CurseScore)):
+    score = await store.load_or(target)
+    if score.score == 0:
+        score.zero_passes += 1
+    await store.save(target, score)
+    return f"{target.capitalize()} = {score.score}{'!' * score.zero_passes}"