Skip to content

Fix double post on modded servers #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 35 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, "`$&`");
Expand All @@ -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;
}

Expand Down