Browse Source

Add art command

Kirk Trombley 4 years ago
parent
commit
a6803e46d7
1 changed files with 24 additions and 0 deletions
  1. 24 0
      src/commands/querying.py

+ 24 - 0
src/commands/querying.py

@@ -182,3 +182,27 @@ async def npc(req: Request, logger: Logger):
     except:
         logger.exception("Failed to call person generator")
         RollbotFailure.SERVICE_DOWN.raise_exc(detail="Failed to call person generator")
+
+
+art_number = 0
+
+
+@as_command
+def art(req: Request, logger: Logger):
+    """
+    The !art command uses the 9gans gallery at https://9gans.com/ which generates 9 images every hour.
+    This command will cycle through those 9 images, so if you fire it 10 times in quick succession, the tenth
+    piece of art might be the same as the first.
+    """
+    global art_number
+    art_number += 1
+    art_number %= 9
+    try:
+        async with req.get(
+            f"https://storage.googleapis.com/9gans/mini/{art_number + 1}.jpg"
+        ) as res:
+            res.raise_for_status()
+            return Attachment("image", await res.read())
+    except:
+        logger.exception("Failed to call art generator")
+        RollbotFailure.SERVICE_DOWN.raise_exc(detail="Failed to call art generator")