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