Files
amari/src/modules/logMenteeJoin.ts
T
naomi 9ada4b9cbe
Node.js CI / Lint and Test (push) Successful in 28s
feat: prep for mentorship to be self-assignable
2025-12-03 15:27:41 -08:00

45 lines
1.4 KiB
TypeScript

/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { ids } from "../config/ids.js";
import { logger } from "../utils/logger.js";
import type { Amari } from "../interfaces/amari.js";
import type { MentorshipRow } from "../interfaces/baserow.js";
import type { GuildMember } from "discord.js";
/**
* Run when a guild member joins. If the member has a mentorship application,
* suggest that they let Naomi know to onboard them.
* @param amari - Amari's instance.
* @param member - The member payload from Discord.
*/
export const logMenteeJoin = async(
amari: Amari,
member: GuildMember,
): Promise<void> => {
const request = await fetch(`https://forms.nhcarrigan.com/api/database/rows/table/756/?user_field_names=true&search=${member.id}`, { headers: {
authorization: `Token ${process.env.BASEROW_TOKEN ?? "huh"}`,
} });
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Fetch accepts no generic here.
const response = await request.json() as MentorshipRow;
if (response.count <= 0) {
return;
}
const channel = amari.discord.channels.cache.get(ids.channels.general)
?? await amari.discord.channels.fetch(ids.channels.general);
if (channel?.isSendable() !== true) {
await logger.log(
"warn",
"General channel does not exist or is not sendable.",
);
return;
}
await logger.metric("processed_mentee_join", 1, { user: member.id });
};