Skip to content
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

Fix double post on modded servers #142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Added storage variable for previous Message.
Added function to filter double Messages
  • Loading branch information
tommywienert committed Apr 24, 2024
commit e009a2a627c01b2429266d7fa8d9ee3c9dd12681
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, "`$&`");
Expand All @@ -152,7 +167,7 @@ function sanitizeMsgFromGame(msg) {
msg = msg.replace(/https:\/\//g, "https\\://");
msg = msg.replace(/http:\/\//g, "http\\://");
}

msg = checkForDoubleMsg(msg)
return msg;
}

Expand Down