generated from didinele/typescript-docker-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@chatsift/automoderator-interactions", | ||
"main": "./dist/index.js", | ||
"private": true, | ||
"version": "1.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"lint": "eslint src", | ||
"build": "tsc" | ||
}, | ||
"engines": { | ||
"node": ">=16.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.10", | ||
"pino": "^9.2.0", | ||
"typescript": "^5.4.5" | ||
}, | ||
"dependencies": { | ||
"@automoderator/core": "workspace:^", | ||
"@chatsift/readdir": "^0.5.0", | ||
"@discordjs/brokers": "^0.3.0", | ||
"@discordjs/core": "^1.2.0", | ||
"@discordjs/rest": "^2.3.0", | ||
"@discordjs/ws": "^1.1.1", | ||
"coral-command": "^0.4.1", | ||
"inversify": "^6.0.2", | ||
"ioredis": "5.3.2", | ||
"reflect-metadata": "^0.2.2", | ||
"tslib": "^2.6.3", | ||
"undici": "^6.19.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'reflect-metadata'; | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { | ||
type ICommandHandler, | ||
CoralCommandHandler, | ||
globalContainer, | ||
DependencyManager, | ||
setupCrashLogs, | ||
encode, | ||
decode, | ||
type DiscordGatewayEventsMap, | ||
USEFUL_HANDLERS_PATH, | ||
type HandlerModuleConstructor, | ||
type HandlerModule, | ||
} from '@automoderator/core'; | ||
import { readdirRecurseManyAsync } from '@chatsift/readdir'; | ||
import { PubSubRedisBroker } from '@discordjs/brokers'; | ||
import { GatewayDispatchEvents } from '@discordjs/core'; | ||
import type { InteractionHandler as CoralInteractionHandler } from 'coral-command'; | ||
|
||
const dependencyManager = globalContainer.get(DependencyManager); | ||
const logger = dependencyManager.registerLogger('interactions'); | ||
const redis = dependencyManager.registerRedis(); | ||
dependencyManager.registerApi(); | ||
|
||
setupCrashLogs(); | ||
|
||
const commandHandler = globalContainer.get<ICommandHandler<CoralInteractionHandler>>(CoralCommandHandler); | ||
|
||
export const serviceHandlersPath = join(dirname(fileURLToPath(import.meta.url)), 'handlers'); | ||
|
||
for (const path of await readdirRecurseManyAsync([serviceHandlersPath, USEFUL_HANDLERS_PATH])) { | ||
const moduleConstructor: HandlerModuleConstructor<CoralInteractionHandler> = await import(path); | ||
const module = globalContainer.get<HandlerModule<CoralInteractionHandler>>(moduleConstructor); | ||
|
||
module.register(commandHandler); | ||
logger.info(`Loaded handler/module ${module.constructor.name}`); | ||
} | ||
|
||
const broker = new PubSubRedisBroker<DiscordGatewayEventsMap>({ | ||
redisClient: redis, | ||
encode, | ||
decode, | ||
}); | ||
|
||
broker.on(GatewayDispatchEvents.InteractionCreate, async ({ data: interaction, ack }) => { | ||
await commandHandler.handle(interaction); | ||
await ack(); | ||
}); | ||
|
||
await broker.subscribe('interactions', [GatewayDispatchEvents.InteractionCreate]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
"**/*.js", | ||
"**/*.cjs", | ||
"**/*.jsx", | ||
"**/*.test.ts", | ||
"**/*.test.js", | ||
"**/*.spec.ts", | ||
"**/*.spec.js" | ||
], | ||
"exclude": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
}, | ||
"include": ["./src/**/*.ts"], | ||
"exclude": ["./**/__tests__"] | ||
} |