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 826fb0e..78337d6 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,10 @@ 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; +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. var config; @@ -143,6 +147,34 @@ 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 = ""; + } + // set new cached message, either because it differed or + // to reset the msg so that only double posts are filtered + previousMsg = msg; + return msg; +} + function sanitizeMsgFromGame(msg) { // Replace @everyone and @here msg = msg.replace(/@everyone|@here|<@.*>/g, "`$&`"); @@ -152,7 +184,9 @@ function sanitizeMsgFromGame(msg) { msg = msg.replace(/https:\/\//g, "https\\://"); msg = msg.replace(/http:\/\//g, "http\\://"); } - + if(config["server-is-modded"]) { + msg = checkForDoubleMsg(msg); + } return msg; }