Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for plugins without commands #216

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions plugins/plpaste.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from util import hook, web
from os import listdir


@hook.command(permissions=["adminonly"])
Expand All @@ -8,5 +9,8 @@ def plpaste(inp):
try:
with open("plugins/%s.py" % inp) 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."
6 changes: 6 additions & 0 deletions plugins/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down