mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 08:23:37 +00:00
Init
This commit is contained in:
52
struct/client.js
Normal file
52
struct/client.js
Normal 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
20
struct/config/config.js
Normal 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
12
struct/funcs/check.js
Normal 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
17
struct/funcs/exe.js
Normal 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
8
struct/funcs/ffmpeg.js
Normal 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);
|
||||
}
|
||||
};
|
31
struct/funcs/handleRadio.js
Normal file
31
struct/funcs/handleRadio.js
Normal 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
17
struct/funcs/msToTime.js
Normal 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
22
struct/funcs/play.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user