Skip to content

Commit 77b54f6

Browse files
committed
refactor: no more enums
1 parent f607ad4 commit 77b54f6

12 files changed

Lines changed: 115 additions & 92 deletions

File tree

backend/src/RecoverablePluginError.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { Guild } from "discord.js";
22

3-
export enum ERRORS {
4-
NO_MUTE_ROLE_IN_CONFIG = 1,
5-
UNKNOWN_NOTE_CASE,
6-
INVALID_EMOJI,
7-
NO_USER_NOTIFICATION_CHANNEL,
8-
INVALID_USER_NOTIFICATION_CHANNEL,
9-
INVALID_USER,
10-
INVALID_MUTE_ROLE_ID,
11-
MUTE_ROLE_ABOVE_ZEP,
12-
USER_ABOVE_ZEP,
13-
USER_NOT_MODERATABLE,
14-
TEMPLATE_PARSE_ERROR,
15-
}
3+
export const ERRORS = {
4+
NO_MUTE_ROLE_IN_CONFIG: 1,
5+
UNKNOWN_NOTE_CASE: 2,
6+
INVALID_EMOJI: 3,
7+
NO_USER_NOTIFICATION_CHANNEL: 4,
8+
INVALID_USER_NOTIFICATION_CHANNEL: 5,
9+
INVALID_USER: 6,
10+
INVALID_MUTE_ROLE_ID: 7,
11+
MUTE_ROLE_ABOVE_ZEP: 8,
12+
USER_ABOVE_ZEP: 9,
13+
USER_NOT_MODERATABLE: 10,
14+
TEMPLATE_PARSE_ERROR: 11,
15+
} as const;
16+
17+
export type ERRORS = typeof ERRORS[keyof typeof ERRORS];
1618

1719
export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = {
1820
[ERRORS.NO_MUTE_ROLE_IN_CONFIG]: "No mute role specified in config",

backend/src/data/ApiPermissionAssignments.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { AuditLogEventTypes } from "./apiAuditLogTypes.js";
66
import { dataSource } from "./dataSource.js";
77
import { ApiPermissionAssignment } from "./entities/ApiPermissionAssignment.js";
88

9-
export enum ApiPermissionTypes {
10-
User = "USER",
11-
Role = "ROLE",
12-
}
9+
export const ApiPermissionTypes = {
10+
User: "USER",
11+
Role: "ROLE",
12+
} as const;
13+
14+
export type ApiPermissionTypes = (typeof ApiPermissionTypes)[keyof typeof ApiPermissionTypes];
1315

1416
export class ApiPermissionAssignments extends BaseRepository {
1517
private apiPermissions: Repository<ApiPermissionAssignment>;

backend/src/data/CaseTypes.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
export enum CaseTypes {
2-
Ban = 1,
3-
Unban,
4-
Note,
5-
Warn,
6-
Kick,
7-
Mute,
8-
Unmute,
9-
Deleted,
10-
Softban,
11-
}
1+
export const CaseTypes = {
2+
Ban: 1,
3+
Unban: 2,
4+
Note: 3,
5+
Warn: 4,
6+
Kick: 5,
7+
Mute: 6,
8+
Unmute: 7,
9+
Deleted: 8,
10+
Softban: 9,
11+
} as const;
12+
13+
export type CaseTypes = typeof CaseTypes[keyof typeof CaseTypes];
1214

1315
export const CaseNameToType = {
1416
ban: CaseTypes.Ban,

backend/src/data/MuteTypes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export enum MuteTypes {
2-
Role = 1,
3-
Timeout = 2,
4-
}
1+
export const MuteTypes = {
2+
Role: 1,
3+
Timeout: 2,
4+
} as const;
5+
6+
export type MuteTypes = typeof MuteTypes[keyof typeof MuteTypes];

backend/src/plugins/Automod/constants.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ export const RECENT_SPAM_EXPIRY_TIME = 10 * SECONDS;
55
export const RECENT_ACTION_EXPIRY_TIME = 5 * MINUTES;
66
export const RECENT_NICKNAME_CHANGE_EXPIRY_TIME = 5 * MINUTES;
77

8-
export enum RecentActionType {
9-
Message = 1,
10-
Mention,
11-
Link,
12-
Attachment,
13-
Emoji,
14-
Line,
15-
Character,
16-
VoiceChannelMove,
17-
MemberJoin,
18-
Sticker,
19-
MemberLeave,
20-
ThreadCreate,
21-
}
8+
export const RecentActionType = {
9+
Message: 1,
10+
Mention: 2,
11+
Link: 3,
12+
Attachment: 4,
13+
Emoji: 5,
14+
Line: 6,
15+
Character: 7,
16+
VoiceChannelMove: 8,
17+
MemberJoin: 9,
18+
Sticker: 10,
19+
MemberLeave: 11,
20+
ThreadCreate: 12,
21+
} as const;
22+
23+
export type RecentActionType = typeof RecentActionType[keyof typeof RecentActionType];
2224

2325
export const zNotify = z.union([z.literal("dm"), z.literal("channel")]);

backend/src/plugins/Cases/functions/getCaseEmbed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function getCaseEmbed(
6868
embed.title += " (hidden)";
6969
}
7070

71-
embed.color = getCaseColor(pluginData, theCase.type);
71+
embed.color = getCaseColor(pluginData, theCase.type as CaseTypes);
7272

7373
if (theCase.notes.length) {
7474
for (const note of theCase.notes) {

backend/src/plugins/Cases/functions/getCaseSummary.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin.js";
77
import { caseAbbreviations } from "../caseAbbreviations.js";
88
import { CasesPluginType } from "../types.js";
99
import { getCaseIcon } from "./getCaseIcon.js";
10+
import type { CaseTypes } from "../../../data/CaseTypes.js";
1011

1112
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
1213
const INCLUDE_MORE_NOTES_THRESHOLD = 20;
@@ -52,7 +53,7 @@ export async function getCaseSummary(
5253
? moment.utc().to(timestamp)
5354
: timestampWithTz.format(timeAndDate.getDateFormat("date"));
5455

55-
const icon = getCaseIcon(pluginData, theCase.type);
56+
const icon = getCaseIcon(pluginData, theCase.type as CaseTypes);
5657

5758
let caseTitle = `\`#${theCase.case_number}\``;
5859
if (withLinks && theCase.log_message_id) {

backend/src/plugins/ContextMenus/types.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@ export interface ContextMenuPluginType extends BasePluginType {
1515
};
1616
}
1717

18-
export const enum ModMenuActionType {
19-
PAGE = "page",
20-
NOTE = "note",
21-
WARN = "warn",
22-
CLEAN = "clean",
23-
MUTE = "mute",
24-
BAN = "ban",
25-
}
18+
export const ModMenuActionType = {
19+
PAGE: "page",
20+
NOTE: "note",
21+
WARN: "warn",
22+
CLEAN: "clean",
23+
MUTE: "mute",
24+
BAN: "ban",
25+
} as const;
2626

27-
export const enum ModMenuNavigationType {
28-
FIRST = "first",
29-
PREV = "prev",
30-
NEXT = "next",
31-
LAST = "last",
32-
INFO = "info",
33-
CASES = "cases",
34-
}
27+
export type ModMenuActionType = typeof ModMenuActionType[keyof typeof ModMenuActionType];
28+
29+
export const ModMenuNavigationType = {
30+
FIRST: "first",
31+
PREV: "prev",
32+
NEXT: "next",
33+
LAST: "last",
34+
INFO: "info",
35+
CASES: "cases",
36+
} as const;
37+
38+
export type ModMenuNavigationType = typeof ModMenuNavigationType[keyof typeof ModMenuNavigationType];
3539

3640
export interface ModMenuActionOpts {
3741
action: ModMenuActionType;

backend/src/plugins/ModActions/commands/massunban/actualMassUnbanCmd.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export async function actualMassUnbanCmd(
112112
}
113113
}
114114

115-
enum UnbanFailReasons {
116-
NOT_BANNED = "Not banned",
117-
UNBAN_FAILED = "Unban failed",
118-
}
115+
const UnbanFailReasons = {
116+
NOT_BANNED: "Not banned",
117+
UNBAN_FAILED: "Unban failed",
118+
} as const;
119+
120+
type UnbanFailReasons = typeof UnbanFailReasons[keyof typeof UnbanFailReasons];

backend/src/plugins/ModActions/types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ export interface ModActionsPluginType extends BasePluginType {
102102
};
103103
}
104104

105-
export enum IgnoredEventType {
106-
Ban = 1,
107-
Unban,
108-
Kick,
109-
}
105+
export const IgnoredEventType = {
106+
Ban: 1,
107+
Unban: 2,
108+
Kick: 3,
109+
} as const;
110+
111+
export type IgnoredEventType = typeof IgnoredEventType[keyof typeof IgnoredEventType];
110112

111113
export interface IIgnoredEvent {
112114
type: IgnoredEventType;

0 commit comments

Comments
 (0)