From a5fcc273ca07787e856737a982bc5b19079442cf Mon Sep 17 00:00:00 2001 From: nodemixaholic Date: Mon, 25 Mar 2024 19:23:26 +0000 Subject: [PATCH] Upload files to '' --- index.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 5d755b7..93e1b2a 100644 --- a/index.js +++ b/index.js @@ -72,21 +72,10 @@ client.once('ready', () => { console.log('Bot is ready!'); }); -async function analyzeMessage(message) { - const result = await perspective.analyze(message.content); - if (result.toxicity > 0.93) { - // Take moderation action - message.delete(); - message.channel.send(`${message.author}, your message has been removed for toxicity.`); - } -} - // Discord.js event listener for when a message is received client.on('messageCreate', async message => { if (message.author.bot) return; - analyzeMessage(message) - // Increment XP every 10 messages if (message.guild) { const guildId = message.guild.id; @@ -102,6 +91,35 @@ client.on('messageCreate', async message => { } }); +client.on('messageCreate', async message => { + if (message.author.bot) { return; } + try { + const result = await perspective.analyze(message.content); + console.log(`TOXICITY [0-1]: ${result.attributeScores.TOXICITY.summaryScore.value}`) + if (message.member.permissions.has("ADMINISTRATOR")) { return; } + if (result.attributeScores.TOXICITY.summaryScore.value > 0.93) { + // Take moderation action + message.delete(); + message.channel.send(`${message.author}, your message has been removed for toxicity.`); + } + } catch {} +}) + +client.on('messageUpdate', async (oldMessage, newMessage) => { + if (newMessage.author.bot) { return; } + console.log(`${oldMessage} ==> ${newMessage}`) + try { + const result = await perspective.analyze(newMessage.content); + console.log(`UPDATED TOXICITY [0-1]: ${result.attributeScores.TOXICITY.summaryScore.value}`) + if (newMessage.member.permissions.has("ADMINISTRATOR")) { return; } + if (result.attributeScores.TOXICITY.summaryScore.value > 0.93) { + // Take moderation action + newMessage.delete(); + newMessage.channel.send(`${newMessage.author}, your message has been removed for toxicity.`); + } + } catch {} +}); + // Discord.js event listener for when a slash command is used client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return;