فهرست منبع

Added shield command

Kirk Trombley 6 سال پیش
والد
کامیت
294c393c00
3فایلهای تغییر یافته به همراه56 افزوده شده و 2 حذف شده
  1. 0 1
      TODO_commands
  2. 1 1
      config/config.toml
  3. 55 0
      src/plugins/querying.py

+ 0 - 1
TODO_commands

@@ -1,7 +1,6 @@
 old:
 seychelles
 pokemon
-shield
 say
 scp
 digest

+ 1 - 1
config/config.toml

@@ -5,7 +5,7 @@ simple = [ "info", "isadmin", "debug", "echo", "thanks", "guess", "meme", "unmem
 teamspeak = [ "teamspeak" ]
 session = [ "session" ]
 roll = [ "roll" ]
-querying = [ "inspire" ]
+querying = [ "inspire", "shield" ]
 
 [teamspeak]
 host = "kirkleon.ddns.net"

+ 55 - 0
src/plugins/querying.py

@@ -1,6 +1,8 @@
 import requests
 
 from command_system import RollbotResponse, RollbotFailure, as_plugin
+from config import API_KEY
+from util import upload_image
 
 @as_plugin
 def inspire(db, message):
@@ -24,3 +26,56 @@ def inspire(db, message):
                 "exception": e
             }
         )
+
+
+@as_plugin
+def shield(db, message):
+    data = """\
+------RollbotBoundary\r\n\
+Content-Disposition: form-data; name=\"blazon\"\r\n\
+\r\n\
+%s\r\n\
+------RollbotBoundary\r\n\
+Content-Disposition: form-data; name=\"asfile\"\r\n\
+\r\n\
+1\r\n\
+------RollbotBoundary\r\n\
+Content-Disposition: form-data; name=\"palette\"\r\n\
+\r\n\
+wappenwiki\r\n\
+------RollbotBoundary\r\n\
+Content-Disposition: form-data; name=\"effect\"\r\n\
+\r\n\
+flat\r\n\
+------RollbotBoundary
+""" % message.raw_args
+    # TODO - this should probably have a random number as part of the boundary
+
+    try:
+        r = requests.post(
+            "https://drawshield.net/include/drawshield.php",
+            headers={
+                'Content-Type': "multipart/form-data; boundary=----RollbotBoundary",
+                'Cache-Control': "no-cache",
+            },
+            data=data
+        )
+    except ConnectionError as e:
+        return RollbotResponse(
+            message,
+            failure_reason=RollbotFailure.SERVICE_DOWN,
+            failure_notes={
+                "explain": "Could not reach DrawShield.",
+                "exception": e,
+            }
+        )
+
+    success, result = upload_image(API_KEY, r.content)
+    if success:
+        return RollbotResponse(message, img=result)
+    else:
+        return RollbotResponse(
+            message,
+            failure_reason=RollbotFailure.SERVICE_DOWN,
+            failure_notes=result
+        )