Fix issue 1
This commit is contained in:
parent
39528ce5a1
commit
cdb0689d23
@ -1 +1 @@
|
|||||||
{"target_phrases":{"idk":"I don't know","hoco":"homecoming","bbl":"be back later","bbg":"baby girl","mb":"my bad","mfw":"my face when","tfw":"that face when","ebr":"East Baton Rouge","ttyl":"talk to you later","abt":"about","ab":"about","dk":"don't know","prolly":"probably","tbh":"to be honest","smh":"shaking my head","btw":"by the way","ngl":"not gonna lie","fr":"for real","yessss":"yes","bc":"because","u":"you","thru":"through","lmao":"laughing my ass off","tldr":"too long; didn't read","ofc":"of course","linux":"GNU/Linux","xfl":"Extreme Football League","bi":"bisexual","abbr":"abbreviation","jk":"just kidding","gm":"good morning","mc":"Minecraft","nfl":"National Football League","ygd":"you're gonna die","gn":"goodnight","gac":"Great American Cookie","ncaa":"National Collegiate Athletic Association","em":"them","tbf":"to be fair","ppl":"people","bb":"baby","stfu":"shut the frick up","nvm":"nevermind","idc":"I don't care","dc":"don't care","ty":"thank you","yw":"you're welcome","lol":"laughing out loud","ok":"okay","sout":"System.out.println(\"\");","serr":"System.err.println(\"\");","psvm":"public static void main(String[] args) { }","rn":"right now","osjhs":"I made it up","trans":"transgender","js":"JavaScript","gc":"group chat","vc":"voice chat"}}
|
{"target_phrases":{"idk":"I don't know","hoco":"homecoming","bbl":"be back later","bbg":"baby girl","mb":"my bad","mfw":"my face when","tfw":"that face when","ebr":"East Baton Rouge","ttyl":"talk to you later","abt":"about","ab":"about","dk":"don't know","prolly":"probably","tbh":"to be honest","smh":"shaking my head","btw":"by the way","ngl":"not gonna lie","fr":"for real","yessss":"yes","bc":"because","u":"you","thru":"through","lmao":"laughing my ass off","tldr":"too long; didn't read","ofc":"of course","linux":"GNU/Linux","xfl":"Extreme Football League","bi":"bisexual","abbr":"abbreviation","jk":"just kidding","gm":"good morning","mc":"Minecraft","nfl":"National Football League","ygd":"you're gonna die","gn":"goodnight","gac":"Great American Cookie","ncaa":"National Collegiate Athletic Association","em":"them","tbf":"to be fair","ppl":"people","bb":"baby","stfu":"shut the frick up","nvm":"nevermind","idc":"I don't care","dc":"don't care","ty":"thank you","yw":"you're welcome","lol":"laughing out loud","sout":"System.out.println(\"\");","serr":"System.err.println(\"\");","psvm":"public static void main(String[] args) { }","rn":"right now","osjhs":"I made it up","trans":"transgender","js":"JavaScript","gc":"group chat","vc":"voice chat","ur":"your","gb":"great Britain"}}
|
2
key.json
2
key.json
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"token": "MTA5MTEyMDI2Nzg1MTQ4NTIxNQ.GUw1W5.SGkSWCfeyAs6cktoAhVE4ivkKAI5kGfhw-8wRc",
|
"token": "MTA5MTEyMDI2Nzg1MTQ4NTIxNQ.GUw1W5.SGkSWCfeyAs6cktoAhVE4ivkKAI5kGfhw-8wRc",
|
||||||
"clientId": "1091120267851485215",
|
"clientId": "1091120267851485215",
|
||||||
"guildId": "475327576110268466"
|
"guildId": "1009146338782490724"
|
||||||
}
|
}
|
33
main.cjs
33
main.cjs
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// Require the necessary discord.js classes
|
// Require the necessary discord.js classes
|
||||||
const { Client, Events, GatewayIntentBits, REST, Routes, Collection, FLAGS, MessageMentionOptions, codeBlock, SlashCommandBuilder } = require('discord.js');
|
const { Client, Events, GatewayIntentBits, REST, Routes, Collection, FLAGS, MessageMentionOptions, codeBlock, SlashCommandBuilder, blockQuote } = require('discord.js');
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const { clientId, guildId, token } = require('./key.json');
|
const { clientId, guildId, token } = require('./key.json');
|
||||||
let fs = require('node:fs');
|
let fs = require('node:fs');
|
||||||
@ -106,7 +106,7 @@ function replyMessage(message, correctedMessage, abbrsUsed) {
|
|||||||
} else {
|
} else {
|
||||||
plural = abbrsUsed + " acronyms"
|
plural = abbrsUsed + " acronyms"
|
||||||
}
|
}
|
||||||
var replyString = "Your message contains " + plural + "! Let me fix that for you: \n > " + correctedMessage + "\n \n \|\|btw I was written by Caleb Fontenot\|\|"
|
var replyString = "Your message contains " + plural + "! Let me fix that for you: \n"+ " \|\|btw I was written by Caleb Fontenot\|\| \n \n" + blockQuote(correctedMessage);
|
||||||
var stringLength = replyString.length;
|
var stringLength = replyString.length;
|
||||||
|
|
||||||
if (stringLength > 2000) {
|
if (stringLength > 2000) {
|
||||||
@ -128,6 +128,21 @@ client.on('messageUpdate', (undefined, newMessage) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getMatchingPhrase(inputString, targetCharacter) {
|
||||||
|
const words = inputString.split(/\s+/);
|
||||||
|
let matchingPhrase = null;
|
||||||
|
for (let i = 0; i < words.length; i++) {
|
||||||
|
const word = words[i];
|
||||||
|
if (word.includes(targetCharacter)) {
|
||||||
|
matchingPhrase = abbreviationKey.target_phrases[word];
|
||||||
|
if (matchingPhrase) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matchingPhrase;
|
||||||
|
}
|
||||||
|
|
||||||
global.checkMessage = function checkMessage(message, runFromGlobal) {
|
global.checkMessage = function checkMessage(message, runFromGlobal) {
|
||||||
if (!runFromGlobal) {
|
if (!runFromGlobal) {
|
||||||
checkInsult(message);
|
checkInsult(message);
|
||||||
@ -140,8 +155,8 @@ global.checkMessage = function checkMessage(message, runFromGlobal) {
|
|||||||
console.log(`${message.author.tag} in #${message.channel.name} sent: ${message.content}`);
|
console.log(`${message.author.tag} in #${message.channel.name} sent: ${message.content}`);
|
||||||
}
|
}
|
||||||
//console.log(message.author);
|
//console.log(message.author);
|
||||||
var matchMessageArray = message.content.toLowerCase().split(/[\‘\’\' ,!?\"@#$%^&*().;:|]+/);
|
var matchMessageArray = message.content.toLowerCase().split(/\W/g);
|
||||||
|
// /[\‘\’\' ,!?\"@#$%^&*().;:|]+/
|
||||||
console.log(matchMessageArray);
|
console.log(matchMessageArray);
|
||||||
let correctedMessage = message.content;
|
let correctedMessage = message.content;
|
||||||
let matchDetected = false;
|
let matchDetected = false;
|
||||||
@ -167,19 +182,23 @@ global.checkMessage = function checkMessage(message, runFromGlobal) {
|
|||||||
console.log("Found abbreviation: " + abbr);
|
console.log("Found abbreviation: " + abbr);
|
||||||
console.log("Phrase that matches used acronym: " + phrase);
|
console.log("Phrase that matches used acronym: " + phrase);
|
||||||
if (abbr !== "") {
|
if (abbr !== "") {
|
||||||
rebuildMessageArray = correctedMessage.split(new RegExp(abbr, 'i'));
|
// let regex = new RegExp(`^(.*?)${ '\\b' + abbr + '\\b'}`, 'i');
|
||||||
console.log("rebuildMessageArray: " + rebuildMessageArray);
|
let regex = new RegExp(`^((?:.*?\n)*?.*?)${ '\\b' + abbr + '\\b'}`, 'i');
|
||||||
|
rebuildMessageArray = correctedMessage.split(regex);
|
||||||
|
console.log("rebuildMessageArray: ", rebuildMessageArray);
|
||||||
} else {
|
} else {
|
||||||
message.reply("Detected abbreviation, but regex matching broke. Caleb is working on this...");
|
message.reply("Detected abbreviation, but regex matching broke. Caleb is working on this...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//https://gitea.calebfontenot.com/CCF_100/NoMoreAcronyms/issues/1
|
//https://gitea.calebfontenot.com/CCF_100/NoMoreAcronyms/issues/1
|
||||||
|
//Insert phrase into string
|
||||||
arrayRotate(rebuildMessageArray, true, 1);
|
arrayRotate(rebuildMessageArray, true, 1);
|
||||||
rebuildMessageArray.unshift("`" + phrase + "`");
|
rebuildMessageArray.unshift("`" + phrase + "`");
|
||||||
arrayRotate(rebuildMessageArray, true, 2);
|
arrayRotate(rebuildMessageArray, true, 2);
|
||||||
console.log(rebuildMessageArray);
|
console.log(rebuildMessageArray);
|
||||||
// Build into string and set to variable!
|
// Build into string and set to variable!
|
||||||
correctedMessage = ""; // clear old message.
|
correctedMessage = "" // clear old message.
|
||||||
|
|
||||||
for (let j = 0; j < rebuildMessageArray.length; j++) {
|
for (let j = 0; j < rebuildMessageArray.length; j++) {
|
||||||
correctedMessage += rebuildMessageArray[j];
|
correctedMessage += rebuildMessageArray[j];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user