diff --git a/package-lock.json b/package-lock.json index 7179681..edb9b81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "agent", - "version": "1.13.21", + "version": "1.13.24", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "agent", - "version": "1.13.21", + "version": "1.13.24", "license": "GPL-3.0", "dependencies": { "@discordjs/rest": "^1.0.1", @@ -14,6 +14,9 @@ "discord-api-types": "^0.37.1", "discord.js": "^14.14.1", "mongoose": "^6.7.0" + }, + "engines": { + "node": ">=20.0.0" } }, "node_modules/@aws-crypto/crc32": { diff --git a/src/commands/checkmembers.js b/src/commands/checkmembers.js new file mode 100644 index 0000000..e76ecd5 --- /dev/null +++ b/src/commands/checkmembers.js @@ -0,0 +1,65 @@ +const { SlashCommandBuilder, PermissionsBitField } = require("discord.js"); +const Command = require("../structures/command.js"); +const config = require("../config.js"); +const constants = require("../utils/constants.js"); + +class CheckMembersCommand extends Command { + constructor() { + super({ + active: true, + data: new SlashCommandBuilder() + .setName("checkmembers") + .setDescription("Faça um checkup de todos os membros do servidor.") + .setDMPermission(false) + .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator), + }); + } + + /** + * @param {import('discord.js').ChatInputCommandInteraction} interaction + */ + async execute(interaction) { + await interaction.deferReply({ ephemeral: true }); + + const memberModel = require("../models/member.js"); + const memberDocs = await memberModel.find({}); + + // @vitoUwu: how tf are we suposed to paginate this? skill issue asf + // remember to update this code when we achieve more than 1000 members + const members = await interaction.guild.members.fetch({ limit: 1000 }); + const warnings = []; + + for (const [id, member] of members) { + if (member.roles.cache.hasAny(...config.levels)) { + const userDocs = memberDocs.filter((doc) => doc.user === id); + if (!userDocs.length) { + const warning = `**<@${id}> (${id})** have a moderator/admin/owner role but is not in any server!`; + if (warnings.length && warnings.at(-1).length + warning.length < constants.maxMessageContentLength) { + warnings[warnings.length - 1] += `\n${warning}`; + } else { + warnings.push(warning); + } + } + } + + if (member.roles.cache.has(config.guestRole)) { + const warning = `**<@${id}> (${id})** is a guest!`; + if (warnings.length && warnings.at(-1).length + warning.length < constants.maxMessageContentLength) { + warnings[warnings.length - 1] += `\n${warning}`; + } else { + warnings.push(warning); + } + } + } + + for (const [index, warning] of warnings.entries()) { + const reply = index === 0 ? interaction.editReply : interaction.followUp; + + await reply({ + content: warning, + }); + } + } +} + +module.exports = new CheckMembersCommand(); diff --git a/src/config.js b/src/config.js index cc3de3f..cd6a1a8 100644 --- a/src/config.js +++ b/src/config.js @@ -38,4 +38,5 @@ module.exports = { suggestionsChannel: '1025927402800558090', pendingTag: '1040402827064922155', guildsChangeLog: "1049034683968663612", + guestRole: "921091439876780052" }; diff --git a/src/utils/constants.js b/src/utils/constants.js new file mode 100644 index 0000000..70c5240 --- /dev/null +++ b/src/utils/constants.js @@ -0,0 +1,3 @@ +module.exports = { + maxMessageContentLength: 2000, +};