|
@@ -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")
|