confoss/src/main.ts

53 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-10-12 13:00:37 -04:00
/*
* Confoss: Anonymous confessions for Discord, free as in freedom and price!
* Copyright (C) 2024 powermaker450
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2024-10-12 18:51:09 -04:00
*/
2024-10-12 13:00:37 -04:00
import { BotClient, BOT_TOKEN, deployCommands } from "./bot";
import { commands } from "./commands";
import { StoreMan } from "./storeman";
import Logger from "./utils/Logger";
export const dt = new StoreMan(StoreMan.checkFile());
const logger = new Logger("Main");
2024-10-13 11:06:08 -04:00
BotClient.once("ready", client => {
2024-10-12 13:00:37 -04:00
logger.log(`We're ready! Logged in as ${client.user.tag}`);
});
2024-10-13 11:06:08 -04:00
BotClient.on("guildCreate", async guild => {
2024-10-12 13:00:37 -04:00
await deployCommands({ guildId: guild.id });
});
2024-10-13 11:06:08 -04:00
BotClient.on("guildDelete", guild => {
2024-10-12 13:00:37 -04:00
logger.log(`${guild.name} didn't want us anymore... :(`);
dt.clearSettings(guild.id);
});
2024-10-13 11:06:08 -04:00
BotClient.on("interactionCreate", async interaction => {
2024-10-12 13:00:37 -04:00
if (!interaction.isCommand()) {
return;
}
const { commandName } = interaction;
if (commands[commandName as keyof typeof commands]) {
commands[commandName as keyof typeof commands].execute(interaction);
}
});
BotClient.login(BOT_TOKEN);