-
Notifications
You must be signed in to change notification settings - Fork 0
/
toxication.js
33 lines (30 loc) · 898 Bytes
/
toxication.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const {google} = require('googleapis');
API_KEY = 'AIzaSyDBT9j6-Ks5xuigiiOSJ0p5G6FJPLurCC8';
DISCOVERY_URL =
'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1';
module.exports = async(message) =>{
if(message.channel.name === "chatbot") return
google.discoverAPI(DISCOVERY_URL)
.then(client => {
const analyzeRequest = {
comment: {
text: message.content,
},
requestedAttributes: {
TOXICITY: {},
},
};
client.comments.analyze(
{
key: API_KEY,
resource: analyzeRequest,
},
async (err, response) => {
if (err) throw err;
let rate = response.data.attributeScores.TOXICITY.summaryScore.value
if(rate > 0.90){
return message.reply('Stop being toxic')
}
});
})
}