First working build™️
This commit is contained in:
parent
b586bc8167
commit
37b411a025
@ -1 +1 @@
|
||||
{"target_phrases":{"test":"test2","test3":"test4","test5":"test6"}}
|
||||
{"target_phrases":{"idk":"I don't know", "hoco":"homecoming","bbl":"be back later","bbg":"baby girl","mb":"my bad", "mfw":"my face when"}}
|
@ -30,7 +30,6 @@ function addPhrase(abbrevation, phrase) {
|
||||
console.log(abbrevation, phrase);
|
||||
abbreviationKey.target_phrases[abbrevation] = phrase;
|
||||
console.log(abbreviationKey);
|
||||
updatePhraseList();
|
||||
|
||||
// Write data to file
|
||||
var jsonString = JSON.stringify(abbreviationKey);
|
||||
|
55
main.ts
55
main.ts
@ -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]]);
|
||||
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user