Explorar o código

Merge branch 'feature/fortunes' of kirkleon/rollbot3 into master

kirkleon %!s(int64=6) %!d(string=hai) anos
pai
achega
b0cc74b629
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      src/plugins/querying.py

+ 10 - 0
src/plugins/querying.py

@@ -184,3 +184,13 @@ def riddle(bot, message, log):
         riddle[0],
         f"I'll post the response in about {get_config('riddle.sleep_time')} seconds!",
     ))
+
+
+@as_plugin
+def fortune():
+    sesh = HTMLSession()
+    r = sesh.get("http://www.fortunecookiemessage.com/")
+    quote = r.html.xpath("//div[contains(@class, 'quote')]/a")[0].text
+    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}"