Files
amari/src/index.ts
T

56 lines
1.5 KiB
TypeScript

/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Client, GatewayIntentBits, Events, Partials } from "discord.js";
import { scheduleJob } from "node-schedule";
import { handleMessageCreate } from "./events/handleMessageCreate.js";
import {
postFreeCodeCampNews,
} from "./modules/postNews.js";
import { respondToDm } from "./modules/respondToDm.js";
import { instantiateServer } from "./server/serve.js";
import { logger } from "./utils/logger.js";
import type { Amari } from "./interfaces/amari.js";
const amari: Amari = {
discord: new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.DirectMessages,
],
partials: [ Partials.Channel ] }),
lastRssItems: {
freeCodeCamp: null,
},
};
amari.discord.once(Events.ClientReady, () => {
void logger.log("debug",
`Authenticated to Discord as ${amari.discord.user?.username ?? "unknown"}`);
scheduleJob("post news", "0 * * * *", async() => {
await postFreeCodeCampNews(amari);
});
});
amari.discord.on(Events.MessageCreate, (message) => {
if (!message.inGuild()) {
void respondToDm(amari, message);
return;
}
void handleMessageCreate(amari, message);
});
amari.discord.on(Events.InteractionCreate, (interaction) => {
if (interaction.isButton() && interaction.customId === "resolve") {
void interaction.message.delete();
}
});
await amari.discord.login(process.env.BOT_TOKEN);
instantiateServer();