|
@@ -1,3 +1,5 @@
|
|
|
+import random
|
|
|
+
|
|
|
import requests
|
|
|
from requests_html import HTMLSession
|
|
|
|
|
@@ -21,8 +23,8 @@ def inspire(db, message):
|
|
|
except ConnectionError as e:
|
|
|
return RollbotResponse(
|
|
|
message,
|
|
|
- failure_reason=RollbotFailure.SERVICE_DOWN,
|
|
|
- failure_notes={
|
|
|
+ failure=RollbotFailure.SERVICE_DOWN,
|
|
|
+ debugging={
|
|
|
"explain": "Could not reach inspirobot.",
|
|
|
"exception": e
|
|
|
}
|
|
@@ -64,8 +66,8 @@ flat\r\n\
|
|
|
except ConnectionError as e:
|
|
|
return RollbotResponse(
|
|
|
message,
|
|
|
- failure_reason=RollbotFailure.SERVICE_DOWN,
|
|
|
- failure_notes={
|
|
|
+ failure=RollbotFailure.SERVICE_DOWN,
|
|
|
+ debugging={
|
|
|
"explain": "Could not reach DrawShield.",
|
|
|
"exception": e,
|
|
|
}
|
|
@@ -77,8 +79,8 @@ flat\r\n\
|
|
|
else:
|
|
|
return RollbotResponse(
|
|
|
message,
|
|
|
- failure_reason=RollbotFailure.SERVICE_DOWN,
|
|
|
- failure_notes=result
|
|
|
+ failure=RollbotFailure.SERVICE_DOWN,
|
|
|
+ debugging=result
|
|
|
)
|
|
|
|
|
|
|
|
@@ -90,8 +92,8 @@ def scp(db, message):
|
|
|
except ValueError as e:
|
|
|
return RollbotResponse(
|
|
|
message,
|
|
|
- failure_reason=RollbotFailure.INVALID_ARGUMENTS,
|
|
|
- failure_notes={
|
|
|
+ failure=RollbotFailure.INVALID_ARGUMENTS,
|
|
|
+ debugging={
|
|
|
"explain": "Could not parse argument %s into integer." % number,
|
|
|
"exception": e,
|
|
|
}
|
|
@@ -129,4 +131,42 @@ def scp(db, message):
|
|
|
response += flavortext + "\n"
|
|
|
response += page_url
|
|
|
|
|
|
- return RollbotResponse(message, txt=response)
|
|
|
+ return RollbotResponse(message, txt=response)
|
|
|
+
|
|
|
+
|
|
|
+@as_plugin
|
|
|
+def riddle(db, message):
|
|
|
+ if message.raw_args is None or message.raw_args != "me piss":
|
|
|
+ return RollbotResponse(message, failure=RollbotFailure.INVALID_ARGUMENTS)
|
|
|
+
|
|
|
+ sesh = HTMLSession()
|
|
|
+ rnum = 7000 # TODO add db logic for if "last_riddle_num" not in store else store["last_riddle_num"]
|
|
|
+
|
|
|
+ def get_riddle(n):
|
|
|
+ r = sesh.get(f"https://www.riddles.com/{n:d}")
|
|
|
+ divs = r.html.find("div")
|
|
|
+ panel_bodies = [d.text for d in divs if "class" in d.attrs and "panel-body" in d.attrs["class"]]
|
|
|
+ if len(panel_bodies) == 3:
|
|
|
+ return panel_bodies[0]
|
|
|
+ else:
|
|
|
+ return None
|
|
|
+
|
|
|
+ n = 0
|
|
|
+ while get_riddle(rnum) is not None:
|
|
|
+ rnum += 1
|
|
|
+ n += 1
|
|
|
+ if n > 100:
|
|
|
+ break
|
|
|
+
|
|
|
+ # store["last_riddle_num"] = rnum
|
|
|
+
|
|
|
+ n = 0
|
|
|
+ riddle = None
|
|
|
+ while riddle is None:
|
|
|
+ chosen = random.randint(2, rnum)
|
|
|
+ riddle = get_riddle(chosen)
|
|
|
+ n += 1
|
|
|
+ if n > 20:
|
|
|
+ return RollbotResponse(message, failure=RollbotFailure.SERVICE_DOWN)
|
|
|
+
|
|
|
+ return RollbotResponse(message, txt=riddle)
|