From fa18d1b3ebacbccc13a294829370d5c890fef00d Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Fri, 20 Nov 2020 16:14:43 +0000 Subject: [PATCH] fix urban dictionary (ud) trigger --- bot/urban.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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]