slack-deep-state
Advanced tools
Comparing version 1.0.1 to 1.2.0
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const RtmClient = require('@slack/client').RtmClient; | ||
@@ -7,3 +9,3 @@ const CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS; | ||
const botToken = process.env.SLACK_BOT_TOKEN || ''; | ||
if (!botToken) { console.log('Please set SLACK_BOT_TOKEN'); process.exit(-1); } | ||
if (!botToken) { console.error('error: Please set SLACK_BOT_TOKEN'); process.exit(-1); } | ||
@@ -14,9 +16,8 @@ const rtm = new RtmClient(botToken, {autoReconnect: false}); | ||
rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, function (rtmStartData) { | ||
console.log(`Logged in as ${rtmStartData.self.name} of team ${rtmStartData.team.name}`); | ||
console.error(`info: Logged in as ${rtmStartData.self.name} of team ${rtmStartData.team.name}`); | ||
rtm.on(RTM_EVENTS.MESSAGE, function (messageEvent) { | ||
if (messageEvent.subtype && messageEvent.subtype === 'message_deleted') { | ||
let message = censor(messageEvent.previous_message.text); | ||
rtm.sendMessage(message, messageEvent.channel); | ||
rtm.sendMessage(censor(messageEvent.previous_message.text), messageEvent.channel); | ||
} | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
function randomInt (min, max) { | ||
@@ -5,14 +7,37 @@ return Math.floor(Math.random() * (max - min)) + min; | ||
function getWordIndices (text) { | ||
let indices = []; | ||
for (let i = 0; i < text.length; i++) { | ||
if ((i-1 < 0 || /\s/.test(text[i-1])) && /\S/.test(text[i])) { | ||
indices.push(i); | ||
} | ||
} | ||
return indices; | ||
} | ||
function censor (text) { | ||
let words = text.split(' '); | ||
let numCensoredWords = randomInt(1, words.length); | ||
text = text.split(''); | ||
let wordIndices = getWordIndices(text); | ||
const numCensoredWords = randomInt(1, wordIndices.length); | ||
for (let i = 0; i < numCensoredWords; i++) { | ||
let censoredIndex = randomInt(0, words.length); | ||
words[censoredIndex] = new Array(words[censoredIndex].length).fill('█').join(''); | ||
let wordIndex = randomInt(0, wordIndices.length); | ||
let censorIndex = wordIndices[wordIndex]; | ||
while (text[censorIndex] && /\S/.test(text[censorIndex])) { | ||
text[censorIndex] = '█'; | ||
censorIndex++; | ||
} | ||
wordIndices.pop(wordIndex); | ||
} | ||
return words.join(' '); | ||
text = text.join(''); | ||
return text; | ||
} | ||
module.exports = censor; |
{ | ||
"name": "slack-deep-state", | ||
"version": "1.0.1", | ||
"description": "We know when you delete shit you worm", | ||
"version": "1.2.0", | ||
"bin": "./index.js", | ||
"description": "Reposts deleted slack messages with some words redacted", | ||
"main": "index.js", | ||
@@ -6,0 +7,0 @@ "scripts": { |
# slack-deep-state | ||
## Usage | ||
```bash | ||
SLACK_BOT_TOKEN=<token> node index.js | ||
``` |
@@ -0,8 +1,16 @@ | ||
'use strict'; | ||
const assert = require('chai').assert; | ||
const censor = require('../lib/censor'); | ||
function isCensored (word) { | ||
return word.split('').every(function (letter) { | ||
return letter === '█'; | ||
}); | ||
function countCensoredWords (text) { | ||
let count = 0; | ||
for (let i = 0; i < text.length; i++) { | ||
if ((i-1 < 0 || /\s/.test(text[i-1])) && /█/.test(text[i])) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
@@ -12,3 +20,3 @@ | ||
it('should always censor at least one word', function () { | ||
let texts = [ | ||
[ | ||
'hello', | ||
@@ -20,13 +28,6 @@ 'well hey', | ||
'elementary arithmetic can be carried out is incomplete' | ||
].join('') | ||
]; | ||
let censoredCounts = texts.map(function (text) { | ||
let censoredText = censor(text); | ||
return censoredText.split(' ').reduce(function (count, word) { | ||
return isCensored(word) ? count + 1 : count; | ||
}, 0); | ||
}); | ||
censoredCounts.forEach(function (count) { | ||
].join('\n') | ||
].map(function (text) { | ||
return countCensoredWords(censor(text)); | ||
}).forEach(function (count) { | ||
assert.isAbove(count, 0); | ||
@@ -33,0 +34,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3319
7
76
8