First working build™️
This commit is contained in:
parent
01373c2b21
commit
557c136fce
@ -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);
|
console.log(abbrevation, phrase);
|
||||||
abbreviationKey.target_phrases[abbrevation] = phrase;
|
abbreviationKey.target_phrases[abbrevation] = phrase;
|
||||||
console.log(abbreviationKey);
|
console.log(abbreviationKey);
|
||||||
updatePhraseList();
|
|
||||||
|
|
||||||
// Write data to file
|
// Write data to file
|
||||||
var jsonString = JSON.stringify(abbreviationKey);
|
var jsonString = JSON.stringify(abbreviationKey);
|
||||||
|
55
main.ts
55
main.ts
@ -68,26 +68,61 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
// My code
|
// My code
|
||||||
|
|
||||||
var abbreviationKey = require("./abbreviation_key.json");
|
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 => {
|
client.on('messageCreate', message => {
|
||||||
console.log(`${message.author.tag} in #${message.channel.name} sent: ${message.content}`);
|
console.log(`${message.author.tag} in #${message.channel.name} sent: ${message.content}`);
|
||||||
if (message.author.bot) {
|
if (message.author.bot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var messageArray = message.content.toLowerCase().split(/[ ,!@#$%^&*()]+/);
|
var matchMessageArray = message.content.toLowerCase().split(/[ ,!@#$%^&*()]+/);
|
||||||
console.log(messageArray);
|
|
||||||
for (let i = 0; i < messageArray.length; ++i) {
|
console.log(matchMessageArray);
|
||||||
if (abbreviationKey.target_phrases[messageArray[i]] != undefined) {
|
|
||||||
console.log("Found an abbreviation!");
|
for (let i = 0; i < matchMessageArray.length; ++i) {
|
||||||
break;
|
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