update music commands to support new module

This commit is contained in:
Emily 2020-04-30 14:06:09 +10:00
parent def26feab3
commit d1acf688c9
9 changed files with 250 additions and 262 deletions

View file

@ -1,11 +1,16 @@
const { skip, getGuild } = require('../modules/music')
exports.run = (client, message) => { exports.run = (client, message) => {
let guild = client.music.getGuild(message.guild.id); const guild = getGuild(message.guild.id)
if(guild.queue.length < 1) return message.channel.send( if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) {
`<:error:466995152976871434> There is nothing for me to skip!` return message.channel.send(
); '<:error:466995152976871434> Nothing is playing.'
skip_song(guild); )
message.channel.send("<:skip:467216735356059660> Skipped the song!") }
skip(message.guild, 'skip')
message.channel.send('<:success:466995111885144095> Song skipped.')
}; };
exports.conf = { exports.conf = {
@ -13,7 +18,7 @@ exports.conf = {
guildOnly: true, guildOnly: true,
aliases: [], aliases: [],
permLevel: "Moderator", permLevel: "Moderator",
requiredPerms: ["SPEAK"] requiredPerms: []
}; };
exports.help = { exports.help = {
@ -22,7 +27,3 @@ exports.help = {
description: "Skips the currently playing song without requiring a vote.", description: "Skips the currently playing song without requiring a vote.",
usage: "forceskip" usage: "forceskip"
}; };
function skip_song(guild) {
guild.dispatcher.end();
}

View file

@ -1,31 +1,30 @@
const Discord = require("discord.js"); const { getGuild, createTimestamp } = require('../modules/music')
const { MessageEmbed } = require('discord.js')
exports.run = async (client, message) => { exports.run = async (client, message) => {
let guild = client.music.getGuild(message.guild.id); const guild = getGuild(message.guild.id)
if(guild.queue.length < 1) { if (guild.queue.length < 1) {
return message.channel.send("<:error:466995152976871434> Nothing is playing."); return message.channel.send(client.config.emojis.error + ' Nothing is in the queue!')
} }
var song = guild.queue[0]; const s = guild.queue[0]
var elapsedTime = client.createTimestamp(guild.dispatcher.streamTime / 1000); const elapsedTime = createTimestamp(guild.dispatcher.streamTime / 1000)
var timestamp; let timestamp = `\`[${createTimestamp(s.video.lengthSeconds)}]\``
if(song.duration == 0) { if (timestamp !== '`[LIVE]`') {
timestamp = "`[LIVE]`"; timestamp = `\`[${elapsedTime + '/' + createTimestamp(s.video.lengthSeconds)}]\``
} else { }
timestamp = `\`[${elapsedTime + "/" + client.createTimestamp(song.duration)}]\``;
};
embed = new Discord.MessageEmbed(); const embed = new MessageEmbed()
embed.setTitle("Now playing:") embed.setTitle('Now playing')
embed.setThumbnail(song.thumbnail) embed.setThumbnail(s.video.videoThumbnails[1].url)
embed.setColor(client.embedColour(message)); embed.setColor(client.embedColour(message))
embed.setDescription(`**[${song.title}](https://www.youtube.com/watch?v=${song.id})**`) embed.setDescription(`**[${s.video.title}](https://www.youtube.com/watch?v=${s.video.videoId})**`)
embed.addField("Channel:", song.author, true) embed.addField('Channel:', s.video.author, true)
embed.addField("Time:", timestamp, true) embed.addField('Time:', timestamp, true)
embed.setFooter("Requested by " + song.requestedBy.tag, song.requestedBy.avatarURL({format: "png", dynamic: true, size: 2048})) embed.setFooter('Requested by ' + s.requestedBy.tag, s.requestedBy.avatarURL({ format: 'png', dynamic: true, size: 2048 }))
message.channel.send(embed) message.channel.send(embed)
}; };
exports.conf = { exports.conf = {

View file

@ -1,15 +1,20 @@
const { getGuild } = require('../modules/music')
exports.run = (client, message, args, level) => { exports.run = (client, message, args, level) => {
let guild = client.music.getGuild(message.guild.id); const guild = getGuild(message.guild.id)
if(guild.queue.length < 1) {
return message.channel.send("<:error:466995152976871434> Nothing is playing.");
};
guild.playing = false; if (guild.paused === true) {
guild.paused = true; return message.channel.send('<:error:466995152976871434> The music has already been paused! Run resume to start the music again.')
guild.dispatcher.pause(); }
message.channel.send("<:pause:467639357961142273> Playback paused!");
if (guild.queue.length < 1 || guild.playing === false) {
return message.channel.send('<:error:466995152976871434> Nothing is playing!')
}
guild.playing = false
guild.paused = true
guild.dispatcher.pause()
message.channel.send('<:pause:467639357961142273> Music playback has been paused.')
}; };
exports.conf = { exports.conf = {
@ -17,7 +22,7 @@ exports.conf = {
guildOnly: true, guildOnly: true,
aliases: [], aliases: [],
permLevel: "Moderator", permLevel: "Moderator",
requiredPerms: ["CONNECT", "SPEAK"] requiredPerms: []
}; };
exports.help = { exports.help = {

View file

@ -1,20 +1,12 @@
const util = require("util") const { play } = require('../modules/music')
const Discord = require("discord.js") const Discord = require("discord.js")
module.exports.run = (client, message, args, level) =>{ module.exports.run = async (client, message, args, level) =>{
if(!args[0]) if (!args[0]) {
{ return message.channel.send(`<:error:466995152976871434> You didn't give me a song name or YouTube URL! Usage: \`${client.commands.get('play').help.usage}\``)
message.channel.send(`<:error:466995152976871434> You didn't give me a song to play! Usage: \`${client.commands.get(`play`).help.usage}\``); }
return;
}
let voiceChannel = message.member.voice.channel; await play(client, message, args.join(' '), false)
if(!voiceChannel) return message.channel.send('<:error:466995152976871434> You need to be in a voice channel to use this command!');
message.channel.send(`🔎 searching YouTube for \`${args.join(" ")}\``);
client.music.play(message, args.join(" "));
} }
exports.conf = { exports.conf = {
@ -28,6 +20,6 @@ exports.conf = {
exports.help = { exports.help = {
name: "play", name: "play",
category: "Music", category: "Music",
description: "Plays a song.", description: 'Plays the song you request, or adds it to the queue.',
usage: "play [youtube-url] **OR** play [song-name]" usage: 'playnext [song]',
}; };

View file

@ -1,171 +1,162 @@
'use strict'; 'use strict';
const Discord = require("discord.js"); const { getGuild, createTimestamp } = require('../modules/music')
const Discord = require('discord.js')
exports.run = (client, message, args) => { exports.run = (client, message, args) => {
var queue = client.music.getGuild(message.guild.id).queue; var queue = getGuild(message.guild.id).queue
if(queue.length < 1) { if (queue.length < 1) {
return message.channel.send("<:error:466995152976871434> Nothing is playing."); return message.channel.send('<:error:466995152976871434> Nothing is playing.')
} }
let lists = []; const lists = []
function generateList(start, number) { function generateList (start, number) {
var list = ""; let list = ''
var timestamp; let timestamp
var livestream;
if(start == 1 && queue.length == 1) { if (start === 1 && queue.length === 1) {
return ["There's nothing else waiting to be played!", 1]; return ['There\'s nothing else waiting to be played!', 1]
} }
if(number == 1 && queue.length + 1 < start) { if (number === 1 && queue.length + 1 < start) {
return false; return false
};
let q = queue.slice(start);
let i = 0;
for(i = 0; i < q.length; i++) {
let song = q[i];
if(song.duration == 0) {
timestamp = "LIVE";
livestream = true;
} else {
timestamp = client.createTimestamp(song.duration);
};
let aaa = list + `\`${(i + 1) + start - 1}:\` **[${song.title}](https://www.youtube.com/watch?v=${song.id})** added by ${song.requestedBy} \`[${timestamp}]\`\n`;
if(aaa.length > 1024) {
return [list, start + i - 1];
} else {
list = aaa;
}
//totalDuration = totalDuration + song.duration;
};
return [list, start + i + 1];
};
let songsInQueue = queue.length - 1;
let songsInQueueEnglish = "song";
let timeRemaining = 0;
function generatePage(list, page) {
if(!list || list == "") {
return false;
} }
var embed = new Discord.MessageEmbed(); const q = queue.slice(start)
embed.setTitle(`Queue for: ${message.guild.name}`);
embed.setColor(client.embedColour(message));
var elapsedTime = client.music.getGuild(message.guild.id).dispatcher.streamTime / 1000
var totalDuration = queue[0].duration - elapsedTime;
let timeRemaining = ""; let i = 0
for(let i = 1; i < queue.length; i++) {
let b = queue[i];
if(b.duration == 0) { for (i = 0; i < q.length; i++) {
timeRemaining = "∞"; const song = q[i]
break; timestamp = createTimestamp(song.video.lengthSeconds)
}
totalDuration += b.duration; const aaa = list + `\`${(i + 1) + start - 1}:\` **[${song.video.title}](https://www.youtube.com/watch?v=${song.video.videoId})** added by ${song.requestedBy} \`[${timestamp}]\`\n`
}
if(timeRemaining == "") {
let queueDuration = client.createTimestamp(totalDuration);
timeRemaining = queueDuration; if (aaa.length > 1024) {
} return [list, start + i - 1]
let timestamp;
if(queue[0].duration == 0) {
timestamp = "LIVE";
livestream = true;
} else {
timestamp = client.createTimestamp(elapsedTime) + '/' + client.createTimestamp(queue[0].duration);
};
embed.addField(`Now playing:`, `**[${queue[0].title}](https://www.youtube.com/watch?v=${queue[0].id})** added by ${queue[0].requestedBy} \`[${timestamp}]\``)
embed.addField(`Up next:`, list);
if(songsInQueue > 1 || songsInQueue == 0) {
songsInQueueEnglish = "songs";
}
embed.setFooter(`Page ${page}/${lists.length} | ${songsInQueue + " " + songsInQueueEnglish} in queue | ${timeRemaining} time remaining`);
return embed;
};
var myMessage = null;
function displayPage(number) {
let page = generatePage(lists[number - 1], number);
if(page) {
if(myMessage) {
myMessage.edit(page);
} else { } else {
myMessage = message.channel.send(page); list = aaa
} }
return true; // totalDuration = totalDuration + song.duration
} else {
return false;
} }
};
function aFunction(start) { return [list, start + i + 1]
}
const songsInQueue = queue.length - 1
let songsInQueueEnglish = 'song'
function generatePage (list, page) {
if (!list || list === '') {
return false
}
var embed = new Discord.MessageEmbed()
embed.setTitle(`Queue for: ${message.guild.name}`)
embed.setColor(client.embedColour(message))
var elapsedTime = getGuild(message.guild.id).dispatcher.streamTime / 1000
var totalDuration = queue[0].video.lengthSeconds - elapsedTime
let timeRemaining = ''
for (let i = 1; i < queue.length; i++) {
const b = queue[i]
if (b.video.lengthSeconds === 0) {
timeRemaining = '∞'
break
}
totalDuration += b.video.lengthSeconds
}
if (timeRemaining === '') {
const queueDuration = createTimestamp(totalDuration)
timeRemaining = queueDuration
}
let timestamp = `\`${createTimestamp(queue[0].video.lengthSeconds)}\``
if (timestamp !== '`[LIVE]`') {
timestamp = `\`[${createTimestamp(elapsedTime) + '/' + createTimestamp(queue[0].video.lengthSeconds)}]\``
}
embed.addField('Now playing:', `**[${queue[0].video.title}](https://www.youtube.com/watch?v=${queue[0].video.videoId})** added by ${queue[0].requestedBy} ${timestamp}`)
embed.addField('Up next:', list)
if (songsInQueue > 1 || songsInQueue === 0) {
songsInQueueEnglish = 'songs'
}
embed.setFooter(`Page ${page}/${lists.length} | ${songsInQueue + ' ' + songsInQueueEnglish} in queue | ${timeRemaining} time remaining`)
return embed
}
var myMessage = null
function displayPage (number) {
const page = generatePage(lists[number - 1], number)
if (page) {
if (myMessage) {
myMessage.edit(page)
} else {
myMessage = message.channel.send(page)
}
return true
} else {
return false
}
}
function aFunction (start) {
// start - index of song, which we should start with // start - index of song, which we should start with
// end - index of song, which we ended with // end - index of song, which we ended with
let [list, end] = generateList(start, lists.length + 1); const [list, end] = generateList(start, lists.length + 1)
if(list && list != "") { if (list && list !== '') {
lists.push(list); lists.push(list)
if(queue[end + 1]) { if (queue[end + 1]) {
aFunction(end + 1); aFunction(end + 1)
} }
} }
}; }
aFunction(1); aFunction(1)
let page = 1; let page = 1
if(args[0]) { if (args[0]) {
let userPage = Number(args[0]); const userPage = Number(args[0])
if(userPage) { if (userPage) {
page = userPage; page = userPage
} else { } else {
return message.channel.send( return message.channel.send(
`<:error:466995152976871434> Invalid page. Usage: \`${client.commands.get(`queue`).help.usage}\`` `<:error:466995152976871434> Invalid page number. Usage: \`${client.commands.get('queue').help.usage}\``
); )
} }
}; }
if(displayPage(page)) { if (displayPage(page)) {
} else { } else {
return message.channel.send( return message.channel.send(
`<:error:466995152976871434> Page ${page} doesn't exist!` `<:error:466995152976871434> Page ${page} doesn't exist!`
); )
} }
}; }
exports.conf = { exports.conf = {
enabled: true, enabled: true,

View file

@ -1,36 +1,30 @@
const util = require("util") const { getGuild } = require('../modules/music')
const Discord = require("discord.js")
module.exports.run = (client, message, args, level) =>{ module.exports.run = (client, message, args, level) =>{
var queue = client.music.getGuild(message.guild.id).queue; var queue = getGuild(message.guild.id).queue
if(queue.length < 2) { if (queue.length < 2) {
return message.channel.send(`<:error:466995152976871434> Not enough songs are in the queue for this command to work!`); return message.channel.send('<:error:466995152976871434> Not enough songs are in the queue for this command to work!')
} }
if(!args[0]) { if (!args[0]) {
return message.channel.send(`<:error:466995152976871434> You didn't tell me what song to remove! Usage: \`${client.commands.get(`removesong`).help.usage}\``); return message.channel.send(`<:error:466995152976871434> You didn't tell me what song to remove! Usage: \`${client.commands.get('removesong').help.usage}\``)
}; }
var input = +args[0]; var input = +args[0]
if(isNaN(input) == true) { if (isNaN(input) === true) {
return message.channel.send(`<:error:466995152976871434> That isn't a number! You need to tell me the songs position in the queue (1, 2, etc.)`); return message.channel.send('<:error:466995152976871434> That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)')
}; }
if(input >= queue.length) { if (input >= queue.length || input < 1) {
return message.channel.send("Invalid (too large)"); return message.channel.send('<:error:466995152976871434> Input is not a valid song ID.')
}; }
if(input < 1) { var songName = queue[input].video.title
return message.channel.send("Invalid (too small)");
};
var songName = queue[input].title; queue.splice(input, 1)
queue.splice(input, 1); message.channel.send(`<:success:466995111885144095> Removed from queue: **${songName}**`)
message.channel.send(`<:success:466995111885144095> Removed from queue: **${songName}**`);
}; };
exports.conf = { exports.conf = {
@ -38,7 +32,7 @@ exports.conf = {
guildOnly: true, guildOnly: true,
aliases: ["rmsong"], aliases: ["rmsong"],
permLevel: "Moderator", permLevel: "Moderator",
requiredPerms: ["SPEAK"] requiredPerms: []
}; };
exports.help = { exports.help = {

View file

@ -1,15 +1,20 @@
const Discord = require("discord.js") const { getGuild } = require('../modules/music')
exports.run = (client, message, args, level) => { exports.run = (client, message, args, level) => {
let guild = client.music.getGuild(message.guild.id); const guild = getGuild(message.guild.id)
if(guild.queue.length < 1) {
return message.channel.send("<:error:466995152976871434> Nothing is playing.");
};
guild.playing = true;
guild.paused = false;
guild.dispatcher.resume();
message.channel.send("<:play:467216788187512832> Playback resumed!");
if (guild.paused === false) {
return message.channel.send('<:error:466995152976871434> The music is already playing, use pause to pause the music first!')
}
if (guild.queue.length < 1) {
return message.channel.send('<:error:466995152976871434> Nothing is playing!')
}
guild.playing = true
guild.paused = false
guild.dispatcher.resume()
message.channel.send('<:success:466995111885144095> Music playback has been resumed.')
}; };
exports.conf = { exports.conf = {

View file

@ -1,49 +1,50 @@
const Discord = require("discord.js") const { skip, getGuild } = require('../modules/music')
exports.run = (client, message, args, level) => { exports.run = (client, message, args, level) => {
let guild = client.music.getGuild(message.guild.id); const guild = getGuild(message.guild.id)
if(guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send( if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) {
"<:error:466995152976871434> Nothing is playing." return message.channel.send(
); '<:error:466995152976871434> Nothing is playing.'
)
let vc = message.guild.members.cache.get(client.user.id).voice.channel;
if(vc != message.member.voice.channel) return message.channel.send(
'<:error:466995152976871434> You need to be in my voice channel to use this command!'
);
if(guild.queue[0].requestedBy.id == message.author.id) {
skip_song(guild);
message.channel.send(
`<:skip:467216735356059660> Song has been skipped by the user who requested it.`
);
return;
} }
if (guild.skippers.indexOf(message.author.id) == -1) { const vc = message.guild.members.cache.get(client.user.id).voice.channel
guild.skippers.push(message.author.id);
if (vc !== message.member.voice.channel) {
return message.channel.send(
'<:error:466995152976871434> You need to be in my voice channel to use this command!'
)
}
if (guild.queue[0].requestedBy.id === message.author.id) {
skip(message.guild, 'skip')
message.channel.send(
'<:success:466995111885144095> Song has been skipped by the user who requested it.'
)
return
}
if (guild.skippers.indexOf(message.author.id) === -1) {
guild.skippers.push(message.author.id)
if (guild.skippers.length >= Math.ceil(vc.members.filter(member => !member.user.bot).size / 2)) { if (guild.skippers.length >= Math.ceil(vc.members.filter(member => !member.user.bot).size / 2)) {
skip(message.guild, 'skip')
skip_song(guild);
message.channel.send( message.channel.send(
`<:skip:467216735356059660> Song has been skipped.` '<:skip:467216735356059660> Song skipped.'
); )
} else { } else {
message.channel.send( message.channel.send(
`<:success:466995111885144095> Your vote has been acknowledged! **${guild.skippers.length + "/" + Math.ceil(vc.members.filter(member => !member.user.bot).size / 2)}**` `<:success:466995111885144095> Your vote has been acknowledged! **${guild.skippers.length + '/' + Math.ceil(vc.members.filter(member => !member.user.bot).size / 2)}**`
); )
}; };
} else { } else {
message.channel.send( message.channel.send(
"<:denied:466995195150336020> You cannot vote twice!" '<:denied:466995195150336020> You cannot vote twice!'
); )
}; }
}; };
exports.conf = { exports.conf = {
@ -51,7 +52,7 @@ exports.conf = {
guildOnly: true, guildOnly: true,
aliases: ["voteskip"], aliases: ["voteskip"],
permLevel: "User", permLevel: "User",
requiredPerms: ["SPEAK"] requiredPerms: []
}; };
exports.help = { exports.help = {

View file

@ -1,18 +1,18 @@
const Discord = require("discord.js"); const { getGuild } = require('../modules/music')
exports.run = async (client, message) => { exports.run = async (client, message) => {
let guild = client.music.getGuild(message.guild.id); const guild = getGuild(message.guild.id)
if(guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send("<:error:466995152976871434> Nothing is playing."); if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send('Nothing is playing.')
if(!message.member.voice.channel) return message.channel.send('<:error:466995152976871434> You need to be in voice channel to use this command!'); if (!message.member.voice.channel) return message.channel.send('You need to be in voice channel to use this command!')
guild.playing = false; guild.dispatcher.end('silent')
guild.paused = false;
guild.queue = [];
guild.dispatcher.end("silent"); guild.queue = []
guild.playing = false
guild.paused = false
guild.skippers = []
message.channel.send("<:stop:467639381390262284> Playback stopped!"); message.channel.send('<:success:466995111885144095> Playback stopped!')
}; };
exports.conf = { exports.conf = {