Skip to content

Commit

Permalink
ignore: move ignorelist to its own command
Browse files Browse the repository at this point in the history
ignorelist shares no logic with /ignore or /unignore so it shouldn't
share a file. That just makes typing awkward.
  • Loading branch information
brunnre8 committed Apr 14, 2024
1 parent cdbdeb9 commit 8ddd8de
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 50 deletions.
51 changes: 1 addition & 50 deletions server/plugins/inputs/ignore.ts
Expand Up @@ -3,9 +3,8 @@ import Helper from "../../helper";
import {PluginInputHandler} from "./index";
import {IgnoreListItem} from "../../models/network";
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 client = this;
Expand Down Expand Up @@ -104,54 +103,6 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
}\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;
}
}
};
Expand Down
57 changes: 57 additions & 0 deletions server/plugins/inputs/ignorelist.ts
@@ -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,
};
1 change: 1 addition & 0 deletions server/plugins/inputs/index.ts
Expand Up @@ -54,6 +54,7 @@ const builtInInputs = [
"ctcp",
"disconnect",
"ignore",
"ignorelist",
"invite",
"kick",
"kill",
Expand Down

0 comments on commit 8ddd8de

Please sign in to comment.