generated from nhcarrigan/template
3f89b7eb4f
- Replace `ephemeral: true` with `flags: [ MessageFlags.Ephemeral ]` in all command files - Add try/catch with logger.error to logMenteeJoin, checkAchievements, processMentorshipRole - Extract handleIssueOpened and handlePrOpened helpers in processGitHubEvent to reduce complexity - Add logger.error calls in all newly introduced catch blocks
51 lines
1.6 KiB
TypeScript
51 lines
1.6 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> => {
|
|
try {
|
|
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 });
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
await logger.error("logMenteeJoin module", error);
|
|
}
|
|
}
|
|
};
|