Kirk Trombley пре 5 година
родитељ
комит
85e43db252
1 измењених фајлова са 19 додато и 1 уклоњено
  1. 19 1
      src/plugins/querying.py

+ 19 - 1
src/plugins/querying.py

@@ -227,4 +227,22 @@ def cat(message):
         return RollbotFailure.SERVICE_DOWN.with_reason("Could not reach cat generator.").with_exception(e)
 
     return run_upload(message, r.content)
-    
+    
+@as_plugin
+def imagine(message):
+    try:
+        r = requests.post(
+            "https://api.deepai.org/api/text2img",
+            data={ "text": message.raw_args },
+            # TODO rules for this API key seem unclear on the site
+            # if this stops working, maybe refresh the key
+            headers={ "api-key": "quickstart-QUdJIGlzIGNvbWluZy4uLi4K"}
+        )
+    except ConnectionError as e:
+        return RollbotFailure.SERVICE_DOWN.with_reason("Could not reach text2img service.").with_exception(e)
+    
+    result = r.json().get("output_url", None)
+    if result is None:
+        return RollbotFailure.SERVICE_DOWN.with_reason(f"Response from text2img was invalid: {r.text}")
+    
+    return RollbotResponse(message, img=result)