diff --git a/bot/urban.py b/bot/urban.py index 551444e..d7404ad 100644 --- a/bot/urban.py +++ b/bot/urban.py @@ -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 ... """ @@ -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]