aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-21 16:08:38 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-21 16:08:38 -0500
commit5116ccf230c933c290676d033a5639b3913ee03b (patch)
tree7ebd8bb012b22c016e8d38d79b551cf43155d4dd /src/lib/extensions/discord.js
parentd3464427ea9b08b54a0444795bf4aedab55d3afc (diff)
downloadtanzanite-5116ccf230c933c290676d033a5639b3913ee03b.tar.gz
tanzanite-5116ccf230c933c290676d033a5639b3913ee03b.tar.bz2
tanzanite-5116ccf230c933c290676d033a5639b3913ee03b.zip
perf: make massban actually work
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r--src/lib/extensions/discord.js/BushClientEvents.ts7
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts85
2 files changed, 92 insertions, 0 deletions
diff --git a/src/lib/extensions/discord.js/BushClientEvents.ts b/src/lib/extensions/discord.js/BushClientEvents.ts
index 50b198d..e6cf93f 100644
--- a/src/lib/extensions/discord.js/BushClientEvents.ts
+++ b/src/lib/extensions/discord.js/BushClientEvents.ts
@@ -1,4 +1,5 @@
import type {
+ BanResponse,
BushApplicationCommand,
BushClient,
BushDMChannel,
@@ -264,6 +265,12 @@ export interface BushClientEvents extends AkairoClientEvents {
channelsSuccessMap: Collection<Snowflake, boolean>,
all?: boolean
];
+ massBan: [
+ moderator: BushGuildMember,
+ guild: BushGuild,
+ reason: string | undefined,
+ results: Collection<Snowflake, BanResponse>
+ ];
}
type Setting = GuildSettings | 'enabledFeatures' | 'blacklistedChannels' | 'blacklistedUsers' | 'disabledCommands';
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index 80799fd..155f32c 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -236,6 +236,69 @@ export class BushGuild extends Guild {
}
/**
+ * {@link bushBan} with less resolving and checks
+ * @param options Options for banning the user.
+ * @returns A string status message of the ban.
+ * **Preconditions:**
+ * - {@link me} has the `BanMembers` permission
+ * **Warning:**
+ * - Doesn't emit bushBan Event
+ */
+ public async massBanOne(options: GuildMassBanOneOptions): Promise<BanResponse> {
+ if (this.bans.cache.has(options.user)) return banResponse.ALREADY_BANNED;
+
+ const ret = await (async () => {
+ // add modlog entry
+ const { log: modlog } = await Moderation.createModLogEntrySimple({
+ type: ModLogType.PERM_BAN,
+ user: options.user,
+ moderator: options.moderator,
+ reason: options.reason,
+ duration: 0,
+ guild: this.id
+ });
+ if (!modlog) return banResponse.MODLOG_ERROR;
+
+ let dmSuccessEvent: boolean | undefined = undefined;
+ // dm user
+ if (this.members.cache.has(options.user)) {
+ dmSuccessEvent = await Moderation.punishDM({
+ modlog: modlog.id,
+ guild: this,
+ user: options.user,
+ punishment: 'banned',
+ duration: 0,
+ reason: options.reason ?? undefined,
+ sendFooter: true
+ });
+ }
+
+ // ban
+ const banSuccess = await this.bans
+ .create(options.user, {
+ reason: `${options.moderator} | ${options.reason}`,
+ deleteMessageDays: options.deleteDays
+ })
+ .catch(() => false);
+ if (!banSuccess) return banResponse.ACTION_ERROR;
+
+ // add punishment entry so they can be unbanned later
+ const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
+ type: 'ban',
+ user: options.user,
+ guild: this,
+ duration: 0,
+ modlog: modlog.id
+ });
+ if (!punishmentEntrySuccess) return banResponse.PUNISHMENT_ENTRY_ADD_ERROR;
+
+ if (!dmSuccessEvent) return banResponse.DM_ERROR;
+ return banResponse.SUCCESS;
+ })();
+ return ret;
+ }
+
+ /**
* Unbans a user, dms them, creates a mod log entry, and destroys the punishment entry.
* @param options Options for unbanning the user.
* @returns A status message of the unban.
@@ -414,6 +477,28 @@ export interface GuildBushUnbanOptions {
evidence?: string;
}
+export interface GuildMassBanOneOptions {
+ /**
+ * The user to ban
+ */
+ user: Snowflake;
+
+ /**
+ * The reason to ban the user
+ */
+ reason: string;
+
+ /**
+ * The moderator who banned the user
+ */
+ moderator: Snowflake;
+
+ /**
+ * The number of days to delete the user's messages for
+ */
+ deleteDays?: number;
+}
+
/**
* Options for banning a user
*/