feat: deduplicate mentee welcome messages
Node.js CI / CI (pull_request) Successful in 29s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m1s

Track welcomed mentees in data/welcomed.txt to prevent sending the onboarding message multiple times if the mentorship role is re-assigned.
This commit is contained in:
2026-03-02 15:55:19 -08:00
committed by Naomi Carrigan
parent 5efac612f9
commit b1196158a5
4 changed files with 38 additions and 1 deletions
+6
View File
@@ -6,6 +6,10 @@
import { ids } from "../config/ids.js";
import { logger } from "../utils/logger.js";
import {
addWelcomedMentee,
welcomedMentees,
} from "../utils/welcomedMentees.js";
import type { Amari } from "../interfaces/amari.js";
import type { GuildMember, PartialGuildMember } from "discord.js";
@@ -25,6 +29,7 @@ export const processMentorshipRole = async(
if (
oldMember.roles.cache.has(ids.roles.mentorship)
|| !updatedMember.roles.cache.has(ids.roles.mentorship)
|| welcomedMentees.has(updatedMember.id)
) {
return;
}
@@ -52,6 +57,7 @@ Last name:
\`\`\`
Then read our [mentorship wiki](<https://docs.nhcarrigan.com/mentorship/00-faq/>) for the next steps!`,
});
addWelcomedMentee(updatedMember.id);
await logger.metric("processed_mentorship_role", 1, {
user: updatedMember.id,
});
+30
View File
@@ -0,0 +1,30 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { appendFileSync, existsSync, readFileSync } from "node:fs";
const filePath = "data/welcomed.txt";
const loadWelcomedMentees = (): Set<string> => {
if (!existsSync(filePath)) {
return new Set();
}
const contents = readFileSync(filePath, "utf-8");
return new Set(contents.split("\n").filter(Boolean));
};
const welcomedMentees = loadWelcomedMentees();
/**
* Appends a mentee's ID to the welcomed set and persists it to disk.
* @param id - The Discord user ID to record.
*/
const addWelcomedMentee = (id: string): void => {
welcomedMentees.add(id);
appendFileSync(filePath, `${id}\n`);
};
export { addWelcomedMentee, welcomedMentees };