Reply message now returns how many abbreviations the bot detected
This commit is contained in:
parent
b5e60c2aa0
commit
cb02b331be
@ -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()
|
||||
|
@ -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()
|
||||
|
14
main.ts
14
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user