diff options
| author | Unknown <jtsshieh@outlook.com> | 2018-02-25 21:58:31 -0500 |
|---|---|---|
| committer | Unknown <jtsshieh@outlook.com> | 2018-02-25 21:58:31 -0500 |
| commit | 2b83e842fea1c9cab7abbe45154a1f140e26f990 (patch) | |
| tree | d5632015dbc0f28a56ee1295d0d32d92378b6204 /Plugins | |
| parent | 6d17517b4543afbf5100b55619efc8a6d8f3c754 (diff) | |
| download | PokeBot-2b83e842fea1c9cab7abbe45154a1f140e26f990.tar.gz PokeBot-2b83e842fea1c9cab7abbe45154a1f140e26f990.tar.bz2 PokeBot-2b83e842fea1c9cab7abbe45154a1f140e26f990.zip | |
Basic music commands
Diffstat (limited to 'Plugins')
| -rw-r--r-- | Plugins/Music.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Plugins/Music.js b/Plugins/Music.js new file mode 100644 index 0000000..5088fdc --- /dev/null +++ b/Plugins/Music.js @@ -0,0 +1,45 @@ +exports.resolveTrack = async (term, sc) => { + const fetch = require('snekfetch'); + let track = await fetch.get('http://localhost:2344/loadtracks?identifier=' + term, { headers: { Authorization: 'iamaverysecurepassword' } }); + if (!track.body[0]) { + const search = 'http://localhost:2344/loadtracks?identifier=' + (sc ? 'scsearch:' : 'ytsearch:') + term; + track = await fetch.get(search, { headers: { Authorization: 'iamaverysecurepassword' } }); + } + return track.body[0]; +}; + +exports.play = async (bot, msg, track) => { + const player = await bot.player.join({ + guild: msg.guild.id, + channel: msg.member.voiceChannelID, + host: 'localhost', + }); + if (!bot.queue.has(msg.guild.id)) { + bot.queue.set(msg.guild.id, []); + bot.queue.get(msg.guild.id).push(track); + player.play(bot.queue.get(msg.guild.id).shift()); + player.on('end', () => { + if (bot.queue.get(msg.guild.id)[0]) { + player.play(bot.queue.get(msg.guild.id).shift()); + } + }); + } + else { + bot.queue.get(msg.guild.id).push(track); + } +}; + +exports.skip = async (bot, msg) => { + const player = await bot.player.join({ + guild: msg.guild.id, + channel: msg.member.voiceChannelID, + host: 'localhost', + }); + if (bot.queue.has(msg.guild.id)) { + player.stop(); + player.emit('end'); + } + else { + return msg.channel.send('There is nothing playing.'); + } +}; |
