Untitled
unknown
javascript
2 years ago
5.6 kB
2
Indexable
Never
const Event = require('../../structures/Event'); const { MessageEmbed } = require('discord.js'); const VCRoleList = require('../../structures/models/VCRoleList'); const voiceMap = new Map(); const textVC = [ { voice: '976610590460112926', text: '976610632302493726' }, { voice: '976610596382457886', text: '976610633216843816' }, { voice: '976610601944117278', text: '976610634101817374' }, { voice: '976610607480578078', text: '976610635032981555' }, { voice: '976610612253692004', text: '976610636198994040' }, { voice: '976610618427727892', text: '976610637037838417' }, { voice: '976610624618516600', text: '976610638094807060' } ]; module.exports = class voiceStateUpdate extends Event { async run(oldVoice, newVoice) { try { if (oldVoice.member.user.bot || !oldVoice.member || !newVoice.member) return; if (oldVoice.channelId && !newVoice.channelId) { const auditChannel = oldVoice.guild.channels.cache.get('976610597540069376'); const leftVoiceEmbed = new MessageEmbed() .setAuthor({ name: 'Left Voice Channel' }) .setColor('RED') .addFields( { name: 'User', value: `${oldVoice.member.displayName}`, inline: true }, { name: 'Status', value: ':red_circle: Left', inline: true }, { name: 'Voice Channel', value: `${oldVoice.channel.name}`, inline: true } ) .setFooter({ text: oldVoice.guild.name, iconURL: oldVoice.guild.iconURL({ dynamic: true }) }) .setTimestamp(); auditChannel.send({ embeds: [leftVoiceEmbed] }); } else if (oldVoice.channelId && newVoice.channelId) { const auditChannel = newVoice.guild.channels.cache.get('976610597540069376'); const leftAndJoinVoiceEmbed = new MessageEmbed() .setAuthor({ name: 'Left & Joined Voice Channel' }) .setColor('BLURPLE') .addFields( { name: 'User', value: `${newVoice.member.displayName}`, inline: true }, { name: 'Status', value: `:green_square: Rejoined`, inline: true }, { name: 'Voice Channels', value: `${oldVoice.channel.name} :arrow_right: ${newVoice.channel.name}`, inline: true } ) .setFooter({ text: newVoice.guild.name, iconURL: newVoice.guild.iconURL({ dynamic: true }) }) .setTimestamp(); auditChannel.send({ embeds: [leftAndJoinVoiceEmbed] }); } else { const auditChannel = newVoice.guild.channels.cache.get('976610597540069376'); const leftVoiceEmbed = new MessageEmbed() .setAuthor({ name: 'Joined Voice Channel' }) .setColor('GREEN') .addFields( { name: 'User', value: `${newVoice.member.displayName}`, inline: true }, { name: 'Status', value: ':green_circle: Joined', inline: true }, { name: 'Voice Channel', value: `${newVoice.channel.name}`, inline: true } ) .setFooter({ text: newVoice.guild.name, iconURL: newVoice.guild.iconURL({ dynamic: true }) }) .setTimestamp(); auditChannel.send({ embeds: [leftVoiceEmbed] }); }; if (oldVoice.channelId) { const channelList = await VCRoleList.find({ channelId: oldVoice.channelId }); if (!channelList.length) return; for (const { roleId } of channelList) await oldVoice.member.roles.remove(roleId); }; if (newVoice.channelId) { const channelList = await VCRoleList.find({ channelId: newVoice.channelId }); if (!channelList.length) return; for (const { roleId } of channelList) await oldVoice.member.roles.add(roleId); }; if (newVoice.channel && newVoice.channel?.members.size >= 10) { let channel = textVC.find(({ voice }) => voice === newVoice.channelId); if (channel) { if (voiceMap.has(channel.text)) { let timestamp = voiceMap.get(channel.text); if ((Date.now() - timestamp) > 120000) { voiceMap.set(channel.text, Date.now()); let textChannel = newVoice.guild.channels.cache.get(channel.text); if (textChannel) await textChannel.send({ content: '*Please register this match after hosting the room using `/start` command*' }); }; } else { voiceMap.set(channel.text, Date.now()); let textChannel = newVoice.guild.channels.cache.get(channel.text); if (textChannel) await textChannel.send({ content: '*Please register this match after hosting the room using `/start` command*' }); }; }; }; } catch (error) { console.error(error); }; }; };