fix urban dictionary (ud) trigger

This commit is contained in:
jkhsjdhjs 2020-11-20 16:14:43 +00:00
parent 81d12c92ae
commit fa18d1b3eb

View File

@ -12,7 +12,7 @@ class Urban(Plugin):
@command
def ud(self, mask: IrcString, target: IrcString, args: Dict):
"""Searches for a term on YouTube and returns first result
"""Searches for a term on urban dictionary and returns first result
%%ud <term>...
"""
@ -30,10 +30,15 @@ class Urban(Plugin):
# Fetch data for term from urban dictionary as json
data = requests.get(self.URL, params=dict(term=term)).json()
res_length = len(data['list'])
# No results
if data['result_type'] == 'no_results':
if res_length == 0:
return 'Term not found'
if index > res_length - 1:
return f"Index out of range [1/{res_length}]"
# Get result by index
res = data['list'][index]