aboutsummaryrefslogtreecommitdiff
path: root/src/lib/common
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/common
parentd3464427ea9b08b54a0444795bf4aedab55d3afc (diff)
downloadtanzanite-5116ccf230c933c290676d033a5639b3913ee03b.tar.gz
tanzanite-5116ccf230c933c290676d033a5639b3913ee03b.tar.bz2
tanzanite-5116ccf230c933c290676d033a5639b3913ee03b.zip
perf: make massban actually work
Diffstat (limited to 'src/lib/common')
-rw-r--r--src/lib/common/util/Moderation.ts101
1 files changed, 70 insertions, 31 deletions
diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts
index 04ccb31..365dbd5 100644
--- a/src/lib/common/util/Moderation.ts
+++ b/src/lib/common/util/Moderation.ts
@@ -123,25 +123,41 @@ export class Moderation {
const user = (await util.resolveNonCachedUser(options.user))!.id;
const moderator = (await util.resolveNonCachedUser(options.moderator))!.id;
const guild = client.guilds.resolveId(options.guild)!;
- const duration = options.duration ? options.duration : undefined;
+ return this.createModLogEntrySimple(
+ {
+ ...options,
+ user: user,
+ moderator: moderator,
+ guild: guild
+ },
+ getCaseNumber
+ );
+ }
+
+ /**
+ * Creates a modlog entry with already resolved ids.
+ * @param options Options for creating a modlog entry.
+ * @param getCaseNumber Whether or not to get the case number of the entry.
+ * @returns An object with the modlog and the case number.
+ */
+ public static async createModLogEntrySimple(
+ options: SimpleCreateModLogEntryOptions,
+ getCaseNumber = false
+ ): Promise<{ log: ModLog | null; caseNum: number | null }> {
// If guild does not exist create it so the modlog can reference a guild.
await Guild.findOrCreate({
- where: {
- id: guild
- },
- defaults: {
- id: guild
- }
+ where: { id: options.guild },
+ defaults: { id: options.guild }
});
const modLogEntry = ModLog.build({
type: options.type,
- user,
- moderator,
+ user: options.user,
+ moderator: options.moderator,
reason: options.reason,
- duration: duration,
- guild,
+ duration: options.duration ? options.duration : undefined,
+ guild: options.guild,
pseudo: options.pseudo ?? false,
evidence: options.evidence,
hidden: options.hidden ?? false
@@ -153,7 +169,9 @@ export class Moderation {
if (!getCaseNumber) return { log: saveResult, caseNum: null };
- const caseNum = (await ModLog.findAll({ where: { type: options.type, user: user, guild: guild, hidden: 'false' } }))?.length;
+ const caseNum = (
+ await ModLog.findAll({ where: { type: options.type, user: options.user, guild: options.guild, hidden: false } })
+ )?.length;
return { log: saveResult, caseNum };
}
@@ -269,7 +287,6 @@ export class Moderation {
if (appealsEnabled && options.modlog)
components = [
new ActionRow({
- type: ComponentType.ActionRow,
components: [
new ButtonComponent({
custom_id: `appeal;${this.punishmentToPresentTense(options.punishment)};${
@@ -294,54 +311,76 @@ export class Moderation {
}
}
-/**
- * Options for creating a modlog entry.
- */
-export interface CreateModLogEntryOptions {
+interface BaseCreateModLogEntryOptions {
/**
* The type of modlog entry.
*/
type: ModLogType;
/**
- * The user that a modlog entry is created for.
+ * The reason for the punishment.
*/
- user: BushGuildMemberResolvable;
+ reason: string | undefined | null;
/**
- * The moderator that created the modlog entry.
+ * The duration of the punishment.
*/
- moderator: BushGuildMemberResolvable;
+ duration?: number;
/**
- * The reason for the punishment.
+ * Whether the punishment is a pseudo punishment.
*/
- reason: string | undefined | null;
+ pseudo?: boolean;
/**
- * The duration of the punishment.
+ * The evidence for the punishment.
*/
- duration?: number;
+ evidence?: string;
+
+ /**
+ * Makes the modlog entry hidden.
+ */
+ hidden?: boolean;
+}
+
+/**
+ * Options for creating a modlog entry.
+ */
+export interface CreateModLogEntryOptions extends BaseCreateModLogEntryOptions {
+ /**
+ * The user that a modlog entry is created for.
+ */
+ user: BushGuildMemberResolvable;
+
+ /**
+ * The moderator that created the modlog entry.
+ */
+ moderator: BushGuildMemberResolvable;
/**
* The guild that the punishment is created for.
*/
guild: BushGuildResolvable;
+}
+/**
+ * Simple options for creating a modlog entry.
+ */
+export interface SimpleCreateModLogEntryOptions extends BaseCreateModLogEntryOptions {
/**
- * Whether the punishment is a pseudo punishment.
+ * The user that a modlog entry is created for.
*/
- pseudo?: boolean;
+ user: Snowflake;
/**
- * The evidence for the punishment.
+ * The moderator that created the modlog entry.
*/
- evidence?: string;
+ moderator: Snowflake;
/**
- * Makes the modlog entry hidden.
+ * The guild that the punishment is created for.
*/
- hidden?: boolean;
+ guild: Snowflake;
}
/**