diff options
| author | Matthieu Pignolet <matthieu@matthieu-dev.xyz> | 2024-06-06 12:55:49 +0400 |
|---|---|---|
| committer | Matthieu Pignolet <matthieu@matthieu-dev.xyz> | 2024-06-06 12:55:49 +0400 |
| commit | 76939f7e11dd032f32b47fe57d8075b87036880d (patch) | |
| tree | bf85e8d4dd50cca6a90fbabfeae86072db0daeca | |
| parent | 39ee647d01f898b3b08f78df85335092bf7da85a (diff) | |
update the probability algorithm
| -rw-r--r-- | discordjs/src/index.mjs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/discordjs/src/index.mjs b/discordjs/src/index.mjs index 0e41164..d9e70a2 100644 --- a/discordjs/src/index.mjs +++ b/discordjs/src/index.mjs @@ -36,22 +36,20 @@ const cutWord = (sentence) => { }; client.on("messageCreate", async (message) => { - // we shall not repond to bots - if (message.author.bot) return; - - if (Math.random() > 0.6) { - try { - // Get the completed word found by the db. - let response = await completeWord(cutWord(message.content)); - - // Ignore if there is no completion - if (response || response === "") { - message.reply(response); - } - } catch (e) { - console.log(e); - } + // we shall not repond to bots + if (message.author.bot) return; + + try { + // Get the completed word found by the db. + let response = await completeWord(cutWord(message.content)); + + // Ignore if there is no completion + if ((response || response === "") && Math.random() > 0.6) { + message.reply(response); } + } catch (e) { + console.log(e); + } }) client.login(process.env.TOKEN); |
