]> git.puffer.fish Git - matthieu/gru.git/commitdiff
change response algorithm
authorMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Tue, 9 Jul 2024 10:21:58 +0000 (14:21 +0400)
committerMatthieu Pignolet <matthieu@matthieu-dev.xyz>
Tue, 9 Jul 2024 10:21:58 +0000 (14:21 +0400)
discordjs/src/index.mjs

index 354d651c58208c87e93419879b14946859b06138..9a37a1f5fcaa84e782fe5ca43168f77ace3ae4f2 100644 (file)
@@ -47,20 +47,29 @@ const specialChannels = [
   "1248226018406301696"
 ]
 
+let counter = 0;
 const messageAction = async (message) => {
   if (message.author.bot) return;
-  const cleanText = sanitizeWord(message.cleanContent);
-  if (countChars(cleanText) > 0) {
-    let response = await completeWord(cleanText);
 
-    // Ignore if there is no completion
-    const shouldReply = (Math.random() > 0.995 || specialChannels.includes(message.channelId) || message.guild == null);
-    if ((response || response === "") && shouldReply) {
-      message.reply(response);
+  counter += 1;
+
+  let shouldReply = (counter >= 75 || specialChannels.includes(message.channelId) || message.guild == null);
+
+  if (shouldReply) {
+    const cleanText = sanitizeWord(message.cleanContent);
+    if (countChars(cleanText) > 0) {
+      let response = await completeWord(cleanText);
+
+      // Ignore if there is no completion
+      if ((response || response === "")) {
+        message.reply(response);
+        counter = 0;
+      }
     }
   }
 
-  if ((message.content.includes("@everyone") && message.guild.id === "1055126989566124083") || specialChannels.includes(message.channelId)) {
+  let isEveryone = message.cleanContent.includes("@everyone") && message.guild.id === "1055126989566124083";
+  if (isEveryone) {
     message.reply("https://cdn.mpgn.dev/pascontent-gabe.gif");
   }
 };