mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-26 13:01:09 -05:00
get catfacts/catpics with api requests
This commit is contained in:
parent
15a04d473f
commit
13465e70a7
@ -12,6 +12,7 @@ import supybot.callbacks as callbacks
|
|||||||
import random
|
import random
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from supybot.i18n import PluginInternationalization
|
from supybot.i18n import PluginInternationalization
|
||||||
@ -51,7 +52,8 @@ class Cayenne(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
Get a random cat fact
|
Get a random cat fact
|
||||||
"""
|
"""
|
||||||
return random.choice(self.cat_facts)
|
data = requests.get("https://catfact.ninja/fact").json()
|
||||||
|
return data['fact']
|
||||||
|
|
||||||
def message_contains_trigger_word(self, message):
|
def message_contains_trigger_word(self, message):
|
||||||
"""
|
"""
|
||||||
@ -77,17 +79,14 @@ class Cayenne(callbacks.Plugin):
|
|||||||
Query cat URL to get a random link
|
Query cat URL to get a random link
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
link_url = self.registryValue("linkURL")
|
response = utils.web.getUrl("http://edgecats.net/random").decode("utf8")
|
||||||
response = utils.web.getUrl(link_url).decode("utf8")
|
|
||||||
|
|
||||||
# Expecting a link
|
# Expecting a link
|
||||||
if "http" in response:
|
if "http" in response:
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
self.log.error("Cayenne: received unexpected response from cat URL: %s" % (response))
|
self.log.error("Received unexpected response from http://edgecats.net/random")
|
||||||
|
|
||||||
except:
|
except:
|
||||||
self.log.exception("Cayenne: error fetching cat URL")
|
self.log.exception("Error fetching URL")
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user