Browse Source

Merge branch 'improvement/imgur-usage-docs' of kirkleon/rollbot3 into master

kirkleon 5 years ago
parent
commit
46d32172fb
3 changed files with 42 additions and 4 deletions
  1. 13 3
      README.md
  2. 0 1
      config/config.toml
  3. 29 0
      src/plugins/querying.py

+ 13 - 3
README.md

@@ -31,16 +31,26 @@ these in your `secrets.toml` under the `groupme_bots` section, with your
 be in quotes).
 
 For example, if your bot ID is `456`, and your group ID is `789`, your
-`secrets.toml` needs to start with the following
+`secrets.toml` needs to contain the following
 
 ```toml
 [groupme_bots]
 789 = "456"
 ```
 
-That's it for secrets! Note that other plugins may require additional secrets,
+Note that other plugins may require additional secrets,
 and that image uploads (namely with the `!seychelles` plugin), require an
-imgur client ID as well.
+imgur client ID as well. You can skip this if you will not be using the
+`upload_image` function in the `util` module, but if you will be uploading
+images, log-in to Imgur and
+[register a new Application](https://api.imgur.com/oauth2/addclient). Name
+the application Rollbot or something similar, tick the box for Anonymous
+usage without authorization, and fill in dummy values for any remaining
+fields. Click submit, and put the `Client ID` you are given on the next page
+(which can also be looked up from Account Settings > Applications) into
+your `secrets.toml`, as the value for `imgur_client_id`.
+
+That's it for secrets!
 
 Save the file and move on to deciding if you want to do your local execution
 and/or development with or without `docker`.

+ 0 - 1
config/config.toml

@@ -27,7 +27,6 @@ vore = "What? No"
 break = "I'm too robust for that!"
 yiff = "Sorry - I don't think I understand the command '!yiff'... I'll talk to Sam, since he loves this command so much, and get back to you!"
 rampart = "Hey guys can we please keep the topic to Rampart?"
-selfie = "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/ne/GEOCOLOR/latest.jpg"
 
 [riddle]
 sleep_time = 45

+ 29 - 0
src/plugins/querying.py

@@ -49,6 +49,10 @@ wappenwiki\r\n\
 Content-Disposition: form-data; name=\"effect\"\r\n\
 \r\n\
 flat\r\n\
+------RollbotBoundary\r\n\
+Content-Disposition: form-data; name=\"size\"\r\n\
+\r\n\
+500\r\n\
 ------RollbotBoundary
 """ % message.raw_args
     # TODO - this should probably have a random number as part of the boundary
@@ -194,3 +198,28 @@ def fortune():
     learn, lotto = [x.split(":", 1)[-1].strip() for x in r.html.xpath("//div[contains(@class, 'bottom-message')]")[0].text.split("\n")[:2]]
 
     return f"'{quote}'\nLucky Numbers: {lotto}\nLearn Chinese: {learn}"
+
+
+@as_plugin
+def selfie(message):
+    try:
+        r = requests.get("https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/ne/GEOCOLOR/latest.jpg")
+    except ConnectionError as e:
+        return RollbotResponse(
+            message,
+            failure=RollbotFailure.SERVICE_DOWN,
+            debugging={
+                "explain": "Could not reach GOES16.",
+                "exception": e
+            }
+        )
+
+    success, result = upload_image(get_secret("imgur_client_id"), r.content)
+    if success:
+        return RollbotResponse(message, img=result)
+    else:
+        return RollbotResponse(
+            message,
+            failure=RollbotFailure.SERVICE_DOWN,
+            debugging=result
+        )