Naomi Carrigan dac4c6f008 feat: re-merge (#2)
Reviewed-on: https://codeberg.org/nhcarrigan/tingle-bot/pulls/2
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
2024-12-21 00:11:48 +00:00

51 lines
1.5 KiB
TypeScript

/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { REST, Routes, type Client, WebhookClient } from "discord.js";
import { commandList } from "../../commands/_commandList.js";
import { loadChannels } from "../../modules/loadChannels.js";
import { scheduleForecasts } from "../../modules/scheduleForecasts.js";
import { logHandler } from "../../utils/logHandler.js";
import type { WeatherCache } from "../../interfaces/weatherCache.js";
/**
* Handler for the READY event from Discord. Logs that the bot is connected,
* then registers the guild slash commands.
* @param bot - The bot's Discord instance.
* @param cache - The cache of weather data.
*/
export const onReady = async(
bot: Client,
cache: WeatherCache,
): Promise<void> => {
const webhook = new WebhookClient({ url: process.env.DEBUG_HOOK as string });
await webhook.send("Ruu Bot is online!");
logHandler.log("info", "Connected to Discord!");
const rest = new REST({ version: "10" }).setToken(
process.env.DISCORD_TOKEN ?? "",
);
const commandData = commandList.map((command) => {
return command.data.toJSON();
});
await rest.put(
Routes.applicationGuildCommands(
bot.user?.id ?? "oopsie whoopsie",
process.env.HOME_GUILD_ID ?? "",
),
{ body: commandData },
);
await webhook.send("Registered commands!");
cache.channels = await loadChannels(bot);
await webhook.send("Loaded channels!");
scheduleForecasts(cache);
};