]> git.puffer.fish Git - matthieu/gru.git/commitdiff
fix wrong sanitization
authorMatthieu Pignolet <m@mpgn.dev>
Thu, 30 Jan 2025 15:03:29 +0000 (19:03 +0400)
committerMatthieu Pignolet <m@mpgn.dev>
Thu, 30 Jan 2025 15:03:29 +0000 (19:03 +0400)
discordjs/src/index.mjs

index f0a4bae73d814f05668c0d2b12d55e7f1234a60b..589d75ad9b0d17092fef2cb1fb857bf0e1851317 100644 (file)
@@ -7,13 +7,14 @@ const SYMBOL_FOR_CREATE = Symbol.for("CREATE");
 const SYMBOL_FOR_UPDATE = Symbol.for("UPDATE");
 
 // Create a new client instance
-const client = new Client({ intents:
-  [
-    GatewayIntentBits.Guilds,
-    GatewayIntentBits.MessageContent,
-    GatewayIntentBits.GuildMessages,
-    GatewayIntentBits.DirectMessages
-  ]
+const client = new Client({
+  intents:
+    [
+      GatewayIntentBits.Guilds,
+      GatewayIntentBits.MessageContent,
+      GatewayIntentBits.GuildMessages,
+      GatewayIntentBits.DirectMessages
+    ]
 });
 
 // `autofeur_db` service
@@ -40,13 +41,13 @@ export const completeWord = (grapheme) => {
  */
 const sanitizeWord = (sentence) => {
   let lastWord = sentence
-    .trim()
-    .split(" ")
-    .slice(-1)[0]
     .replaceAll(/(?:https?|ftp):\/\/[\n\S]+/g, "")
     .replaceAll(/\:([a-z]|[A-Z])+\:/g, "")
     .replaceAll(/(\?|\!|\.|\,|\;)/g, "")
-    .replaceAll(/([^A-z])/g, "");
+    .replaceAll(/([^A-z])/g, "")
+    .trim()
+    .split(" ")
+    .slice(-1)[0];
   return lastWord;
 };
 const anyTrivialCharRegex = /([a-z]|[A-Z])+/g;
@@ -74,11 +75,11 @@ const messageAction = async (message, ctx) => {
     .messages
     .fetch({
       limit: 2,
-      cache : false
+      cache: false
     }))
     .last()
     .createdTimestamp;
-  
+
   let shouldReplyByTimestamp = currentTimestamp - lastMessageTimestamp >= 3600000;
   let shouldReplyByCounter =
     messageReplyCounter >= Math.floor(Math.random() * 75) + 35;
@@ -107,7 +108,7 @@ const messageAction = async (message, ctx) => {
       messageReplyCounter = oldCounter;
     }
   }
-  
+
   if (message.content.includes("@everyone") && !ignoredChannels.includes(message.channelId)) {
     message.reply("https://cdn.mpgn.dev/pascontent-gabe.gif");
   }