fp/services/bot/src/index.ts
CJ_Clippy fdd295e2b8
Some checks failed
ci / build (push) Failing after 0s
change scout to a service
2024-08-26 23:11:24 -08:00

66 lines
1.6 KiB
TypeScript

import { type WorkerUtils, type RunnerOptions, run } from 'graphile-worker'
import { bot } from './bot.ts'
import type { Interaction } from '@discordeno/bot'
import { importDirectory } from './utils/loader.ts'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'url'
import { configs } from './config.ts'
import { updateApplicationCommands } from './utils/update-commands.ts'
const __dirname = dirname(fileURLToPath(import.meta.url));
export interface ExecuteArguments {
interaction: Interaction;
workerUtils: WorkerUtils;
}
async function setupGraphileWorker() {
const preset: GraphileConfig.Preset = {
worker: {
connectionString: configs.connectionString,
concurrentJobs: 3,
fileExtensions: [".js", ".ts"],
taskDirectory: join(__dirname, 'tasks')
},
};
const runnerOptions: RunnerOptions = {
preset
}
const runner = await run(runnerOptions)
if (!runner) throw new Error('failed to initialize graphile worker');
await runner.promise
}
async function setupBot() {
bot.logger.info('Starting @futureporn/bot.')
bot.logger.info('Loading commands...')
await importDirectory(join(__dirname, './commands'))
bot.logger.info('Loading events...')
await importDirectory(join(__dirname, './events'))
await bot.start()
}
async function main() {
await setupBot()
await setupGraphileWorker()
await updateApplicationCommands() // this needs to run after importDirectory() has run
}
main().catch((e) => {
console.error("error during main() function")
console.error(e)
process.exit(3)
})