All messages in separate file.

This commit is contained in:
Christer Warén 2020-03-13 00:53:23 +02:00
parent 695c5a1e40
commit 7f2a1755eb
14 changed files with 105 additions and 42 deletions

View File

@ -6,11 +6,18 @@ module.exports = {
permission: 'none', permission: 'none',
category: 'info', category: 'info',
async execute(msg, args, client, Discord, prefix) { async execute(msg, args, client, Discord, prefix) {
let message = {};
message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username);
message.bugDescription = client.messages.bugDescription.replace("%client.developers%", client.developers);
message.bugDescription = message.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`Found a bug with ${client.user.username}?\nDM the core developer:`) .setTitle(message.bugTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setDescription(`${client.developers}\nOr join the support server: ${client.config.supportGuild}`) .setDescription(message.bugDescription)
.setFooter('EximiaBots by Warén Media'); .setFooter('EximiaBots by Warén Media');
msg.channel.send(embed); msg.channel.send(embed);
}, },
}; };

View File

@ -6,13 +6,22 @@ module.exports = {
permission: 'none', permission: 'none',
category: 'info', category: 'info',
execute(msg, args, client, Discord, prefix, command) { execute(msg, args, client, Discord, prefix, command) {
let message = {};
if (args[1]) { if (args[1]) {
if (!client.commands.has(args[1]) || (client.commands.has(args[1]) && client.commands.get(args[1]).omitFromHelp === true)) return msg.channel.send('That command does not exist'); if (!client.commands.has(args[1]) || (client.commands.has(args[1]) && client.commands.get(args[1]).omitFromHelp === true)) return msg.channel.send('That command does not exist');
const command = client.commands.get(args[1]); const command = client.commands.get(args[1]);
message.helpCommandTitle = client.messages.helpCommandTitle.replace("%client.config.prefix%", client.config.prefix);
message.helpCommandTitle = message.helpCommandTitle.replace("%command.name%", command.name);
message.helpCommandTitle = message.helpCommandTitle.replace("%command.usage%", command.usage);
message.helpCommandDescription = client.messages.helpCommandTitle.replace("%command.description%", command.description);
message.helpCommandDescription = message.helpCommandDescription.replace("%command.alias%", command.alias);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`${client.global.db.guilds[msg.guild.id].prefix}${command.name} ${command.usage}`) .setTitle(message.helpCommandTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setDescription(command.description + `\n Command Alias: \`${command.alias}\``) .setDescription(message.helpCommandDescription)
.setFooter('EximiaBots by Warén Media') .setFooter('EximiaBots by Warén Media')
msg.channel.send(embed); msg.channel.send(embed);
} else { } else {
@ -24,10 +33,15 @@ module.exports = {
for (let i = 0; i < categories.length; i++) { for (let i = 0; i < categories.length; i++) {
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`; commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`;
} }
message.helpTitle = client.messages.helpTitle.replace("%client.user.username%", client.user.username);
message.helpDescription = client.messages.helpDescription.replace("%commands%", commands);
message.helpDescription = message.helpDescription.replace("%client.config.prefix%", client.config.prefix);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`${client.user.username} help:`) .setTitle(message.helpTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setDescription(commands + `\n "${client.config.prefix}help <command>" to see more information about a command.`) .setDescription(message.helpDescription)
.setFooter('EximiaBots by Warén Media'); .setFooter('EximiaBots by Warén Media');
msg.channel.send(embed); msg.channel.send(embed);
} }

View File

@ -6,8 +6,10 @@ module.exports = {
permission: 'none', permission: 'none',
category: 'info', category: 'info',
execute(msg, args, client, Discord, prefix) { execute(msg, args, client, Discord, prefix) {
let message = {};
message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`Invite ${client.user.username} to your Discord server!`) .setTitle(message.inviteTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setURL(client.config.invite) .setURL(client.config.invite)
.setFooter('EximiaBots by Warén Media'); .setFooter('EximiaBots by Warén Media');

View File

@ -11,8 +11,9 @@ module.exports = {
for (let i = 0; i < hashs; i++) { for (let i = 0; i < hashs; i++) {
stations = stations.replace('**#**', `**${i + 1}**`); stations = stations.replace('**#**', `**${i + 1}**`);
} }
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`Radio Stations`) .setTitle(client.messages.listTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setDescription(stations) .setDescription(stations)
.setFooter('EximiaBots by Warén Media') .setFooter('EximiaBots by Warén Media')

View File

@ -6,15 +6,20 @@ module.exports = {
permission: 'none', permission: 'none',
category: 'music', category: 'music',
async execute(msg, args, client, Discord, prefix) { async execute(msg, args, client, Discord, prefix) {
let message = {};
const radio = client.radio.get(msg.guild.id); const radio = client.radio.get(msg.guild.id);
if (!radio || !radio.playing) return msg.channel.send('There is nothing playing.'); if (!radio || !radio.playing) return msg.channel.send('There is nothing playing.');
radio.time = radio.connection.dispatcher.streamTime; radio.time = radio.connection.dispatcher.streamTime;
const completed = (radio.time.toFixed(0)); const completed = (radio.time.toFixed(0));
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner);
message.nowplayingDescription = message.nowplayingDescription.replace("%msToTime(completed, \"hh:mm:ss\")%", msToTime(completed, "hh:mm:ss"));
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle("Now Playing") .setTitle(client.messages.nowplayingTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setDescription(`**${radio.station.name}** \n Owner: ${radio.station.owner} \n\`${msToTime(completed, "hh:mm:ss")}\``) .setDescription(message.nowplayingDescription)
.setFooter('EximiaBots by Warén Media'); .setFooter('EximiaBots by Warén Media');
return msg.channel.send(embed); return msg.channel.send(embed);
} }

View File

@ -10,17 +10,17 @@ module.exports = {
const radio = client.radio.get(msg.guild.id); const radio = client.radio.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel; const voiceChannel = msg.member.voice.channel;
if (!radio) { if (!radio) {
if (!msg.member.voice.channel) return msg.channel.send('You need to be in a voice channel to play music!'); if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
} else { } else {
if (voiceChannel !== radio.voiceChannel) return msg.channel.send('You need to be in the same voice channel as RadioX to play music!'); if (voiceChannel !== radio.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
} }
if (!args[1]) return msg.channel.send('You need to use a number or search for a supported station!'); if (!args[1]) return msg.channel.send(client.messages.noQuery);
const permissions = voiceChannel.permissionsFor(msg.client.user); const permissions = voiceChannel.permissionsFor(msg.client.user);
if (!permissions.has('CONNECT')) { if (!permissions.has('CONNECT')) {
return msg.channel.send('I cannot connect to your voice channel.'); return msg.channel.send(client.messages.noPermsConnect);
} }
if (!permissions.has('SPEAK')) { if (!permissions.has('SPEAK')) {
return msg.channel.send('I cannot speak in your voice channel.'); return msg.channel.send(client.messages.noPermsSpeak);
} }
let station; let station;
const number = parseInt(args[1] - 1); const number = parseInt(args[1] - 1);
@ -28,15 +28,15 @@ module.exports = {
return; return;
} else if (!isNaN(number)) { } else if (!isNaN(number)) {
if (number > client.stations.length - 1) { if (number > client.stations.length - 1) {
return msg.channel.send('No such station!'); return msg.channel.send(client.messages.wrongStationNumber);
} else { } else {
url = client.stations[number].stream[client.stations[number].stream.default]; url = client.stations[number].stream[client.stations[number].stream.default];
station = client.stations[number]; station = client.stations[number];
} }
} else { } else {
if (args[1].length < 3) return msg.channel.send('Station must be over 2 characters!'); if (args[1].length < 3) return msg.channel.send(client.messages.tooShortSearch);
const sstation = await searchStation(args.slice(1).join(' '), client); const sstation = await searchStation(args.slice(1).join(' '), client);
if (!sstation) return msg.channel.send('No stations found!'); if (!sstation) return msg.channel.send(client.messages.noSearchResults);
url = sstation.stream[sstation.stream.default]; url = sstation.stream[sstation.stream.default];
station = sstation station = sstation
} }
@ -65,13 +65,12 @@ module.exports = {
play(msg.guild, client, url); play(msg.guild, client, url);
} catch (error) { } catch (error) {
client.radio.delete(msg.guild.id); client.radio.delete(msg.guild.id);
client.debug_channel.send("Error with connecting to voice channel: " + error);
return msg.channel.send(`An error occured: ${error}`); return msg.channel.send(`An error occured: ${error}`);
} }
} }
}; };
function play(guild, client, url) { function play(guild, client, url) {
let message = {};
const radio = client.radio.get(guild.id); const radio = client.radio.get(guild.id);
const dispatcher = radio.connection const dispatcher = radio.connection
@ -90,12 +89,13 @@ function play(guild, client, url) {
console.error(error); console.error(error);
radio.voiceChannel.leave(); radio.voiceChannel.leave();
client.radio.delete(guild.id); client.radio.delete(guild.id);
return radio.textChannel.send('An error has occured while playing radio!'); return radio.textChannel.send(client.messages.errorPlaying);
}); });
dispatcher.setVolume(radio.volume / 10); dispatcher.setVolume(radio.volume / 10);
radio.textChannel.send(`Start playing: ${radio.station.name}`); message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
radio.textChannel.send(message.play);
radio.playing = true; radio.playing = true;
}; };

View File

@ -11,7 +11,7 @@ module.exports = {
radio.connection.dispatcher.destroy(); radio.connection.dispatcher.destroy();
radio.voiceChannel.leave(); radio.voiceChannel.leave();
client.radio.delete(msg.guild.id); client.radio.delete(msg.guild.id);
msg.channel.send('Stopped playback!'); msg.channel.send(client.messages.stop);
} }
} }
}; };

View File

@ -6,16 +6,19 @@ module.exports = {
permission: 'MANAGE_MESSAGES', permission: 'MANAGE_MESSAGES',
category: 'music', category: 'music',
execute(msg, args, client, Discord, prefix, command) { execute(msg, args, client, Discord, prefix, command) {
let message = {};
const radio = client.radio.get(msg.guild.id); const radio = client.radio.get(msg.guild.id);
if (!args[1] && radio) return msg.channel.send(`Current volume: **${radio.volume}**`); /*message.currentVolume = client.messages.currentVolume.replace("%radio.volume%", radio.volume)*/
if (!args[1] && radio) return msg.channel.send(client.messages.currentVolume);
const volume = parseFloat(args[1]); const volume = parseFloat(args[1]);
if (client.funcs.check(client, msg, command)) { if (client.funcs.check(client, msg, command)) {
if (isNaN(volume)) return msg.channel.send('you need to enter a valid __number__.'); if (isNaN(volume)) return msg.channel.send(client.messages.invalidVolume);
if (volume > 100) return msg.channel.send('The max volume is `100`!'); if (volume > 100) return msg.channel.send(client.messages.maxVolume);
if (volume < 0) return msg.channel.send('The volume needs to be a positive number!'); if (volume < 0) return msg.channel.send(client.messages.negativeVolume);
radio.volume = volume; radio.volume = volume;
radio.connection.dispatcher.setVolume(volume / 5); radio.connection.dispatcher.setVolume(volume / 5);
return msg.channel.send(`Volume is now: **${volume}**`); message.newVolume = client.messages.newVolume.replace("%volume%", volume);
return msg.channel.send(message.newVolume);
} }
} }
}; };

View File

@ -4,6 +4,7 @@ module.exports = {
//credentials //credentials
token: process.env.DISCORD_TOKEN, token: process.env.DISCORD_TOKEN,
//support //support
supportGuild: "https://discord.gg/rRA65Mn", supportGuild: "https://discord.gg/rRA65Mn",
devId: [ devId: [
@ -16,7 +17,7 @@ module.exports = {
invite: "https://discordapp.com/api/oauth2/authorize?client_id=684109535312609409&permissions=3427328&scope=bot", invite: "https://discordapp.com/api/oauth2/authorize?client_id=684109535312609409&permissions=3427328&scope=bot",
//Settings //Settings
prefix: "rx>", prefix: process.env.PREFIX || "rx>",
volume: 5 volume: 5
} }

View File

@ -10,12 +10,12 @@ module.exports = {
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName); 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 && msg.content !== `${prefix}`) return;
const permissions = msg.channel.permissionsFor(msg.client.user); const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send('I cannot send embeds (Embed links).'); if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
try { try {
command.uses++; command.uses++;
command.execute(msg, args, client, Discord, prefix, command); command.execute(msg, args, client, Discord, prefix, command);
} catch (error) { } catch (error) {
msg.reply(`Error!`); msg.reply(client.messages.runningCommandFailed);
console.error(error); console.error(error);
} }
} }

View File

@ -23,8 +23,7 @@ module.exports = {
radio.connection.dispatcher.destroy(); radio.connection.dispatcher.destroy();
radio.voiceChannel.leave(); radio.voiceChannel.leave();
client.radio.delete(msg.guild.id); client.radio.delete(msg.guild.id);
client.debug_channel.send("Error with connecting to voice channel: " + error); return;
return msg.channel.send(`An error occured: ${error}`);
} }
} }
if (newState.channel !== radio.voiceChannel) { if (newState.channel !== radio.voiceChannel) {

View File

@ -1,12 +1,11 @@
module.exports = function (client, msg, command) { module.exports = function (client, msg, command) {
const radio = client.radio.get(msg.guild.id); const radio = client.radio.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author); const permissions = msg.channel.permissionsFor(msg.author);
if (!radio || !radio.playing) return msg.channel.send('There is nothing playing!'); if (!radio || !radio.playing) return msg.channel.send(client.messages.notPlaying);
if (msg.author.id !== client.config.devId) { if (msg.member.voice.channel !== radio.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
if (msg.member.voice.channel !== radio.voiceChannel) return msg.channel.send(`You need to be in the same voice channel as RadioX to use this command!`); if (!permissions.has(command.permission)) {
if (!permissions.has(command.permission)) { client.messages.noPerms = client.messages.noPerms.replace("%commands.permissions%", commands.permissions);
msg.channel.send(`You need the \`${command.permission}\` permission to use this command!`); msg.channel.send(client.messages.noPerms);
return false; return false;
} else return true;
} else return true; } else return true;
}; };

View File

@ -15,8 +15,8 @@ module.exports = class extends Client {
this.radio = new Map(); this.radio = new Map();
this.funcs = {}; this.funcs = {};
this.dispatcher = {}; this.dispatcher = {};
this.config = require('./config.js'); this.config = require('../config.js');
this.messages = require('./messages.js');
this.funcs.check = require('./check.js'); this.funcs.check = require('./check.js');
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js')); const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));

32
struct/messages.js Normal file
View File

@ -0,0 +1,32 @@
module.exports = {
wrongVoiceChannel: "You need to be in the same voice channel as RadioX to use this command!",
noPerms: "You need the %command.permission% permission to use this command!",
notPlaying: "There is nothing playing!",
runningCommandFailed: "Running this command failed!",
noPermsEmbed: "I cannot send embeds (Embed links).",
bugTitle: "Found a bug with %client.user.username%?\nDM one of the core developers:",
bugDescription: "%client.developers%\nOr join the support server: %client.config.supportGuild%",
helpTitle: "%client.user.username% help:",
helpDescription: "%commands% \n %client.config.prefix%help <command> to see more information about a command.",
helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%",
helpCommandDescription: "%command.description% \n Command Alias: %command.alias%",
inviteTitle: "Invite %client.user.username% to your Discord server!",
listTitle: "Radio Stations",
nowplayingTitle: "Now Playing",
nowplayingDescription: "**%radio.station.name%** \n Owner: %radio.station.owner% \n %msToTime(completed, \"hh:mm:ss\")%",
noVoiceChannel: "You need to be in a voice channel to play music!",
noQuery: "You need to use a number or search for a supported station!",
noPermsConnect: "I cannot connect to your voice channel.",
noPermsSpeak: "I cannot speak in your voice channel.",
wrongStationNumber: "No such station!",
tooShortSearch: "Station must be over 2 characters!",
noSearchResults: "No stations found!",
errorPlaying: "An error has occured while playing radio!",
play: "Start playing: %radio.station.name%",
stop: "Stopped playback!",
currentVolume: "Current volume: **%radio.volume%**",
maxVolume: "The max volume is `100`!",
invalidVolume: "You need to enter a valid __number__.",
negativeVolume: "The volume needs to be a positive number!",
newVolume: "Volume is now: **%volume%**"
};