mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 08:23:37 +00:00
Folder re-structuring
This commit is contained in:
27
client/events/msg.js
Normal file
27
client/events/msg.js
Normal 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(msg.mentions.members.first()){
|
||||
if(msg.mentions.members.first().user.id === client.user.id){
|
||||
prefix = "<@!" + client.user.id + "> ";
|
||||
}
|
||||
}
|
||||
const args = msg.content.slice(prefix.length).split(' ');
|
||||
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;
|
||||
const permissions = msg.channel.permissionsFor(msg.client.user);
|
||||
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
|
||||
try {
|
||||
command.execute(msg, args, client, Discord, command);
|
||||
} catch (error) {
|
||||
msg.reply(client.messages.runningCommandFailed);
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
37
client/events/ready.js
Normal file
37
client/events/ready.js
Normal file
@ -0,0 +1,37 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
async execute(client, Discord) {
|
||||
|
||||
console.log('RadioX');
|
||||
console.log('We will bring you finnish radio to your discord server');
|
||||
console.log('(c)2020 EximiaBots by Warén Media / Christer Warén & MatteZ02');
|
||||
|
||||
client.developers = "";
|
||||
let user = "";
|
||||
for (i = 0; i < client.config.devId.length; i++) {
|
||||
user = await client.users.fetch(client.config.devId[i]);
|
||||
if (i == client.config.devId.length - 1) {
|
||||
client.developers += user.tag;
|
||||
} else {
|
||||
client.developers += user.tag + " & ";
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
||||
.then(res => res.json());
|
||||
} catch (err) {
|
||||
client.stations = null;
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
setInterval(async () => {
|
||||
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
||||
.then(res => res.json());
|
||||
}, 3600000);
|
||||
|
||||
require(`./emojis.js`).execute(client);
|
||||
}
|
||||
}
|
45
client/events/voiceStateUpdate.js
Normal file
45
client/events/voiceStateUpdate.js
Normal file
@ -0,0 +1,45 @@
|
||||
module.exports = {
|
||||
name: 'voiceStateUpdate',
|
||||
async execute(client, oldState, newState) {
|
||||
if (oldState.channel === null) return;
|
||||
let change = false;
|
||||
const radio = client.radio.get(newState.guild.id);
|
||||
if (!radio) return;
|
||||
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
||||
if (newState.channel === null) {
|
||||
statisticsUpdate(client, newState, radio);
|
||||
return client.radio.delete(newState.guild.id);
|
||||
}
|
||||
|
||||
const newPermissions = newState.channel.permissionsFor(newState.client.user);
|
||||
if (!newPermissions.has('CONNECT') || !newPermissions.has('SPEAK') || !newPermissions.has('VIEW_CHANNEL')) {
|
||||
try {
|
||||
const connection = await oldState.channel.join();
|
||||
return radio.connection = connection;
|
||||
} catch (error) {
|
||||
statisticsUpdate(client, newState, radio);
|
||||
radio.connection.dispatcher.destroy();
|
||||
radio.voiceChannel.leave();
|
||||
client.radio.delete(oldState.guild.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (newState.channel !== radio.voiceChannel) {
|
||||
change = true;
|
||||
radio.voiceChannel = newState.channel;
|
||||
radio.connection = newState.connection;
|
||||
}
|
||||
}
|
||||
if (oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel || change) {
|
||||
setTimeout(() => {
|
||||
if (!radio) return;
|
||||
if (radio.voiceChannel.members.size === 1) {
|
||||
statisticsUpdate(client, newState, radio);
|
||||
radio.connection.dispatcher.destroy();
|
||||
radio.voiceChannel.leave();
|
||||
client.radio.delete(newState.guild.id);
|
||||
}
|
||||
}, 120000);
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user