Files
ZitateBot/index.js
T

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-05-01 18:51:04 +02:00
const path = require("path");
const dotenv = require("dotenv");
const { createBotClient, sendQuoteForUser, wireQuoteCommandHandlers } = require("./src/bot");
const { createWebServer } = require("./src/web");
const { loadAppConfig } = require("./src/config");
dotenv.config();
async function main() {
const configPath = process.env.QUOTE_CONFIG_PATH || path.join(__dirname, "config", "quotes.config.json");
const appConfig = loadAppConfig(configPath);
const client = createBotClient();
wireQuoteCommandHandlers(client, appConfig);
client.once("ready", () => {
console.log(`Discord bot connected as ${client.user.tag}`);
});
await client.login(process.env.DISCORD_TOKEN);
const port = Number(process.env.PORT || 3000);
const app = createWebServer({
users: appConfig.users,
allowedSubmitterDiscordIds: appConfig.allowedSubmitterDiscordIds,
onQuoteSubmit: ({ userId, quoteText, creator, attachmentUrl }) =>
sendQuoteForUser(client, appConfig, userId, quoteText, creator, "website", attachmentUrl),
});
app.listen(port, () => {
console.log(`Web form available at http://localhost:${port}`);
});
}
main().catch((error) => {
console.error("Failed to start application:", error);
process.exit(1);
});