From 726cac029dec237abca2f032d7928f2f28a1785b Mon Sep 17 00:00:00 2001 From: Szedann <65607498+Szedann@users.noreply.github.com> Date: Thu, 28 Dec 2023 17:22:31 +0100 Subject: [PATCH] button :+1: --- src/handlers/spam.handler.ts | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/handlers/spam.handler.ts b/src/handlers/spam.handler.ts index fd6cc1a..8b2eadf 100644 --- a/src/handlers/spam.handler.ts +++ b/src/handlers/spam.handler.ts @@ -1,10 +1,88 @@ import { + ActionRowBuilder, + ButtonBuilder, + ButtonStyle, EmbedBuilder, GuildNSFWLevel, Message, + ModalActionRowComponentBuilder, + ModalBuilder, TextBasedChannel, + TextInputBuilder, } from 'discord.js'; import { Handler } from '..'; +import { Button } from './button.handler'; + +const banButton = new Button( + 'spammer-ban', + async (interaction, data: { userId: string }) => { + + const modal = new ModalBuilder() + .setCustomId(`ban`) + .setTitle(`Ban <@${data.userId}>`) + .addComponents( + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setCustomId('banReason') + .setLabel('Ban reason') + .setValue("spam (autodetected)") + ) + ); + await interaction.showModal(modal); + interaction + .awaitModalSubmit({ + filter: (interaction) => + interaction.customId == modal.data.custom_id, + time: 300_000, + }) + .then(async (modalResponse) => { + interaction.guild?.bans.create(data.userId, { + reason: modalResponse.components[0].components[0].value, + }); + await interaction.reply({ + content: `<@${data.userId}> (\`${data.userId}\`) was banned.`, + ephemeral: true, + }); + await interaction.update({ + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setLabel('ban') + .setStyle(ButtonStyle.Danger) + .setDisabled(true) + ), + ], + }); + if (interaction.guild != null) { + const channel = await interaction.guild.channels.fetch( + process.env.BAN_LOGS_CHANNEL + ); + if (channel?.isTextBased()) { + channel.send({ + embeds: [ + new EmbedBuilder() + .setTitle('User Banned via Banshare') + .setDescription( + `<@!${data.userId}> was banned!` + ) + .setFields([ + { + name: 'Reason', + value: modalResponse.components[0] + .components[0].value, + }, + { + name: 'By', + value: interaction.user.username, + }, + ]), + ], + }); + } + } + }); + } +); const getMessageSuspicion = async (message: Message) => { let suspicionLevel = 0; @@ -12,6 +90,7 @@ const getMessageSuspicion = async (message: Message) => { /(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?\/[a-zA-Z0-9]{2,}|((https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?/g ); if (message.content.toLowerCase().includes('nitro')) suspicionLevel += 5; + // eslint-disable-next-line @typescript-eslint/no-unused-vars for (const _ of links) suspicionLevel += 5; const invites = message.content.matchAll( @@ -70,6 +149,9 @@ export const spamHandler: Handler = (client) => { description: `suspicion level ${suspicionLevel} for ${message.author}, from message ${message.url}`, }), ], + components: [ + new ActionRowBuilder().addComponents(banButton.button({label: "Ban", style: ButtonStyle.Danger}, {userId: message.author.id})) + ] }); } });