I'm currently making a discord.js bot that helps with auto-moderation using perspective API. After making the API calls to perspective's API, I then sort through each "attribute". The problem is I'm left with this sort of thing:
However, I am not sure how I would sort it by the summaryScore.value
, and then also get the top result from that. Any help is appreciated! Here is my current code:
try {
google.discoverAPI(DISCOVERY_URL)
.then(client => {
const analyzeRequest = {
comment: {
text: message.content,
},
requestedAttributes: {
SEVERE_TOXICITY: {
scoreThreshold: 0.85,
},
IDENTITY_ATTACK: {
scoreThreshold: 0.85,
},
THREAT: {
scoreThreshold: 0.85,
},
INSULT: {
scoreThreshold: 0.85,
},
PROFANITY: {
scoreThreshold: 0.85,
},
FLIRTATION: {
scoreThreshold: 0.85,
},
SEXUALLY_EXPLICIT: {
scoreThreshold: 0.85,
},
INCOHERENT: {
scoreThreshold: 0.85,
},
INFLAMMATORY: {
scoreThreshold: 0.85,
},
SPAM: {
scoreThreshold: 0.85,
},
},
languages: ['en'],
};
client.comments.analyze({
key: API_KEY,
resource: analyzeRequest,
},
(err, response) => {
if (err) console.log(err);
else {
complete = false;
if (response.data.attributeScores) {
var array = [response.data.attributeScores]
for (const attributeScore of array) {
console.log(attributeScore)
if (attributeScore.name.summaryScore.value > 0.85) {
message.reply(`your message has been removed for: "${attributeScore.name}".`)
message.delete()
}
}
}
}
});
})
.catch(err => {
console.log(err);
});
} catch (err) {
}
Thank you so much! Any help is appreciated! I am new-ish to javascript so I apologize if it's a simple answer.