diff --git a/src/features/emojiMod.ts b/src/features/emojiMod.ts index a2d3cb40..5f825b4e 100644 --- a/src/features/emojiMod.ts +++ b/src/features/emojiMod.ts @@ -163,8 +163,8 @@ const emojiMod: ChannelHandlers = { reactor, message: fullMessage, reaction: fullReaction, - usersWhoReacted: usersWhoReacted.filter((x): x is GuildMember => - Boolean(x), + usersWhoReacted: usersWhoReacted.filter( + (x): x is GuildMember => Boolean(x) && authorMember.id !== reactor.id, ), }); }, diff --git a/src/features/log.ts b/src/features/log.ts index bc5e6a3b..ac0ca1cf 100644 --- a/src/features/log.ts +++ b/src/features/log.ts @@ -19,7 +19,7 @@ export const channelLog = if (channel?.type == ChannelType.GuildText) { channel.send({ - content: `[${type}] ${text}`, + content: `[${type}] ${text}`.slice(0, 2000), allowedMentions: { users: [] }, }); } diff --git a/src/features/resume.ts b/src/features/resume.ts index 738a485f..5368c558 100644 --- a/src/features/resume.ts +++ b/src/features/resume.ts @@ -16,6 +16,8 @@ import { findResumeAttachment, REVIEW_COMMAND, } from "./resume-review"; +import { constructDiscordLink } from "../helpers/discord"; +import { retry } from "./retry"; const openai = new OpenAI({ apiKey: openAiKey, @@ -74,7 +76,8 @@ export const resumeResources = async (bot: Client) => { deferred.edit("Looking for a resumeā€¦"); const messages = await interaction.channel.messages.fetch(); - const firstMessage = await interaction.channel.fetchStarterMessage(); + const { fetchStarterMessage } = interaction.channel; + const firstMessage = await retry(() => fetchStarterMessage(), 5, 10); if (!firstMessage) { await interaction.reply({ ephemeral: true, @@ -162,8 +165,11 @@ export const resumeResources = async (bot: Client) => { console.log({ content }); const trimmed = content.at(0)?.slice(0, 2000) ?? "Oops! Something went wrong."; - logger.log("[RESUME]", `Feedback given:`); - logger.log("[RESUME]", trimmed); + logger.log( + "RESUME", + `Feedback given: ${constructDiscordLink(firstMessage)}`, + ); + logger.log("RESUME", trimmed); deferred.edit({ content: trimmed, }); diff --git a/src/features/retry.ts b/src/features/retry.ts new file mode 100644 index 00000000..a724b951 --- /dev/null +++ b/src/features/retry.ts @@ -0,0 +1,49 @@ +/** + * This is a chatGPT generated function, don't blame me. I did verify it works: +```ts +console.log(retryCount, { + backoff: delay * Math.pow(factor, retries - retryCount), + retryCount, +}); +``` +as the first line of the `attempt` function produced: +``` +> 5 { backoff: 20, retryCount: 5 } +> 4 { backoff: 40, retryCount: 4 } +> 3 { backoff: 80, retryCount: 3 } +> 2 { backoff: 160, retryCount: 2 } +> 1 { backoff: 320, retryCount: 1 } +> 0 { backoff: 640, retryCount: 0 } +``` + + * Retries a promise-returning function with exponential backoff. + * + * @template T + * @param {() => Promise} fn - The function returning a promise to be retried. + * @param {number} [retries=3] - The number of retry attempts. + * @param {number} [delayMs=1000] - The initial delay in milliseconds before retrying. + * @returns {Promise} A promise that resolves with the result of the function or rejects after all retries have been exhausted. + */ +export function retry( + fn: () => Promise, + retries = 3, + delayMs = 1000, +): Promise { + return new Promise((resolve, reject) => { + const attempt = (retryCount: number) => { + fn() + .then(resolve) + .catch((error) => { + if (retryCount <= 0) { + reject(error); + } else { + setTimeout(() => { + attempt(retryCount - 1); + }, delayMs * Math.pow(2, retries - retryCount)); + } + }); + }; + + attempt(retries); + }); +} diff --git a/src/features/scheduled-messages.ts b/src/features/scheduled-messages.ts index 0f6f0b2c..b9ecee77 100644 --- a/src/features/scheduled-messages.ts +++ b/src/features/scheduled-messages.ts @@ -94,17 +94,17 @@ How do I ask a good question message: { content: `Check our the other channels too! This is our highest-traffic channel, which may mean your question gets missed as other discussions happen. -#help-js For questions about pure Javscript problems. -#help-styling For questions about CSS or other visual problems. -#help-backend For questions about issues with your server code. -#code-review Get deeper review of a snippet of code. -#jobs-advice If you have a question about your job or career, ask it in here. -#general-tech Discussion of non-JS code, or that new laptop you're deciding on. -#tooling for questions about building, linting, generating, or otherwise processing your code. +<#565213527673929729> For questions about pure Javscript problems. +<#105765765117935616> For questions about CSS or other visual problems. +<#145170347921113088> For questions about issues with your server code. +<#105765859191975936> Get deeper review of a snippet of code. +<#287623405946011648> If you have a question about your job or career, ask it in here. +<#547620660482932737> Discussion of non-JS code, or that new laptop you're deciding on. +<#108428584783220736> for questions about building, linting, generating, or otherwise processing your code. -Looking for work? Trying to hire? Check out #job-board, or +Looking for work? Trying to hire? Check out <#103882387330457600>, or -Has someone been really helpful? Shoutout who and what in #thanks! We keep an eye in there as one way to find new MVPs. Give us all the reactions in there too! +Has someone been really helpful? Shoutout who and what in <#798567961468076072>! We keep an eye in there as one way to find new MVPs. Give us all the reactions in there too! Please remember our Code of Conduct: and our guidelines for promotion: