-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kick/ban buttons to spam account embed
- Loading branch information
Showing
7 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/interactions/buttons/Spam Account Detection/spamAccountBan.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
73
src/interactions/buttons/Spam Account Detection/spamAccountKick.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
21 changes: 21 additions & 0 deletions
21
.../interactions/buttons/Spam Account Detection/spamAccountBan/SpamAccountBanLocalization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}; | ||
} |
15 changes: 15 additions & 0 deletions
15
...buttons/Spam Account Detection/spamAccountBan/translations/SpamAccountBanENTranslation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?", | ||
}; | ||
} |
21 changes: 21 additions & 0 deletions
21
...nteractions/buttons/Spam Account Detection/spamAccountKick/SpamAccountKickLocalization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}; | ||
} |
15 changes: 15 additions & 0 deletions
15
...ttons/Spam Account Detection/spamAccountKick/translations/SpamAccountKickENTranslation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?", | ||
}; | ||
} |