diff --git a/config.json b/config.json index 342bcdd..cf71e3d 100644 --- a/config.json +++ b/config.json @@ -4,7 +4,8 @@ "plugins": [ "plugins.dicer", "plugins.references", - "plugins.coffee" + "plugins.coffee", + "plugins.ytconvert" ] } } \ No newline at end of file diff --git a/plugins/ytconvert.py b/plugins/ytconvert.py new file mode 100644 index 0000000..a687944 --- /dev/null +++ b/plugins/ytconvert.py @@ -0,0 +1,49 @@ +from disco.bot import Bot, Plugin +from urllib.parse import urlparse + +GREAT_TUNES = 537635615483887667 + +class YT_Convert(Plugin): + @Plugin.command('ytmusic', '') + def on_yt(self, event, url): + try: + scheme, netloc, path, params, query, fragment = urlparse(url) + if netloc.lower().endswith("youtube.com"): + if query.split('&')[0].startswith('v='): + result = "**On YT Music:** https://music.youtube.com/watch?{}".format(query.split('&')[0]) + else: + result = "Not a video." + elif netloc.lower().endswith("youtu.be"): + if len(path) > 3: + result = "**On YT Music:** https://music.youtube.com/watch?v={}".format(path[1:]) + else: + result = "Uhhh???!" + else: + result = "Not a YT link." + except Exception as e: + event.msg.reply(str(e)) + else: + event.msg.reply(result) + + @Plugin.listen('MessageCreate') + def on_message(self, event): + if event.message.channel_id == GREAT_TUNES: + try: + scheme, netloc, path, params, query, fragment = urlparse(event.message.content) + if netloc.lower().endswith("youtube.com"): + if query.split('&')[0].startswith('v='): + result = "**On YT Music:** https://music.youtube.com/watch?{}".format(query.split('&')[0]) + else: + result = False + elif netloc.lower().endswith("youtu.be"): + if len(path) > 3: + result = "**On YT Music:** https://music.youtube.com/watch?v={}".format(path[1:]) + else: + result = False + else: + result = False + except Exception as e: + print(e) + else: + if result: + event.reply(result)