diff options
| author | Unknown <jtsshieh@outlook.com> | 2018-03-24 18:45:30 -0400 |
|---|---|---|
| committer | Unknown <jtsshieh@outlook.com> | 2018-03-24 18:45:30 -0400 |
| commit | 06c0f1af844d23c27d06f42502f5943a18a9004f (patch) | |
| tree | ccceb7429d5d89fa3c29b99140aa739a96bc0bdc /src/music.js | |
| parent | 53e984dc1f1673a162da1d93a3f3a24c1ea54c34 (diff) | |
| download | AleeBot-06c0f1af844d23c27d06f42502f5943a18a9004f.tar.gz AleeBot-06c0f1af844d23c27d06f42502f5943a18a9004f.tar.bz2 AleeBot-06c0f1af844d23c27d06f42502f5943a18a9004f.zip | |
spoonfeeding alee pfft
Diffstat (limited to 'src/music.js')
| -rw-r--r-- | src/music.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/music.js b/src/music.js new file mode 100644 index 0000000..81c6326 --- /dev/null +++ b/src/music.js @@ -0,0 +1,67 @@ +// Created by jtsshieh#6434 in the BonGon project: https://github.com/jtsshieh/BonGon + +const YTDL = require('ytdl-core'); +module.exports.playYT = async (bot, connection, msg) => { + const EventEmitter = require('events'); + class MyEmitter extends EventEmitter {} + bot.musicEmit = new MyEmitter(); + + const server = bot.MusicVariables(msg.member.guild.id); + + server.dispatcher = connection; + + connection.play(YTDL(server.queue[0].url, { + filter: 'audioonly' + })); + + server.nowPlaying = server.queue[0]; + server.beforeNowPlaying = server.nowPlaying; + + + server.queue.shift(); + + server.nowPlaying.playing = true; + + let time = 0; + let counter = setInterval( + function() { + time = time + 1; + server.dispatcher.time = time; + }, 1000); + + bot.musicEmit.on('paused', () => { + clearInterval(counter); + }); + + bot.musicEmit.on('resumed',() =>{ + counter = setInterval( + function() { + time = time + 1; + server.dispatcher.time = time; + }, 1000); + }); + + connection.once('end', function() { + clearInterval(counter); + + if (server.queue[0] || server.beforeNowPlaying) { + if (server.repeat) { + server.queue.push(server.beforeNowPlaying); + } + + server.nowPlaying = null; + bot.playYT(connection, msg); + } + + else { + bot.leaveVoiceChannel(connection.channelID); + bot.servers[msg.member.guild.id] = null; + } + }); +}; +module.exports.MusicVariables = (bot, guildID) => { + if (!bot.servers[guildID]) { + bot.servers[guildID] = {'queue' : [], 'dispatcher': null, 'repeat': false}; + } + return bot.servers[guildID]; +}; |
