From e009a2a627c01b2429266d7fa8d9ee3c9dd12681 Mon Sep 17 00:00:00 2001 From: tommywienert Date: Wed, 24 Apr 2024 14:34:50 +0200 Subject: [PATCH 1/3] Added storage variable for previous Message. Added function to filter double Messages --- index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 826fb0e..e6bf86f 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,9 @@ var d7dtdState = { // We have to treat the channel ID as a string or the number will parse incorrectly. var argv = minimist(process.argv.slice(2), {string: ["channel","port"]}); +// cache previous Message to check for double messages +var previousMsg; + // This is a simple check to see if we're using arguments or the config file. // If the user is using arguments, config.json is ignored. var config; @@ -143,6 +146,18 @@ const configPrivate = { new DishordeInitializer(pjson, config, configPrivate); ////// # Functions # ////// +function checkForDoubleMsg(msg) { + if(msg == previousMsg) { + // Message was the same, so return nothing + msg = ""; + } + else { + // message differed, so this is the new cached message + previousMsg = msg; + } + return msg; +} + function sanitizeMsgFromGame(msg) { // Replace @everyone and @here msg = msg.replace(/@everyone|@here|<@.*>/g, "`$&`"); @@ -152,7 +167,7 @@ function sanitizeMsgFromGame(msg) { msg = msg.replace(/https:\/\//g, "https\\://"); msg = msg.replace(/http:\/\//g, "http\\://"); } - + msg = checkForDoubleMsg(msg) return msg; } From 7f82d302ed13f37ae8874252d7e6673236b1795e Mon Sep 17 00:00:00 2001 From: tommywienert Date: Wed, 24 Apr 2024 14:51:38 +0200 Subject: [PATCH 2/3] reset the cached message after a check to only filter double posts --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e6bf86f..958f752 100644 --- a/index.js +++ b/index.js @@ -151,10 +151,9 @@ function checkForDoubleMsg(msg) { // Message was the same, so return nothing msg = ""; } - else { - // message differed, so this is the new cached message - previousMsg = msg; - } + // set new cached message, either because it differed or + // to reset the msg so that only double posts are filtered + previousMsg = msg; return msg; } From 42571ab40b81a9d2ca18cf248ed45fa75a5c3cd0 Mon Sep 17 00:00:00 2001 From: tommywienert Date: Sat, 27 Apr 2024 22:20:18 +0200 Subject: [PATCH 3/3] add config option to define whether the server is modded or not. Add regex example for ServerTools mod (WIP). --- config.example.json | 1 + index.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/config.example.json b/config.example.json index e70fc88..00a2e62 100644 --- a/config.example.json +++ b/config.example.json @@ -22,6 +22,7 @@ "disable-status-updates": false, "disable-version-check": false, "hide-prefix": false, + "server-is-modded": false, "horde-frequency": "7", "log-console": false, "log-messages": false, diff --git a/index.js b/index.js index 958f752..78337d6 100644 --- a/index.js +++ b/index.js @@ -45,6 +45,7 @@ var argv = minimist(process.argv.slice(2), {string: ["channel","port"]}); // cache previous Message to check for double messages var previousMsg; +var reg = /\[.*\]\(.*\)\[-\]\[[a-fA-F\d]{3,6}\]([^[]+)\[-](: .+)/; // This is a simple check to see if we're using arguments or the config file. // If the user is using arguments, config.json is ignored. @@ -146,7 +147,24 @@ const configPrivate = { new DishordeInitializer(pjson, config, configPrivate); ////// # Functions # ////// +function ServerToolsRegex(msg) { + // Check for ServerTools color code prefix and remove it to + // align with normal messages + try { + let newMsg = msg.match(reg); + msg = newMsg[1] + newMsg[2]; + console.log(`regex matched, ${newMsg}`); + } + catch { + // regex did not match + console.log(`regex did not match`); + } + return msg; +} + function checkForDoubleMsg(msg) { + // Check for ServerTools + msg = ServerToolsRegex(msg); if(msg == previousMsg) { // Message was the same, so return nothing msg = ""; @@ -166,7 +184,9 @@ function sanitizeMsgFromGame(msg) { msg = msg.replace(/https:\/\//g, "https\\://"); msg = msg.replace(/http:\/\//g, "http\\://"); } - msg = checkForDoubleMsg(msg) + if(config["server-is-modded"]) { + msg = checkForDoubleMsg(msg); + } return msg; }