Skip to content

Commit

Permalink
Add kick/ban buttons to spam account embed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Oct 5, 2024
1 parent f54d8b3 commit 12df043
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/events/guildMemberUpdate/utils/onboardingAccountCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { Constants } from "@alice-core/Constants";
import { EventUtil } from "@alice-structures/core/EventUtil";
import { EmbedCreator } from "@alice-utils/creators/EmbedCreator";
import { DateTimeFormatHelper } from "@alice-utils/helpers/DateTimeFormatHelper";
import { bold, GuildMember, GuildMemberFlags, userMention } from "discord.js";
import {
ActionRowBuilder,
bold,
ButtonBuilder,
ButtonStyle,
GuildMember,
GuildMemberFlags,
userMention,
} from "discord.js";

export const run: EventUtil["run"] = async (
_,
Expand Down Expand Up @@ -52,6 +60,18 @@ export const run: EventUtil["run"] = async (
}

await reportChannel.send({
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(`spamAccountKick#${newMember.id}`)
.setStyle(ButtonStyle.Danger)
.setLabel("Kick"),
new ButtonBuilder()
.setCustomId(`spamAccountBan#${newMember.id}`)
.setStyle(ButtonStyle.Danger)
.setLabel("Ban"),
),
],
embeds: [
EmbedCreator.createNormalEmbed({
color: "Red",
Expand Down
75 changes: 75 additions & 0 deletions src/interactions/buttons/Spam Account Detection/spamAccountBan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { SpamAccountBanLocalization } from "@alice-localization/interactions/buttons/Spam Account Detection/spamAccountBan/SpamAccountBanLocalization";
import { ButtonCommand } from "@alice-structures/core/ButtonCommand";
import { MessageButtonCreator } from "@alice-utils/creators/MessageButtonCreator";
import { MessageCreator } from "@alice-utils/creators/MessageCreator";
import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { InteractionHelper } from "@alice-utils/helpers/InteractionHelper";

export const run: ButtonCommand["run"] = async (_, interaction) => {
if (!interaction.inCachedGuild()) {
return;
}

await InteractionHelper.deferReply(interaction);

const localization = new SpamAccountBanLocalization(
CommandHelper.getLocale(interaction),
);

const userId = interaction.customId.split("#")[1];
const member = await interaction.guild.members
.fetch(userId)
.catch(() => null);

if (!member) {
return InteractionHelper.reply(interaction, {
content: MessageCreator.createReject(
localization.getTranslation("userNotFound"),
),
});
}

const confirmation = await MessageButtonCreator.createConfirmation(
interaction,
{
content: MessageCreator.createWarn(
localization.getTranslation("confirmBan"),
member.toString(),
),
},
[interaction.user.id],
15,
localization.language,
);

if (!confirmation) {
return;
}

const banned = await member
.ban({
reason: "Flagged as alternate account/engaged in suspected spam activity",
})
.then(() => true)
.catch(() => false);

if (banned) {
InteractionHelper.reply(interaction, {
content: MessageCreator.createAccept(
localization.getTranslation("banSuccess"),
member.toString(),
),
});
} else {
InteractionHelper.reply(interaction, {
content: MessageCreator.createReject(
localization.getTranslation("banFailed"),
member.toString(),
),
});
}
};

export const config: ButtonCommand["config"] = {
replyEphemeral: true,
};
73 changes: 73 additions & 0 deletions src/interactions/buttons/Spam Account Detection/spamAccountKick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { SpamAccountKickLocalization } from "@alice-localization/interactions/buttons/Spam Account Detection/spamAccountKick/SpamAccountKickLocalization";
import { ButtonCommand } from "@alice-structures/core/ButtonCommand";
import { MessageButtonCreator } from "@alice-utils/creators/MessageButtonCreator";
import { MessageCreator } from "@alice-utils/creators/MessageCreator";
import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { InteractionHelper } from "@alice-utils/helpers/InteractionHelper";

export const run: ButtonCommand["run"] = async (_, interaction) => {
if (!interaction.inCachedGuild()) {
return;
}

await InteractionHelper.deferReply(interaction);

const localization = new SpamAccountKickLocalization(
CommandHelper.getLocale(interaction),
);

const userId = interaction.customId.split("#")[1];
const member = await interaction.guild.members
.fetch(userId)
.catch(() => null);

if (!member) {
return InteractionHelper.reply(interaction, {
content: MessageCreator.createReject(
localization.getTranslation("userNotFound"),
),
});
}

const confirmation = await MessageButtonCreator.createConfirmation(
interaction,
{
content: MessageCreator.createWarn(
localization.getTranslation("confirmKick"),
member.toString(),
),
},
[interaction.user.id],
15,
localization.language,
);

if (!confirmation) {
return;
}

const kicked = await member
.kick("Flagged as alternate account/engaged in suspected spam activity")
.then(() => true)
.catch(() => false);

if (kicked) {
InteractionHelper.reply(interaction, {
content: MessageCreator.createAccept(
localization.getTranslation("kickSuccess"),
member.toString(),
),
});
} else {
InteractionHelper.reply(interaction, {
content: MessageCreator.createReject(
localization.getTranslation("kickFailed"),
member.toString(),
),
});
}
};

export const config: ButtonCommand["config"] = {
replyEphemeral: true,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Localization } from "@alice-localization/base/Localization";
import { Translations } from "@alice-localization/base/Translations";
import { SpamAccountBanENTranslation } from "./translations/SpamAccountBanENTranslation";

export interface SpamAccountBanStrings {
readonly userNotFound: string;
readonly confirmBan: string;
readonly banSuccess: string;
readonly banFailed: string;
}

/**
* Localizations for the `spamAccountBan` button command.
*/
export class SpamAccountBanLocalization extends Localization<SpamAccountBanStrings> {
protected override readonly localizations: Readonly<
Translations<SpamAccountBanStrings>
> = {
en: new SpamAccountBanENTranslation(),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Translation } from "@alice-localization/base/Translation";
import { SpamAccountBanStrings } from "../SpamAccountBanLocalization";

/**
* The English translation for the `spamAccountBan` button command.
*/
export class SpamAccountBanENTranslation extends Translation<SpamAccountBanStrings> {
override readonly translations: SpamAccountBanStrings = {
userNotFound: "I'm sorry, this user is not in the server!",
confirmBan: "Are you sure you want to ban %s?",
banSuccess: "Successfully banned %s.",
banFailed:
"I'm sorry, I couldn't ban %s. Perhaps they have a higher role than me?",
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Localization } from "@alice-localization/base/Localization";
import { Translations } from "@alice-localization/base/Translations";
import { SpamAccountKickENTranslation } from "./translations/SpamAccountKickENTranslation";

export interface SpamAccountKickStrings {
readonly userNotFound: string;
readonly confirmKick: string;
readonly kickSuccess: string;
readonly kickFailed: string;
}

/**
* Localizations for the `spamAccountKick` button command.
*/
export class SpamAccountKickLocalization extends Localization<SpamAccountKickStrings> {
protected override readonly localizations: Readonly<
Translations<SpamAccountKickStrings>
> = {
en: new SpamAccountKickENTranslation(),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Translation } from "@alice-localization/base/Translation";
import { SpamAccountKickStrings } from "../SpamAccountKickLocalization";

/**
* The English translation for the `spamAccountKick` button command.
*/
export class SpamAccountKickENTranslation extends Translation<SpamAccountKickStrings> {
override readonly translations: SpamAccountKickStrings = {
userNotFound: "I'm sorry, this user is not in the server!",
confirmKick: "Are you sure you want to kick %s?",
kickSuccess: "Successfully kicked %s.",
kickFailed:
"I'm sorry, I couldn't kick %s. Perhaps they have a higher role than me?",
};
}

0 comments on commit 12df043

Please sign in to comment.