generated from nhcarrigan/template
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @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 channel.send({
|
||||
content: `Hey <@${member.id}>~!
|
||||
|
||||
Welcome to our community! It looks like you may have applied for our mentorship programme!
|
||||
|
||||
If that is correct, you should ping Naomi to grant your role and begin onboarding! <a:love:1364089736557494353>`,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user