From b9d2bf0dec40f77decc92eb900155dcda6d98d69 Mon Sep 17 00:00:00 2001 From: David Germain Date: Fri, 14 Jun 2024 19:09:40 +0200 Subject: [PATCH] chore: move code to discord file --- .../src/Integrations/firebase-discord.ts | 25 +++++++++++++++ functions/src/Integrations/firebase-slack.ts | 32 ------------------- functions/src/Integrations/index.ts | 2 +- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/functions/src/Integrations/firebase-discord.ts b/functions/src/Integrations/firebase-discord.ts index 40d6a029d..9639adfff 100644 --- a/functions/src/Integrations/firebase-discord.ts +++ b/functions/src/Integrations/firebase-discord.ts @@ -54,6 +54,31 @@ export const notifyHowToAccepted = functions .catch(handleErr) }) +export const notifyAcceptedQuestion = functions + .runWith({ memory: '512MB' }) + .firestore.document('questions_rev20230926/{id}') + // currently, questions are immediately posted with no review. + // if that changes, this code will need to be updated. + .onCreate(async (snapshot) => { + const info = snapshot.data() + console.log(info) + + const username = info._createdBy + const title = info.title + const slug = info.slug + + try { + const response = await axios.post(DISCORD_WEBHOOK_URL, { + json: { + text: `❓ ${username} has a new question: ${title}\n Help them out and answer here: ${SITE_URL}/questions/${slug}`, + }, + }) + handleResponse(response) + } catch (error) { + handleErr(error) + } + }) + const handleResponse = (res: AxiosResponse) => { console.log('post success') return res diff --git a/functions/src/Integrations/firebase-slack.ts b/functions/src/Integrations/firebase-slack.ts index 1ea6c2d8e..8c618a5a4 100644 --- a/functions/src/Integrations/firebase-slack.ts +++ b/functions/src/Integrations/firebase-slack.ts @@ -7,7 +7,6 @@ const SITE_URL = CONFIG.deployment.site_url // e.g. https://dev.onearmy.world or https://community.preciousplastic.com const SLACK_WEBHOOK_URL = CONFIG.integrations.slack_webhook -const DISCORD_WEBHOOK_URL = CONFIG.integrations.discord_webhook export const notifyNewPin = functions .runWith({ memory: '512MB' }) @@ -65,34 +64,3 @@ export const notifyNewHowTo = functions }, ) }) - -export const notifyAcceptedQuestion = functions - .runWith({ memory: '512MB' }) - .firestore.document('questions_rev20230926/{id}') - // currently, questions are immediately posted with no review. - // if that changes, this code will need to change. - .onCreate((snapshot) => { - const info = snapshot.data() - console.log(info) - - const username = info._createdBy - const title = info.title - const slug = info.slug - - request.post( - DISCORD_WEBHOOK_URL, - { - json: { - text: `❓ ${username} has a new question: ${title}\n Help them out and answer here: ${SITE_URL}/questions/${slug}`, - }, - }, - (error, response) => { - if (error) { - console.error(error) - return - } else { - return response - } - }, - ) - }) diff --git a/functions/src/Integrations/index.ts b/functions/src/Integrations/index.ts index a8d2bce4c..6cb475ffa 100644 --- a/functions/src/Integrations/index.ts +++ b/functions/src/Integrations/index.ts @@ -8,6 +8,6 @@ exports.notifyPinAccepted = IntegrationsDiscord.notifyPinAccepted exports.notifyNewHowTo = IntegrationsSlack.notifyNewHowTo exports.notifyHowToAccepted = IntegrationsDiscord.notifyHowToAccepted -exports.notifyAcceptedQuestion = IntegrationsSlack.notifyAcceptedQuestion +exports.notifyAcceptedQuestion = IntegrationsDiscord.notifyAcceptedQuestion exports.patreonAuth = IntegrationsPatreon.patreonAuth