diff --git a/config/options.json b/config/options.json index bc225ec..e5e52d1 100644 --- a/config/options.json +++ b/config/options.json @@ -2,8 +2,9 @@ "color": "#eeaadb", "applicationsChannel": "776705352456470550", "staffApplicationsChannel": "1039258641393520700", - "inactivityLogChannel": "829742524796239882", + "inactivityLogChannel": "829742524796239882", "staffOtherChannel": "1082036748558803104", "hypixelGuildID": "5a353a170cf2e529044f2935", - "botLogChannel": "1101144489306886226" + "onlineLogChannel": "1101144489306886226", + "botLogChannel": "1174403585149243472" } diff --git a/events/other/vcJoinLeave.js b/events/other/vcJoinLeave.js new file mode 100644 index 0000000..fe3d3f4 --- /dev/null +++ b/events/other/vcJoinLeave.js @@ -0,0 +1,76 @@ +const { userMention, channelMention } = require('discord.js') +const { botLogChannel, color } = require('../../config/options.json') + +module.exports = { + name: 'vcJoinLeave', + description: 'Logs when a user joins or leaves a voice channel.', + type: 'other', + event: 'voiceStateUpdate', + + /** + * @param { import('discord.js').VoiceState } oldState + * @param { import('discord.js').VoiceState } newState + */ + + execute(oldState, newState) { + + const oldChannel = oldState.channel + const newChannel = newState.channel + const guild = oldState.guild + const channel = guild.channels.cache.get(botLogChannel) + const embedColor = Number(color.replace('#', '0x')) + + if (oldChannel === null && newChannel !== null) { + + channel.send({ + embeds: [{ + title: "Voice Channel Join", + description: userMention(oldState.member.id) + + " joined " + + channelMention(newChannel.id), + color: embedColor, + footer: { + text: "ID: " + oldState.member.id + }, + timestamp: new Date() + }] + }) + + } else if (oldChannel !== null && newChannel === null) { + + channel.send({ + embeds: [{ + title: "Voice Channel Leave", + description: userMention(oldState.member.id) + + " left " + + channelMention(oldChannel.id), + color: embedColor, + footer: { + text: "ID: " + oldState.member.id + }, + timestamp: new Date() + }] + }) + + } else if (oldChannel !== null && newChannel !== null) { + + channel.send({ + embeds: [{ + title: "Voice Channel Switch", + description: userMention(oldState.member.id) + + " switched from " + + channelMention(oldChannel.id) + + " to " + + channelMention(newChannel.id), + color: embedColor, + footer: { + text: "ID: " + oldState.member.id + }, + timestamp: new Date() + }] + }) + + } + + } +} diff --git a/events/ready/sendOnlineMessage.js b/events/ready/sendOnlineMessage.js index 3a2ee9c..75577a5 100644 --- a/events/ready/sendOnlineMessage.js +++ b/events/ready/sendOnlineMessage.js @@ -1,4 +1,4 @@ -const { botLogChannel, color } = require('../../config/options.json'); +const { onlineLogChannel, color } = require('../../config/options.json'); module.exports = { name: 'sendonlinemessage', @@ -7,10 +7,11 @@ module.exports = { execute(client) { if (process.env.NODE_ENV !== 'dev') { - const channel = client.channels.cache.get(botLogChannel); + const channel = client.channels.cache.get(onlineLogChannel); const embedColor = Number(color.replace('#', '0x')) if (!channel) { + console.log(`[ERROR] Could not find channel used for online message.`); return; } diff --git a/index.js b/index.js index 29ac2d0..b935427 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,14 @@ const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js'); -const { loadSlashCommands, loadMessageEvents, loadContextMenu, loadModalEvents, loadButtonEvents, loadReadyEvents, loadInteractionEvents } = require('./utils/eventHandler.js') +const { + loadSlashCommands, + loadMessageEvents, + loadContextMenu, + loadModalEvents, + loadButtonEvents, + loadReadyEvents, + loadInteractionEvents, + loadOtherEvents +} = require('./utils/eventHandler.js') const { autoDeployCommands } = require('./utils/autodeploy.js'); require('dotenv').config(); const mongoURI = process.env.MONGOURI; @@ -20,7 +29,8 @@ const client = new Client({ GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, - GatewayIntentBits.DirectMessages + GatewayIntentBits.DirectMessages, + GatewayIntentBits.GuildVoiceStates ], partials: [ Partials.GuildMember, @@ -41,6 +51,7 @@ loadModalEvents(client); loadMessageEvents(client); loadReadyEvents(client) loadInteractionEvents(client); +loadOtherEvents(client); client.login(token); diff --git a/utils/eventHandler.js b/utils/eventHandler.js index 990ebc7..3cd79f4 100644 --- a/utils/eventHandler.js +++ b/utils/eventHandler.js @@ -5,5 +5,15 @@ const { loadMessageEvents } = require('./eventHandlers/message.js') const { loadModalEvents } = require('./eventHandlers/modal.js') const { loadReadyEvents } = require('./eventHandlers/ready.js') const { loadInteractionEvents } = require('./eventHandlers/interaction.js') +const { loadOtherEvents } = require('./eventHandlers/other.js') -module.exports = { loadSlashCommands, loadButtonEvents, loadContextMenu, loadMessageEvents, loadModalEvents, loadReadyEvents, loadInteractionEvents } +module.exports = { + loadSlashCommands, + loadButtonEvents, + loadContextMenu, + loadMessageEvents, + loadModalEvents, + loadReadyEvents, + loadInteractionEvents, + loadOtherEvents +} diff --git a/utils/eventHandlers/other.js b/utils/eventHandlers/other.js new file mode 100644 index 0000000..ba303d4 --- /dev/null +++ b/utils/eventHandlers/other.js @@ -0,0 +1,22 @@ +const path = require('path'); +const fs = require('fs'); + +/** @param { import('discord.js').Client } client */ + +function loadOtherEvents(client) { + const otherPath = path.join(__dirname, '..', '..', 'events', 'other') + const otherFiles = fs.readdirSync(otherPath).filter(file => file.endsWith('.js')); + + for (const file of otherFiles) { + const filePath = path.join(otherPath, file); + const other = require(filePath); + + if ('name' in other && 'execute' in other && 'event' in other && other.type === 'other') { + client.on(other.event, other.execute) + } else { + console.log(`[WARNING] The other event at ${filePath} is missing a required "name", "execute", "type" or "event" property.`); + } + } +} + +module.exports = { loadOtherEvents }