2016-08-27 03:12:23 +00:00
/* eslint-disable camelcase */
2020-11-30 19:03:04 +00:00
import { IncomingWebhook } from '@slack/webhook' ;
2016-08-27 03:12:23 +00:00
import nconf from 'nconf' ;
2018-06-15 09:01:10 +00:00
import moment from 'moment' ;
2019-10-08 14:57:10 +00:00
import logger from './logger' ;
2020-12-10 22:53:37 +00:00
import { getCurrentEvent } from './worldState' ; // eslint-disable-line import/no-cycle
2019-10-10 18:11:50 +00:00
import { TAVERN _ID } from '../models/group' ; // eslint-disable-line import/no-cycle
2016-08-27 03:12:23 +00:00
2018-12-06 16:13:49 +00:00
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' ) ;
2016-08-27 03:12:23 +00:00
const BASE _URL = nconf . get ( 'BASE_URL' ) ;
2018-06-02 16:14:53 +00:00
const IS _PRODUCTION = nconf . get ( 'IS_PROD' ) ;
2020-11-30 19:03:04 +00:00
const IS _TEST = nconf . get ( 'IS_TEST' ) ;
2018-06-02 16:14:53 +00:00
2020-11-30 19:03:04 +00:00
const SKIP _FLAG _METHODS = ( IS _PRODUCTION || IS _TEST ) && ! SLACK _FLAGGING _URL ;
const SKIP _SUB _METHOD = ( IS _PRODUCTION || IS _TEST ) && ! SLACK _SUBSCRIPTIONS _URL ;
2016-08-27 03:12:23 +00:00
2016-08-27 04:09:54 +00:00
let flagSlack ;
2016-12-09 02:08:56 +00:00
let subscriptionSlack ;
2016-08-27 04:09:54 +00:00
try {
2024-09-28 14:23:16 +00:00
if ( ( IS _TEST || IS _PRODUCTION ) && SLACK _FLAGGING _URL && SLACK _SUBSCRIPTIONS _URL ) {
2020-11-30 19:03:04 +00:00
flagSlack = new IncomingWebhook ( SLACK _FLAGGING _URL ) ;
subscriptionSlack = new IncomingWebhook ( SLACK _SUBSCRIPTIONS _URL ) ;
} else {
2019-10-10 18:11:50 +00:00
subscriptionSlack = {
2020-11-30 19:03:04 +00:00
// async so that it works like the original Slack send method
async send ( data ) {
2018-06-02 16:14:53 +00:00
logger . info ( 'Data sent to slack' , data ) ;
} ,
} ;
2019-10-10 18:11:50 +00:00
flagSlack = subscriptionSlack ;
2018-06-02 16:14:53 +00:00
}
2020-11-30 19:03:04 +00:00
} catch ( err ) {
logger . error ( err , 'Error setting up Slack.' ) ;
2016-08-27 04:09:54 +00:00
}
2016-08-27 03:12:23 +00:00
2018-11-29 19:15:47 +00:00
/ * *
*
* @ param formatObj . name userName
* @ param formatObj . displayName displayName
* @ param formatObj . email email
* @ param formatObj . uuid uuid
* @ returns { string }
* /
function formatUser ( formatObj ) {
2019-01-27 18:05:00 +00:00
return ` @ ${ formatObj . name } ${ formatObj . displayName } ( ${ formatObj . email } ; ${ formatObj . uuid } ) ` ;
2018-11-29 19:15:47 +00:00
}
2016-08-27 03:12:23 +00:00
function sendFlagNotification ( {
2016-09-30 12:42:51 +00:00
authorEmail ,
2016-08-27 03:12:23 +00:00
flagger ,
group ,
message ,
2018-03-14 12:41:13 +00:00
userComment ,
2018-08-03 10:04:01 +00:00
automatedComment ,
2016-08-27 03:12:23 +00:00
} ) {
2018-06-02 16:14:53 +00:00
if ( SKIP _FLAG _METHODS ) {
2016-08-27 04:09:54 +00:00
return ;
}
2016-08-27 03:12:23 +00:00
let titleLink ;
2016-09-02 20:23:56 +00:00
let authorName ;
2016-08-27 03:12:23 +00:00
let title = ` Flag in ${ group . name } ` ;
2018-06-02 17:27:28 +00:00
let text = ` ${ flagger . profile . name } ( ${ flagger . id } ; language: ${ flagger . preferences . language } ) flagged a group message ` ;
2018-08-03 10:04:01 +00:00
let footer = ` < ${ SLACK _FLAGGING _FOOTER _LINK } ?groupId= ${ group . id } &chatId= ${ message . id } |Flag this message.> ` ;
2016-08-27 03:12:23 +00:00
2018-03-14 12:41:13 +00:00
if ( userComment ) {
text += ` and commented: ${ userComment } ` ;
}
2018-08-03 10:04:01 +00:00
if ( automatedComment ) {
footer += ` ${ automatedComment } ` ;
}
2018-03-14 12:41:13 +00:00
2016-08-27 03:12:23 +00:00
if ( group . id === TAVERN _ID ) {
2017-09-16 12:19:07 +00:00
titleLink = ` ${ BASE _URL } /groups/tavern ` ;
2016-08-27 03:12:23 +00:00
} else if ( group . privacy === 'public' ) {
2017-09-16 12:19:07 +00:00
titleLink = ` ${ BASE _URL } /groups/guild/ ${ group . id } ` ;
2016-08-27 03:12:23 +00:00
} else {
title += ` - ( ${ group . privacy } ${ group . type } ) ` ;
}
2016-09-02 20:23:56 +00:00
if ( ! message . user && message . uuid === 'system' ) {
authorName = 'System Message' ;
} else {
2018-11-29 19:15:47 +00:00
authorName = formatUser ( {
name : message . username ,
displayName : message . user ,
email : authorEmail ,
uuid : message . uuid ,
} ) ;
2016-09-02 20:23:56 +00:00
}
2018-06-15 09:01:10 +00:00
const timestamp = ` ${ moment ( message . timestamp ) . utc ( ) . format ( 'YYYY-MM-DD HH:mm' ) } UTC ` ;
2020-11-30 19:03:04 +00:00
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.' ) ) ;
2016-08-27 03:12:23 +00:00
}
2018-06-02 17:27:28 +00:00
function sendInboxFlagNotification ( {
2020-12-13 17:15:19 +00:00
messageUserEmail ,
2018-06-02 17:27:28 +00:00
flagger ,
message ,
userComment ,
} ) {
if ( SKIP _FLAG _METHODS ) {
return ;
}
2019-10-08 14:57:10 +00:00
const titleLink = '' ;
const title = ` Flag in ${ flagger . profile . name } 's Inbox ` ;
2018-06-02 17:27:28 +00:00
let text = ` ${ flagger . profile . name } ( ${ flagger . id } ; language: ${ flagger . preferences . language } ) flagged a PM ` ;
2019-10-08 14:57:10 +00:00
const footer = '' ;
2018-06-02 17:27:28 +00:00
if ( userComment ) {
text += ` and commented: ${ userComment } ` ;
}
2019-10-08 14:57:10 +00:00
const messageText = message . text ;
2018-10-10 18:46:43 +00:00
let sender = '' ;
let recipient = '' ;
2018-06-02 17:27:28 +00:00
2018-11-29 19:15:47 +00:00
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 ,
2020-12-13 17:15:19 +00:00
email : messageUserEmail ,
2018-11-29 19:15:47 +00:00
uuid : message . uuid ,
} ) ;
2018-10-10 18:46:43 +00:00
if ( message . sent ) {
sender = flaggerFormat ;
recipient = messageUserFormat ;
2018-06-02 17:27:28 +00:00
} else {
2018-10-10 18:46:43 +00:00
sender = messageUserFormat ;
recipient = flaggerFormat ;
2018-06-02 17:27:28 +00:00
}
2019-10-10 18:11:50 +00:00
const authorName = ` ${ sender } wrote this message to ${ recipient } . ` ;
2018-10-10 18:46:43 +00:00
2020-11-30 19:03:04 +00:00
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.' ) ) ;
2018-06-02 17:27:28 +00:00
}
2023-10-24 14:24:56 +00:00
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' ,
] ,
} ] ,
} ) ;
}
2023-10-03 18:29:26 +00:00
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 \n Image URL: ${ flaggedUser . profile . imageUrl } ` ;
}
if ( flaggedUser . profile . blurb ) {
profileData += ` \n \n About: ${ 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.' ) ) ;
}
2016-12-09 02:08:56 +00:00
function sendSubscriptionNotification ( {
buyer ,
recipient ,
paymentMethod ,
months ,
2017-03-10 01:11:21 +00:00
groupId ,
2021-12-22 20:58:15 +00:00
autoRenews ,
2016-12-09 02:08:56 +00:00
} ) {
2018-06-02 16:14:53 +00:00
if ( SKIP _SUB _METHOD ) {
2016-12-09 02:08:56 +00:00
return ;
}
let text ;
2019-10-08 14:57:10 +00:00
const timestamp = new Date ( ) ;
2017-01-07 15:42:03 +00:00
if ( recipient . id ) {
2020-12-10 22:53:37 +00:00
const currentEvent = getCurrentEvent ( ) ;
2020-12-11 21:59:41 +00:00
const promoString = currentEvent && currentEvent . promo ? ' and got a promo' : '' ;
2020-12-10 22:53:37 +00:00
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 } ` ;
2017-03-10 01:11:21 +00:00
} else if ( groupId ) {
text = ` ${ buyer . name } ${ buyer . id } ${ buyer . email } bought a 1-month recurring group-plan for ${ groupId } using ${ paymentMethod } on ${ timestamp } ` ;
2021-12-22 20:58:15 +00:00
} else if ( autoRenews ) {
2017-01-07 15:42:03 +00:00
text = ` ${ buyer . name } ${ buyer . id } ${ buyer . email } bought a ${ months } -month recurring subscription using ${ paymentMethod } on ${ timestamp } ` ;
2021-12-22 20:58:15 +00:00
} else {
text = ` ${ buyer . name } ${ buyer . id } ${ buyer . email } bought a ${ months } -month non-recurring subscription using ${ paymentMethod } on ${ timestamp } ` ;
2016-12-09 02:08:56 +00:00
}
2020-11-30 19:03:04 +00:00
subscriptionSlack
. send ( {
text ,
} )
. catch ( err => logger . error ( err , 'Error while sending subscription data to Slack.' ) ) ;
2016-12-09 02:08:56 +00:00
}
2019-07-30 17:09:42 +00:00
function sendShadowMutedPostNotification ( {
authorEmail ,
author ,
group ,
message ,
} ) {
if ( SKIP _FLAG _METHODS ) {
return ;
}
2019-10-08 14:57:10 +00:00
const title = ` Shadow-Muted Post in ${ group . name } ` ;
const text = ` @ ${ author . auth . local . username } / ${ author . profile . name } posted while shadow-muted ` ;
2019-07-30 17:09:42 +00:00
2019-10-10 18:11:50 +00:00
let titleLink ;
2019-07-30 17:09:42 +00:00
if ( group . id === TAVERN _ID ) {
titleLink = ` ${ BASE _URL } /groups/tavern ` ;
} else {
titleLink = ` ${ BASE _URL } /groups/guild/ ${ group . id } ` ;
}
2019-10-10 18:11:50 +00:00
const authorName = formatUser ( {
2019-07-30 17:09:42 +00:00
name : author . auth . local . username ,
displayName : author . profile . name ,
email : authorEmail ,
uuid : author . id ,
} ) ;
2020-11-30 19:03:04 +00:00
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.' ) ) ;
2019-07-30 17:09:42 +00:00
}
2024-01-10 21:14:11 +00:00
// slack slur notification for Profiles
function sendProfileSlurNotification ( {
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
authorEmail ,
author ,
2024-01-10 21:14:11 +00:00
uuid ,
language ,
problemContent ,
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
} ) {
2018-06-02 16:14:53 +00:00
if ( SKIP _FLAG _METHODS ) {
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
return ;
}
2024-01-10 21:14:11 +00:00
const title = 'User Profile Report: Slur' ;
const titleLink = ` ${ BASE _URL } /profile/ ${ uuid } ` ;
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
2024-01-10 21:14:11 +00:00
const text = ` @ ${ author } ${ authorEmail } ( ${ uuid } , ${ language } ) tried to post a slur in their Profile. ` ;
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
2020-11-30 19:03:04 +00:00
flagSlack
. send ( {
text ,
attachments : [ {
fallback : 'Slur Message' ,
color : 'danger' ,
2024-01-10 21:14:11 +00:00
author _email : authorEmail ,
2020-11-30 19:03:04 +00:00
title ,
title _link : titleLink ,
2024-01-10 21:14:11 +00:00
text : problemContent ,
2020-11-30 19:03:04 +00:00
mrkdwn _in : [
'text' ,
] ,
} ] ,
} )
. catch ( err => logger . error ( err , 'Error while sending flag data to Slack.' ) ) ;
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
}
2024-01-16 20:22:03 +00:00
function sendChallengeSlurNotification ( {
authorEmail ,
author ,
language ,
problemContent ,
uuid ,
} ) {
if ( SKIP _FLAG _METHODS ) {
return ;
}
const text = ` ${ author . profile . name } ${ authorEmail } ( ${ uuid } , ${ language } ) tried to create a Challenge with a slur or banned word. ` ;
const authorName = formatUser ( {
name : author . auth . local . username ,
displayName : author . profile . name ,
email : authorEmail ,
uuid : author . id ,
language ,
} ) ;
flagSlack
. send ( {
text ,
attachments : [ {
fallback : 'Slur Message' ,
color : 'danger' ,
author _name : authorName ,
text : problemContent ,
mrkdwn _in : [
'text' ,
] ,
} ] ,
} )
. catch ( err => logger . error ( err , 'Error while sending flag data to Slack.' ) ) ;
}
2019-10-02 17:45:27 +00:00
export {
2018-06-02 16:14:53 +00:00
sendFlagNotification ,
2018-06-02 17:27:28 +00:00
sendInboxFlagNotification ,
2023-10-24 14:24:56 +00:00
sendChallengeFlagNotification ,
2023-10-03 18:29:26 +00:00
sendProfileFlagNotification ,
2018-06-02 16:14:53 +00:00
sendSubscriptionNotification ,
2019-07-30 17:09:42 +00:00
sendShadowMutedPostNotification ,
2024-01-10 21:14:11 +00:00
sendProfileSlurNotification ,
2024-01-16 20:22:03 +00:00
sendChallengeSlurNotification ,
2018-11-29 19:15:47 +00:00
formatUser ,
Automatically mute users who attempt to post a slur, fixes #8062 (#8177)
* Initial psuedo-code for checking for slurs in messages
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Fixing rebase
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* First attempt at the muteUser function: revokes user's chat privileges and notifies moderators
* Manual merge for cherry-pick
* Initial working prototype for blocking posting of slurs. Moved check from group.js to the chat api. Still needs: to permanently revoke chat privileges, to notify the moderators, a better method for checking for the blacklisted words, and a way to get the real list of words to check.
* Permanently revoke chat privileges when attempting to post a slur.
* Removed console logs
* Created report to be sent to moderators via email
* Do not moderate private groups
* Moved slur check to a generic check for banned words function
* Moved list of slurs to a separate file, fixed misplacement of return in ContainsBannedWords() function
* Slurs are blocked in both public and private groups
* Added code to send a slack message for slurs
* Fixed formatting issues
* Incorporated tectContainsBannedWords() function from PR 8197, added an argument to specify the list of banned words to check
* Added initial tests for blocking slurs and revoking chat priviliges
* Uncommented line to save revoked privileges
* Check that privileges are revoked in private groups
* Moved code to email/slack mods to chat api file
* Switched to BadRequest instead of NotFound error
* Restore chat privileges after test
* Using official placeholder slur
* Fixed line to export sendSubscriptionNotification function for slack
* Replaced muteUser function in user methods with a single line in the chat controller file
* Reset chatRevoked flag to false in a single line
* Switched method of setting chatRevoked flag so that it is updated locally and in the database
* Removed some code that got re-added after rebase
* Tests for automatic slur muting pass but are incomplete (do not check that chatRevoked flag is true)
* Moved list of banned slurs to server side
* Added warning to bannedSlurs file
* Test chat privileges revoked when posting slur in public chat
* Fix issues left over after rebase (I hope)
* Added code to test for revoked chat privileges after posting a slur in a private group
* Moved banned slur message into locales message
* Added new code to check for banned slurs (parallels banned words code)
* Fixed AUTHOR_MOTAL_URL in sendTxn for slur blocking
* Added tests that email sent on attempted slur in chat post
* Created context for slur-related-tests, fixed sandboxing of email. Successfully tests that email.sendTxn is called, but the email content test fails
* commented out slack (for now) and cleaned up tests of sending email
* Successfully tests that slur-report-to-mods email is sent
* Slack message is sent, and testing works, but some user variables seem to only work when found in chat.js and passed to slack
* Made some fixes for lint, but not sure what to do about the camel case requirement fail, since that's how they're defined in other slack calls
* Slack tests pass, skipped camelcase check around those code blocks
* Fixed InternalServerError caused by slack messaging
* Updated chat privileges revoked error
* fix(locale): typo correction
2017-07-19 21:06:15 +00:00
} ;