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) => {
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> There is nothing for me to skip!`
);
skip_song(guild);
message.channel.send("<:skip:467216735356059660> Skipped the song!")
if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) {
return message.channel.send(
'<:error:466995152976871434> Nothing is playing.'
)
}
skip(message.guild, 'skip')
message.channel.send('<:success:466995111885144095> Song skipped.')
};
exports.conf = {
@ -13,7 +18,7 @@ exports.conf = {
guildOnly: true,
aliases: [],
permLevel: "Moderator",
requiredPerms: ["SPEAK"]
requiredPerms: []
};
exports.help = {
@ -22,7 +27,3 @@ exports.help = {
description: "Skips the currently playing song without requiring a vote.",
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) => {
let guild = client.music.getGuild(message.guild.id);
if(guild.queue.length < 1) {
return message.channel.send("<:error:466995152976871434> Nothing is playing.");
const guild = getGuild(message.guild.id)
if (guild.queue.length < 1) {
return message.channel.send(client.config.emojis.error + ' Nothing is in the queue!')
}
var song = guild.queue[0];
var elapsedTime = client.createTimestamp(guild.dispatcher.streamTime / 1000);
var timestamp;
const s = guild.queue[0]
const elapsedTime = createTimestamp(guild.dispatcher.streamTime / 1000)
let timestamp = `\`[${createTimestamp(s.video.lengthSeconds)}]\``
if(song.duration == 0) {
timestamp = "`[LIVE]`";
} else {
timestamp = `\`[${elapsedTime + "/" + client.createTimestamp(song.duration)}]\``;
};
if (timestamp !== '`[LIVE]`') {
timestamp = `\`[${elapsedTime + '/' + createTimestamp(s.video.lengthSeconds)}]\``
}
embed = new Discord.MessageEmbed();
embed.setTitle("Now playing:")
embed.setThumbnail(song.thumbnail)
embed.setColor(client.embedColour(message));
embed.setDescription(`**[${song.title}](https://www.youtube.com/watch?v=${song.id})**`)
embed.addField("Channel:", song.author, true)
embed.addField("Time:", timestamp, true)
embed.setFooter("Requested by " + song.requestedBy.tag, song.requestedBy.avatarURL({format: "png", dynamic: true, size: 2048}))
const embed = new MessageEmbed()
embed.setTitle('Now playing')
embed.setThumbnail(s.video.videoThumbnails[1].url)
embed.setColor(client.embedColour(message))
embed.setDescription(`**[${s.video.title}](https://www.youtube.com/watch?v=${s.video.videoId})**`)
embed.addField('Channel:', s.video.author, true)
embed.addField('Time:', timestamp, true)
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 = {

View file

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

View file

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

View file

@ -1,171 +1,162 @@
'use strict';
const Discord = require("discord.js");
const { getGuild, createTimestamp } = require('../modules/music')
const Discord = require('discord.js')
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) {
return message.channel.send("<:error:466995152976871434> Nothing is playing.");
if (queue.length < 1) {
return message.channel.send('<:error:466995152976871434> Nothing is playing.')
}
let lists = [];
const lists = []
function generateList(start, number) {
var list = "";
var timestamp;
var livestream;
function generateList (start, number) {
let list = ''
let timestamp
if(start == 1 && queue.length == 1) {
return ["There's nothing else waiting to be played!", 1];
if (start === 1 && queue.length === 1) {
return ['There\'s nothing else waiting to be played!', 1]
}
if(number == 1 && queue.length + 1 < start) {
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;
if (number === 1 && queue.length + 1 < start) {
return false
}
var embed = new Discord.MessageEmbed();
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;
const q = queue.slice(start)
let timeRemaining = "";
for(let i = 1; i < queue.length; i++) {
let b = queue[i];
let i = 0
if(b.duration == 0) {
timeRemaining = "∞";
for (i = 0; i < q.length; i++) {
const song = q[i]
break;
}
timestamp = createTimestamp(song.video.lengthSeconds)
totalDuration += b.duration;
}
if(timeRemaining == "") {
let queueDuration = client.createTimestamp(totalDuration);
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`
timeRemaining = queueDuration;
}
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);
if (aaa.length > 1024) {
return [list, start + i - 1]
} else {
myMessage = message.channel.send(page);
list = aaa
}
return true;
} else {
return false;
// totalDuration = totalDuration + song.duration
}
};
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
// 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 != "") {
lists.push(list);
if(queue[end + 1]) {
aFunction(end + 1);
if (list && list !== '') {
lists.push(list)
if (queue[end + 1]) {
aFunction(end + 1)
}
}
};
}
aFunction(1);
aFunction(1)
let page = 1;
let page = 1
if(args[0]) {
let userPage = Number(args[0]);
if (args[0]) {
const userPage = Number(args[0])
if(userPage) {
page = userPage;
if (userPage) {
page = userPage
} else {
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 {
return message.channel.send(
`<:error:466995152976871434> Page ${page} doesn't exist!`
);
)
}
};
}
exports.conf = {
enabled: true,

View file

@ -1,36 +1,30 @@
const util = require("util")
const Discord = require("discord.js")
const { getGuild } = require('../modules/music')
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) {
return message.channel.send(`<:error:466995152976871434> Not enough songs are in the queue for this command to work!`);
if (queue.length < 2) {
return message.channel.send('<:error:466995152976871434> Not enough songs are in the queue for this command to work!')
}
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}\``);
};
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}\``)
}
var input = +args[0];
var input = +args[0]
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.)`);
};
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.)')
}
if(input >= queue.length) {
return message.channel.send("Invalid (too large)");
};
if (input >= queue.length || input < 1) {
return message.channel.send('<:error:466995152976871434> Input is not a valid song ID.')
}
if(input < 1) {
return message.channel.send("Invalid (too small)");
};
var songName = queue[input].video.title
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 = {
@ -38,7 +32,7 @@ exports.conf = {
guildOnly: true,
aliases: ["rmsong"],
permLevel: "Moderator",
requiredPerms: ["SPEAK"]
requiredPerms: []
};
exports.help = {

View file

@ -1,15 +1,20 @@
const Discord = require("discord.js")
const { getGuild } = require('../modules/music')
exports.run = (client, message, args, level) => {
let guild = client.music.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!");
const guild = getGuild(message.guild.id)
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 = {

View file

@ -1,49 +1,50 @@
const Discord = require("discord.js")
const { skip, getGuild } = require('../modules/music')
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(
"<: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.queue.length < 1 || !guild.playing || !guild.dispatcher) {
return message.channel.send(
'<:error:466995152976871434> Nothing is playing.'
)
}
if (guild.skippers.indexOf(message.author.id) == -1) {
guild.skippers.push(message.author.id);
const 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(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)) {
skip_song(guild);
skip(message.guild, 'skip')
message.channel.send(
`<:skip:467216735356059660> Song has been skipped.`
);
'<:skip:467216735356059660> Song skipped.'
)
} else {
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 {
message.channel.send(
"<:denied:466995195150336020> You cannot vote twice!"
);
};
'<:denied:466995195150336020> You cannot vote twice!'
)
}
};
exports.conf = {
@ -51,7 +52,7 @@ exports.conf = {
guildOnly: true,
aliases: ["voteskip"],
permLevel: "User",
requiredPerms: ["SPEAK"]
requiredPerms: []
};
exports.help = {

View file

@ -1,18 +1,18 @@
const Discord = require("discord.js");
const { getGuild } = require('../modules/music')
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(!message.member.voice.channel) return message.channel.send('<:error:466995152976871434> You need to be in voice channel to use this command!');
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('You need to be in voice channel to use this command!')
guild.playing = false;
guild.paused = false;
guild.queue = [];
guild.dispatcher.end('silent')
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 = {