mirror of
https://github.com/thelounge/thelounge
synced 2024-11-21 19:43:07 +00:00
ignore: clean up the types and conditionals
Now that ignorelist doesn't muddy the waters, we can clean up all the funny conditional types and enforce `when`
This commit is contained in:
parent
071a5afda6
commit
b8400a3a46
2 changed files with 13 additions and 21 deletions
|
@ -45,7 +45,7 @@ type NetworkStatus = {
|
|||
};
|
||||
|
||||
export type IgnoreListItem = Hostmask & {
|
||||
when?: number;
|
||||
when: number;
|
||||
};
|
||||
|
||||
type IgnoreList = IgnoreListItem[];
|
||||
|
|
|
@ -8,11 +8,8 @@ const commands = ["ignore", "unignore"];
|
|||
|
||||
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
||||
const client = this;
|
||||
let target: string;
|
||||
// let hostmask: cmd === "ignoreList" ? string : undefined;
|
||||
let hostmask: IgnoreListItem | undefined;
|
||||
|
||||
if (cmd !== "ignorelist" && (args.length === 0 || args[0].trim().length === 0)) {
|
||||
if (args.length === 0 || args[0].trim().length === 0) {
|
||||
chan.pushMessage(
|
||||
client,
|
||||
new Msg({
|
||||
|
@ -24,16 +21,13 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (cmd !== "ignorelist") {
|
||||
// Trim to remove any spaces from the hostmask
|
||||
target = args[0].trim();
|
||||
hostmask = Helper.parseHostmask(target) as IgnoreListItem;
|
||||
}
|
||||
const target = args[0].trim();
|
||||
const hostmask = Helper.parseHostmask(target);
|
||||
|
||||
switch (cmd) {
|
||||
case "ignore": {
|
||||
// IRC nicks are case insensitive
|
||||
if (hostmask!.nick.toLowerCase() === network.nick.toLowerCase()) {
|
||||
if (hostmask.nick.toLowerCase() === network.nick.toLowerCase()) {
|
||||
chan.pushMessage(
|
||||
client,
|
||||
new Msg({
|
||||
|
@ -46,7 +40,7 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
|
|||
|
||||
if (
|
||||
network.ignoreList.some(function (entry) {
|
||||
return Helper.compareHostmask(entry, hostmask!);
|
||||
return Helper.compareHostmask(entry, hostmask);
|
||||
})
|
||||
) {
|
||||
chan.pushMessage(
|
||||
|
@ -59,17 +53,17 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
|
|||
return;
|
||||
}
|
||||
|
||||
hostmask!.when = Date.now();
|
||||
network.ignoreList.push(hostmask!);
|
||||
network.ignoreList.push({
|
||||
...hostmask,
|
||||
when: Date.now(),
|
||||
});
|
||||
|
||||
client.save();
|
||||
chan.pushMessage(
|
||||
client,
|
||||
new Msg({
|
||||
type: MessageType.ERROR, // TODO: Successfully added via type.Error 🤔 ?
|
||||
text: `\u0002${hostmask!.nick}!${hostmask!.ident}@${
|
||||
hostmask!.hostname
|
||||
}\u000f added to ignorelist`,
|
||||
text: `\u0002${hostmask.nick}!${hostmask.ident}@${hostmask.hostname}\u000f added to ignorelist`,
|
||||
})
|
||||
);
|
||||
return;
|
||||
|
@ -77,7 +71,7 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
|
|||
|
||||
case "unignore": {
|
||||
const idx = network.ignoreList.findIndex(function (entry) {
|
||||
return Helper.compareHostmask(entry, hostmask!);
|
||||
return Helper.compareHostmask(entry, hostmask);
|
||||
});
|
||||
|
||||
if (idx === -1) {
|
||||
|
@ -98,9 +92,7 @@ const input: PluginInputHandler = function (network, chan, cmd, args) {
|
|||
client,
|
||||
new Msg({
|
||||
type: MessageType.ERROR, // TODO: Successfully removed via type.Error 🤔 ?
|
||||
text: `Successfully removed \u0002${hostmask!.nick}!${hostmask!.ident}@${
|
||||
hostmask!.hostname
|
||||
}\u000f from ignorelist`,
|
||||
text: `Successfully removed \u0002${hostmask.nick}!${hostmask.ident}@${hostmask.hostname}\u000f from ignorelist`,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue