diff options
| author | Matthieu Pignolet <matthieu@matthieu-dev.xyz> | 2024-06-21 18:25:46 +0400 | 
|---|---|---|
| committer | Matthieu Pignolet <matthieu@matthieu-dev.xyz> | 2024-06-21 18:25:46 +0400 | 
| commit | a3b83a8f5ce574a41b46dcc892b207a64dfb307c (patch) | |
| tree | 4288aee4b7be0a198ee40776dc0e8d4e5faab0e9 /discordjs | |
| parent | 14acfd4476809cc6dc9894c27ac6f03e7972ebc4 (diff) | |
better sanitizing
Diffstat (limited to 'discordjs')
| -rw-r--r-- | discordjs/src/index.mjs | 16 | 
1 files changed, 11 insertions, 5 deletions
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);      }    }  | 
