|
|
|
@ -68,26 +68,61 @@ client.on(Events.InteractionCreate, async interaction => {
|
|
|
|
|
// My code
|
|
|
|
|
|
|
|
|
|
var abbreviationKey = require("./abbreviation_key.json");
|
|
|
|
|
function updatePhraseList() {
|
|
|
|
|
abbreviationKey = require("./abbreviation_key.json");
|
|
|
|
|
|
|
|
|
|
function arrayRotate(arr, reverse, amount) {
|
|
|
|
|
for (var i = 0; i < amount; i++) {
|
|
|
|
|
if (reverse) arr.unshift(arr.pop());
|
|
|
|
|
else arr.push(arr.shift());
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function matchAbbr(abbrTarget) {
|
|
|
|
|
for (var abbr in abbreviationKey.target_phrases) {
|
|
|
|
|
if (abbreviationKey.target_phrases[abbr] === abbrTarget) {
|
|
|
|
|
return abbr;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replyMessage(message, correctedMessage) {
|
|
|
|
|
message.reply("Your message contains an acronym! Let me fix that for you: \n `" + correctedMessage + "1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.on('messageCreate', message => {
|
|
|
|
|
console.log(`${message.author.tag} in #${message.channel.name} sent: ${message.content}`);
|
|
|
|
|
if (message.author.bot) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var messageArray = message.content.toLowerCase().split(/[ ,!@#$%^&*()]+/);
|
|
|
|
|
console.log(messageArray);
|
|
|
|
|
for (let i = 0; i < messageArray.length; ++i) {
|
|
|
|
|
if (abbreviationKey.target_phrases[messageArray[i]] != undefined) {
|
|
|
|
|
console.log("Found an abbreviation!");
|
|
|
|
|
break;
|
|
|
|
|
var matchMessageArray = message.content.toLowerCase().split(/[ ,!@#$%^&*()]+/);
|
|
|
|
|
|
|
|
|
|
console.log(matchMessageArray);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < matchMessageArray.length; ++i) {
|
|
|
|
|
if (abbreviationKey.target_phrases[matchMessageArray[i]] !== undefined) {
|
|
|
|
|
//Return key
|
|
|
|
|
var phrase = abbreviationKey.target_phrases[matchMessageArray[i]];
|
|
|
|
|
var abbr = matchAbbr(phrase);
|
|
|
|
|
|
|
|
|
|
console.log("Found abbreviation: " + abbr);
|
|
|
|
|
console.log("Phrase that matches used acronym: " + phrase);
|
|
|
|
|
var rebuildMessageArray = message.content.split(new RegExp(abbr, 'i'));
|
|
|
|
|
arrayRotate(rebuildMessageArray, true, 1);
|
|
|
|
|
rebuildMessageArray.unshift(phrase);
|
|
|
|
|
arrayRotate(rebuildMessageArray, true, 2);
|
|
|
|
|
console.log(rebuildMessageArray);
|
|
|
|
|
// Build into string and set to variable!
|
|
|
|
|
var correctedMessage = "";
|
|
|
|
|
for (let j = 0; j < rebuildMessageArray.length; j++) {
|
|
|
|
|
correctedMessage += rebuildMessageArray[j];
|
|
|
|
|
}
|
|
|
|
|
console.log(correctedMessage);
|
|
|
|
|
replyMessage(message, correctedMessage);
|
|
|
|
|
//break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
message.reply("Your message contains an acronym. Here's what your message would say without it: \n " + "");
|
|
|
|
|
console.log(abbreviationKey.target_phrases[messageArray[0]]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|