1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-16 18:56:00 +00:00

Update V3.0.4

This commit is contained in:
MatteZ02
2020-03-21 19:49:25 +02:00
parent b9f0eb3a96
commit 7e20f54362
63 changed files with 124 additions and 90 deletions

2
src/bot.js Normal file
View File

@ -0,0 +1,2 @@
const MusicClient = require('./struct/client.js');
const client = new MusicClient({});

24
src/commands/bass.js Normal file
View File

@ -0,0 +1,24 @@
module.exports = {
name: 'bass',
description: 'Bassboost command.',
alias: 'none',
usage: '<bass>',
cooldown: 5,
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (!args[1] && queue) return msg.channel.send(`${client.messages.currentBass}**${queue.bass}**`);
const bass = parseFloat(args[1]);
if (client.funcs.check(client, msg, command)) {
if (isNaN(bass)) return msg.channel.send(client.messages.validNumber);
if (bass > 100) return msg.channel.send(client.messages.maxBass);
if (bass < 0) return msg.channel.send(client.messages.positiveBass);
queue.bass = bass;
let message;
message = client.messages.bassApplied.replace("%BASS%", bass);
return msg.channel.send(message);
}
}
};

31
src/commands/cmduses.js Normal file
View File

@ -0,0 +1,31 @@
module.exports = {
name: 'cmduses',
alias: 'none',
usage: '',
description: 'list all commands and how many times they\'ve been used',
onlyDev: true,
permission: 'dev',
category: 'info',
async execute(msg, args, client, Discord, command) {
const cmduses = [];
client.commands.forEach((value, key) => {
cmduses.push([key, value.uses]);
});
cmduses.sort((a, b) => {
return b[1] - a[1];
});
const cmdnamelength = Math.max(...cmduses.map(x => x[0].length)) + 4;
const numberlength = Math.max(...cmduses.map(x => x[1].toString().length), 4);
const markdownrows = ['Command' + ' '.repeat(cmdnamelength - 'command'.length) + ' '.repeat(numberlength - 'uses'.length) + 'Uses'];
cmduses.forEach(x => {
if (x[1] > 0) markdownrows.push(x[0] + '.'.repeat(cmdnamelength - x[0].length) + ' '.repeat(numberlength - x[1].toString().length) + x[1].toString());
});
const embed = new Discord.MessageEmbed();
embed
.setTitle(client.messages.cmdUsesTitle)
.setDescription('```ml\n' + markdownrows.join('\n') + '\n```')
.setFooter(client.messages.cmdUsesFooter)
.setColor(client.config.embedColor);
msg.channel.send(embed);
},
};

13
src/commands/end.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
name: 'end',
alias: 'e',
usage: '',
description: 'end the queue',
onlyDev: true,
permission: 'dev',
category: 'util',
async execute(msg, args, client, Discord, command) {
client.queue.delete(msg.guild.id);
msg.channel.send(client.messages.queueDeleted);
}
};

29
src/commands/eval.js Normal file
View File

@ -0,0 +1,29 @@
module.exports = {
name: 'eval',
alias: 'e',
usage: '<code>',
description: 'Evaluation command. DEV ONLY!',
onlyDev: true,
permission: 'dev',
category: 'util',
async execute(msg, args, client, Discord, command) {
const ytdl = require('ytdl-core');
const queue = client.queue.get(msg.guild.id);
let data;
if (queue) {
data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
}
const input = msg.content.slice(client.global.db.guilds[msg.guild.id].prefix.length + 5);
let output;
try {
output = await eval(input);
} catch (error) {
output = error.toString();
}
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.evalTitle)
.setColor(client.config.embedColor)
.setDescription(`Input: \`\`\`js\n${input.replace(/; /g, ';').replace(/;/g, ';\n')}\n\`\`\`\nOutput: \`\`\`\n${output}\n\`\`\``);
return msg.channel.send(embed);
},
};

38
src/commands/help.js Normal file
View File

@ -0,0 +1,38 @@
module.exports = {
name: 'help',
alias: 'h',
usage: '<command(opt)>',
description: 'See the help for Musix.',
onlyDev: false,
permission: 'none',
category: 'info',
execute(msg, args, client, Discord, command) {
if (args[1]) {
if (!client.commands.has(args[1]) || (client.commands.has(args[1]) && client.commands.get(args[1]).omitFromHelp === true && msg.guild.id !== '489083836240494593')) return msg.channel.send('That command does not exist');
const command = client.commands.get(args[1]);
const embed = new Discord.MessageEmbed()
.setTitle(`${client.global.db.guilds[msg.guild.id].prefix}${command.name} ${command.usage}`)
.setDescription(command.description)
.setFooter(`${client.messages.helpCmdFooter} \`${command.alias}\``)
.setColor(client.config.embedColor)
msg.channel.send(embed);
} else {
const categories = [];
for (let i = 0; i < client.commands.size; i++) {
if (!categories.includes(client.commands.array()[i].category)) categories.push(client.commands.array()[i].category);
}
let commands = '';
for (let i = 0; i < categories.length; i++) {
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp && !x.onlyDev).map(x => `\`${x.name}\``).join(', ')}\n`;
}
let message;
message = client.messages.helpFooter.replace("%PREFIX%", client.global.db.guilds[msg.guild.id].prefix);
const embed = new Discord.MessageEmbed()
.setTitle(`${client.user.username} ${client.messages.helpTitle}`)
.setDescription(commands)
.setFooter(message)
.setColor(client.config.embedColor)
msg.channel.send(embed);
}
}
};

17
src/commands/invite.js Normal file
View File

@ -0,0 +1,17 @@
module.exports = {
name: 'invite',
alias: 'i',
usage: '',
description: 'Invite Musix.',
onlyDev: false,
permission: 'none',
category: 'info',
execute(msg, args, client, Discord, command) {
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.inviteTitle)
.setURL(client.config.invite)
.setColor(client.config.embedColor)
msg.channel.send(embed);
msg.channel.send(client.messages.joinSupport + client.config.supportServer);
}
};

24
src/commands/join.js Normal file
View File

@ -0,0 +1,24 @@
module.exports = {
name: 'join',
alias: 'j',
usage: '',
description: 'Make Musix join the channel your channel',
onlyDev: true,
permission: 'none',
category: 'util',
async execute(msg, args, client, Discord, command) {
try {
const queue = client.queue.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
const connection = await voiceChannel.join();
if (queue) {
queue.connection = connection;
}
msg.channel.send(`${client.messages.joined} ${voiceChannel.name}!`);
} catch (error) {
client.queue.delete(msg.guild.id);
client.channels.get(client.config.debug_channel).send(client.messages.errorConnecting + error);
return msg.channel.send(client.messages.error);
}
}
};

21
src/commands/loop.js Normal file
View File

@ -0,0 +1,21 @@
module.exports = {
name: 'loop',
alias: 'none',
usage: '',
description: 'loop the queue.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
async execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!queue.looping) {
queue.looping = true;
msg.channel.send(client.messages.looping);
} else {
queue.looping = false;
msg.channel.send(client.messages.noLooping);
}
}
}
};

23
src/commands/loopsong.js Normal file
View File

@ -0,0 +1,23 @@
module.exports = {
name: 'loopsong',
alias: 'loops',
usage: '',
description: 'loop the currently playing song.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
async execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!queue.songLooping) {
queue.songLooping = true;
let message;
message = client.messages.loopingSong.replace("%TITLE%", queue.songs[0].title);
msg.channel.send(message);
} else {
queue.songLooping = false;
msg.channel.send(message);
}
}
}
};

View File

@ -0,0 +1,32 @@
module.exports = {
name: 'nowplaying',
alias: 'np',
usage: '',
description: 'See the currently playing song position and length.',
onlyDev: false,
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, command) {
const getThumb = require('video-thumbnail-url');
const ytdl = require('ytdl-core');
const queue = client.queue.get(msg.guild.id);
if (!queue) return msg.channel.send(client.messages.noServerQueue);
let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
let songtime = (data.length_seconds * 1000).toFixed(0);
queue.time = queue.connection.dispatcher.streamTime;
let completed = (queue.time.toFixed(0));
let barlength = 30;
let completedpercent = ((completed / songtime) * barlength).toFixed(0);
let array = []; for (let i = 0; i < completedpercent - 1; i++) { array.push('⎯'); } array.push('⭗'); for (let i = 0; i < barlength - completedpercent - 1; i++) { array.push('⎯'); }
const thumbnail = getThumb(queue.songs[0].url);
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.nowPlaying)
.setDescription(`${client.messages.nowPlayingDesc} ${queue.songs[0].title}\n${array.join('')} | \`${client.funcs.msToTime(completed, "hh:mm:ss")} / ${client.funcs.msToTime(songtime, "hh:mm:ss")}\``)
.setFooter(`Queued by ${queue.songs[0].author.tag}`)
.setURL(queue.songs[0].url)
.setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor)
return msg.channel.send(embed);
}
};

18
src/commands/pause.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
name: 'pause',
alias: 'none',
usage: '',
description: 'Pause the currently playing music.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (queue.paused) return msg.channel.send(client.messages.alreadyPaused);
queue.paused = true;
queue.connection.dispatcher.pause(true);
return msg.channel.send(client.messages.paused);
}
}
};

54
src/commands/play.js Normal file
View File

@ -0,0 +1,54 @@
const YouTube = require("simple-youtube-api");
module.exports = {
name: 'play',
alias: 'p',
usage: '<song name>',
description: 'Play some music.',
onlyDev: false,
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, command) {
const youtube = new YouTube(client.config.api_key);
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const queue = client.queue.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
if (!queue) {
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
} else {
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
}
if (!args[1]) return msg.channel.send(client.messages.noQuery);
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
}
client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
return lmsg.edit(client.messages.playlistAdded);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
const videos = await youtube.searchVideos(searchString, 1);
var video = await youtube.getVideoByID(videos[0].id);
} catch (err) {
console.error(err);
if (err.code === 403) {
return msg.channel.send(client.messages.quotaReached);
}
return msg.channel.send(client.messages.noResults);
}
}
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
}
}
};

28
src/commands/queue.js Normal file
View File

@ -0,0 +1,28 @@
module.exports = {
name: 'queue',
alias: 'q',
usage: '<page(opt)>',
description: 'See the queue.',
onlyDev: false,
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (!queue) return msg.channel.send(client.messages.noServerQueue);
const page = 1;
let queuesongs = queue.songs.slice((page - 1) * 20 + 1, page * 20 + 1);
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}**`);
}
let message;
message = client.messages.queueDesc.replace("%SONG%", queue.songs[0].title);
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.queueTitle)
.setDescription(`${message}\n${queuemessage}`)
.setFooter(`${queue.songs.length} ${client.messages.queueFooter}`)
.setColor(client.config.embedColor)
return msg.channel.send(embed);
}
};

25
src/commands/remove.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
name: 'remove',
alias: 'rm',
usage: '<song pos>',
description: 'Remove a song from the queue',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!args[1]) return msg.channel.send(client.messages.provideASong);
const pos = parseInt(args[1]);
if (isNaN(pos)) return msg.channel.send(client.messages.validNumber);
if (pos < 1) return msg.channel.send(client.messages.noSongs);
let message1;
let message2;
message1 = client.messages.queueLength.replace("%LENGTH%", queue.songs.length);
if (pos > queue.songs.length) return msg.channel.send(message1);
message2 = client.messages.removed.replace("%SONG%", queue.songs[pos].title);
msg.channel.send(message2);
return queue.songs.splice(pos, 1);
}
}
};

12
src/commands/restart.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = {
name: 'restart',
alias: 'none',
usage: '',
description: 'restart all shards',
onlyDev: true,
permission: 'dev',
category: 'util',
async execute(msg, args, client, Discord, command) {
client.shard.respawnAll(client.config.shardDelay, client.config.respawnDelay, client.config.spawnTimeout);
}
};

18
src/commands/resume.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
name: 'resume',
alias: 'none',
usage: '',
description: 'Resume the paused music.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!queue.paused) return msg.channel.send(client.messages.notPaused);
queue.paused = false;
queue.connection.dispatcher.resume(true);
return msg.channel.send(client.messages.resumed);
}
}
};

13
src/commands/savedb.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
name: 'savedb',
alias: 'save',
usage: '',
description: 'save the database',
onlyDev: true,
permission: 'dev',
category: 'util',
async execute(msg, args, client, Discord, command) {
client.funcs.saveDB(client);
msg.channel.send(client.messages.dbSaved);
}
};

71
src/commands/search.js Normal file
View File

@ -0,0 +1,71 @@
const YouTube = require("simple-youtube-api");
const he = require('he');
module.exports = {
name: 'search',
alias: 'sr',
usage: '<search word(s)>',
description: 'Search the top 10 queryes and choose one.',
onlyDev: false,
permission: 'none',
category: 'music',
async execute(msg, args, client, Discord, command) {
const youtube = new YouTube(client.config.api_key);
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const queue = client.queue.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
if (!queue) {
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
} else {
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
}
if (!args[1]) return msg.channel.send(client.messages.noQuery);
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
}
let message;
message = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
return lmsg.edit(message);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.songSelection)
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
.setFooter(client.messages.provideANumber)
.setColor(client.config.embedColor)
msg.channel.send(embed);
try {
var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, {
max: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
console.error(err);
return msg.channel.send(client.messages.cancellingVideoSelection);
}
const videoIndex = parseInt(response.first().content);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) {
console.error(err);
return msg.channel.send(client.messages.noResults);
}
}
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
}
}
};

29
src/commands/seek.js Normal file
View File

@ -0,0 +1,29 @@
module.exports = {
name: 'seek',
alias: 'none',
usage: '<point in song>',
description: 'Seek to a specific point in the currently playing song.',
onlyDev: true,
permission: 'MANAGE_MESSAGES',
category: 'music',
async execute(msg, args, client, Discord, command) {
const ytdl = require('ytdl-core');
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${client.global.db.guilds[msg.guild.id].prefix}seek ${command.usage}\``);
let point = args[1];
const pos = parseInt(args[1]);
if (isNaN(pos)) {
if (pos < 0) return msg.channel.send(client.messages.seekingPointPositive);
let message;
message = client.messages.seekMax.replace("%LENGTH%", data.length_seconds);
if (pos > data.length_seconds) return msg.channel.send(message);
point = pos;
}
queue.connection.dispatcher.end();
queue.endReason = "seek";
client.funcs.play(msg.guild, queue.songs[0], client, msg, point, false);
}
}
};

44
src/commands/settings.js Normal file
View File

@ -0,0 +1,44 @@
module.exports = {
name: 'settings',
alias: 'pref',
usage: '<setting> <value(opt)>',
description: 'Change the server settings for Musix.',
onlyDev: false,
permission: 'MANAGE_GUILD',
category: 'util',
async execute(msg, args, client, Discord, command) {
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.settingsTitle)
.addField(client.messages.settingsPrefix, client.messages.settingsPrefixDesc, true)
.addField(client.messages.settingsVolume, client.messages.settingsVolumeDesc, true)
.addField(client.messages.settingsPermissions, client.messages.settingsPermissionsDesc, true)
.addField(client.messages.settingsSetDj, client.messages.settingsSetDjDesc, true)
.addField(client.messages.settingsAnnounceSongs, client.messages.settingsAnnounceSongsDesc)
.addField(client.messages.settingsBass, client.messages.settingsBassDesc, true)
.setFooter(client.messages.settingsFooter)
.setAuthor(client.user.username, client.user.displayAvatarURL)
.setColor(client.config.embedColor)
const permissions = msg.channel.permissionsFor(msg.author);
if (msg.author.id !== client.config.devId) {
if (!permissions.has(command.permission)) return msg.channel.send(client.messages.noPermsManageSettings);
}
if (args[1]) {
const optionName = args[1].toLowerCase();
const option = client.settingCmd.get(optionName) || client.settingCmd.find(cmd => cmd.aliases && cmd.aliases.includes(optionName));
if (!option) return msg.channel.send(embed);
try {
option.execute(msg, args, client);
} catch (error) {
msg.reply(client.messages.errorExeOpt);
const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **'))
.setColor(client.config.embedColor);
client.fetchUser(client.config.devId).then(user => user.send(embed)).catch(console.error);
client.channels.get(client.config.debug_channel).send(embed);
}
} else {
return msg.channel.send(embed);
}
},
};

View File

@ -0,0 +1,17 @@
module.exports = {
name: 'announcesongs',
async execute(msg, args, client) {
if (!args[2]) return msg.channel.send(`${client.messages.announceSongs} \`${client.global.db.guilds[msg.guild.id].permissions}\``);
if (args[2] === 'true') {
if (!client.global.db.guilds[msg.guild.id].announceSongs) {
client.global.db.guilds[msg.guild.id].announceSongs = true;
msg.channel.send(client.messages.permissionsSetTrue);
} else return msg.channel.send(client.messages.announceSongsTrue);
} else if (args[2] === 'false') {
if (client.global.db.guilds[msg.guild.id].announceSongs) {
client.global.db.guilds[msg.guild.id].announceSongs = false;
msg.channel.send(client.messages.announceSongsFalse);
} else return msg.channel.send(client.messages.announceSongsFalse);
} else return msg.channel.send(client.messages.boolean);
}
};

View File

@ -0,0 +1,14 @@
module.exports = {
name: 'bass',
async execute(msg, args, client) {
if (!args[2]) return msg.channel.send(client.messages.currentDefaultBass + client.global.db.guilds[msg.guild.id].bass);
if (args[2] === "false") {
client.global.db.guilds[msg.guild.id].bass = false;
msg.channel.send(client.messages.bassFalse);
}
const level = parseInt(args[2]);
if (isNaN(level)) return msg.channel.send(client.messages.validNumber);
client.global.db.guilds[msg.guild.id].bass = level;
msg.channel.send(`${client.messages.bassLevel} ${level}!`);
}
};

View File

@ -0,0 +1,17 @@
module.exports = {
name: 'permissions',
async execute(msg, args, client) {
if (!args[2]) return msg.channel.send(`${client.messages.permission} \`${client.global.db.guilds[msg.guild.id].permissions}\``);
if (args[2] === 'true') {
if (!client.global.db.guilds[msg.guild.id].permissions) {
client.global.db.guilds[msg.guild.id].permissions = true;
msg.channel.send(client.messages.permissionsSetTrue);
} else return msg.channel.send(client.messages.permissionsTrue);
} else if (args[2] === 'false') {
if (client.global.db.guilds[msg.guild.id].permissions) {
client.global.db.guilds[msg.guild.id].permissions = false;
msg.channel.send(client.messages.permissionsSetFalse);
} else return msg.channel.send(client.messages.permissionsFalse);
} else return msg.channel.send(client.messages.boolean);
}
};

View File

@ -0,0 +1,9 @@
module.exports = {
name: 'prefix',
async execute(msg, args, client) {
if (!args[2]) return msg.channel.send(`${client.messages.currentPrefix} \`${client.global.db.guilds[msg.guild.id].prefix}\``);
if (args[2].length > 5) return msg.channel.send(client.messages.prefixMaxLength);
client.global.db.guilds[msg.guild.id].prefix = args[2];
msg.channel.send(`${client.messages.prefixSet} \`${args[2]}\``);
}
};

View File

@ -0,0 +1,14 @@
module.exports = {
name: 'reset',
async execute(msg, args, client) {
client.global.db.guilds[msg.guild.id] = {
prefix: client.config.prefix,
defaultVolume: 5,
permissions: false,
premium: false,
dj: false,
djrole: null
};
msg.channel.send(client.messages.reset);
}
};

View File

@ -0,0 +1,28 @@
module.exports = {
name: 'setdj',
async execute(msg, args, client) {
if (!client.global.db.guilds[msg.guild.id].dj) {
if (!client.global.db.guilds[msg.guild.id].permissions) {
client.global.db.guilds[msg.guild.id].permissions = true;
}
if (msg.guild.roles.cache.find(x => x.name === "DJ")) {
client.global.db.guilds[msg.guild.id].djrole = msg.guild.roles.cache.find(x => x.name === "DJ").id;
msg.channel.send(client.messages.djRoleFound);
client.global.db.guilds[msg.guild.id].dj = true;
} else {
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('MANAGE_ROLES')) return msg.channel.send(client.messages.noPermsManageRoles);
msg.guild.createRole({
name: 'DJ',
})
.then(role => client.global.db.guilds[msg.guild.id].djrole = role.id)
.catch(console.error)
client.global.db.guilds[msg.guild.id].dj = true;
msg.channel.send(client.messages.djRoleCreated);
}
} else {
client.global.db.guilds[msg.guild.id].dj = false;
msg.channel.send(client.messages.djFalse);
}
}
};

View File

@ -0,0 +1,10 @@
module.exports = {
name: 'volume',
async execute(msg, args, client) {
if (!args[2]) return msg.channel.send(`${client.messages.currentDefaultVolume} \`${client.global.db.guilds[msg.guild.id].defaultVolume}\``);
if (isNaN(args[2])) return msg.channel.send(client.messages.defaultVolumeNumber);
if (args[2].length > 2) return msg.channel.send(client.messages.defaultVolumeMax);
client.global.db.guilds[msg.guild.id].defaultVolume = args[2];
msg.channel.send(`${client.messages.defaultVolumeSet} \`${args[2]}\``);
}
};

16
src/commands/shuffle.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
name: 'shuffle',
alias: 'none',
usage: '',
description: 'Shuffle the queue.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
client.funcs.shuffle(queue.songs);
msg.channel.send(client.messages.shuffled);
}
}
};

50
src/commands/skip.js Normal file
View File

@ -0,0 +1,50 @@
module.exports = {
name: 'skip',
alias: 's',
usage: '',
description: 'Skip the currently playing song.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!queue || !queue.playing) return msg.channel.send(client.messages.noServerQueue);
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
if (client.global.db.guilds[msg.guild.id].permissions) {
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole) || !permissions.has(command.permission)) {
return vote(queue, msg, client);
} else {
return skipSong(queue, msg, client);
}
} else {
return skipSong(queue, msg, client);
}
} else {
return skipSong(queue, msg, client);
}
}
};
function skipSong(queue, msg, client) {
msg.channel.send(client.messages.skipped);
queue.endReason = "skip";
queue.connection.dispatcher.end();
};
function vote(queue, msg, client) {
queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2);
queue.votesNeeded.toFixed();
if (queue.voiceChannel.members.size > 2) {
if (queue.voters.includes(msg.member.id)) return msg.channel.send(client.messages.alreadyVoted);
queue.votes++;
queue.voters.push(msg.member.id);
if (queue.votes >= queue.votesNeeded) {
queue.voters = [];
queue.votes = 0;
queue.votesNeeded = null;
return skipSong(queue, msg);
} else return msg.channel.send(`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`);
} else {
return skipSong(queue, msg);
}
};

24
src/commands/skipto.js Normal file
View File

@ -0,0 +1,24 @@
module.exports = {
name: 'skipto',
alias: 'st',
usage: '<point in queue>',
description: 'Skip to a point in the queue',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
async execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``);
const point = parseInt(args[1] - 1);
if (isNaN(point)) return msg.channel.send(client.messages.validNumber);
if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs);
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent);
for (let i = 0; i < point; i++) {
queue.songs.shift();
}
queue.endReason = "skipto";
queue.connection.dispatcher.end();
}
}
};

26
src/commands/status.js Normal file
View File

@ -0,0 +1,26 @@
module.exports = {
name: 'status',
alias: 'stats',
usage: '',
description: 'See the current status for Musix.',
onlyDev: false,
permission: 'none',
category: 'info',
execute(msg, args, client, Discord, command) {
const uptime = client.funcs.msToTime(client.uptime, "dd:hh:mm:ss");
msg.channel.send(client.messages.pinging).then(m => {
const latency = m.createdTimestamp - msg.createdTimestamp;
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.statusTitle)
.addField(client.messages.statusField1, client.ws.ping, true)
.addField(client.messages.statusField2, latency, true)
.addField(client.messages.statusField3, uptime, true)
.addField(client.messages.statusField4, client.shard.ids)
.setAuthor(client.user.username, client.user.displayAvatarURL)
.setColor(client.config.embedColor)
m.delete();
return msg.channel.send(embed);
});
}
};

19
src/commands/stop.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
name: 'stop',
description: 'Stop command.',
alias: 'none',
usage: '',
onlyDev: false,
permission: 'MANAGE_CHANNELS',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
queue.songs = [];
queue.looping = false;
queue.endReason = "stop";
queue.connection.dispatcher.end();
msg.channel.send(client.messages.stop)
}
}
};

23
src/commands/volume.js Normal file
View File

@ -0,0 +1,23 @@
module.exports = {
name: 'volume',
description: 'Volume command.',
alias: 'none',
usage: '<volume>',
cooldown: 5,
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
if (!args[1] && queue) return msg.channel.send(`${client.messages.currentVolume}**${queue.volume}**`);
const volume = parseFloat(args[1]);
if (client.funcs.check(client, msg, command)) {
if (isNaN(volume)) return msg.channel.send(client.messages.validNumber);
if (volume > 100) return msg.channel.send(client.messages.maxVolume);
if (volume < 0) return msg.channel.send(client.messages.positiveVolume);
queue.volume = volume;
queue.connection.dispatcher.setVolume(volume / 5);
return msg.channel.send(`${client.messages.setVolume}**${volume}**`);
}
}
};

View File

@ -0,0 +1,23 @@
module.exports = {
name: 'guildcreate',
async execute(client, guild) {
client.db.collection('guilds').doc(guild.id).set({
prefix: client.config.prefix,
defaultVolume: client.config.defaultVolume,
permissions: client.config.permissions,
dj: client.config.dj,
djrole: client.config.djrole,
startPlaying: client.config.startPlaying,
bass: client.config.bass,
});
client.global.db.guilds[guild.id] = {
prefix: client.config.prefix,
defaultVolume: client.config.defaultVolume,
permissions: client.config.permissions,
dj: client.config.dj,
djrole: client.config.djrole,
startPlaying: client.config.startPlaying,
bass: client.config.bass,
};
}
}

View File

@ -0,0 +1,29 @@
module.exports = {
name: 'message',
async execute(client, msg, Discord) {
if (msg.author.bot || !msg.guild) return;
if (!client.global.db.guilds[msg.guild.id]) return;
let prefix = client.global.db.guilds[msg.guild.id].prefix;
if (client.config.devMode) prefix = client.config.devPrefix;
const args = msg.content.slice(prefix.length).split(' ');
if (msg.mentions.users.first()) {
if (msg.mentions.users.first().id === client.user.id) {
if (!args[1]) return;
if (args[1] === 'prefix') return msg.channel.send(`${client.messages.prefixHere}\`${prefix}\`.`);
if (args[1] === 'help') {
const command = client.commands.get("help");
return client.funcs.exe(msg, args, client, Discord, prefix, command);
}
}
}
if (!msg.content.startsWith(prefix)) return;
if (!args[0]) return;
const commandName = args[0].toLowerCase();
if (commandName === "none") return;
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName);
if (!command && msg.content !== `${prefix}`) return;
if (command.onlyDev && msg.author.id !== client.config.devId) return;
if (client.config.devMode && msg.member.id !== client.config.devId) return msg.channel.send(client.messages.devMode);
client.funcs.exe(msg, args, client, Discord, command);
}
}

View File

@ -0,0 +1,51 @@
const DBL = require("dblapi.js");
module.exports = {
name: 'ready',
async execute(client, Discord) {
const debugChannel = await client.channels.fetch(client.config.debug_channel);
client.debug_channel = debugChannel
const remoteMusixGuildsData = await client.funcs.dbget('guilds', null, client);
remoteMusixGuildsData.forEach(guildData => {
client.global.db.guilds[guildData.id] = guildData.d;
});
if (client.config.devMode) {
console.log('dev mode');
client.guilds.cache.forEach(guild => {
client.global.db.guilds[guild.id] = {
prefix: client.config.prefix,
defaultVolume: client.config.defaultVolume,
permissions: client.config.permissions,
dj: client.config.dj,
djrole: client.config.djrole,
startPlaying: client.config.startPlaying,
bass: client.config.bass,
};
});
}
console.log(`- DB Set - Shard: ${client.shard.ids} -`);
client.user.setActivity(`@${client.user.username} help | 🎶`, { type: 'LISTENING' });
client.user.setStatus('online');
const dbl = new DBL(client.config.dblKey, client);
if (client.config.dblApi && !client.config.devMode) {
dbl.on('posted', () => {
console.log('Server count posted!');
});
dbl.on('error', error => {
console.log('Error with DBL: ' + error);
});
dbl.postStats(client.guilds.size);
}
console.log(`- Activated - Shard: ${client.shard.ids} -`);
setInterval(() => {
client.funcs.checkDB(client);
}, 60000);
setInterval(async () => {
client.funcs.saveDB(client);
if (client.config.dblApi && !client.config.devMode) dbl.postStats(client.guilds.cache.size);
}, 1800000);
setInterval(() => {
client.funcs.ffmpeg(client, Discord);
}, 7200000);
}
}

View File

@ -0,0 +1,33 @@
module.exports = {
name: 'voiceStateUpdate',
async execute(client, oldState, newState) {
if (oldState.channel === null) return newState.setSelfDeaf(true);
let change = false;
const queue = client.queue.get(newState.guild.id);
if (!queue) return;
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
if (newState.member.voice.channel === null) {
queue.songs = [];
queue.looping = false;
queue.endReason = "manual disconnect";
return client.queue.delete(newState.guild.id);
}
if (newState.member.voice.channel !== queue.voiceChannel) {
change = true;
queue.voiceChannel = newState.member.voice.channel;
queue.connection = newState.connection;
}
}
if (oldState.channel.members.size === 1 && oldState.channel === queue.voiceChannel || change) {
setTimeout(() => {
if (!queue) return;
if (queue.voiceChannel.members.size === 1) {
queue.songs = [];
queue.looping = false;
queue.endReason = "Timeout";
queue.connection.dispatcher.end();
}
}, 120000);
}
}
}

View File

@ -0,0 +1,13 @@
module.exports = async function (client, error, guild) {
const queue = client.queue.get(guild.id);
console.error(error);
/*if (error = "Error: input stream: This video contains content from WMG, who has blocked it on copyright grounds.") {
queue.endReason = "skip";
queue.connection.dispatcher.end();
return queue.textChannel.send(client.messages.songBlockedWMG);
}*/
client.debug_channel.send(client.messages.dispatcherError + error);
queue.voiceChannel.leave();
client.queue.delete(guild.id);
return queue.textChannel.send(client.messages.errorDispatcher);
};

View File

@ -0,0 +1,18 @@
module.exports = async function (client, reason, guild) {
const queue = client.queue.get(guild.id);
queue.playing = false;
if (reason === "seek") {
return queue.playing = true;
}
if (!queue.songLooping) {
if (queue.looping) {
queue.songs.push(queue.songs[0]);
}
queue.votes = 0;
queue.voters = [];
queue.songs.shift();
}
client.funcs.play(guild, queue.songs[0], client, 0, true);
};

19
src/events/events.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = function (client) {
const Discord = require('discord.js');
const events = './clientEvents/';
client.on('ready', () => {
require(`${events}ready`).execute(client, Discord);
});
client.on('message', (msg) => {
require(`${events}msg`).execute(client, msg, Discord);
});
client.on('guildCreate', (guild) => {
require(`${events}guildCreate`).execute(client, guild);
});
client.on('voiceStateUpdate', (oldState, newState) => {
require(`${events}voiceStateUpdate`).execute(client, oldState, newState);
});
client.on('error', (error) => {
client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${client.shard}`);
});
}

60
src/struct/client.js Normal file
View File

@ -0,0 +1,60 @@
const { Client, Collection } = require('discord.js');
const admin = require('firebase-admin');
const serviceAccount = require('./config/serviceAccount.json');
const fs = require('fs');
const path = require('path');
const events = require('../events/events.js');
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START']
});
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
this.commands = new Collection();
this.commandAliases = new Collection();
this.settingCmd = new Collection();
this.queue = new Map();
this.funcs = {};
this.dispatcher = {};
this.config = require('./config/config.js');
this.messages = require('./config/messages.js');
this.db = admin.firestore();
this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
this.dispatcher.finish = require('../events/dispatcherEvents/finish.js');
this.dispatcher.error = require('../events/dispatcherEvents/error.js');
this.global = {
db: {
guilds: {},
},
};
fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => {
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`);
});
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
command.uses = 0;
this.commands.set(command.name, command);
this.commandAliases.set(command.alias, command);
}
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.js'));
for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option);
}
if (this.config.devMode) {
this.config.token = this.config.devToken;
}
events(this);
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
}
};

View File

@ -0,0 +1,32 @@
require('dotenv/config');
module.exports = {
token: process.env.TOKEN,
devToken: process.env.DEVTOKEN,
dblKey: process.env.DBLKEY,
api_key: process.env.GOOGLE_API_KEY,
testServer: "489111553321336832",
debug_channel: "634718645188034560",
primary_test_channel: "617633098296721409",
secondary_test_channel: "570531724002328577",
devId: "360363051792203779",
embedColor: "#b50002",
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
supportServer: "https://discord.gg/rvHuJtB",
devMode: false,
dblApi: false,
saveDB: true,
respawn: true,
shards: 10,
shardDelay: 10000,
spawnTimeout: 60000,
respawnDelay: 1000,
prefix: ">",
devPrefix: "-",
defaultVolume: 5,
permissions: false,
dj: false,
djrole: null,
startPlaying: true,
bass: 1
}

View File

@ -0,0 +1,126 @@
module.exports = {
alreadyPaused: "<:redx:674263474704220182> The music is already paused!",
alreadyVoted: "<:redx:674263474704220182> You have already voted to skip!",
announceSongs: "📣 Current setting:",
announceSongsFalse: "<:green_check_mark:674265384777416705> announcesongs now set to `false`!",
announceSongsTrue: "<:green_check_mark:674265384777416705> announcesongs now set to `true`!",
bassApplied: "<:volumehigh:674685637626167307> The bass level **%BASS%** will be applied when the next song starts playing!",
bassFalse: "<:green_check_mark:674265384777416705> Bass is now false!",
bassLevel: "<:green_check_mark:674265384777416705> Bass level is now",
boolean: "<:redx:674263474704220182> Please define a boolean! (true/false)",
cancellingVideoSelection: "<:redx:674263474704220182> Cancelling video selection",
cantSkipToCurrent: "<:redx:674263474704220182> You can't skip to the song currently playing!",
channelFull: "<:redx:674263474704220182> Your voice channel is full!",
cmdUsesFooter: "These statistics are from the current uptime.",
cmdUsesTitle: "Musix Command Usage During Current Uptime",
correctUsage: "<:redx:674263474704220182> correct usage: ",
currentBass: ":loud_sound: The current bass is: ",
currentDefaultBass: ":speaker: Currect default bass level: ",
currentDefaultVolume: ":speaker: Current default volume is:",
currentPrefix: "Current prefix:",
currentVolume: ":loud_sound: The current volume is: ",
dbSaved: "<:green_check_mark:674265384777416705> DB Saved!",
defaultVolumeMax: "<:redx:674263474704220182> The default volume must be below `100` for quality and safety resons.",
defaultVolumeNumber: "<:redx:674263474704220182> I'm sorry, But the default volume needs to be a valid __number__.",
defaultVolumeSet: "<:green_check_mark:674265384777416705> Default volume set to:",
devMode: "<:redx:674263474704220182> Dev mode has been turned on! Commands are only available to developer(s)!",
dispatcherError: "Error with the dispatcher: ",
djFalse: "<:green_check_mark:674265384777416705> `DJ` now set to `false`",
djRoleCreated: "<:green_check_mark:674265384777416705> I did not find a role `DJ` so i have created one for you!",
djRoleFound: "<:green_check_mark:674265384777416705> I found a `DJ` role from this guild! This role is now the DJ role.",
error: "<:redx:674263474704220182> An error occured!",
errorConnecting: "Error with connecting to voice channel: ",
errorDetected: "Error detected: ",
errorDispatcher: "<:redx:674263474704220182> An error has occured while playing music! The queue has been deleted.",
errorExe: "<:redx:674263474704220182> there was an error trying to execute that command!",
errorExeOpt: "<:redx:674263474704220182> there was an error trying to execute that option!",
evalTitle: "Evaluation Command",
helpCmdFooter: "Command Alias:",
helpFooter: "\"%PREFIX%help <command>\" to see more information about a command.",
helpTitle: "help",
inviteTitle: "Invite Musix to your Discord server!",
joined: "<:green_check_mark:674265384777416705> Joined",
joinSupport: "Join the musix support server: ",
loadingSongs: "<a:loading:674284196700618783> Loading song(s)",
looping: "<:repeat1:674685561377914892> Looping the queue now!",
loopingSong: "<:repeatsong:674685573419761716> Looping **%TITLE%** now!",
maxBass: "<:redx:674263474704220182> The max bass is `100`!",
maxVolume: "<:redx:674263474704220182> The max volume is `100`!",
noDj: "<:redx:674263474704220182> You need the `DJ` role to use this command!",
noLooping: "<:repeat1:674685561377914892> No longer looping the queue!",
noLoopingSong: "<:repeatsong:674685573419761716> No longer looping the song!",
noPerms: `<:redx:674263474704220182> You need the %PERMS% permission to use this command!`,
noPermsConnect: "<:redx:674263474704220182> I cannot connect to your voice channel, make sure I have the proper permissions!",
noPermsEmbed: "<:redx:674263474704220182> I cannot send embeds (Embed links), make sure I have the proper permissions!",
noPermsManageRoles: "<:redx:674263474704220182> I cannot create roles (Manage roles), make sure I have the proper permissions! I will need this permission to create a `DJ` role since i did not find one!",
noPermsManageSettings: "<:redx:674263474704220182> You need the `MANAGE_SERVER` permission to change the settings!",
noPermsSpeak: "<:redx:674263474704220182> I cannot speak in your voice channel, make sure I have the proper permissions!",
noPermsUseExternalEmojis: "<:redx:674263474704220182> I cannot use external emojis, make sure I have the proper permissions!",
noQuery: "<:redx:674263474704220182> You need to use a link or search for a song!",
noResults: "<:redx:674263474704220182> I could not obtain any search results!",
noServerQueue: "<:redx:674263474704220182> There is nothing playing!",
noSongs: "'<:redx:674263474704220182> That song does not exist!",
nowPlayingDesc: "<a:aNotes:674602408105476106>**Now playing:**",
notAllowed: "<:redx:674263474704220182> You are not allowed to do that!",
notEnoughVotes: "<:redx:674263474704220182> Not enough votes!",
notPaused: "<:redx:674263474704220182> The music in not paused!",
noVoiceChannel: "<:redx:674263474704220182> I'm sorry but you need to be in a voice channel to play music!",
nowPlaying: "__Now playing__",
paused: "<:pause:674685548610322462> Paused the music!",
permission: "🔒 Permission requirement:",
permissionsFalse: "<:redx:674263474704220182> That value is already `false`!",
permissionsSetFalse: "<:green_check_mark:674265384777416705> Permissions requirement now set to: `false`",
permissionsSetTrue: "<:green_check_mark:674265384777416705> Permissions requirement now set to: `true`",
permissionsTrue: "<:redx:674263474704220182> That value is already `true`!",
pinging: "<a:loading:674284196700618783> Pinging...",
playlistAdded: "<:green_check_mark:674265384777416705> Playlist: **%TITLE%** has been added to the queue!",
positiveBass: "<:redx:674263474704220182> The bass needs to be a positive number!",
positiveVolume: "<:redx:674263474704220182> The volume needs to be a positive number!",
prefixHere: "My prefix here is: ",
prefixMaxLength: "The prefix must be shorter or equal to 5 letters!",
prefixSet: "<:green_check_mark:674265384777416705> New prefix set to:",
provideANumber: "Please provide a number ranging from 1-10 to select one of the search results.",
provideASong: "<:redx:674263474704220182> Please provide a song position in queue for me to remove!",
queueDeleted: "Queue deleted!",
queueDesc: "**Now playing:** %SONG%<a:aNotes:674602408105476106>\n:arrow_down: Next in queue :arrow_down:",
queueFooter: "songs in the queue!",
queueLength: "<:redx:674263474704220182> There are only %SONGS% amount of songs in the queue!",
queueTitle: "__Song queue__",
quotaReached: "<:redx:674263474704220182> Quota reached please try again after midnight Pacific Time (PT)!",
reloaded: "All files reloaded!",
removed: "🗑 removed `%SONG%` from the queue!",
reset: "<:green_check_mark:674265384777416705> Reset __all__ guild settings!",
restart: "restarting all shards...",
resumed: "<:resume:674685585478254603> Resumed the music!",
seekingPointPositive: "<:redx:674263474704220182> The seeking point needs to be a positive number!",
seekMax: "<:redx:674263474704220182> The lenght of this song is %LENGTH% seconds! You can't seek further than that!",
settingsAnnounceSongs: "announcesongs",
settingsAnnounceSongsDesc: "Whether to announce songs that start playing or not.",
settingsBass: "bass",
settingsBassDesc: "Change the default bass level.",
settingsFooter: "how to use: %PREFIX%settings <Setting name> <value>",
settingsPermissions: "permissions",
settingsPermissionsDesc: "Change whether to require permissions to use eg `skip, stop, pause, loop, etc...`",
settingsPrefix: "prefix",
settingsPrefixDesc: "Change the guild specific prefix. (string)",
settingsSetDj: "setdj",
settingsSetDjDesc: "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!",
settingsTitle: "Guild settings for Musix",
settingsVolume: "volume",
settingsVolumeDesc: "Change the default volume that the bot will start playing at. (number)",
setVolume: "<:volumehigh:674685637626167307> I set the volume to: ",
shuffled: "<:shuffle:674685595980791871> Queue suffled!",
skipped: "<:skip:674685614221688832> Skipped the song!",
songAdded: "<:green_check_mark:674265384777416705> **%TITLE%** has been added to the queue!",
songBlockedWMG: "<:redx:674263474704220182> This song had been blocked by WMG (Warner Music Groud).\n<:skip:674685614221688832> Skipped to next song.",
songSelection: "__Song Selection__",
startPlaying: "<a:aNotes:674602408105476106> Start playing: ",
statusField1: ":signal_strength: Ping",
statusField2: "Latency",
statusField3: ":stopwatch: Uptime",
statusField4: "Shard: ",
statusTitle: "Status for Musix",
stop: "<:stop:674685626108477519> Stopped the music!",
validNumber: "<:redx:674263474704220182> I'm sorry, But you need to enter a valid __number__.",
wrongVoiceChannel: "<:redx:674263474704220182> I'm sorry but you need to be in the same voice channel as Musix to use this command!",
};

View File

@ -0,0 +1,17 @@
module.exports = {
textChannel: null,
voiceChannel: null,
connection: null,
songs: [],
volume: null,
bass: null,
playing: false,
paused: false,
looping: false,
songLooping: false,
votes: 0,
voters: [],
votesNeeded: null,
time: 0,
endReason: null,
}

View File

@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "musix-248615",
"private_key_id": "2c30ab611233b72e89a992c802a8f8ad5bb2854c",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCrmJ92a7s+uKSu\nN0nfGyTpNNNbTbvowJ34mIUEsHUK39dq5aWqR7RSbpHv9RNn6zHHL4cAWpTLkj3z\n/FMOXgopgb01RcQ72pxN492fZb7ik4JRdvLe6dgeisH8tbbtk8c1lMLKJrjPJJqt\nCnihjzWbEmnVdZBMJMfYX3Q3cBVFFbV5n50ldaUXo62QLzvgkx7pOTPRDNFCla3l\nIgG0EhDopn5swl5V9Ebym1hjpsrDod7Ci6mj+stLgCuu5TllR9hI52g4oUqpoyfy\nqMXo5qUaKBVpBxE4zNKW+mlQDpAJVIrDktt0vWwzLY0aXJwjMJMhDLLu3yJWnpsn\n5rcUzohDAgMBAAECggEAAL7XI6a1BWW8PfzxgH/qHiL15mOAfjLLc8CZTaAODYtT\nsK57lMOn1wj7FHfvYcpV7XRQZ2a0Mn7Hb40zygbnavgsUmZ/VZqpYlE+G2GZD/vI\n7ZQ+2rlZEExVKo5RQUWKp0w5JiEa75Nw/boHxrPnkdtTDPOjFY9QfTtwW2JxIKRp\nzwl6cS3ESBVj1snF4I/QwCo+mIlBvJcPHvFmWJW8zf2thr+JU4iDFAz1GWh7KXLD\nPyYfg0w6baMuWeKAy9SkFynpKxiba7DCqp4NsSsNmkbKs2vaPRrZGGXIw9KItxFb\nHPkzXtUur/BXpCvfYN+KsyuYlorqklIRxXF/38N56QKBgQDt6qx/4bC/k7EmgdtA\nKZhR2X0KFaL0w+fCCFg/eqCs7xIK6msTbWNCgBwHk7N9L7Q6aW4NDhLeujDHl5Zn\nG8IL3O2XVQxKFKhyORe8Jr7BBtg+OTEsS+f618r6N0p7zJVNocaXPhRHvpD1J1w+\nyNHNOeVGFgtRhxKw8xQA+00ABQKBgQC4o4AbQs+HfxrNST/9Nkrt9k5s2f0TewJx\ntIAndNcHen6p2HlkqgdIiI7676tfXgwaFl/wV3SQ2NKMXXGpRMMj0Iz6PldEZIT8\navNH226+h1UgmMuJ5JhdHQ/RVDnl1vN7xrOuJ4U5BuOeS44QYiYgE5afdbmCXzgV\nSii+eB2BpwKBgQC5igrOjA5PyPkdI6X9irKsGiVGSQtVQLYrfmB72MEXPDXg52Fr\nvCHtiYTSb+BJH3u5FeFqMvCKW7+Q1+nGLUKOB9QN8Zhs6WFX+qhE5h5a4GChXe64\nMdYOrF0x9w6SL0C8Uw5RgmtEbBwV44UvvWLIXn8rwiM/iEwOTPLrtQ8elQKBgQCE\nErhNR8IpOxtR4ua52r9Ibpp0tI2aBLCf4yyUjLhPqii2l5lmD1W8ZapZB11/j0d6\n1ax0wCoqfl5Fd4YZPY2UrdZaHoPP8VNLN7mkGeuisC2Nbp6RmYn/eQ1agDQWG2b5\nkA3xMmXSgAILtiH9yCdbZIemstAq2K/GUtDIRiVdGwKBgQC3ahm4dP/Tf5y1YT3P\n0GD2vfppAGWW6m3anbV97IWzHdOb0lVNoPLi8RaCH60hqV7CewolOT2d/IwAPpJH\nlSAj5NM8wOU5LsBZQ9NO6FH6KtWErsC4wES8U6KI9enMViwG7E39EaCZ65A5VT7W\n0VL7SEPN9iYy882fYuTYqV2ogg==\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-zq2bj@musix-248615.iam.gserviceaccount.com",
"client_id": "112286897035848826432",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-zq2bj%40musix-248615.iam.gserviceaccount.com"
}

View File

@ -0,0 +1,4 @@
module.exports = {
ytdlOptions: { filter: "audio", highWaterMark: 1 << 25, volume: false, begin: null },
options: { seek: 0, bitrate: 1024, passes: 10, volume: 1, type: "converted" }
};

27
src/struct/funcs/check.js Normal file
View File

@ -0,0 +1,27 @@
module.exports = function (client, msg, command) {
const queue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!queue || !queue.playing) {
msg.channel.send(client.messages.noServerQueue);
return false;
}
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== queue.voiceChannel) {
msg.channel.send(client.messages.wrongVoiceChannel);
return false;
}
if (client.global.db.guilds[msg.guild.id].permissions === true) {
if (client.global.db.guilds[msg.guild.id].dj) {
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole)) {
msg.channel.send(client.messages.noDj);
return false;
} else return true;
} else if (!permissions.has(command.permission)) {
let message
message = client.messages.noPerms.replace("%PERMS%", commands.permissions);
msg.channel.send(message);
return false;
} else return true;
} else return true;
} else return true;
};

View File

@ -0,0 +1,11 @@
module.exports = async function (client) {
client.guilds.cache.forEach(guild => {
if (client.global.db.guilds[guild.id].prefix === undefined) client.global.db.guilds[guild.id].prefix = client.config.prefix;
if (client.global.db.guilds[guild.id].defaultVolume === undefined) client.global.db.guilds[guild.id].defaultVolume = client.config.defaultVolume;
if (client.global.db.guilds[guild.id].permissions === undefined) client.global.db.guilds[guild.id].permissions = client.config.permissions;
if (client.global.db.guilds[guild.id].dj === undefined) client.global.db.guilds[guild.id].dj = client.config.dj;
if (client.global.db.guilds[guild.id].djrole === undefined) client.global.db.guilds[guild.id].djrole = client.config.djrole;
if (client.global.db.guilds[guild.id].startPlaying === undefined) client.global.db.guilds[guild.id].startPlaying = client.config.startPlaying;
if (client.global.db.guilds[guild.id].bass === undefined) client.global.db.guilds[guild.id].bass = client.config.bass;
});
};

22
src/struct/funcs/dbget.js Normal file
View File

@ -0,0 +1,22 @@
module.exports = async function (collection, doc, client) {
if (doc) {
let d = await client.db.collection(collection).doc(doc).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
return d.data();
} else {
let d = await client.db.collection(collection).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
let finalD = [];
d.forEach(doc => {
finalD.push({
id: doc.id,
d: doc.data(),
});
});
return finalD;
}
};

19
src/struct/funcs/exe.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = function (msg, args, client, Discord, command) {
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
if (!permissions.has('USE_EXTERNAL_EMOJIS')) return msg.channel.send(client.noPermsUseExternalEmojis);
try {
command.uses++;
command.execute(msg, args, client, Discord, command);
} catch (error) {
const date = new Date();
msg.reply(client.messages.errorExe);
const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **'))
.setFooter(`guild: ${msg.guild.id} (${msg.guild.name}), user: ${msg.member.id} (${msg.member.displayName}), channel: ${msg.channel.id} (${msg.channel.name}), date: ${date}, Shard: ${client.shard.ids}`)
.setColor('#b50002');
client.debug_channel.send(embed);
console.error(error);
}
};

View File

@ -0,0 +1,9 @@
module.exports = async function (client) {
if (!client.guilds.cache.has(client.config.testServer)) return;
try {
await client.channels.fetch(client.config.secondary_test_channel)
.then(x => x.join());
} catch (error) {
client.debug_channel.send(client.messages.errorDetected + error);
}
};

View File

@ -0,0 +1,41 @@
module.exports = async function (video, msg, voiceChannel, client, playlist = false) {
const Discord = require('discord.js');
const song = {
id: video.id,
title: Discord.Util.escapeMarkdown(video.title),
url: `https://www.youtube.com/watch?v=${video.id}`,
author: msg.author
}
const queue = client.queue.get(msg.guild.id);
if (queue) {
queue.songs.push(song);
if (playlist) return;
let message;
message = client.messages.songAdded.replace("%TITLE%", song.title);
return msg.channel.send(message);
}
const construct = require("../config/queueConfig.js");
construct.textChannel = msg.channel;
construct.voiceChannel = voiceChannel;
construct.volume = client.global.db.guilds[msg.guild.id].defaultVolume;
construct.bass = client.global.db.guilds[msg.guild.id].bass;
construct.songs.push(song);
client.queue.set(msg.guild.id, construct);
try {
const connection = await voiceChannel.join();
construct.connection = connection;
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
} catch (error) {
client.queue.delete(msg.guild.id);
client.debug_channel.send(client.messages.errorConnecting + error);
return msg.channel.send(client.messages.error);
}
return;
}

View File

@ -0,0 +1,17 @@
module.exports = function msToTime(duration, format) {
var seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24);
days = (days < 10) ? "0" + days : days;
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
if (format === "hh:mm:ss") {
return `${hours}:${minutes}:${seconds}`;
} else if (format === "dd:hh:mm:ss") {
return `${days}:${hours}:${minutes}:${seconds}`;
}
}

48
src/struct/funcs/play.js Normal file
View File

@ -0,0 +1,48 @@
module.exports = async function (guild, song, client, seek, play) {
const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const streamConfig = require("../config/streamConfig.js");
const getThumb = require('video-thumbnail-url');
const prism = require('prism-media');
const queue = client.queue.get(guild.id);
if (!song) {
queue.voiceChannel.leave();
client.queue.delete(guild.id);
return;
}
streamConfig.ytdlOptions.begin = seek;
const ffmpegArgs = [
"-analyzeduration", "0",
"-loglevel", "0",
"-f", "s16le",
"-ar", "48000",
"-ac", "2",
"-af", `bass=g=${queue.bass}`
];
const transcoder = new prism.FFmpeg({ args: ffmpegArgs });
const dispatcher = queue.connection
.play(await ytdl(song.url, streamConfig.ytdlOptions).pipe(transcoder), streamConfig.options).on("finish", () => {
client.dispatcher.finish(client, queue.endReason, guild);
}).on('start', () => {
dispatcher.player.streamingData.pausedTime = 0;
}).on('error', error => {
client.dispatcher.error(client, error, guild);
});
dispatcher.setVolume(queue.volume / 10);
if (client.global.db.guilds[guild.id].startPlaying || play) {
const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
const songtime = (data.length_seconds * 1000).toFixed(0);
const thumbnail = getThumb(queue.songs[0].url);
const embed = new Discord.MessageEmbed()
.setTitle(`${client.messages.startPlaying}**${song.title}**`)
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``)
.setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor)
queue.textChannel.send(embed);
}
queue.playing = true;
}

View File

@ -0,0 +1,16 @@
module.exports = async function (client) {
if (client.config.saveDB && !client.config.devMode) {
console.log('DB saved');
client.guilds.cache.forEach(guild => {
client.db.collection('guilds').doc(guild.id).set({
prefix: client.global.db.guilds[guild.id].prefix,
defaultVolume: client.global.db.guilds[guild.id].defaultVolume,
permissions: client.global.db.guilds[guild.id].permissions,
dj: client.global.db.guilds[guild.id].dj,
djrole: client.global.db.guilds[guild.id].djrole,
startPlaying: client.global.db.guilds[guild.id].startPlaying,
bass: client.global.db.guilds[guild.id].bass,
});
});
}
}

View File

@ -0,0 +1,11 @@
module.exports = function (a) {
for (let i = a.length - 1; i > 1; i--) {
const j = Math.floor(Math.random() * (i + 1));
if (i === 0 || j === 0) {
console.log(`J or I is 0. I: ${i} J: ${j}`);
} else {
[a[i], a[j]] = [a[j], a[i]];
}
}
return a;
};

View File

@ -0,0 +1,17 @@
module.exports = async function (client, msg, youtube, voiceChannel, url) {
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
}
let message;
message = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
lmsg.edit(message);
return true;
} else {
return false;
}
};