Reply message now returns how many abbreviations the bot detected

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2023-04-01 12:15:12 -05:00
parent b5e60c2aa0
commit cb02b331be
3 changed files with 13 additions and 5 deletions

View File

@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require('discord.js');
var abbreviationKey = require("../abbreviation_key.json"); var abbreviationKey = require("../abbreviation_key.json");
const fs = require('node:fs'); const fs = require('node:fs');
var path = require('node:path');; var path = require('node:path');;
console.log(abbreviationKey); //console.log(abbreviationKey);
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()

View File

@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require('discord.js');
var abbreviationKey = require("../abbreviation_key.json"); var abbreviationKey = require("../abbreviation_key.json");
const fs = require('node:fs'); const fs = require('node:fs');
var path = require('node:path');; var path = require('node:path');;
console.log(abbreviationKey); //console.log(abbreviationKey);
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()

14
main.ts
View File

@ -92,8 +92,14 @@ function matchAbbr(abbrTarget) {
return ""; return "";
} }
function replyMessage(message, correctedMessage) { function replyMessage(message, correctedMessage, abbrsUsed) {
message.reply("Your message contains an acronym! Let me fix that for you: \n > " + correctedMessage); 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 => { client.on('messageCreate', message => {
@ -109,11 +115,13 @@ client.on('messageCreate', message => {
console.log(matchMessageArray); console.log(matchMessageArray);
let correctedMessage = message.content; let correctedMessage = message.content;
let matchDetected = false; let matchDetected = false;
var abbrsUsed = 0;
for (let i = 0; i < matchMessageArray.length; ++i) { for (let i = 0; i < matchMessageArray.length; ++i) {
var rebuildMessageArray = []; var rebuildMessageArray = [];
//console.log("Corrected Message: " + correctedMessage); //console.log("Corrected Message: " + correctedMessage);
if (abbreviationKey.target_phrases[matchMessageArray[i]] !== undefined) { if (abbreviationKey.target_phrases[matchMessageArray[i]] !== undefined) {
matchDetected = true; matchDetected = true;
abbrsUsed++;
//Return key //Return key
var phrase = abbreviationKey.target_phrases[matchMessageArray[i]]; var phrase = abbreviationKey.target_phrases[matchMessageArray[i]];
var abbr = matchAbbr(phrase); //abbreviationKey.target_phrases[phrase]; var abbr = matchAbbr(phrase); //abbreviationKey.target_phrases[phrase];
@ -143,7 +151,7 @@ client.on('messageCreate', message => {
} }
} }
if (matchDetected) { if (matchDetected) {
replyMessage(message, correctedMessage); replyMessage(message, correctedMessage, abbrsUsed);
} }
} }