This commit is contained in:
MatteZ02 2020-03-02 21:38:42 +02:00
commit a96305e807
29 changed files with 599 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
node_modules/
.env
.vscode/
package-lock.json

16
commands/bug.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
name: 'bug',
alias: 'none',
usage: '',
description: 'Report a bug',
onlyDev: false,
permission: 'none',
category: 'info',
async execute(msg, args, client, Discord, prefix) {
const embed = new Discord.MessageEmbed()
.setTitle(`Found a bug with ${client.user.username}?\nDM the core developer:`)
.setDescription(`Matte#0002\nOr join the support server: https://discord.gg/rvHuJtB`)
.setColor(client.config.embedColor);
msg.channel.send(embed);
},
};

31
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) {
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('Musix Command Usage During Current Uptime')
.setDescription('```ml\n' + markdownrows.join('\n') + '\n```')
.setFooter('These statistics are from the current uptime.')
.setColor(client.config.embedColor);
msg.channel.send(embed);
},
};

24
commands/eval.js Normal file
View File

@ -0,0 +1,24 @@
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, prefix) {
const radio = client.radio.get(msg.guild.id);
const input = msg.content.slice(prefix.length + 4);
let output;
try {
output = await eval(input);
} catch (error) {
output = error.toString();
}
const embed = new Discord.MessageEmbed()
.setTitle('Evaluation Command')
.setColor(client.config.embedColor)
.setDescription(`Input: \`\`\`js\n${input.replace(/; /g, ';').replace(/;/g, ';\n')}\n\`\`\`\nOutput: \`\`\`\n${output}\n\`\`\``);
return msg.channel.send(embed);
},
};

36
commands/help.js Normal file
View File

@ -0,0 +1,36 @@
module.exports = {
name: 'help',
alias: 'h',
usage: '<command(opt)>',
description: 'See the help for RadioX.',
onlyDev: false,
permission: 'none',
category: 'info',
execute(msg, args, client, Discord, prefix, 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(`Command Alias: \`${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`;
}
const embed = new Discord.MessageEmbed()
.setTitle(`${client.user.username} help:`)
.setDescription(commands)
.setFooter(`"${client.config.prefix}help <command>" to see more information about a command.`)
.setColor(client.config.embedColor)
msg.channel.send(embed);
}
}
};

16
commands/invite.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
name: 'invite',
alias: 'i',
usage: '',
description: 'Invite RadioX.',
onlyDev: false,
permission: 'none',
category: 'info',
execute(msg, args, client, Discord, prefix) {
const embed = new Discord.MessageEmbed()
.setTitle(`Invite ${client.user.username} to your Discord server!`)
.setURL(client.config.invite)
.setColor(client.config.embedColor)
return msg.channel.send(embed);
}
};

24
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, prefix) {
try {
const radio = client.radio.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
const connection = await voiceChannel.join();
if (radio) {
radio.connection = connection;
}
msg.channel.send(`<:green_check_mark:674265384777416705> Joined ${voiceChannel.name}!`);
} catch (error) {
client.radio.delete(msg.guild.id);
client.channels.fetch(client.config.debug_channel).send("Error with connecting to voice channel: " + error);
return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`);
}
}
};

25
commands/nowplaying.js Normal file
View File

@ -0,0 +1,25 @@
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, prefix) {
const radio = client.radio.get(msg.guild.id);
if (!radio) return msg.channel.send('<:redx:674263474704220182> There is nothing playing.');
if (!radio.playing) return msg.channel.send('<:redx:674263474704220182> There is nothing playing.');
radio.time = radio.connection.dispatcher.streamTime;
let completed = (radio.time.toFixed(0));
const embed = new Discord.MessageEmbed()
.setTitle("__Now playing__")
.setDescription(`<a:aNotes:674602408105476106>**Now playing:** ${radio.url}\n\`${client.funcs.msToTime(completed, "hh:mm:ss")}\``)
.setFooter(`Queued by ${radio.songs[0].author.tag}`)
.setURL(radio.songs[0].url)
.setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor)
return msg.channel.send(embed);
}
};

18
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, prefix, command) {
const radio = client.radio.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (radio.paused) return msg.channel.send('<:redx:674263474704220182> The music is already paused!');
radio.paused = true;
radio.connection.dispatcher.pause(true);
return msg.channel.send('<:pause:674685548610322462> Paused the music!');
}
}
};

29
commands/play.js Normal file
View File

@ -0,0 +1,29 @@
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, prefix) {
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const radio = client.radio.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel;
if (!radio) {
if (!msg.member.voice.channel) return msg.channel.send('<:redx:674263474704220182> I\'m sorry but you need to be in a voice channel to play music!');
} else {
if (voiceChannel !== radio.voiceChannel) return msg.channel.send('<:redx:674263474704220182> I\'m sorry but you need to be in the same voice channel as Musix to play music!');
}
if (!args[1]) return msg.channel.send('<:redx:674263474704220182> You need to use a link or search for a song!');
const permissions = voiceChannel.permissionsFor(msg.client.user);
if (!permissions.has('CONNECT')) {
return msg.channel.send('<:redx:674263474704220182> I cannot connect to your voice channel, make sure I have the proper permissions!');
}
if (!permissions.has('SPEAK')) {
return msg.channel.send('<:redx:674263474704220182> I cannot speak in your voice channel, make sure I have the proper permissions!');
}
return client.funcs.handleRadio(msg, voiceChannel, client, url);
}
};

30
commands/reload.js Normal file
View File

@ -0,0 +1,30 @@
const fs = require('fs');
const path = require('path')
module.exports = {
name: 'reload',
alias: 'none',
usage: '',
description: 'Reload all files',
onlyDev: true,
permission: 'none',
category: 'util',
async execute(msg, args, client, Discord, prefix, command) {
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./${file}`);
command.uses = 0;
client.commands.set(command.name, command);
client.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(`./settings/${file}`);
client.settingCmd.set(option.name, option);
}
/*fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => {
this.funcs[filename.slice(0, -3)] = require(`../struct/funcs/${filename}`);
});*/
msg.channel.send('All files reloaded!');
}
};

14
commands/restart.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
name: 'restart',
alias: 'none',
usage: '',
description: 'Restart the bot',
onlyDev: true,
permission: 'none',
category: 'util',
async execute(msg, args, client, Discord, prefix, command) {
client.destroy();
require('../index.js');
msg.channel.send('restarted!');
}
};

18
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, prefix, command) {
const radio = client.radio.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
if (!radio.paused) return msg.channel.send('<:redx:674263474704220182> The music in not paused!');
radio.paused = false;
radio.connection.dispatcher.resume(true);
return msg.channel.send('<:resume:674685585478254603> Resumed the music!');
}
}
};

18
commands/stop.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
name: 'stop',
description: 'Stop command.',
alias: 'none',
usage: '',
onlyDev: false,
permission: 'MANAGE_CHANNELS',
category: 'music',
execute(msg, args, client, Discord, prefix, command) {
const radio = client.radio.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) {
radio.songs = [];
radio.looping = false;
radio.connection.dispatcher.end('Stopped');
msg.channel.send('<:stop:674685626108477519> Stopped the music!')
}
}
};

23
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, prefix, command) {
const radio = client.radio.get(msg.guild.id);
if (!args[1] && radio) return msg.channel.send(`:loud_sound: The current volume is: **${radio.volume}**`);
const volume = parseFloat(args[1]);
if (client.funcs.check(client, msg, command)) {
if (isNaN(volume)) return msg.channel.send('<:redx:674263474704220182> I\'m sorry, But you need to enter a valid __number__.');
if (volume > 100) return msg.channel.send('<:redx:674263474704220182> The max volume is `100`!');
if (volume < 0) return msg.channel.send('<:redx:674263474704220182> The volume needs to be a positive number!');
radio.volume = volume;
radio.connection.dispatcher.setVolume(volume / 5);
return msg.channel.send(`<:volumehigh:674685637626167307> I set the volume to: **${volume}**`);
}
}
};

View File

@ -0,0 +1,20 @@
module.exports = async function (client, reason, guild) {
const radio = client.radio.get(guild.id);
radio.playing = false;
if (reason === "Stream is not generating quickly enough.") {
console.log("Song ended");
} else if (reason === "seek") {
return;
} else {
console.log(reason);
}
if (!radio.songLooping) {
if (radio.looping) {
radio.songs.push(radio.songs[0]);
}
radio.votes = 0;
radio.voters = [];
radio.songs.shift();
}
client.funcs.play(guild, radio.songs[0], client, 0, true);
};

27
events/msg.js Normal file
View File

@ -0,0 +1,27 @@
module.exports = {
name: 'message',
async execute(client, msg, Discord) {
if (msg.author.bot || !msg.guild) return;
let prefix = client.config.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(`My prefix here is: \`${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();
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 msg.channel.send('<:redx:674263474704220182> You are not allowed to do that!');
if (client.config.devMode && msg.member.id !== client.config.devId) return msg.channel.send('<:redx:674263474704220182> Dev mode has been turned on! Commands are only available to developer(s)!');
client.funcs.exe(msg, args, client, Discord, prefix, command);
}
}

14
events/ready.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
name: 'ready',
async execute(client, Discord) {
if (client.config.devMode) {
console.log('dev mode');
}
client.user.setActivity(`@${client.user.username} help | 🎶`, { type: 'LISTENING' });
client.user.setStatus('online');
console.log('- Activated -');
setInterval(() => {
client.funcs.ffmpeg(client, Discord);
}, 7200000);
}
}

View File

@ -0,0 +1,13 @@
module.exports = {
name: 'voiceStateUpdate',
async execute(client, newMember) {
const serverQueue = client.radio.get(newMember.guild.id);
if (!serverQueue) return;
if (newMember === client.user) {
if (newMember.voice.channel !== serverQueue.voiceChannel) {
serverQueue.voiceChannel = newMember.voice.channel;
console.log(`Changed serverQueue voiceChannel since Musix was moved to a different channel!`);
}
}
}
}

2
index.js Normal file
View File

@ -0,0 +1,2 @@
const radioClient = require("./struct/client.js");
const client = new radioClient();

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "radiox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^12.0.1",
"dotenv": "^8.2.0",
"fs": "0.0.1-security",
"node-opus": "^0.3.3",
"path": "^0.12.7"
}
}

52
struct/client.js Normal file
View File

@ -0,0 +1,52 @@
const { Client, Collection } = require('discord.js');
const Discord = require('discord.js');
const fs = require('fs');
const path = require('path')
const events = '../events/';
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START']
});
this.commands = new Collection();
this.commandAliases = new Collection();
this.radio = new Map();
this.funcs = {};
this.dispatcher = {};
this.config = require('./config/config.js');
this.dispatcher.finish = require('../events/dispatcher/finish.js');
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);
}
if (this.config.devMode) {
this.config.token = this.config.devToken;
}
this.on('ready', () => {
require(`${events}ready`).execute(this, Discord);
});
this.on('message', (msg) => {
require(`${events}msg`).execute(this, msg, Discord);
});
this.on('voiceStateUpdate', (newMember) => {
require(`${events}voiceStateUpdate`).execute(this, newMember);
});
this.on('error', (error) => {
client.channels.fetch(client.config.debug_channel).send('Error: ' + error);
});
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
}
};

20
struct/config/config.js Normal file
View File

@ -0,0 +1,20 @@
require('dotenv/config');
module.exports = {
//credentials
token: process.env.TOKEN,
devToken: process.env.DEVTOKEN,
//channels
debug_channel: "634718645188034560",
primary_test_channel: "617633098296721409",
secondary_test_channel: "570531724002328577",
devId: "360363051792203779",
//misc
embedColor: "",
invite: "",
//Settings
devMode: false,
prefix: "?",
devPrefix: "-",
volume: 5,
}

12
struct/funcs/check.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = function (client, msg, command) {
const radio = client.radio.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!radio || !radio.playing) return msg.channel.send('<:redx:674263474704220182> There is nothing playing!');
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== radio.voiceChannel) return msg.channel.send(`<:redx:674263474704220182> I'm sorry but you need to be in the same voice channel as RadioX to use this command!`);
if (!permissions.has(command.permission)) {
msg.channel.send(`<:redx:674263474704220182> You need the \`${command.permission}\` permission to use this command!`);
return false;
} else return true;
} else return true;
};

17
struct/funcs/exe.js Normal file
View File

@ -0,0 +1,17 @@
module.exports = function (msg, args, client, Discord, prefix, command) {
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send('<:redx:674263474704220182> I cannot send embeds (Embed links), make sure I have the proper permissions!');
//if (!permissions.has('EXTERNAL_EMOJIS')) return msg.channel.send('<:redx:674263474704220182> I cannot use external emojis, make sure I have the proper permissions!'); DEPRACATED!
try {
command.uses++;
command.execute(msg, args, client, Discord, prefix, command);
} catch (error) {
msg.reply(`<:redx:674263474704220182> there was an error trying to execute that command! Please contact support with \`${prefix}bug\`!`);
const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **'))
.setColor('#b50002');
//client.channels.fetch(client.config.debug_channel).send(embed);
console.error(error);
}
};

8
struct/funcs/ffmpeg.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = async function (client) {
try {
await client.channels.fetch(client.config.secondary_test_channel)
.then(x => x.join());
} catch (error) {
client.channels.fetch(client.config.debug_channel).send("Error detected: " + error);
}
};

View File

@ -0,0 +1,31 @@
module.exports = async function (msg, voiceChannel, client, url) {
const radio = client.radio.get(msg.guild.id);
if (radio) {
radio.songs.push(song);
if (playlist) return;
return msg.channel.send(`<:green_check_mark:674265384777416705> **${song.title}** has been added to the queue!`);
}
const construct = {
textChannel: msg.channel,
voiceChannel: voiceChannel,
connection: null,
playing: false,
url: url,
name: null,
volume: client.config.volume,
};
client.radio.set(msg.guild.id, construct);
try {
const connection = await voiceChannel.join();
construct.connection = connection;
client.funcs.play(msg.guild, client, url);
} catch (error) {
client.radio.delete(msg.guild.id);
//client.channels.fetch(client.config.debug_channel).send("Error with connecting to voice channel: " + error);
return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`);
}
return;
}

17
struct/funcs/msToTime.js Normal file
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}`;
}
}

22
struct/funcs/play.js Normal file
View File

@ -0,0 +1,22 @@
module.exports = async function (guild, client, url) {
const radio = client.radio.get(guild.id);
const dispatcher = radio.connection
.play(url, { bitrate: 1024, passes: 10, volume: 1, highWaterMark: 1 << 25 })
.on("finish", reason => {
client.dispatcher.finish(client, reason, guild);
});
dispatcher.on('start', () => {
dispatcher.player.streamingData.pausedTime = 0;
});
dispatcher.on('error', error => {
console.error(error);
client.channels.fetch(client.config.debug_channel).send('Error with the dispatcher: ' + error);
radio.voiceChannel.leave();
client.radio.delete(guild.id);
return radio.textChannel.send('<:redx:674263474704220182> An error has occured while playing radio!');
});
dispatcher.setVolume(radio.volume / 10);
radio.textChannel.send('Start playing');
radio.playing = true;
}