b7def686e9
commit83bcd07e20Author: SabreCat <sabrecat@gmail.com> Date: Fri Dec 22 17:24:45 2023 -0600 fix(profile): revert state on error commit6aa6278727Author: SabreCat <sabrecat@gmail.com> Date: Fri Dec 22 14:37:28 2023 -0600 fix(test): no longer care about swears in profile commit0882c77038Author: SabreCat <sabe@habitica.com> Date: Fri Dec 22 14:15:42 2023 -0600 fix(lint): remove unused functions commit9b275ef72dAuthor: SabreCat <sabe@habitica.com> Date: Fri Dec 22 14:09:11 2023 -0600 fix(profiles): restore reporting functionality Also remove unused and/or unrelated code and clean up comments commitf4ed8c1461Merge:da16aa9c75f8ba191eeaAuthor: SabreCat <sabe@habitica.com> Date: Fri Dec 22 12:11:00 2023 -0600 Merge branch 'release' into slur-swear-blocker commitda16aa9c75Author: CuriousMagpie <eilatan@gmail.com> Date: Thu Dec 21 13:20:28 2023 -0500 feat(s/s blocker): challenge updates to slack commit51bed61c4cAuthor: CuriousMagpie <eilatan@gmail.com> Date: Tue Dec 19 15:36:59 2023 -0500 feat(s/s blocker): work on challenges commit139cbcb21cAuthor: CuriousMagpie <eilatan@gmail.com> Date: Wed Dec 13 13:20:45 2023 -0500 fix(slack): update Slack notification to include authorEmail and remove undefined commit805b287721Author: SabreCat <sabe@habitica.com> Date: Tue Dec 12 16:35:54 2023 -0600 fix(profiles): improve profanity check logic commit02ef7e8822Author: CuriousMagpie <eilatan@gmail.com> Date: Tue Dec 12 17:22:29 2023 -0500 feat(slur blocker): arghhhhhh commit949dee9b1eAuthor: CuriousMagpie <eilatan@gmail.com> Date: Tue Dec 12 13:57:29 2023 -0500 feat(slur blocker): more refactoring commitbf953998f4Merge:d21aa687b7f572aa442eAuthor: CuriousMagpie <eilatan@gmail.com> Date: Mon Dec 11 15:20:06 2023 -0500 Merge branch 'release' into slur-swear-blocker commitd21aa687b7Author: CuriousMagpie <eilatan@gmail.com> Date: Thu Dec 7 18:00:29 2023 -0500 feat(slur blocker): refactoring code commitf2db90c494Author: CuriousMagpie <eilatan@gmail.com> Date: Wed Dec 6 12:12:55 2023 -0500 feat(slur/swear blocker): work on Profiles commit8f9822ffe8Author: CuriousMagpie <eilatan@gmail.com> Date: Mon Dec 4 17:25:17 2023 -0500 feat(profiles/challenges): work on profile block & slack report commitbdb2e06e5eAuthor: CuriousMagpie <eilatan@gmail.com> Date: Fri Dec 1 16:11:27 2023 -0500 feat(slur/swear): working on it commit7277b5cad5Merge:24d14277ab941f1f976cAuthor: CuriousMagpie <eilatan@gmail.com> Date: Fri Dec 1 15:04:46 2023 -0500 Merge branch 'profile-slur-swear-blocker' into slur-swear-blocker commit941f1f976cAuthor: CuriousMagpie <eilatan@gmail.com> Date: Thu Nov 30 14:34:30 2023 -0500 feat(profiles/PMs): slur/swear blocker upgrade commit0863017efcAuthor: CuriousMagpie <eilatan@gmail.com> Date: Tue Nov 28 16:21:21 2023 -0500 feat(profiles): slur/swear blocker commite9937d864fAuthor: CuriousMagpie <eilatan@gmail.com> Date: Mon Nov 27 15:24:37 2023 -0500 feat(profiles): slur/swear blocker commit24d14277abAuthor: CuriousMagpie <eilatan@gmail.com> Date: Mon Nov 27 14:12:46 2023 -0500 feat(challenges): update behavior based on public/private groups commit1251f5b6a7Author: CuriousMagpie <eilatan@gmail.com> Date: Tue Nov 14 16:28:29 2023 -0500 feat(challenges): swear and slur blocker commita771045ca7Author: CuriousMagpie <eilatan@gmail.com> Date: Tue Nov 14 15:46:16 2023 -0500 feat(challenges): even more slur blocker commite5e91aa78aAuthor: CuriousMagpie <eilatan@gmail.com> Date: Tue Nov 14 14:31:25 2023 -0500 feat(challenges): more slur blocker commit50e824e4e3Author: CuriousMagpie <eilatan@gmail.com> Date: Mon Nov 13 15:12:14 2023 -0500 feat(challenges): slur blocker commit315ea24ef4Author: CuriousMagpie <eilatan@gmail.com> Date: Fri Nov 3 12:31:12 2023 -0400 feat(challenges): slur blocker work commit0f742d219fAuthor: CuriousMagpie <eilatan@gmail.com> Date: Thu Nov 2 16:22:31 2023 -0400 feat(challenges): add banned words & slur blocker to challenges commit40d6b60ee3Author: CuriousMagpie <eilatan@gmail.com> Date: Mon Oct 23 13:00:46 2023 -0400 update packages on local/origin repo
371 lines
9.5 KiB
JavaScript
371 lines
9.5 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import { IncomingWebhook } from '@slack/webhook';
|
|
import nconf from 'nconf';
|
|
import moment from 'moment';
|
|
import logger from './logger';
|
|
import { getCurrentEvent } from './worldState'; // eslint-disable-line import/no-cycle
|
|
import { TAVERN_ID } from '../models/group'; // eslint-disable-line import/no-cycle
|
|
|
|
const SLACK_FLAGGING_URL = nconf.get('SLACK_FLAGGING_URL');
|
|
const SLACK_FLAGGING_FOOTER_LINK = nconf.get('SLACK_FLAGGING_FOOTER_LINK');
|
|
const SLACK_SUBSCRIPTIONS_URL = nconf.get('SLACK_SUBSCRIPTIONS_URL');
|
|
const BASE_URL = nconf.get('BASE_URL');
|
|
const IS_PRODUCTION = nconf.get('IS_PROD');
|
|
const IS_TEST = nconf.get('IS_TEST');
|
|
|
|
const SKIP_FLAG_METHODS = (IS_PRODUCTION || IS_TEST) && !SLACK_FLAGGING_URL;
|
|
const SKIP_SUB_METHOD = (IS_PRODUCTION || IS_TEST) && !SLACK_SUBSCRIPTIONS_URL;
|
|
|
|
let flagSlack;
|
|
let subscriptionSlack;
|
|
|
|
try {
|
|
if (IS_TEST || IS_PRODUCTION) {
|
|
flagSlack = new IncomingWebhook(SLACK_FLAGGING_URL);
|
|
subscriptionSlack = new IncomingWebhook(SLACK_SUBSCRIPTIONS_URL);
|
|
} else {
|
|
subscriptionSlack = {
|
|
// async so that it works like the original Slack send method
|
|
async send (data) {
|
|
logger.info('Data sent to slack', data);
|
|
},
|
|
};
|
|
flagSlack = subscriptionSlack;
|
|
}
|
|
} catch (err) {
|
|
logger.error(err, 'Error setting up Slack.');
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param formatObj.name userName
|
|
* @param formatObj.displayName displayName
|
|
* @param formatObj.email email
|
|
* @param formatObj.uuid uuid
|
|
* @returns {string}
|
|
*/
|
|
function formatUser (formatObj) {
|
|
return `@${formatObj.name} ${formatObj.displayName} (${formatObj.email}; ${formatObj.uuid})`;
|
|
}
|
|
|
|
function sendFlagNotification ({
|
|
authorEmail,
|
|
flagger,
|
|
group,
|
|
message,
|
|
userComment,
|
|
automatedComment,
|
|
}) {
|
|
if (SKIP_FLAG_METHODS) {
|
|
return;
|
|
}
|
|
let titleLink;
|
|
let authorName;
|
|
let title = `Flag in ${group.name}`;
|
|
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a group message`;
|
|
let footer = `<${SLACK_FLAGGING_FOOTER_LINK}?groupId=${group.id}&chatId=${message.id}|Flag this message.>`;
|
|
|
|
if (userComment) {
|
|
text += ` and commented: ${userComment}`;
|
|
}
|
|
if (automatedComment) {
|
|
footer += ` ${automatedComment}`;
|
|
}
|
|
|
|
if (group.id === TAVERN_ID) {
|
|
titleLink = `${BASE_URL}/groups/tavern`;
|
|
} else if (group.privacy === 'public') {
|
|
titleLink = `${BASE_URL}/groups/guild/${group.id}`;
|
|
} else {
|
|
title += ` - (${group.privacy} ${group.type})`;
|
|
}
|
|
|
|
if (!message.user && message.uuid === 'system') {
|
|
authorName = 'System Message';
|
|
} else {
|
|
authorName = formatUser({
|
|
name: message.username,
|
|
displayName: message.user,
|
|
email: authorEmail,
|
|
uuid: message.uuid,
|
|
});
|
|
}
|
|
|
|
const timestamp = `${moment(message.timestamp).utc().format('YYYY-MM-DD HH:mm')} UTC`;
|
|
|
|
flagSlack
|
|
.send({
|
|
text,
|
|
attachments: [{
|
|
fallback: 'Flag Message',
|
|
color: 'danger',
|
|
author_name: `${authorName}\n${timestamp}`,
|
|
title,
|
|
title_link: titleLink,
|
|
text: message.text,
|
|
footer,
|
|
mrkdwn_in: [
|
|
'text',
|
|
],
|
|
}],
|
|
})
|
|
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
|
}
|
|
|
|
function sendInboxFlagNotification ({
|
|
messageUserEmail,
|
|
flagger,
|
|
message,
|
|
userComment,
|
|
}) {
|
|
if (SKIP_FLAG_METHODS) {
|
|
return;
|
|
}
|
|
const titleLink = '';
|
|
const title = `Flag in ${flagger.profile.name}'s Inbox`;
|
|
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a PM`;
|
|
const footer = '';
|
|
|
|
if (userComment) {
|
|
text += ` and commented: ${userComment}`;
|
|
}
|
|
|
|
const messageText = message.text;
|
|
let sender = '';
|
|
let recipient = '';
|
|
|
|
const flaggerFormat = formatUser({
|
|
displayName: flagger.profile.name,
|
|
name: flagger.auth.local.username,
|
|
email: flagger.auth.local.email,
|
|
uuid: flagger._id,
|
|
});
|
|
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}.`;
|
|
|
|
flagSlack
|
|
.send({
|
|
text,
|
|
attachments: [{
|
|
fallback: 'Flag Message',
|
|
color: 'danger',
|
|
author_name: authorName,
|
|
title,
|
|
title_link: titleLink,
|
|
text: messageText,
|
|
footer,
|
|
mrkdwn_in: [
|
|
'text',
|
|
],
|
|
}],
|
|
})
|
|
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
|
}
|
|
|
|
function sendChallengeFlagNotification ({
|
|
flagger,
|
|
challenge,
|
|
userComment,
|
|
}) {
|
|
if (SKIP_FLAG_METHODS) {
|
|
return;
|
|
}
|
|
const titleLink = `${BASE_URL}/challenges/${challenge.id}`;
|
|
const title = `Flag in challenge "${challenge.name}"`;
|
|
let text = `${flagger.profile.name} (${flagger.id}; language: ${flagger.preferences.language}) flagged a challenge`;
|
|
const footer = '';
|
|
|
|
if (userComment) {
|
|
text += ` and commented: ${userComment}`;
|
|
}
|
|
|
|
const challengeText = challenge.summary;
|
|
|
|
flagSlack.send({
|
|
text,
|
|
attachments: [{
|
|
fallback: 'Flag Message',
|
|
color: 'danger',
|
|
title,
|
|
title_link: titleLink,
|
|
text: challengeText,
|
|
footer,
|
|
mrkdwn_in: [
|
|
'text',
|
|
],
|
|
}],
|
|
});
|
|
}
|
|
|
|
function sendProfileFlagNotification ({
|
|
reporter,
|
|
flaggedUser,
|
|
userComment,
|
|
source,
|
|
}) {
|
|
const title = 'User Profile Report';
|
|
const titleLink = `${BASE_URL}/profile/${flaggedUser._id}`;
|
|
let text = `@${reporter.auth.local.username} (${reporter._id}; language: ${reporter.preferences.language}) flagged @${flaggedUser.auth.local.username}'s profile from ${source}`;
|
|
if (userComment) {
|
|
text += ` and commented: ${userComment}`;
|
|
}
|
|
let profileData = `Display Name: ${flaggedUser.profile.name}`;
|
|
if (flaggedUser.profile.imageUrl) {
|
|
profileData += `\n\nImage URL: ${flaggedUser.profile.imageUrl}`;
|
|
}
|
|
if (flaggedUser.profile.blurb) {
|
|
profileData += `\n\nAbout: ${flaggedUser.profile.blurb}`;
|
|
}
|
|
|
|
flagSlack
|
|
.send({
|
|
text,
|
|
attachments: [{
|
|
fallback: 'Flag Profile',
|
|
color: 'danger',
|
|
title,
|
|
title_link: titleLink,
|
|
text: profileData,
|
|
mrkdwn_in: [
|
|
'text',
|
|
],
|
|
}],
|
|
})
|
|
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
|
}
|
|
|
|
function sendSubscriptionNotification ({
|
|
buyer,
|
|
recipient,
|
|
paymentMethod,
|
|
months,
|
|
groupId,
|
|
autoRenews,
|
|
}) {
|
|
if (SKIP_SUB_METHOD) {
|
|
return;
|
|
}
|
|
let text;
|
|
const timestamp = new Date();
|
|
if (recipient.id) {
|
|
const currentEvent = getCurrentEvent();
|
|
const promoString = currentEvent && currentEvent.promo ? ' and got a promo' : '';
|
|
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a ${months}-month gift subscription for ${recipient.name} ${recipient.id} ${recipient.email}${promoString} using ${paymentMethod} on ${timestamp}`;
|
|
} else if (groupId) {
|
|
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a 1-month recurring group-plan for ${groupId} using ${paymentMethod} on ${timestamp}`;
|
|
} else if (autoRenews) {
|
|
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a ${months}-month recurring subscription using ${paymentMethod} on ${timestamp}`;
|
|
} else {
|
|
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a ${months}-month non-recurring subscription using ${paymentMethod} on ${timestamp}`;
|
|
}
|
|
|
|
subscriptionSlack
|
|
.send({
|
|
text,
|
|
})
|
|
.catch(err => logger.error(err, 'Error while sending subscription data to Slack.'));
|
|
}
|
|
|
|
function sendShadowMutedPostNotification ({
|
|
authorEmail,
|
|
author,
|
|
group,
|
|
message,
|
|
}) {
|
|
if (SKIP_FLAG_METHODS) {
|
|
return;
|
|
}
|
|
const title = `Shadow-Muted Post in ${group.name}`;
|
|
const text = `@${author.auth.local.username} / ${author.profile.name} posted while shadow-muted`;
|
|
|
|
let titleLink;
|
|
if (group.id === TAVERN_ID) {
|
|
titleLink = `${BASE_URL}/groups/tavern`;
|
|
} else {
|
|
titleLink = `${BASE_URL}/groups/guild/${group.id}`;
|
|
}
|
|
|
|
const authorName = formatUser({
|
|
name: author.auth.local.username,
|
|
displayName: author.profile.name,
|
|
email: authorEmail,
|
|
uuid: author.id,
|
|
});
|
|
|
|
flagSlack
|
|
.send({
|
|
text,
|
|
attachments: [{
|
|
fallback: 'Shadow-Muted Message',
|
|
color: 'danger',
|
|
author_name: authorName,
|
|
title,
|
|
title_link: titleLink,
|
|
text: message,
|
|
mrkdwn_in: [
|
|
'text',
|
|
],
|
|
}],
|
|
})
|
|
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
|
}
|
|
|
|
// slack slur notification for Profiles
|
|
function sendProfileSlurNotification ({
|
|
authorEmail,
|
|
author,
|
|
uuid,
|
|
language,
|
|
problemContent,
|
|
}) {
|
|
if (SKIP_FLAG_METHODS) {
|
|
return;
|
|
}
|
|
const title = 'User Profile Report: Slur';
|
|
const titleLink = `${BASE_URL}/profile/${uuid}`;
|
|
|
|
const text = `@${author} ${authorEmail} (${uuid}, ${language}) tried to post a slur in their Profile.`;
|
|
|
|
flagSlack
|
|
.send({
|
|
text,
|
|
attachments: [{
|
|
fallback: 'Slur Message',
|
|
color: 'danger',
|
|
author_email: authorEmail,
|
|
title,
|
|
title_link: titleLink,
|
|
text: problemContent,
|
|
mrkdwn_in: [
|
|
'text',
|
|
],
|
|
}],
|
|
})
|
|
.catch(err => logger.error(err, 'Error while sending flag data to Slack.'));
|
|
}
|
|
|
|
export {
|
|
sendFlagNotification,
|
|
sendInboxFlagNotification,
|
|
sendChallengeFlagNotification,
|
|
sendProfileFlagNotification,
|
|
sendSubscriptionNotification,
|
|
sendShadowMutedPostNotification,
|
|
sendProfileSlurNotification,
|
|
formatUser,
|
|
};
|