Skip to content

Commit

Permalink
button 👍
Browse files Browse the repository at this point in the history
  • Loading branch information
Szedann committed Dec 28, 2023
1 parent f98949e commit 726cac0
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/handlers/spam.handler.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,96 @@
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<ModalActionRowComponentBuilder>().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<ButtonBuilder>().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;
const links = message.content.matchAll(
/(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(
Expand Down Expand Up @@ -70,6 +149,9 @@ export const spamHandler: Handler = (client) => {
description: `suspicion level ${suspicionLevel} for ${message.author}, from message ${message.url}`,
}),
],
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(banButton.button({label: "Ban", style: ButtonStyle.Danger}, {userId: message.author.id}))
]
});
}
});
Expand Down

0 comments on commit 726cac0

Please sign in to comment.