You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.5 KiB
68 lines
2.5 KiB
import dotenv from 'dotenv';
|
|
import { SlashCreator, FastifyServer } from 'slash-create';
|
|
import path from 'path';
|
|
import { fastify } from 'fastify';
|
|
import { HealCharacterCommand } from './commands/heal.js';
|
|
import { HarmCharacterCommand } from './commands/harm.js';
|
|
import { ExperienceCharacterCommand } from './commands/experience.js';
|
|
import { LuckCharacterCommand } from './commands/luck.js';
|
|
import { CharacterStatusCommand } from './commands/status.js';
|
|
import { PartyCommand } from './commands/party.js';
|
|
|
|
let dotenvPath = path.join(process.cwd(), '.env');
|
|
if (path.parse(process.cwd()).name === 'dist') dotenvPath = path.join(process.cwd(), '..', '.env');
|
|
|
|
dotenv.config({ path: dotenvPath });
|
|
|
|
const creator = new SlashCreator({
|
|
applicationID: process.env.DISCORD_APP_ID!,
|
|
publicKey: process.env.DISCORD_PUBLIC_KEY!,
|
|
token: process.env.DISCORD_BOT_TOKEN!,
|
|
serverPort: parseInt(process.env.PORT ?? '0', 10) || 8020,
|
|
serverHost: process.env.HOST ?? '0.0.0.0',
|
|
endpointPath: '/interactions'
|
|
});
|
|
|
|
creator.on('debug', (message) => console.log(message));
|
|
creator.on('warn', (message) => console.warn(message));
|
|
creator.on('error', (error) => console.error(error));
|
|
creator.on('synced', () => console.info('Commands synced!'));
|
|
creator.on('commandRun', (command, _, ctx) =>
|
|
console.info(`${ctx.user.username}#${ctx.user.discriminator} (${ctx.user.id}) ran command ${command.commandName}`)
|
|
);
|
|
creator.on('commandRegister', (command) => console.info(`Registered command ${command.commandName}`));
|
|
creator.on('commandError', (command, error) => console.error(`Command ${command.commandName}:`, error));
|
|
|
|
const server = fastify({
|
|
logger: true
|
|
});
|
|
|
|
const options = {
|
|
dataDir: process.env.DATA_DIR ?? '../data'
|
|
};
|
|
|
|
creator
|
|
.withServer(new FastifyServer(server))
|
|
.registerCommands([
|
|
new HealCharacterCommand(creator, options),
|
|
new HarmCharacterCommand(creator, options),
|
|
new ExperienceCharacterCommand(creator, options),
|
|
new LuckCharacterCommand(creator, options),
|
|
new CharacterStatusCommand(creator, options),
|
|
new PartyCommand(creator, options)
|
|
]);
|
|
creator
|
|
.startServer()
|
|
.then(() => {
|
|
console.info('startServer completed');
|
|
if (process.env.DEVELOPMENT_GUILD_ID) {
|
|
creator.syncCommandsIn(process.env.DEVELOPMENT_GUILD_ID).then(() => {
|
|
console.info('synchronized commands');
|
|
});
|
|
}
|
|
})
|
|
.catch((err: unknown) => {
|
|
console.error(err);
|
|
});
|
|
|
|
console.info(`Starting server at "localhost:${creator.options.serverPort}/interactions"`);
|
|
|