mirror of
https://github.com/musix-org/musix-oss
synced 2024-12-22 21:13:18 +00:00
More powerful number handling. Setting whether to announce songs starting to play. Remove command fixes
This commit is contained in:
parent
bd9ef87dde
commit
38c0103281
@ -9,6 +9,7 @@ module.exports = {
|
||||
.addField(`${prefix}skip | ${prefix}s`, 'Skip a song.', true)
|
||||
.addField(`${prefix}queue | ${prefix}q`, 'Display the queue.', true)
|
||||
.addField(`${prefix}nowplaying | ${prefix}np`, 'Display what\'s currently playing.', true)
|
||||
.addField(`${prefix}remove | ${prefix}rm`, 'Remove songs from the queue.', true)
|
||||
.addField(`${prefix}volume`, 'Change or check the volume.', true)
|
||||
.addField(`${prefix}pause`, 'Pause the music.', true)
|
||||
.addField(`${prefix}resume`, 'Resume the music.', true)
|
||||
|
@ -50,7 +50,7 @@ module.exports = {
|
||||
try {
|
||||
var connection = await message.member.voiceChannel.join();
|
||||
construct.connection = connection;
|
||||
client.funcs.play(message.guild, construct.songs[0], client, message, 0);
|
||||
client.funcs.play(message.guild, construct.songs[0], client, message, 0, false);
|
||||
} catch (error) {
|
||||
client.queue.delete(message.guild.id);
|
||||
return message.channel.send(`:x: An error occured: ${error}`);
|
||||
@ -70,7 +70,7 @@ module.exports = {
|
||||
};
|
||||
message.channel.send(":white_check_mark: Queue saved!");
|
||||
} else if (args[1] === 'add') {
|
||||
if (client.global.db.playlists[args[2]].saved) {
|
||||
if (client.global.db.playlists[message.guild.id].saved) {
|
||||
const youtube = new YouTube(client.config.apikey);
|
||||
const searchString = args.slice(2).join(" ");
|
||||
const url = args[2] ? args[2].replace(/<(.+)>/g, "$1") : "";
|
||||
@ -112,12 +112,42 @@ module.exports = {
|
||||
client.global.db.playlists[message.guild.id].songs.push(song);
|
||||
message.channel.send(`:white_check_mark: ${song.title} added to the playlist!`);
|
||||
} else return message.channel.send(':x: There is no playlist saved! Start by using the save option!')
|
||||
} else if (args[1] === 'remove') {
|
||||
if (client.global.db.playlists[message.guild.id].saved) {
|
||||
if (!args[2]) return message.channel.send(':x: Please provide a number on the position of the song that you wan\'t to remove!');
|
||||
const songNum = parseInt(args[2]) - 1;
|
||||
if (isNaN(songNum)) return message.channel.send(':x: You need to enter a __number__!');
|
||||
if (songNum === 0) return message.channel.send(':x: You can not remove the currently playing song!');
|
||||
if (parseInt(songNum) > client.global.db.playlists[message.guild.id].songs.size) return message.channel.send(`:x: There is only ${serverQueue.songs.size} amount of songs in the queue!`);
|
||||
message.channel.send(`🗑️ removed \`${client.global.db.playlists[message.guild.id].songs[songNum].title}\` from the queue!`);
|
||||
return client.global.db.playlists[message.guild.id].songs.splice(songNum, 1);
|
||||
} else return message.channel.send(':x: There is no playlist saved! Start by using the save option!')
|
||||
} else if (args[1] === 'list') {
|
||||
if (args[2]) {
|
||||
if (isNaN(args[2])) return msg.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.');
|
||||
}
|
||||
let page = parseInt(args[2]);
|
||||
if (!page) page = 1;
|
||||
let pagetext = `:page_facing_up: Page: ${page} :page_facing_up:`
|
||||
let queuesongs = client.global.db.playlists[message.guild.id].songs.slice((page - 1) * 20, page * 20);
|
||||
let queuemessage = `${queuesongs.map(song => `**#** ${song.title}`).join('\n')}`
|
||||
const hashs = queuemessage.split('**#**').length;
|
||||
for (let i = 0; i < hashs; i++) {
|
||||
queuemessage = queuemessage.replace('**#**', `**${i + 1}**`);
|
||||
}
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle("__playlist queue__")
|
||||
.setDescription(`${pagetext}\n${queuemessage}`)
|
||||
.setColor("#b50002")
|
||||
return message.channel.send(embed);
|
||||
} else {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('Options for playlist!')
|
||||
.addField('play', 'Play the guild specific queue.', true)
|
||||
.addField('save', 'Save the currently playing queue. Note that this will overwrite the currently saved queue!', true)
|
||||
.addField('add', 'Add songs to the playlist. Like song selection', true)
|
||||
.addField('remove', 'Remove songs from the playlist.', true)
|
||||
.addField('list', 'Display the playlist.', true)
|
||||
.setFooter(`how to use: ${prefix}playlist <Option> <Optional option>`)
|
||||
.setAuthor(client.user.username, client.user.displayAvatarURL)
|
||||
.setColor('#b50002')
|
||||
|
@ -7,18 +7,20 @@ module.exports = {
|
||||
const serverQueue = client.queue.get(message.guild.id);
|
||||
const permissions = message.channel.permissionsFor(message.author);
|
||||
if (!serverQueue) return message.channel.send(':x: There is nothing playing');
|
||||
if (isNaN(args[1])) return message.channel.send(':x: You need to enter a number!');
|
||||
if (args[1] === "0") return message.channel.send(':x: You can not remove the currently playing song!');
|
||||
if (args[1] > serverQueue.songs.size) return message.channel.send(`:x: There is only ${serverQueue.songs.size} amount of songs in the queue!`);
|
||||
if (!args[1]) return message.channel.send(':x: Please provide a song position in queue for me to remove!');
|
||||
const pos = parseInt(args[1]);
|
||||
if (isNaN(pos)) return message.channel.send(':x: You need to enter a number!');
|
||||
if (pos === 0) return message.channel.send(':x: You can not remove the currently playing song!');
|
||||
if (pos > serverQueue.songs.size) return message.channel.send(`:x: There is only ${serverQueue.songs.size} amount of songs in the queue!`);
|
||||
if (message.author.id !== '360363051792203779') {
|
||||
if (voiceChannel !== serverQueue.voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in the same voice channel as Musix to remove songs!');
|
||||
if (client.global.db.guilds[message.guild.id].dj) {
|
||||
if (serverQueue.songs[args[1]].author !== message.author) {
|
||||
if (serverQueue.songs[pos].author !== message.author) {
|
||||
if (!message.member.roles.has(client.global.db.guilds[message.guild.id].djrole)) return message.channel.send(':x: You need the `DJ` role to remove songs queue by others!');
|
||||
}
|
||||
} else if (!permissions.has('MANAGE_MESSAGES') && serverQueue.songs[args[1]].author !== message.author) return message.channel.send(':x: You need the `MANAGE_MESSAGES` permission to remove songs queued by others!');
|
||||
} else if (!permissions.has('MANAGE_MESSAGES') && serverQueue.songs[pos].author !== message.author) return message.channel.send(':x: You need the `MANAGE_MESSAGES` permission to remove songs queued by others!');
|
||||
}
|
||||
message.channel.send(`🗑️ removed \`${serverQueue.songs[args[1]].title}\` from the queue!`);
|
||||
return serverQueue.songs.splice(args[1], 1);
|
||||
message.channel.send(`🗑️ removed \`${serverQueue.songs[pos].title}\` from the queue!`);
|
||||
return serverQueue.songs.splice(pos, 1);
|
||||
}
|
||||
};
|
||||
|
@ -19,12 +19,12 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
if (!args[1]) return message.channel.send(`:x: Correct usage: \`${prefix}seek <seeking point in seconds>\``);
|
||||
if (isNaN(args[1])) return message.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.');
|
||||
const argsNumber = parseInt(args[1]);
|
||||
if (argsNumber < 0) return message.channel.send(':x: The seeking point needs to be a positive number!');
|
||||
if (argsNumber > data.length_seconds) return message.channel.send(`:x: The lenght of this song is ${data.length_seconds} seconds! You can't seek further than that!`);
|
||||
const pos = parseInt(args[1])
|
||||
if (isNaN(pos)) return message.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.');
|
||||
if (pos < 0) return message.channel.send(':x: The seeking point needs to be a positive number!');
|
||||
if (pos > data.length_seconds) return message.channel.send(`:x: The lenght of this song is ${data.length_seconds} seconds! You can't seek further than that!`);
|
||||
serverQueue.connection.dispatcher.end('seek');
|
||||
client.funcs.play(message.guild, serverQueue.songs[0], client, message, args[1]);
|
||||
client.funcs.play(message.guild, serverQueue.songs[0], client, message, pos, false);
|
||||
} else {
|
||||
message.channel.send(':x: There is nothing playing!');
|
||||
}
|
||||
|
@ -86,10 +86,11 @@ module.exports = {
|
||||
} else {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('Guild settings for Musix')
|
||||
.addField('prefix', 'Change the guild specific prefix.', true)
|
||||
.addField('volume', 'Change the default volume that the bot will start playing at.', true)
|
||||
.addField('permissions', 'Change whether to require permissions to use eg `skip, stop, pause, loop, etc...`', true)
|
||||
.addField('setdj', 'Set a DJ role. This will allow chosen users to freely use all Musix commands. This will automatically set the `permissions` settings to true in order for the `DJ` role to have effect!', true)
|
||||
.addField('prefix', 'Change the guild specific prefix. (string)', true)
|
||||
.addField('volume', 'Change the default volume that the bot will start playing at. (number)', true)
|
||||
.addField('permissions', 'Change whether to require permissions to use eg `skip, stop, pause, loop, etc... (boolean)`', true)
|
||||
.addField('setdj', 'Set a DJ role. This will allow chosen users to freely use all Musix commands. This will automatically set the `permissions` settings to true in order for the `DJ` role to have effect! (boolean)', true)
|
||||
.addField('announce songs', 'Whether to announce songs that start playing or not.')
|
||||
.setFooter(`how to use: ${prefix}settings <Setting name> <value>`)
|
||||
.setAuthor(client.user.username, client.user.displayAvatarURL)
|
||||
.setColor('#b50002')
|
||||
|
@ -9,6 +9,7 @@ module.exports = {
|
||||
if (message.author.id === '384002606621655040') return message.channel.send('You are not doying that!');
|
||||
if (!serverQueue) return message.channel.send(':x: There is nothing playing.');
|
||||
if (!args[1]) return message.channel.send(`:loud_sound: The current volume is: **${serverQueue.volume}**`);
|
||||
const volume = parseInt(args[1])
|
||||
if (message.author.id !== '360363051792203779') {
|
||||
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to change the volume!');
|
||||
if (client.global.db.guilds[message.guild.id].permissions === true) {
|
||||
@ -16,12 +17,12 @@ module.exports = {
|
||||
if (!message.member.roles.has(client.global.db.guilds[message.guild.id].djrole)) return message.channel.send(':x: You need the `DJ` role to change the volume!');
|
||||
} else if (!permissions.has('MANAGE_CHANNELS')) return message.channel.send(':x: You need the `MANAGE_CHANNELS` permission to change the volume!');
|
||||
}
|
||||
if (isNaN(args[1])) return message.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.');
|
||||
if (args[1] > 100) return message.channel.send(':x: The max volume is `100`!');
|
||||
if (args[1] < 0) return message.channel.send(':x: The volume needs to be a positive number!');
|
||||
}
|
||||
serverQueue.volume = args[1];
|
||||
serverQueue.connection.dispatcher.setVolume(args[1] / 5);
|
||||
return message.channel.send(`:loud_sound: I set the volume to: **${args[1]}**`);
|
||||
if (isNaN(volume)) return message.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.');
|
||||
if (volume > 100) return message.channel.send(':x: The max volume is `100`!');
|
||||
if (volume < 0) return message.channel.send(':x: The volume needs to be a positive number!');
|
||||
serverQueue.volume = volume;
|
||||
serverQueue.connection.dispatcher.setVolume(volume / 5);
|
||||
return message.channel.send(`:loud_sound: I set the volume to: **${volume}**`);
|
||||
}
|
||||
};
|
||||
|
@ -7,7 +7,8 @@ module.exports = {
|
||||
permissions: false,
|
||||
premium: false,
|
||||
dj: false,
|
||||
djrole: null
|
||||
djrole: null,
|
||||
startPlaying: true
|
||||
});
|
||||
client.global.db.guilds[guild.id] = {
|
||||
prefix: ">",
|
||||
@ -15,7 +16,8 @@ module.exports = {
|
||||
permissions: false,
|
||||
premium: false,
|
||||
dj: false,
|
||||
djrole: null
|
||||
djrole: null,
|
||||
startPlaying: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ module.exports = {
|
||||
premium: client.global.db.guilds[guild.id].premium,
|
||||
dj: client.global.db.guilds[guild.id].dj,
|
||||
djrole: client.global.db.guilds[guild.id].djrole,
|
||||
startPlaying: client.global.db.guilds[guild.id].startPlaying
|
||||
});
|
||||
if (client.global.db.guilds[guild.id].premium) {
|
||||
client.db.collection('playlists').doc(guild.id).set({
|
||||
|
@ -29,7 +29,7 @@ module.exports = async function (video, message, voiceChannel, client, playlist
|
||||
try {
|
||||
var connection = await voiceChannel.join();
|
||||
construct.connection = connection;
|
||||
client.funcs.play(message.guild, construct.songs[0], client, message, 0);
|
||||
client.funcs.play(message.guild, construct.songs[0], client, message, 0, true);
|
||||
} catch (error) {
|
||||
client.queue.delete(message.guild.id);
|
||||
client.channels.get('634718645188034560').send("Error with connecting to voice channel: " + error);
|
||||
|
@ -1,4 +1,4 @@
|
||||
module.exports = async function (guild, song, client, message, seek) {
|
||||
module.exports = async function (guild, song, client, message, seek, play) {
|
||||
const Discord = require('discord.js');
|
||||
const ytdl = require('ytdl-core');
|
||||
const serverQueue = client.queue.get(guild.id);
|
||||
@ -25,11 +25,13 @@ module.exports = async function (guild, song, client, message, seek) {
|
||||
});
|
||||
dispatcher.setVolume(serverQueue.volume / 10);
|
||||
dispatcher.on("error", error => console.error(error));
|
||||
let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
|
||||
let songtime = (data.length_seconds * 1000).toFixed(0);
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`:musical_note: Start playing: **${song.title}**`)
|
||||
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
|
||||
.setColor("#b50002")
|
||||
serverQueue.textChannel.send(embed);
|
||||
if (client.global.db.guilds[guild.id].startPlaying || play) {
|
||||
let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
|
||||
let songtime = (data.length_seconds * 1000).toFixed(0);
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`:musical_note: Start playing: **${song.title}**`)
|
||||
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
|
||||
.setColor("#b50002")
|
||||
serverQueue.textChannel.send(embed);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user