mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-15 20:15:11 +02:00
ignore: move ignorelist to its own command
ignorelist shares no logic with /ignore or /unignore so it shouldn't share a file. That just makes typing awkward.
This commit is contained in:
parent
5274fdc21a
commit
071a5afda6
|
@ -3,9 +3,8 @@ import Helper from "../../helper";
|
||||||
import {PluginInputHandler} from "./index";
|
import {PluginInputHandler} from "./index";
|
||||||
import {IgnoreListItem} from "../../models/network";
|
import {IgnoreListItem} from "../../models/network";
|
||||||
import {MessageType} from "../../../shared/types/msg";
|
import {MessageType} from "../../../shared/types/msg";
|
||||||
import {ChanType, SpecialChanType} from "../../../shared/types/chan";
|
|
||||||
|
|
||||||
const commands = ["ignore", "unignore", "ignorelist"];
|
const commands = ["ignore", "unignore"];
|
||||||
|
|
||||||
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
||||||
const client = this;
|
const client = this;
|
||||||
|
@ -104,54 +103,6 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
|
||||||
}\u000f from ignorelist`,
|
}\u000f from ignorelist`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "ignorelist": {
|
|
||||||
if (network.ignoreList.length === 0) {
|
|
||||||
chan.pushMessage(
|
|
||||||
client,
|
|
||||||
new Msg({
|
|
||||||
type: MessageType.ERROR,
|
|
||||||
text: "Ignorelist is empty",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const chanName = "Ignored users";
|
|
||||||
const ignored = network.ignoreList.map((data) => ({
|
|
||||||
hostmask: `${data.nick}!${data.ident}@${data.hostname}`,
|
|
||||||
when: data.when,
|
|
||||||
}));
|
|
||||||
let newChan = network.getChannel(chanName);
|
|
||||||
|
|
||||||
if (typeof newChan === "undefined") {
|
|
||||||
newChan = client.createChannel({
|
|
||||||
type: ChanType.SPECIAL,
|
|
||||||
special: SpecialChanType.IGNORELIST,
|
|
||||||
name: chanName,
|
|
||||||
data: ignored,
|
|
||||||
});
|
|
||||||
client.emit("join", {
|
|
||||||
network: network.uuid,
|
|
||||||
chan: newChan.getFilteredClone(true),
|
|
||||||
shouldOpen: false,
|
|
||||||
index: network.addChannel(newChan),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add type for this chan/event
|
|
||||||
newChan.data = ignored;
|
|
||||||
|
|
||||||
client.emit("msg:special", {
|
|
||||||
chan: newChan.id,
|
|
||||||
data: ignored,
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
57
server/plugins/inputs/ignorelist.ts
Normal file
57
server/plugins/inputs/ignorelist.ts
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import {PluginInputHandler} from "./index";
|
||||||
|
import Msg from "../../models/msg";
|
||||||
|
import {ChanType, SpecialChanType} from "../../../shared/types/chan";
|
||||||
|
import {MessageType} from "../../../shared/types/msg";
|
||||||
|
|
||||||
|
const commands = ["ignorelist"];
|
||||||
|
|
||||||
|
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
||||||
|
const client = this;
|
||||||
|
|
||||||
|
if (network.ignoreList.length === 0) {
|
||||||
|
chan.pushMessage(
|
||||||
|
client,
|
||||||
|
new Msg({
|
||||||
|
type: MessageType.ERROR,
|
||||||
|
text: "Ignorelist is empty",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chanName = "Ignored users";
|
||||||
|
const ignored = network.ignoreList.map((data) => ({
|
||||||
|
hostmask: `${data.nick}!${data.ident}@${data.hostname}`,
|
||||||
|
when: data.when,
|
||||||
|
}));
|
||||||
|
let newChan = network.getChannel(chanName);
|
||||||
|
|
||||||
|
if (typeof newChan === "undefined") {
|
||||||
|
newChan = client.createChannel({
|
||||||
|
type: ChanType.SPECIAL,
|
||||||
|
special: SpecialChanType.IGNORELIST,
|
||||||
|
name: chanName,
|
||||||
|
data: ignored,
|
||||||
|
});
|
||||||
|
client.emit("join", {
|
||||||
|
network: network.uuid,
|
||||||
|
chan: newChan.getFilteredClone(true),
|
||||||
|
shouldOpen: false,
|
||||||
|
index: network.addChannel(newChan),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add type for this chan/event
|
||||||
|
newChan.data = ignored;
|
||||||
|
|
||||||
|
client.emit("msg:special", {
|
||||||
|
chan: newChan.id,
|
||||||
|
data: ignored,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
commands,
|
||||||
|
input,
|
||||||
|
};
|
|
@ -54,6 +54,7 @@ const builtInInputs = [
|
||||||
"ctcp",
|
"ctcp",
|
||||||
"disconnect",
|
"disconnect",
|
||||||
"ignore",
|
"ignore",
|
||||||
|
"ignorelist",
|
||||||
"invite",
|
"invite",
|
||||||
"kick",
|
"kick",
|
||||||
"kill",
|
"kill",
|
||||||
|
|
Loading…
Reference in a new issue