From: Matthieu Pignolet Date: Fri, 21 Jun 2024 14:25:46 +0000 (+0400) Subject: better sanitizing X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a3b83a8f5ce574a41b46dcc892b207a64dfb307c;p=matthieu%2Fgru.git better sanitizing --- diff --git a/discordjs/src/index.mjs b/discordjs/src/index.mjs index 6021b0c..1d5c81f 100644 --- a/discordjs/src/index.mjs +++ b/discordjs/src/index.mjs @@ -32,24 +32,30 @@ const sanitizeWord = (sentence) => { .trim() .split(" ") .slice(-1)[0] + .normalize('NFKD') + .replace(/[\u0300-\u036f]/g, "") + .replaceAll(/(?:https?|ftp):\/\/[\n\S]+/g, "") + .replaceAll(/\:([a-z]|[A-Z])+\:/g, "") .replaceAll(/(\?|\!|\.|\,|\;)/g, "") - .replaceAll(/(\s)?([^\x41-\x5A\s^\x61-\x7A^\xC0-\xFF])/g, "") - .replaceAll(/\<([a-z]|[A-Z])+\:([a-z]|[A-Z])+\:[0-9]+\>/g, "") - .replaceAll(/(?:https?|ftp):\/\/[\n\S]+/g, ''); + .replaceAll(/([^A-z])/g, ""); return lastWord; }; const re = /([a-z]|[A-Z])+/g; const countChars = (str) => ((str || '').match(re) || []).length; +const specialChannels = [ + "1248226018406301696" +] + const messageAction = async (message) => { if (message.author.bot) return; const cleanText = sanitizeWord(message.cleanContent); - if (countChars(cleanText) > 0) { let response = await completeWord(); // Ignore if there is no completion - if ((response || response === "") && (Math.random() > 0.98 || message.channelId == '1248226018406301696' || message.guild == null)) { + const shouldReply = (Math.random() > 0.98 || specialChannels.includes(message.channelId) || message.guild == null); + if ((response || response === "") && shouldReply) { message.reply(response); } }