{"action":"created","issue":{"url":"https://api.github.com/repos/np1/mps-youtube/issues/314","labels_url":"https://api.github.com/repos/np1/mps-youtube/issues/314/labels{/name}","comments_url":"https://api.github.com/repos/np1/mps-youtube/issues/314/comments","events_url":"https://api.github.com/repos/np1/mps-youtube/issues/314/events","html_url":"https://github.com/np1/mps-youtube/issues/314","id":88420009,"number":314,"title":"Plugin API","user":{"login":"lol768","id":2552726,"avatar_url":"https://avatars.githubusercontent.com/u/2552726?v=3","gravatar_id":"","url":"https://api.github.com/users/lol768","html_url":"https://github.com/lol768","followers_url":"https://api.github.com/users/lol768/followers","following_url":"https://api.github.com/users/lol768/following{/other_user}","gists_url":"https://api.github.com/users/lol768/gists{/gist_id}","starred_url":"https://api.github.com/users/lol768/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lol768/subscriptions","organizations_url":"https://api.github.com/users/lol768/orgs","repos_url":"https://api.github.com/users/lol768/repos","events_url":"https://api.github.com/users/lol768/events{/privacy}","received_events_url":"https://api.github.com/users/lol768/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-06-15T12:58:34Z","updated_at":"2015-06-16T23:27:14Z","closed_at":null,"body":"It's great to see the code now split up into more modular pieces across multiple files. To take this further, it'd be interesting to see some sort of API which allowed users to load their own scripts which extend the core. This could perhaps also reduce the required maintenance of core functionality.\r\n\r\nIdeally users could place a script file in a folder somewhere and have them loaded on startup. Scripts/plugins could potentially:\r\n\r\n* Register their own commands\r\n* Add new help entries\r\n* Listen for common events (e.g. a new song has been played, a user performed a search, an item was added to a playlist)\r\n\r\nDoes this sound like it'd be useful to have? It's inspired to an extent by weechat's script system."},"comment":{"url":"https://api.github.com/repos/np1/mps-youtube/issues/comments/112601519","html_url":"https://github.com/np1/mps-youtube/issues/314#issuecomment-112601519","issue_url":"https://api.github.com/repos/np1/mps-youtube/issues/314","id":112601519,"user":{"login":"ids1024","id":2263150,"avatar_url":"https://avatars.githubusercontent.com/u/2263150?v=3","gravatar_id":"","url":"https://api.github.com/users/ids1024","html_url":"https://github.com/ids1024","followers_url":"https://api.github.com/users/ids1024/followers","following_url":"https://api.github.com/users/ids1024/following{/other_user}","gists_url":"https://api.github.com/users/ids1024/gists{/gist_id}","starred_url":"https://api.github.com/users/ids1024/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ids1024/subscriptions","organizations_url":"https://api.github.com/users/ids1024/orgs","repos_url":"https://api.github.com/users/ids1024/repos","events_url":"https://api.github.com/users/ids1024/events{/privacy}","received_events_url":"https://api.github.com/users/ids1024/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T23:27:14Z","updated_at":"2015-06-16T23:27:14Z","body":"It seems python decorators don't work quite how I though they did when applied to methods, so the code several posts back will not work. Moving the commands and event handlers out of the `Plugin` class fixes this. This is perhaps better for consistency, since some things (like uis) might require classes rather than functions, and thus could not be implemented as methods.\r\n\r\n```python\r\n# mps_youtube.c is used here for handling colors, plugins should be able\r\n# to import it or a few other mpsyt modules\r\nfrom mps_youtube import Plugin, registerPlugin, c\r\n\r\n@registerPlugin\r\nclass MyPlugin(Plugin):\r\n    name = \"The Plugin\"\r\n    author = \"God\"\r\n    version = 2000\r\n    description = \"Does EVERYTHING\"\r\n\r\n    def __init__(self):\r\n    # Some initialization\r\n        ...\r\n\r\n# Category is what help page the usage should be listed in\r\n# There should be some mechanism for registering a new help page\r\n@MyPlugin.command(r'some/regex/.*', 'category', 'usage')\r\ndef command1(self, *parameters):\r\n     ...\r\n\r\n@MyPlugin.eventHandler('computer_explodes')\r\ndef explode(self, event):\r\n    ...\r\n\r\n```"}}