Skip to content

Commit a21d851

Browse files
committed
eventWrapper -> eventDispatcher, make more self-contained
1 parent 4b01c4e commit a21d851

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

backend/src/plugins/core/eventWrapper.ts renamed to backend/src/plugins/core/eventDispatcher.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
import type { Awaitable } from "#common/general.ts";
22
import { moduleLogger } from "#common/logger/index.ts";
3+
import { onBotInit } from "#discord/extensionPoints.ts";
34
import type { SquirrelDiscordContext } from "#discord/index.ts";
5+
import { EventListenerPhase } from "#extensionPoint.ts";
46
import { isGuildAllowed } from "#plugins/core/guildInfoSync.ts";
7+
import { onBotEvent } from "#plugins/core/public/extensionPoints.ts";
58
import type { ClientEvents } from "oceanic.js";
69

710
const logger = moduleLogger();
811

12+
export default [onBotInit(installListeners, EventListenerPhase.Post)];
13+
14+
function installListeners(ctx: SquirrelDiscordContext): void {
15+
logger.debug?.("Installing onBotEvent listeners");
16+
17+
for (const listener of onBotEvent.contributions) {
18+
installWrappedListener(
19+
ctx,
20+
listener.type,
21+
listener.listener.bind(listener),
22+
);
23+
}
24+
}
25+
926
export function wrapListener<E extends keyof ClientEvents>(
1027
ctx: SquirrelDiscordContext,
1128
event: E,

backend/src/plugins/core/index.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { moduleLogger } from "#common/logger/index.ts";
2-
import { onBotInit } from "#discord/extensionPoints.ts";
3-
import type { SquirrelDiscordContext } from "#discord/index.ts";
4-
import { EventListenerPhase } from "#extensionPoint.ts";
52
import { definePlugin } from "#plugin.ts";
63
import commandCache from "#plugins/core/commandEngine/commandCache.ts";
74
import autoCompleteHandler from "#plugins/core/commandEngine/handler/autocompleteHandler.ts";
@@ -14,15 +11,12 @@ import groups from "#plugins/core/commands/groups.ts";
1411
import help from "#plugins/core/commands/help/index.ts";
1512
import { CoreConfig } from "#plugins/core/config.ts";
1613
import configSync from "#plugins/core/configSync.ts";
17-
import { installWrappedListener } from "#plugins/core/eventWrapper.ts";
14+
import eventDispatcher from "#plugins/core/eventDispatcher.ts";
1815
import guildInfoSync from "#plugins/core/guildInfoSync.ts";
1916
import configRoutes from "#plugins/core/http/configRoutes.ts";
2017
import iconSync from "#plugins/core/iconSync.ts";
2118
import { ConfigStore } from "#plugins/core/public/configStore.ts";
22-
import {
23-
defineConfig,
24-
onBotEvent,
25-
} from "#plugins/core/public/extensionPoints.ts";
19+
import { defineConfig } from "#plugins/core/public/extensionPoints.ts";
2620

2721
const logger = moduleLogger();
2822

@@ -58,14 +52,13 @@ export default definePlugin({
5852
...configSync,
5953
...iconSync,
6054

55+
...eventDispatcher,
6156
...commandCache,
6257
...prefixHandler,
6358
...slashHandler,
6459
...autoCompleteHandler,
6560
...componentHandler,
6661

67-
onBotInit(postInit, EventListenerPhase.Post),
68-
6962
help,
7063
about,
7164
...access,
@@ -74,15 +67,3 @@ export default definePlugin({
7467
configRoutes,
7568
],
7669
});
77-
78-
function postInit(ctx: SquirrelDiscordContext): void {
79-
logger.debug?.("Installing onBotEvent listeners");
80-
81-
for (const listener of onBotEvent.contributions) {
82-
installWrappedListener(
83-
ctx,
84-
listener.type,
85-
listener.listener.bind(listener),
86-
);
87-
}
88-
}

0 commit comments

Comments
 (0)