add error messages

This commit is contained in:
oddluck 2020-03-02 14:17:25 +00:00
parent e2c8e89440
commit 96c37944c0
3 changed files with 20 additions and 11 deletions

View File

@ -77,6 +77,9 @@ class IMDb(callbacks.Plugin):
url = None
result = None
apikey = self.registryValue('omdbAPI')
if not apikey:
irc.reply("Error: You must set an API key to use this plugin.")
return
if self.registryValue("googleSearch", channel):
url = self.dosearch(query)
if url and 'imdb.com/title/' in url:

View File

@ -53,18 +53,22 @@ class Weed(callbacks.Plugin):
"""<strain>
Searches API based on user input
"""
response1 = None
response2 = None
channel = msg.args[0]
strain = re.sub('[^\w\:\"\#\-\.\' ]', '', strain).casefold()
strain_api = self.registryValue('strain_api')
if not strain_api:
irc.reply("Error: You must set an API key to use this plugin.")
return
url = "http://strainapi.evanbusse.com/{0}/strains/search/name/{1}".format(strain_api, strain)
data = requests.get(url)
data = json.loads(data.content)
request = requests.get(url)
ok = request.status_code == requests.codes.ok
if not ok:
irc.reply("Error: Unable to retrieve data. Did you set an API key?")
log.error("IMDB: API Error %s: %s" % (request.status_code, request.content.decode()))
return
data = json.loads(request.content)
for item in data:
if item['desc'] is not None and item['name'].casefold() == strain:
id = item['id']
@ -93,13 +97,12 @@ class Weed(callbacks.Plugin):
flavor3 = data2[2]
response2 = "{0} | {1} | Flavors: {2}, {3}, {4} | {5}".format(name, type.title(), flavor1, flavor2, flavor3, desc)
break
if response1 != None:
if response1 != None:
irc.reply(response1)
elif response1 == None and response2 != None:
irc.reply(response2)
else:
irc.reply('No results found, what have you been smoking?')
strain = wrap(strain, ['text'])
Class = Weed

View File

@ -69,8 +69,8 @@ class YouTube(callbacks.Plugin):
try:
log.debug("YouTube: requesting %s" % (api_url))
request = requests.get(api_url, timeout=10)
request = json.loads(request.content)
video_id = request["items"][0]["id"]["videoId"]
response = json.loads(request.content)
video_id = response["items"][0]["id"]["videoId"]
except Exception:
log.error("YouTube: YouTube API HTTP %s: %s" % (request.status_code, request.content.decode()))
pass
@ -113,6 +113,9 @@ class YouTube(callbacks.Plugin):
Search for YouTube videos
"""
apikey = self.registryValue('developerKey')
if not apikey:
irc.reply("Error: You need to set an API key to use this plugin.")
return
channel = msg.channel
yt_template = Template(self.registryValue("template", channel))
response = None