From a2994edb7fc8c66cbee47f85feca759f8673217d Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Fri, 8 May 2020 15:53:05 +0100 Subject: [PATCH] completed the queue system --- commands/music/queue.js | 46 +++++++++++++++++++++++++++++++++++ index.js | 53 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 commands/music/queue.js diff --git a/commands/music/queue.js b/commands/music/queue.js new file mode 100644 index 0000000..3e8cee4 --- /dev/null +++ b/commands/music/queue.js @@ -0,0 +1,46 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); + +module.exports = class Play extends Command { + constructor(client) { + super(client, { + name: 'queue', + memberName: 'queue', + group: 'music', + description: 'shows the queue', + guildOnly: true, + throttling: { + usages: 1, + duration: 5 + } + }); + } + + run = async message => { + try { + if (message.guild.music.queue.length === 0 && !message.guild.music.nowPlaying) { + const embed = new MessageEmbed().setColor('#000099').setTitle(':musical_note: Queue is empty'); + return await message.say({ embed }); + } else { + const embed = new MessageEmbed().setColor('#000099').setTitle(':musical_note: Queue'); + + embed.addField('Now playing', message.guild.music.nowPlaying.title).addField('Duration', `${message.guild.music.nowPlaying.playingFor.string}/${message.guild.music.nowPlaying.duration.string}`); + + if (message.guild.music.queue.length === 0) embed.addField('Queue', 'nothing in the queue'); + else embed.addField('Queue', `${message.guild.music.queue.length} track(s)`); + + message.guild.music.queue.forEach((item, index) => { + let itemString = `${item.title}`; + if (item.type === 'youtube' || item.type === 'search' || item.type === 'facebook') itemString += ` By ${item.by}`; + embed.addField(index + 1, itemString); + }); + + return await message.say({ embed }); + } + } catch(err) { + console.error(err); + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Error occured, if you are my creator please fix me soon'); + return message.say({ embed }); + } + } +} \ No newline at end of file diff --git a/index.js b/index.js index c207eaf..58f66f9 100644 --- a/index.js +++ b/index.js @@ -11,9 +11,60 @@ Structures.extend('Guild', Guild => { isPlaying: false, nowPlaying: null, volume: 1, - dispatcher: null + dispatcher: null, + sfx: { + earrape: false + } }; } + + startCounter = message => { + if (!message.guild.music.nowPlaying.playingFor) message.guild.music.nowPlaying.playingFor = { hours: 0, minutes: 0, seconds: 0, string: '00:00:00' }; + + const interval = setInterval(() => { + if (!message.guild.music.nowPlaying || message.guild.music.paused) clearInterval(interval); + else if (message.guild.music.nowPlaying.playingFor.seconds === 60) { + message.guild.music.nowPlaying.playingFor = { + hours: message.guild.music.nowPlaying.playingFor.hours, + minutes: message.guild.music.nowPlaying.playingFor.minutes + 1, + seconds: 0, + string: this.formatDuration({ + hours: message.guild.music.nowPlaying.playingFor.hours, + minutes: message.guild.music.nowPlaying.playingFor.minutes + 1, + seconds: 0 + }) + }; + } + else if (message.guild.music.nowPlaying.playingFor.minutes === 60) { + message.guild.music.nowPlaying.playingFor = { + hours: message.guild.music.nowPlaying.playingFor.hours + 1, + minutes: 0, + seconds: 0, + string: this.formatDuration({ + hours: message.guild.music.nowPlaying.playingFor.hours + 1, + minutes: 0, + seconds: 0 + }) + }; + } + else { + message.guild.music.nowPlaying.playingFor = { + hours: message.guild.music.nowPlaying.playingFor.hours, + minutes: message.guild.music.nowPlaying.playingFor.minutes, + seconds: message.guild.music.nowPlaying.playingFor.seconds + 1, + string: this.formatDuration({ + hours: message.guild.music.nowPlaying.playingFor.hours, + minutes: message.guild.music.nowPlaying.playingFor.minutes, + seconds: message.guild.music.nowPlaying.playingFor.seconds + 1 + }) + }; + } + }, 1000); + } + + formatDuration = durationObject => { + return `${durationObject.hours < 10 ? '0' + durationObject.hours : durationObject.hours ? durationObject.hours : '00'}:${durationObject.minutes < 10 ? '0' + durationObject.minutes : durationObject.minutes ? durationObject.minutes : '00'}:${durationObject.seconds < 10 ? '0' + durationObject.seconds : durationObject.seconds ? durationObject.seconds : '00'}`; + } } return MusicGuild;