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.
 
 
 
motw-tracker/src/index.ts

51 lines
2.2 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 {AbstractCharacterStatusCommand} from "./commands/base.js";
import {CharacterStatusCommand} from "./commands/status.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: '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,
})
creator.withServer(new FastifyServer(server)).registerCommands([HealCharacterCommand, HarmCharacterCommand, ExperienceCharacterCommand, LuckCharacterCommand, CharacterStatusCommand]).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) => {
console.error(err)
});
console.info(`Starting server at "localhost:${creator.options.serverPort}/interactions"`);