72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
|
|
import updateDiscordMessage from './tasks/update_discord_message.js'
|
|
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'
|
|
|
|
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')
|
|
},
|
|
};
|
|
console.log('worker preset as follows')
|
|
console.log(preset)
|
|
const runnerOptions: RunnerOptions = {
|
|
preset
|
|
// concurrency: 3,
|
|
// connectionString: configs.connectionString,
|
|
// taskDirectory: join(__dirname, 'tasks'),
|
|
// taskList: {
|
|
// 'update_discord_message': updateDiscordMessage
|
|
// }
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error("error during main() function")
|
|
console.error(e)
|
|
process.exit(3)
|
|
})
|