From dd6bd417d09f15b787d7b5cc9c08a898fbaf60ca Mon Sep 17 00:00:00 2001 From: Shadow Date: Tue, 3 Dec 2024 09:02:19 -0500 Subject: [PATCH] Fix helper pings in meta discussions when triggered by TripSit mode (#896) * fix(tripsitmode): helpers not being pinged in discussions * remove invalid chars from env --- .env.example | 3 +-- src/discord/commands/global/d.tripsitmode.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 454e2267..17552d75 100644 --- a/.env.example +++ b/.env.example @@ -59,5 +59,4 @@ WOLFRAM_TOKEN = # For WolframAlpha API IMGUR_ID = # For Imgur API IMGUR_SECRET = # For Imgur API YOUTUBE_TOKEN = # For YouTube API -IMDB_TOKEN = # For IMDB API -``` \ No newline at end of file +IMDB_TOKEN = # For IMDB API \ No newline at end of file diff --git a/src/discord/commands/global/d.tripsitmode.ts b/src/discord/commands/global/d.tripsitmode.ts index 0c5fa087..4e08d30d 100644 --- a/src/discord/commands/global/d.tripsitmode.ts +++ b/src/discord/commands/global/d.tripsitmode.ts @@ -227,6 +227,7 @@ async function tripsitmodeOn( const now = new Date(); const diff = now.getTime() - createdDate.getTime(); const minutes = Math.floor(diff / 1000 / 60); + // const seconds = Math.floor(diff / 1000); // Uncomment this for dev server if (minutes > 5) { const helperStr = `and/or ${roleHelper}`; // log.debug(F, `Target has open ticket, and it was created over 5 minutes ago!`); @@ -247,9 +248,15 @@ async function tripsitmodeOn( // If the meta thread exists, update the name and ping the team if (ticketData.meta_thread_id) { let metaMessage = ''; - if (minutes > 5) { + if (minutes > 5) { // Switch to seconds > 10 for dev server const helperString = `and/or ${roleHelper}`; - metaMessage = `Hey ${roleTripsitter} ${guildData.role_helper ?? helperString} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`; // eslint-disable-line max-len + try { + metaMessage = `Hey ${roleTripsitter} ${guildData.role_helper ? helperString : ''} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`; + } catch (err) { + // If for example helper role has been deleted but the ID is still stored, do this + metaMessage = `Hey ${roleTripsitter} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`; + log.error(F, `Stored Helper ID for guild ${guildData.id} is no longer valid. Role is unfetchable or deleted.`); + } } else { metaMessage = `${interaction.member} has indicated that ${target.displayName} needs assistance!`; }