From 93336efd38d2fff96f4cfbaf45eacda199caca88 Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 8 Jan 2019 10:14:03 +0000 Subject: [PATCH] Handle !soundcloud returning no results (soundcloud.py) --- modules/soundcloud.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/soundcloud.py b/modules/soundcloud.py index 04b8beee..d2e3ba39 100644 --- a/modules/soundcloud.py +++ b/modules/soundcloud.py @@ -48,15 +48,18 @@ class Module(ModuleManager.BaseModule): get_params=get_params, json=True) if page: - page = page.data[0] if has_query else page - title = page["title"] - user = page["user"]["username"] - duration = time.strftime("%H:%M:%S", time.gmtime(page[ - "duration"]/1000)) - if duration.startswith("00:"): - duration = duration[3:] - link = page["permalink_url"] - event["stdout"].write("%s [%s] (posted by %s) %s" % (title, - duration, user, link)) + if len(page.data): + page = page.data[0] if has_query else page + title = page["title"] + user = page["user"]["username"] + duration = time.strftime("%H:%M:%S", time.gmtime(page[ + "duration"]/1000)) + if duration.startswith("00:"): + duration = duration[3:] + link = page["permalink_url"] + event["stdout"].write("%s [%s] (posted by %s) %s" % (title, + duration, user, link)) + else: + event["stderr"].write("No results found") else: raise utils.EventsResultsError()