diff --git a/backend/src/RecoverablePluginError.ts b/backend/src/RecoverablePluginError.ts index 64fed618..a286c12f 100644 --- a/backend/src/RecoverablePluginError.ts +++ b/backend/src/RecoverablePluginError.ts @@ -1,18 +1,20 @@ import { Guild } from "discord.js"; -export enum ERRORS { - NO_MUTE_ROLE_IN_CONFIG = 1, - UNKNOWN_NOTE_CASE, - INVALID_EMOJI, - NO_USER_NOTIFICATION_CHANNEL, - INVALID_USER_NOTIFICATION_CHANNEL, - INVALID_USER, - INVALID_MUTE_ROLE_ID, - MUTE_ROLE_ABOVE_ZEP, - USER_ABOVE_ZEP, - USER_NOT_MODERATABLE, - TEMPLATE_PARSE_ERROR, -} +export const ERRORS = { + NO_MUTE_ROLE_IN_CONFIG: 1, + UNKNOWN_NOTE_CASE: 2, + INVALID_EMOJI: 3, + NO_USER_NOTIFICATION_CHANNEL: 4, + INVALID_USER_NOTIFICATION_CHANNEL: 5, + INVALID_USER: 6, + INVALID_MUTE_ROLE_ID: 7, + MUTE_ROLE_ABOVE_ZEP: 8, + USER_ABOVE_ZEP: 9, + USER_NOT_MODERATABLE: 10, + TEMPLATE_PARSE_ERROR: 11, +} as const; + +export type ERRORS = typeof ERRORS[keyof typeof ERRORS]; export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = { [ERRORS.NO_MUTE_ROLE_IN_CONFIG]: "No mute role specified in config", diff --git a/backend/src/data/ApiPermissionAssignments.ts b/backend/src/data/ApiPermissionAssignments.ts index 3c1ef2c6..bfa4c937 100644 --- a/backend/src/data/ApiPermissionAssignments.ts +++ b/backend/src/data/ApiPermissionAssignments.ts @@ -6,10 +6,12 @@ import { AuditLogEventTypes } from "./apiAuditLogTypes.js"; import { dataSource } from "./dataSource.js"; import { ApiPermissionAssignment } from "./entities/ApiPermissionAssignment.js"; -export enum ApiPermissionTypes { - User = "USER", - Role = "ROLE", -} +export const ApiPermissionTypes = { + User: "USER", + Role: "ROLE", +} as const; + +export type ApiPermissionTypes = (typeof ApiPermissionTypes)[keyof typeof ApiPermissionTypes]; export class ApiPermissionAssignments extends BaseRepository { private apiPermissions: Repository; diff --git a/backend/src/data/CaseTypes.ts b/backend/src/data/CaseTypes.ts index e403e92f..14efbde1 100644 --- a/backend/src/data/CaseTypes.ts +++ b/backend/src/data/CaseTypes.ts @@ -1,14 +1,16 @@ -export enum CaseTypes { - Ban = 1, - Unban, - Note, - Warn, - Kick, - Mute, - Unmute, - Deleted, - Softban, -} +export const CaseTypes = { + Ban: 1, + Unban: 2, + Note: 3, + Warn: 4, + Kick: 5, + Mute: 6, + Unmute: 7, + Deleted: 8, + Softban: 9, +} as const; + +export type CaseTypes = typeof CaseTypes[keyof typeof CaseTypes]; export const CaseNameToType = { ban: CaseTypes.Ban, diff --git a/backend/src/data/MuteTypes.ts b/backend/src/data/MuteTypes.ts index 5e609606..40b3c42b 100644 --- a/backend/src/data/MuteTypes.ts +++ b/backend/src/data/MuteTypes.ts @@ -1,4 +1,6 @@ -export enum MuteTypes { - Role = 1, - Timeout = 2, -} +export const MuteTypes = { + Role: 1, + Timeout: 2, +} as const; + +export type MuteTypes = typeof MuteTypes[keyof typeof MuteTypes]; diff --git a/backend/src/plugins/Automod/constants.ts b/backend/src/plugins/Automod/constants.ts index aecbc97d..2e3056b0 100644 --- a/backend/src/plugins/Automod/constants.ts +++ b/backend/src/plugins/Automod/constants.ts @@ -5,19 +5,21 @@ export const RECENT_SPAM_EXPIRY_TIME = 10 * SECONDS; export const RECENT_ACTION_EXPIRY_TIME = 5 * MINUTES; export const RECENT_NICKNAME_CHANGE_EXPIRY_TIME = 5 * MINUTES; -export enum RecentActionType { - Message = 1, - Mention, - Link, - Attachment, - Emoji, - Line, - Character, - VoiceChannelMove, - MemberJoin, - Sticker, - MemberLeave, - ThreadCreate, -} +export const RecentActionType = { + Message: 1, + Mention: 2, + Link: 3, + Attachment: 4, + Emoji: 5, + Line: 6, + Character: 7, + VoiceChannelMove: 8, + MemberJoin: 9, + Sticker: 10, + MemberLeave: 11, + ThreadCreate: 12, +} as const; + +export type RecentActionType = typeof RecentActionType[keyof typeof RecentActionType]; export const zNotify = z.union([z.literal("dm"), z.literal("channel")]); diff --git a/backend/src/plugins/Cases/functions/getCaseEmbed.ts b/backend/src/plugins/Cases/functions/getCaseEmbed.ts index 15bcae1c..320ebe98 100644 --- a/backend/src/plugins/Cases/functions/getCaseEmbed.ts +++ b/backend/src/plugins/Cases/functions/getCaseEmbed.ts @@ -68,7 +68,7 @@ export async function getCaseEmbed( embed.title += " (hidden)"; } - embed.color = getCaseColor(pluginData, theCase.type); + embed.color = getCaseColor(pluginData, theCase.type as CaseTypes); if (theCase.notes.length) { for (const note of theCase.notes) { diff --git a/backend/src/plugins/Cases/functions/getCaseSummary.ts b/backend/src/plugins/Cases/functions/getCaseSummary.ts index 79f8687a..fc3b4a89 100644 --- a/backend/src/plugins/Cases/functions/getCaseSummary.ts +++ b/backend/src/plugins/Cases/functions/getCaseSummary.ts @@ -7,6 +7,7 @@ import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin.js"; import { caseAbbreviations } from "../caseAbbreviations.js"; import { CasesPluginType } from "../types.js"; import { getCaseIcon } from "./getCaseIcon.js"; +import type { CaseTypes } from "../../../data/CaseTypes.js"; const CASE_SUMMARY_REASON_MAX_LENGTH = 300; const INCLUDE_MORE_NOTES_THRESHOLD = 20; @@ -52,7 +53,7 @@ export async function getCaseSummary( ? moment.utc().to(timestamp) : timestampWithTz.format(timeAndDate.getDateFormat("date")); - const icon = getCaseIcon(pluginData, theCase.type); + const icon = getCaseIcon(pluginData, theCase.type as CaseTypes); let caseTitle = `\`#${theCase.case_number}\``; if (withLinks && theCase.log_message_id) { diff --git a/backend/src/plugins/ContextMenus/types.ts b/backend/src/plugins/ContextMenus/types.ts index 80c56dd1..3a964994 100644 --- a/backend/src/plugins/ContextMenus/types.ts +++ b/backend/src/plugins/ContextMenus/types.ts @@ -15,23 +15,27 @@ export interface ContextMenuPluginType extends BasePluginType { }; } -export const enum ModMenuActionType { - PAGE = "page", - NOTE = "note", - WARN = "warn", - CLEAN = "clean", - MUTE = "mute", - BAN = "ban", -} +export const ModMenuActionType = { + PAGE: "page", + NOTE: "note", + WARN: "warn", + CLEAN: "clean", + MUTE: "mute", + BAN: "ban", +} as const; -export const enum ModMenuNavigationType { - FIRST = "first", - PREV = "prev", - NEXT = "next", - LAST = "last", - INFO = "info", - CASES = "cases", -} +export type ModMenuActionType = typeof ModMenuActionType[keyof typeof ModMenuActionType]; + +export const ModMenuNavigationType = { + FIRST: "first", + PREV: "prev", + NEXT: "next", + LAST: "last", + INFO: "info", + CASES: "cases", +} as const; + +export type ModMenuNavigationType = typeof ModMenuNavigationType[keyof typeof ModMenuNavigationType]; export interface ModMenuActionOpts { action: ModMenuActionType; diff --git a/backend/src/plugins/ModActions/commands/massunban/actualMassUnbanCmd.ts b/backend/src/plugins/ModActions/commands/massunban/actualMassUnbanCmd.ts index 9a132bf5..5fb8ca4b 100644 --- a/backend/src/plugins/ModActions/commands/massunban/actualMassUnbanCmd.ts +++ b/backend/src/plugins/ModActions/commands/massunban/actualMassUnbanCmd.ts @@ -112,7 +112,9 @@ export async function actualMassUnbanCmd( } } -enum UnbanFailReasons { - NOT_BANNED = "Not banned", - UNBAN_FAILED = "Unban failed", -} +const UnbanFailReasons = { + NOT_BANNED: "Not banned", + UNBAN_FAILED: "Unban failed", +} as const; + +type UnbanFailReasons = typeof UnbanFailReasons[keyof typeof UnbanFailReasons]; diff --git a/backend/src/plugins/ModActions/types.ts b/backend/src/plugins/ModActions/types.ts index 7f4c0aa6..115ecb62 100644 --- a/backend/src/plugins/ModActions/types.ts +++ b/backend/src/plugins/ModActions/types.ts @@ -102,11 +102,13 @@ export interface ModActionsPluginType extends BasePluginType { }; } -export enum IgnoredEventType { - Ban = 1, - Unban, - Kick, -} +export const IgnoredEventType = { + Ban: 1, + Unban: 2, + Kick: 3, +} as const; + +export type IgnoredEventType = typeof IgnoredEventType[keyof typeof IgnoredEventType]; export interface IIgnoredEvent { type: IgnoredEventType; diff --git a/backend/src/plugins/Spam/types.ts b/backend/src/plugins/Spam/types.ts index d7f7aaec..a4be68ac 100644 --- a/backend/src/plugins/Spam/types.ts +++ b/backend/src/plugins/Spam/types.ts @@ -30,17 +30,19 @@ export const zSpamConfig = z.strictObject({ max_voice_moves: zBaseSingleSpamConfig.nullable().default(null), }); -export enum RecentActionType { - Message = 1, - Mention, - Link, - Attachment, - Emoji, - Newline, - Censor, - Character, - VoiceChannelMove, -} +export const RecentActionType = { + Message: 1, + Mention: 2, + Link: 3, + Attachment: 4, + Emoji: 5, + Newline: 6, + Censor: 7, + Character: 8, + VoiceChannelMove: 9, +} as const; + +export type RecentActionType = typeof RecentActionType[keyof typeof RecentActionType]; export interface IRecentAction { type: RecentActionType; diff --git a/backend/src/plugins/Utility/search.ts b/backend/src/plugins/Utility/search.ts index 130db796..8d2b0cf1 100644 --- a/backend/src/plugins/Utility/search.ts +++ b/backend/src/plugins/Utility/search.ts @@ -36,10 +36,12 @@ const SEARCH_RESULTS_PER_PAGE = 15; const SEARCH_ID_RESULTS_PER_PAGE = 50; const SEARCH_EXPORT_LIMIT = 1_000_000; -export enum SearchType { - MemberSearch, - BanSearch, -} +export const SearchType = { + MemberSearch: 0, + BanSearch: 1, +} as const; + +export type SearchType = typeof SearchType[keyof typeof SearchType]; class SearchError extends Error {} @@ -72,13 +74,13 @@ function getOptimizedRegExpRunner(pluginData: GuildPluginData export async function displaySearch( pluginData: GuildPluginData, args: MemberSearchParams, - searchType: SearchType.MemberSearch, + searchType: (typeof SearchType)["MemberSearch"], msg: OmitPartialGroupDMChannel, ); export async function displaySearch( pluginData: GuildPluginData, args: BanSearchParams, - searchType: SearchType.BanSearch, + searchType: (typeof SearchType)["BanSearch"], msg: OmitPartialGroupDMChannel, ); export async function displaySearch( @@ -239,13 +241,13 @@ export async function displaySearch( export async function archiveSearch( pluginData: GuildPluginData, args: MemberSearchParams, - searchType: SearchType.MemberSearch, + searchType: (typeof SearchType)["MemberSearch"], msg: OmitPartialGroupDMChannel, ); export async function archiveSearch( pluginData: GuildPluginData, args: BanSearchParams, - searchType: SearchType.BanSearch, + searchType: (typeof SearchType)["BanSearch"], msg: OmitPartialGroupDMChannel, ); export async function archiveSearch(