Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable denylist for tweet contents #438

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ module.exports = config = convict({
}
},
twitter: {
badWords: {
doc: 'Words the bot should never tweet',
format: String,
default: [
/* Racial slurs that might get output from owo() for @BBCBweaking
* (we only wish to block if it's a word the bot might generate
* for itself; other words have a chance of being newsworthy so
* we'll outsource the editorial judgement to the BBC and Reuters)
*/
'wog', 'wogs', 'wop', 'wops'
]
},
keys: {
consumerKey: {
doc: 'Twitter consumer key',
Expand Down
6 changes: 6 additions & 0 deletions modules/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ module.exports = {
const user = bot.config.get('twitter.tweetUser')
if (!user) return 'tweeting disabled'
bot.log('silly', 'Tweeting...')
if (bot.config.has('twitter.badWords')) {
const badTweet = bot.config.get('twitter.badWords').some((x) => {
msg.body.test(new RegExp(`\\b${x}\\b`))
})
if (badTweet) throw new Error('Word on denylist; not tweeting')
}
const tweet = await bot.tweet(user, { status: msg.body })
return 'https://twitter.com/statuses/' + tweet.id_str
}
Expand Down