From 4eb6aa4872b2036acfe631fcef2cf11e64de7341 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Mon, 24 Mar 2014 11:01:46 +0800 Subject: [PATCH 1/2] Add support for plugins without commands regex plugins, etc --- plugins/plpaste.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/plpaste.py b/plugins/plpaste.py index 238037de..ac6603a7 100644 --- a/plugins/plpaste.py +++ b/plugins/plpaste.py @@ -1,12 +1,14 @@ from util import hook, web +from os import listdir @hook.command(adminonly=True) -def plpaste(inp): - if "/" in inp and inp.split("/")[0] != "util": - return "Invalid input" - try: - with open("plugins/%s.py" % inp) as f: +def plpaste(inp, bot=None): + if inp in bot.commands: + with open(bot.commands[inp][0].func_code.co_filename.strip()) as f: return web.haste(f.read(), ext='py') - except IOError: - return "Plugin not found (must be in plugins folder)" + elif inp + ".py" in listdir('plugins/'): + with open('plugins/{}.py'.format(inp)) as f: + return web.haste(f.read(), ext='py') + else: + return "Could not find specified plugin." From a67c3de28161caacbcb522b954a8d7315f65dfef Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Mon, 17 Nov 2014 11:26:11 +0800 Subject: [PATCH 2/2] Fix no-results output --- plugins/spotify.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/spotify.py b/plugins/spotify.py index 6ad97281..7217eab8 100644 --- a/plugins/spotify.py +++ b/plugins/spotify.py @@ -54,6 +54,8 @@ def spotify(inp): try: data = http.get_json("https://api.spotify.com/v1/search", type="track", limit="1", q=inp.strip()) item = data["tracks"]["items"][0] + except IndexError: + return "Could not find track: no results." except Exception as e: return "Could not get information: {}".format(e) return format_track(item) @@ -69,6 +71,8 @@ def spotify_album(inp): try: data = http.get_json("https://api.spotify.com/v1/search", type="album", limit="1", q=inp.strip()) item = data["albums"]["items"][0] + except IndexError: + return "Could not find track: no results." except Exception as e: return "Could not get information: {}".format(e) return format_album(item) @@ -84,6 +88,8 @@ def spotify_artist(inp): try: data = http.get_json("https://api.spotify.com/v1/search", type="artist", limit="1", q=inp.strip()) item = data["artists"]["items"][0] + except IndexError: + return "Could not find track: no results." except Exception as e: return "Could not get information: {}".format(e) return format_artist(item)