diff --git a/src/config/ids.ts b/src/config/ids.ts index d8ca8d5..185cb33 100644 --- a/src/config/ids.ts +++ b/src/config/ids.ts @@ -7,6 +7,7 @@ export const ids = { channels: { formSubmissions: "1410435042898874471", + menteeChat: "1400589073613062204", mentorshipGoalForum: "1400629118110011526", mentorshipProjectForum: "1400616702265266186", naomiDiscussionForum: "1408154690121633917", @@ -17,6 +18,7 @@ export const ids = { nhcarrigan: "1354624415861833870", }, roles: { + mentorship: "1400588705273745550", nhcarrigan: "1355033209037127771", representing: "1407861842847469598", }, diff --git a/src/index.ts b/src/index.ts index f9c95cd..6b87270 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import { postFreeCodeCampNews, postHackerNews, } from "./modules/postNews.js"; +import { processMentorshipRole } from "./modules/processMentorshipRole.js"; import { processUserGuildTag } from "./modules/processUserGuildTag.js"; import { respondToDm } from "./modules/respondToDm.js"; import { instantiateServer } from "./server/serve.js"; @@ -102,5 +103,9 @@ amari.discord.on(Events.UserUpdate, (_oldUser, updatedUser) => { void processUserGuildTag(amari, updatedUser); }); +amari.discord.on(Events.GuildMemberUpdate, (oldMember, updatedMember) => { + void processMentorshipRole(amari, oldMember, updatedMember); +}); + await amari.discord.login(process.env.BOT_TOKEN); instantiateServer(amari); diff --git a/src/modules/processMentorshipRole.ts b/src/modules/processMentorshipRole.ts new file mode 100644 index 0000000..daae341 --- /dev/null +++ b/src/modules/processMentorshipRole.ts @@ -0,0 +1,52 @@ +/** + * @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 { GuildMember, PartialGuildMember } from "discord.js"; + +/** + * Handles the guild member update. If a member has + * been granted the mentorship role, send them an + * onboarding message. + * @param amari - Amari's instance. + * @param oldMember - The cached member record. + * @param updatedMember - The updated member payload from Discord. + */ +export const processMentorshipRole = async( + amari: Amari, + oldMember: GuildMember | PartialGuildMember, + updatedMember: GuildMember, +): Promise => { + if (oldMember.roles.cache.has(ids.roles.mentorship) + || !updatedMember.roles.cache.has(ids.roles.mentorship)) { + return; + } + + const channel = amari.discord.channels.cache.get(ids.channels.menteeChat) + ?? await amari.discord.channels.fetch(ids.channels.menteeChat); + + if (channel?.isSendable() !== true) { + await logger.log( + "warn", + "Mentee Chat channel does not exist or is not sendable.", + ); + return; + } + + await channel.send({ + content: `Hey <@${updatedMember.id}>~! + +Welcome to our mentorship programme! We are excited to have you here and help you grow and reach success. + +To get started, please make sure you have accepted the GitHub invite for your dedicated repository under the [NHCarrigan Mentorship organsation](). + +Once you have done this, your next step is to read our [wiki](). Then, create your post in <#1400629118110011526> as outlined in the wiki. + +Naomi will follow up with you from there! Best of luck on your journey~! `, + }); +};