mirror of
https://github.com/thelounge/thelounge.git
synced 2024-05-15 20:56:36 +02:00
4be9a282fa
Co-authored-by: Reto <reto@labrat.space>
62 lines
1.2 KiB
JavaScript
62 lines
1.2 KiB
JavaScript
"use strict";
|
|
const Msg = require("../../models/msg");
|
|
|
|
exports.commands = ["mute", "unmute"];
|
|
|
|
function args_to_channels(network, args) {
|
|
const targets = [];
|
|
|
|
for (const arg of args) {
|
|
const target = network.channels.find((c) => c.name === arg);
|
|
|
|
if (target) {
|
|
targets.push(target);
|
|
}
|
|
}
|
|
|
|
return targets;
|
|
}
|
|
|
|
function change_mute_state(client, target, valueToSet) {
|
|
if (target.type === "special") {
|
|
return;
|
|
}
|
|
|
|
target.setMuteStatus(valueToSet);
|
|
client.emit("mute:changed", {
|
|
target: target.id,
|
|
status: valueToSet,
|
|
});
|
|
}
|
|
|
|
exports.input = function (network, chan, cmd, args) {
|
|
const valueToSet = cmd === "mute" ? true : false;
|
|
const client = this;
|
|
|
|
if (args.length === 0) {
|
|
change_mute_state(client, chan, valueToSet);
|
|
return;
|
|
}
|
|
|
|
const targets = args_to_channels(network, args);
|
|
|
|
if (targets.length !== args.length) {
|
|
const targetNames = targets.map((ch) => ch.name);
|
|
const missing = args.filter((x) => !targetNames.includes(x));
|
|
chan.pushMessage(
|
|
client,
|
|
new Msg({
|
|
type: Msg.Type.ERROR,
|
|
text: `No open ${
|
|
missing.length === 1 ? "channel or user" : "channels or users"
|
|
} found for ${missing.join(",")}`,
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
for (const target of targets) {
|
|
change_mute_state(client, target, valueToSet);
|
|
}
|
|
};
|