Open Rafafrias2012 opened 4 months ago
To add a silent mute context menu and command, we need to make changes both on the frontend and backend. The frontend will handle the user interface and emit the command, while the backend will process the command and mute the user silently.
frontend/lib/jquery.contextMenu.min.js
Since this file is minified, we should locate the unminified version or the part of the codebase where the context menu is initialized. Assuming we have access to the unminified version, we will add the 'silent mute' option to the context menu.
frontend/script.js
We will add the 'silent mute' option to the context menu and emit a socket event to notify the backend when this option is selected.
$.contextMenu({
selector: this.selCanvas,
build: function (a, b) {
let menu = {
items: {
cancel: {
name: "Cancel",
callback: function () {
d.cancel();
},
},
// Other existing items...
}
};
// Add mod options to menu if king
if (authlevel >= 1) {
menu.items.mod = {
name: "Gamer Mod CMDs",
items: {
// Other mod options...
silentmute: {
name: "Silent Mute",
disabled: authlevel < 1.1,
callback: function () {
socket.emit("command", { list: ["silentmute", d.id] });
}
},
// Other mod options...
}
}
}
return menu;
},
animation: { duration: 175, show: "fadeIn", hide: "fadeOut" },
});
index.js
We will add the 'silentmute' command to the commands list and implement the logic to mute a user silently.
var commands = {
// Other commands...
silentmute: (victim, param) => {
if (victim.level < 1.1 || !victim.room.usersPublic[param]) return;
if (users[param].muted == 0) {
users[param].muted = 1; // Set the muted state to 1 (muted)
// Do not update the typing status or notify others in the room
} else if (users[param].muted == 1) {
users[param].muted = 0; // Unmute the user
// Do not update the typing status or notify others in the room
}
},
// Other commands...
};
// User object, with handlers and user data
class user {
constructor(socket) {
// Existing code...
// COMMAND HANDLER
this.socket.on("command", cmd => {
// parse and check
if (cmd.list[0] == undefined || this.muted != 0) return;
var comd = cmd.list[0];
var param = ""
if (cmd.list[1] == undefined) param = [""]
else {
param = cmd.list;
param.splice(0, 1);
}
param = param.join(" ");
// filter
if (typeof param !== 'string') return;
if (this.sanitize) param = param.replace(/</g, "<").replace(/>/g, ">").replace(/\[\[/g, "[[");
if (filtertext(param) && this.sanitize) return;
// carry it out
if (!this.slowed) {
if (commands[comd] !== undefined) commands[comd](this, param);
// Slowmode
this.slowed = true;
setTimeout(() => {
this.slowed = false;
}, config.slowmode)
}
});
// Existing code...
}
}
// Existing code...
Frontend:
Backend:
This ensures that the 'silent mute' functionality is integrated seamlessly into the application.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Hey @autopilot add a silent mute context menu and command?