Kirk Trombley 4 rokov pred
rodič
commit
aaa04b2220
1 zmenil súbory, kde vykonal 31 pridanie a 3 odobranie
  1. 31 3
      src/commands/querying.py

+ 31 - 3
src/commands/querying.py

@@ -1,9 +1,11 @@
-from rollbot import as_command, RollbotFailure
-from rollbot.injection import Request
+from logging import Logger
+
+from rollbot import as_command, RollbotFailure, Attachment
+from rollbot.injection import Request, Args
 
 
 @as_command
-async def inspire(req: Request):
+async def inspire(req: Request, logger: Logger):
     """
     Using the command !inspire will request an inspiration image from http://inspirobot.me/
     """
@@ -11,4 +13,30 @@ async def inspire(req: Request):
         async with req.get("http://inspirobot.me/api?generate=true") as res:
             return await res.text()
     except:
+        logger.exception("Failed !inspire")
         RollbotFailure.SERVICE_DOWN.raise_exc(detail="Could not reach inspirobot")
+
+
+@as_command
+async def shield(req: Request, blazon: Args, logger: Logger):
+    try:
+        async with req.post(
+            "https://drawshield.net/include/drawshield.php",
+            headers={
+                "Content-Type": "multipart/form-data; boundary=----RollbotBoundary",
+                "Cache-Control": "no-cache",
+            },
+            data={
+                "blazon": blazon,
+                "asfile": 1,
+                "palette": "wappenwiki",
+                "effect": "flat",
+                "size": 500,
+            },
+        ) as res:
+            res.raise_for_status()
+            shield = await res.read()
+            return Attachment("image", shield)
+    except:
+        logger.exception("Failed !shield")
+        RollbotFailure.SERVICE_DOWN.raise_exc(detail="Could not reach DrawShield")