Skip to content

Commit f607ad4

Browse files
committed
refactor: remove Timeout imports and constructor syntax sugar
1 parent 62da0a6 commit f607ad4

20 files changed

Lines changed: 32 additions & 42 deletions

backend/src/RegExpRunner.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import { CooldownManager } from "knub";
22
import { EventEmitter } from "node:events";
33
import { RegExpWorker, TimeoutError } from "regexp-worker";
44
import { MINUTES, SECONDS } from "./utils.js";
5-
import Timeout = NodeJS.Timeout;
65

76
const isTimeoutError = (a): a is TimeoutError => {
87
return a.message != null && a.elapsedTimeMs != null;
98
};
109

1110
export class RegExpTimeoutError extends Error {
12-
constructor(message: string, public elapsedTimeMs: number) {
11+
public elapsedTimeMs: number;
12+
13+
constructor(message: string, elapsedTimeMs: number) {
1314
super(message);
15+
16+
this.elapsedTimeMs = elapsedTimeMs;
1417
}
1518
}
1619

@@ -47,7 +50,7 @@ export interface RegExpRunner {
4750
*/
4851
export class RegExpRunner extends EventEmitter {
4952
private _worker: RegExpWorker | null;
50-
private readonly _failedTimesInterval: Timeout;
53+
private readonly _failedTimesInterval: NodeJS.Timeout;
5154

5255
private cooldown: CooldownManager;
5356
private failedTimes: Map<string, number>;

backend/src/SimpleCache.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import Timeout = NodeJS.Timeout;
2-
31
const CLEAN_INTERVAL = 1000;
42

53
export class SimpleCache<T = any> {
64
protected readonly retentionTime: number;
75
protected readonly maxItems: number;
86

9-
protected cleanTimeout: Timeout;
7+
protected cleanTimeout: NodeJS.Timeout;
108
protected unloaded: boolean;
119

1210
protected store: Map<string, { remove_at: number; value: T }>;

backend/src/data/loops/expiringMutesLoop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { lazyMemoize, MINUTES, SECONDS } from "../../utils.js";
55
import { Mute } from "../entities/Mute.js";
66
import { emitGuildEvent, hasGuildEventListener } from "../GuildEvents.js";
77
import { Mutes, TIMEOUT_RENEWAL_THRESHOLD } from "../Mutes.js";
8-
import Timeout = NodeJS.Timeout;
98

109
const LOOP_INTERVAL = 15 * MINUTES;
1110
const MAX_TRIES_PER_SERVER = 3;
1211
const getMutesRepository = lazyMemoize(() => new Mutes());
13-
const timeouts = new Map<string, Timeout>();
12+
const timeouts = new Map<string, NodeJS.Timeout>();
1413

1514
function muteToKey(mute: Mute) {
1615
return `${mute.guild_id}/${mute.user_id}`;

backend/src/data/loops/expiringTempbansLoop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { lazyMemoize, MINUTES } from "../../utils.js";
55
import { Tempban } from "../entities/Tempban.js";
66
import { emitGuildEvent, hasGuildEventListener } from "../GuildEvents.js";
77
import { Tempbans } from "../Tempbans.js";
8-
import Timeout = NodeJS.Timeout;
98

109
const LOOP_INTERVAL = 15 * MINUTES;
1110
const MAX_TRIES_PER_SERVER = 3;
1211
const getBansRepository = lazyMemoize(() => new Tempbans());
13-
const timeouts = new Map<string, Timeout>();
12+
const timeouts = new Map<string, NodeJS.Timeout>();
1413

1514
function tempbanToKey(tempban: Tempban) {
1615
return `${tempban.guild_id}/${tempban.user_id}`;

backend/src/data/loops/expiringVCAlertsLoop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { lazyMemoize, MINUTES } from "../../utils.js";
55
import { VCAlert } from "../entities/VCAlert.js";
66
import { emitGuildEvent, hasGuildEventListener } from "../GuildEvents.js";
77
import { VCAlerts } from "../VCAlerts.js";
8-
import Timeout = NodeJS.Timeout;
98

109
const LOOP_INTERVAL = 15 * MINUTES;
1110
const MAX_TRIES_PER_SERVER = 3;
1211
const getVCAlertsRepository = lazyMemoize(() => new VCAlerts());
13-
const timeouts = new Map<number, Timeout>();
12+
const timeouts = new Map<number, NodeJS.Timeout>();
1413

1514
function broadcastExpiredVCAlert(alert: VCAlert, tries = 0) {
1615
console.log(`[EXPIRING VCALERTS LOOP] Broadcasting expired vcalert: ${alert.guild_id}/${alert.user_id}`);

backend/src/data/loops/upcomingRemindersLoop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { lazyMemoize, MINUTES } from "../../utils.js";
55
import { Reminder } from "../entities/Reminder.js";
66
import { emitGuildEvent, hasGuildEventListener } from "../GuildEvents.js";
77
import { Reminders } from "../Reminders.js";
8-
import Timeout = NodeJS.Timeout;
98

109
const LOOP_INTERVAL = 15 * MINUTES;
1110
const MAX_TRIES_PER_SERVER = 3;
1211
const getRemindersRepository = lazyMemoize(() => new Reminders());
13-
const timeouts = new Map<number, Timeout>();
12+
const timeouts = new Map<number, NodeJS.Timeout>();
1413

1514
function broadcastReminder(reminder: Reminder, tries = 0) {
1615
if (!hasGuildEventListener(reminder.guild_id, "reminder")) {

backend/src/data/loops/upcomingScheduledPostsLoop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { lazyMemoize, MINUTES } from "../../utils.js";
55
import { ScheduledPost } from "../entities/ScheduledPost.js";
66
import { emitGuildEvent, hasGuildEventListener } from "../GuildEvents.js";
77
import { ScheduledPosts } from "../ScheduledPosts.js";
8-
import Timeout = NodeJS.Timeout;
98

109
const LOOP_INTERVAL = 15 * MINUTES;
1110
const MAX_TRIES_PER_SERVER = 3;
1211
const getScheduledPostsRepository = lazyMemoize(() => new ScheduledPosts());
13-
const timeouts = new Map<number, Timeout>();
12+
const timeouts = new Map<number, NodeJS.Timeout>();
1413

1514
function broadcastScheduledPost(post: ScheduledPost, tries = 0) {
1615
if (!hasGuildEventListener(post.guild_id, "scheduledPost")) {

backend/src/plugins/AutoDelete/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { GuildLogs } from "../../data/GuildLogs.js";
44
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
55
import { SavedMessage } from "../../data/entities/SavedMessage.js";
66
import { MINUTES, zDelayString } from "../../utils.js";
7-
import Timeout = NodeJS.Timeout;
87

98
export const MAX_DELAY = 5 * MINUTES;
109

@@ -26,7 +25,7 @@ export interface AutoDeletePluginType extends BasePluginType {
2625

2726
deletionQueue: IDeletionQueueItem[];
2827
nextDeletion: number | null;
29-
nextDeletionTimeout: Timeout | null;
28+
nextDeletionTimeout: NodeJS.Timeout | null;
3029

3130
maxDelayWarningSent: boolean;
3231

backend/src/plugins/Automod/actions/changePerms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const ChangePermsAction = automodAction({
175175
const realKey = legacyPermMap[key] ?? key;
176176
perms[realKey] = actionConfig.perms[key];
177177
}
178-
const permsArray = <PermissionsString[]>Object.keys(perms).filter((key) => perms[key]);
178+
const permsArray = (Object.keys(perms) as PermissionsString[]).filter((key) => perms[key]);
179179
await role.setPermissions(new PermissionsBitField(permsArray)).catch(noop);
180180
},
181181
});

backend/src/plugins/Automod/types.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import { availableActions } from "./actions/availableActions.js";
1717
import { RecentActionType } from "./constants.js";
1818
import { availableTriggers } from "./triggers/availableTriggers.js";
1919

20-
import Timeout = NodeJS.Timeout;
21-
2220
export type ZTriggersMapHelper = {
2321
[TriggerName in keyof typeof availableTriggers]: (typeof availableTriggers)[TriggerName]["configSchema"];
2422
};
@@ -86,7 +84,7 @@ export interface AutomodPluginType extends BasePluginType {
8684
* Recent actions are used for spam triggers
8785
*/
8886
recentActions: RecentAction[];
89-
clearRecentActionsInterval: Timeout;
87+
clearRecentActionsInterval: NodeJS.Timeout;
9088

9189
/**
9290
* After a spam trigger is tripped and the rule's action carried out, a unique identifier is placed here so further
@@ -95,10 +93,10 @@ export interface AutomodPluginType extends BasePluginType {
9593
* Key: rule_name-match_identifier
9694
*/
9795
recentSpam: RecentSpam[];
98-
clearRecentSpamInterval: Timeout;
96+
clearRecentSpamInterval: NodeJS.Timeout;
9997

10098
recentNicknameChanges: Map<string, { timestamp: number }>;
101-
clearRecentNicknameChangesInterval: Timeout;
99+
clearRecentNicknameChangesInterval: NodeJS.Timeout;
102100

103101
ignoredRoleChanges: Set<{
104102
memberId: string;

0 commit comments

Comments
 (0)