/**
 * @copyright nhcarrigan
 * @license Naomi's Public License
 * @author Naomi Carrigan
 */
import { Client } from "discord.js";
import { intentOptions } from "./config/intentOptions.js";
import { handleEvents } from "./events/handleEvents.js";
import { getWeatherForecast } from "./modules/getWeatherForecast.js";
import { loadChannels } from "./modules/loadChannels.js";
import { errorHandler } from "./utils/errorHandler.js";
import type { WeatherCache } from "./interfaces/weatherCache.js";

const bot = new Client({ intents: intentOptions });

const cache: WeatherCache = {
  Inariko:  getWeatherForecast("Inariko"),
  Rudania:  getWeatherForecast("Rudania"),
  Vhintl:   getWeatherForecast("Vhintl"),
  channels: await loadChannels(bot),
};

handleEvents(bot, cache);

await bot.login(process.env.DISCORD_TOKEN ?? "").catch(async(error: unknown) => {
  return await errorHandler(error, "login");
});
