From bdb2e06e5e4fc9c34c0abc27139737be05d1320b Mon Sep 17 00:00:00 2001 From: CuriousMagpie Date: Fri, 1 Dec 2023 16:11:27 -0500 Subject: [PATCH] feat(slur/swear): working on it --- .../server/controllers/api-v3/challenges.js | 2 +- website/server/libs/slack.js | 53 ++++++------------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/website/server/controllers/api-v3/challenges.js b/website/server/controllers/api-v3/challenges.js index 0a2201be5d..418d2d1925 100644 --- a/website/server/controllers/api-v3/challenges.js +++ b/website/server/controllers/api-v3/challenges.js @@ -240,7 +240,7 @@ api.createChallenge = { || (textContainsBannedSlur(req.body.description)))) { // slack flagged-posts const authorEmail = getUserInfo(user, ['email']).email; - slack.sendSlurNotification({ + slack.sendChallengeSlurNotification({ authorEmail, author: user, group, diff --git a/website/server/libs/slack.js b/website/server/libs/slack.js index 1fa5cc93d4..afee5490d6 100644 --- a/website/server/libs/slack.js +++ b/website/server/libs/slack.js @@ -416,58 +416,39 @@ function sendProfileSlurNotification ({ .catch(err => logger.error(err, 'Error while sending flag data to Slack.')); } -function sendPersonalMessageSlurNotification ({ +function sendChallengeSlurNotification ({ authorEmail, author, - message, - flagger, + group, + body, + title, }) { if (SKIP_FLAG_METHODS) { return; } + const text = `${author.profile.name} (${author._id}) tried to post a slur in ${group},`; + let titleLink; - let text = `${author.profile.name} (${author.id}; language: ${author.preferences.language}) tried to post a slur.`; - const footer = ''; - - // if (userComment) { - // text += ` and commented: ${userComment}`; - // } - - // const messageText = message.text; - // let sender; - // let recipient; - - // const messageUserFormat = formatUser({ - // displayName: message.user, - // name: message.username, - // email: messageUserEmail, - // uuid: message.uuid, - // }); - - // if (message.sent) { - // sender = flaggerFormat; - // recipient = messageUserFormat; - // } else { - // sender = messageUserFormat; - // recipient = flaggerFormat; - // } - - const authorName = `${sender} wrote this message to ${recipient}.`; + const authorName = formatUser({ + name: author.auth.local.username, + displayName: author.profile.name, + email: authorEmail, + uuid: author.id, + }); flagSlack .send({ text, attachments: [{ - fallback: 'Flag Message', + fallback: 'Slur Message', color: 'danger', author_name: authorName, - title, + titleName: title, title_link: titleLink, - text: messageText, - footer, + text: body, mrkdwn_in: [ - 'text', + 'body', ], }], }) @@ -483,6 +464,6 @@ export { sendShadowMutedPostNotification, sendGroupSlurNotification, sendProfileSlurNotification, - sendPersonalMessageSlurNotification, + sendChallengeSlurNotification, formatUser, };