Skip to content

Commit 53eccd3

Browse files
committed
Create constants files to make them easier to find (and fix an error)
1 parent 9cf2abd commit 53eccd3

11 files changed

Lines changed: 42 additions & 29 deletions

File tree

backend/src/plugin/core/commandEngine/handler/componentHandler.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { moduleLogger } from "#common/logger/index.ts";
22
import { TTLMap } from "#common/ttlMap.ts";
33
import type { SquirrelDiscordContext } from "#discord/index.ts";
44
import {
5-
AUTO_DEFER_AFTER,
6-
STATE_CLEANUP_INTERVAL,
7-
STATE_EXPIRE_AFTER,
8-
} from "#plugin/core/commandEngine/index.ts";
5+
COMMAND_AUTO_DEFER_AFTER,
6+
COMMAND_STATE_CLEANUP_INTERVAL,
7+
COMMAND_STATE_EXPIRE_AFTER,
8+
} from "#plugin/core/constants.ts";
99
import { transformReply } from "#plugin/core/helper/commands.ts";
1010
import type {
1111
ComponentContext,
@@ -35,9 +35,12 @@ interface ComponentHandler {
3535
const logger = moduleLogger();
3636

3737
const activeHandlers: TTLMap<string, ComponentHandler> = new TTLMap(
38-
STATE_EXPIRE_AFTER,
38+
COMMAND_STATE_EXPIRE_AFTER,
3939
);
40-
setInterval(() => activeHandlers.cleanup(), STATE_CLEANUP_INTERVAL).unref();
40+
setInterval(
41+
() => activeHandlers.cleanup(),
42+
COMMAND_STATE_CLEANUP_INTERVAL,
43+
).unref();
4144

4245
export default [onBotEvent({ type: "interactionCreate", listener: handle })];
4346

@@ -158,7 +161,7 @@ class ComponentContextImpl implements ComponentContext {
158161
},
159162
Math.max(
160163
0,
161-
AUTO_DEFER_AFTER -
164+
COMMAND_AUTO_DEFER_AFTER -
162165
(Date.now() - interaction.createdAt.getTime()),
163166
),
164167
).unref();

backend/src/plugin/core/commandEngine/handler/prefixHandler.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {
99
listenForInteractions,
1010
unlistenForInteractions,
1111
} from "#plugin/core/commandEngine/handler/componentHandler.ts";
12-
import {
13-
STATE_CLEANUP_INTERVAL,
14-
STATE_EXPIRE_AFTER,
15-
} from "#plugin/core/commandEngine/index.ts";
1612
import { formatArgsParseError } from "#plugin/core/commandEngine/parsing/index.ts";
1713
import {
1814
readPrefixArgs,
1915
readPrefixName,
2016
} from "#plugin/core/commandEngine/parsing/prefixParser.ts";
2117
import { StringReader } from "#plugin/core/commandEngine/parsing/stringReader.ts";
18+
import {
19+
COMMAND_STATE_CLEANUP_INTERVAL,
20+
COMMAND_STATE_EXPIRE_AFTER,
21+
} from "#plugin/core/constants.ts";
2222
import { transformReply } from "#plugin/core/helper/commands.ts";
2323
import { coreConfigStore } from "#plugin/core/index.ts";
2424
import type {
@@ -57,8 +57,13 @@ export default [
5757
// if anything is added here, make sure the message type can be replied to
5858
const ALLOWED_MESSAGE_TYPES = [MessageTypes.DEFAULT, MessageTypes.REPLY];
5959

60-
const trackedMessages: TTLMap<string, Message> = new TTLMap(STATE_EXPIRE_AFTER);
61-
setInterval(() => trackedMessages.cleanup(), STATE_CLEANUP_INTERVAL).unref();
60+
const trackedMessages: TTLMap<string, Message> = new TTLMap(
61+
COMMAND_STATE_EXPIRE_AFTER,
62+
);
63+
setInterval(
64+
() => trackedMessages.cleanup(),
65+
COMMAND_STATE_CLEANUP_INTERVAL,
66+
).unref();
6267

6368
async function handle(
6469
squirrelCtx: SquirrelDiscordContext,

backend/src/plugin/core/commandEngine/handler/slashHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import {
1313
listenForInteractions,
1414
unlistenForInteractions,
1515
} from "#plugin/core/commandEngine/handler/componentHandler.ts";
16-
import { AUTO_DEFER_AFTER } from "#plugin/core/commandEngine/index.ts";
1716
import { formatArgsParseError } from "#plugin/core/commandEngine/parsing/index.ts";
1817
import { readSlashArgs } from "#plugin/core/commandEngine/parsing/slashParser.ts";
18+
import { COMMAND_AUTO_DEFER_AFTER } from "#plugin/core/constants.ts";
1919
import { safePreRun, transformReply } from "#plugin/core/helper/commands.ts";
2020
import { coreConfigStore } from "#plugin/core/index.ts";
2121
import {
@@ -333,7 +333,7 @@ class SlashContext implements CommandContext {
333333
},
334334
Math.max(
335335
0,
336-
AUTO_DEFER_AFTER -
336+
COMMAND_AUTO_DEFER_AFTER -
337337
(Date.now() - interaction.createdAt.getTime()),
338338
),
339339
).unref();
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* How long to expire command state (edit tracking + component listening)
33
*/
4-
export const STATE_EXPIRE_AFTER = 1000 * 60 * 30;
5-
export const STATE_CLEANUP_INTERVAL = 1000 * 60;
4+
export const COMMAND_STATE_EXPIRE_AFTER = 1000 * 60 * 30;
5+
export const COMMAND_STATE_CLEANUP_INTERVAL = 1000 * 60;
66
/**
77
* Interactions are deferred if the command is taking some time to finish rather than relying on the author of the command to remember to defer it manually
88
* (this should also improve latency - in the best case only one api call is being sent back to Discord)
99
*/
10-
export const AUTO_DEFER_AFTER = 1000;
10+
export const COMMAND_AUTO_DEFER_AFTER = 1000;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { HOUR, MINUTE } from "#common/time.ts";
2+
3+
export const MESSAGE_CLEANUP_INTERVAL = 30 * MINUTE;
4+
export const MESSAGE_CLEANUP_THRESHOLD = 6 * HOUR;

backend/src/plugin/logging/logger/messages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { getDefaultAvatarURL } from "#common/discord/urls.ts";
22
import { moduleLogger } from "#common/logger/index.ts";
33
import { makeMemberUserView, makeUserView } from "#common/template/user.ts";
4-
import { HOUR, MINUTE } from "#common/time.ts";
54
import { onBotInit } from "#discord/extensionPoints.ts";
65
import type { SquirrelDiscordContext } from "#discord/index.ts";
76
import { onBotEvent } from "#plugin/core/public/extensionPoints.ts";
7+
import {
8+
MESSAGE_CLEANUP_INTERVAL,
9+
MESSAGE_CLEANUP_THRESHOLD,
10+
} from "#plugin/logging/constants.ts";
811
import { logEvent } from "#plugin/logging/helper/logging.ts";
912
import { loggingConfigStore } from "#plugin/logging/index.ts";
1013
import {
@@ -17,9 +20,6 @@ import { Message, Routes, type PossiblyUncachedMessage } from "oceanic.js";
1720

1821
const logger = moduleLogger();
1922

20-
const MESSAGE_CLEANUP_INTERVAL = 30 * MINUTE;
21-
const MESSAGE_CLEANUP_THRESHOLD = 6 * HOUR;
22-
2323
export default [
2424
onBotInit(beginMessageCleanupLoop),
2525
onBotEvent({ type: "messageCreate", listener: handleCreate }),

backend/src/plugin/tags/command/tag.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { OptionType } from "#plugin/core/public/command.ts";
33
import { defineCommand } from "#plugin/core/public/extensionPoints.ts";
44
import { permissionsGuard } from "#plugin/core/public/helper/commandGuards.ts";
55
import { icons } from "#plugin/core/public/icons.ts";
6-
import { MAX_TAG_NAME_LENGTH, tagsConfigStore } from "#plugin/tags/index.ts";
6+
import { MAX_TAG_NAME_LENGTH } from "#plugin/tags/constants.ts";
7+
import { tagsConfigStore } from "#plugin/tags/index.ts";
78
import { getTag, searchTags } from "#plugin/tags/storage/tags.ts";
89

910
export default defineCommand({

backend/src/plugin/tags/command/tagDelete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { OptionType } from "#plugin/core/public/command.ts";
33
import { defineCommand } from "#plugin/core/public/extensionPoints.ts";
44
import { permissionsGuard } from "#plugin/core/public/helper/commandGuards.ts";
55
import { icons } from "#plugin/core/public/icons.ts";
6-
import { MAX_TAG_NAME_LENGTH, tagsConfigStore } from "#plugin/tags/index.ts";
6+
import { MAX_TAG_NAME_LENGTH } from "#plugin/tags/constants.ts";
7+
import { tagsConfigStore } from "#plugin/tags/index.ts";
78
import { deleteTag, searchTags } from "#plugin/tags/storage/tags.ts";
89

910
export default defineCommand({

backend/src/plugin/tags/command/tagSet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { icons } from "#plugin/core/public/icons.ts";
66
import {
77
MAX_TAG_CONTENT_LENGTH,
88
MAX_TAG_NAME_LENGTH,
9-
tagsConfigStore,
10-
} from "#plugin/tags/index.ts";
9+
} from "#plugin/tags/constants.ts";
10+
import { tagsConfigStore } from "#plugin/tags/index.ts";
1111
import {
1212
createTag,
1313
searchTags,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const MAX_TAG_NAME_LENGTH = 30;
2+
export const MAX_TAG_CONTENT_LENGTH = 4000;

0 commit comments

Comments
 (0)