From cb02b331be83d955ca83ec70fa695cda49cf0f43 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Sat, 1 Apr 2023 12:15:12 -0500 Subject: [PATCH] Reply message now returns how many abbreviations the bot detected --- commands/addPhrase.ts | 2 +- commands/removePhrase.ts | 2 +- main.ts | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/commands/addPhrase.ts b/commands/addPhrase.ts index 615dcdd..37ff897 100644 --- a/commands/addPhrase.ts +++ b/commands/addPhrase.ts @@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require('discord.js'); var abbreviationKey = require("../abbreviation_key.json"); const fs = require('node:fs'); var path = require('node:path');; -console.log(abbreviationKey); +//console.log(abbreviationKey); module.exports = { data: new SlashCommandBuilder() diff --git a/commands/removePhrase.ts b/commands/removePhrase.ts index c618099..b493575 100644 --- a/commands/removePhrase.ts +++ b/commands/removePhrase.ts @@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require('discord.js'); var abbreviationKey = require("../abbreviation_key.json"); const fs = require('node:fs'); var path = require('node:path');; -console.log(abbreviationKey); +//console.log(abbreviationKey); module.exports = { data: new SlashCommandBuilder() diff --git a/main.ts b/main.ts index 5457a38..96cb363 100644 --- a/main.ts +++ b/main.ts @@ -92,8 +92,14 @@ function matchAbbr(abbrTarget) { return ""; } -function replyMessage(message, correctedMessage) { - message.reply("Your message contains an acronym! Let me fix that for you: \n > " + correctedMessage); +function replyMessage(message, correctedMessage, abbrsUsed) { + var plural = ""; + if (abbrsUsed == 1) { + plural = "an acronym"; + } else { + plural = abbrsUsed + " acronyms" + } + message.reply("Your message contains " + plural +"! Let me fix that for you: \n > " + correctedMessage); } client.on('messageCreate', message => { @@ -109,11 +115,13 @@ client.on('messageCreate', message => { console.log(matchMessageArray); let correctedMessage = message.content; let matchDetected = false; + var abbrsUsed = 0; for (let i = 0; i < matchMessageArray.length; ++i) { var rebuildMessageArray = []; //console.log("Corrected Message: " + correctedMessage); if (abbreviationKey.target_phrases[matchMessageArray[i]] !== undefined) { matchDetected = true; + abbrsUsed++; //Return key var phrase = abbreviationKey.target_phrases[matchMessageArray[i]]; var abbr = matchAbbr(phrase); //abbreviationKey.target_phrases[phrase]; @@ -143,7 +151,7 @@ client.on('messageCreate', message => { } } if (matchDetected) { - replyMessage(message, correctedMessage); + replyMessage(message, correctedMessage, abbrsUsed); } }