mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-20 22:45:11 +02:00
Remove whois irc-event event handler, send whois/whowas response to current buffer
This commit is contained in:
parent
57ed37c1fd
commit
a38096c752
|
@ -47,7 +47,6 @@ const events = [
|
||||||
"sasl",
|
"sasl",
|
||||||
"topic",
|
"topic",
|
||||||
"welcome",
|
"welcome",
|
||||||
"whois",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
type ClientPushSubscription = {
|
type ClientPushSubscription = {
|
||||||
|
|
|
@ -1,16 +1,76 @@
|
||||||
|
import Msg, {MessageType} from "../../models/msg";
|
||||||
import {PluginInputHandler} from "./index";
|
import {PluginInputHandler} from "./index";
|
||||||
|
|
||||||
const commands = ["whois"];
|
const commands = ["whois"];
|
||||||
|
|
||||||
|
type DataError = {
|
||||||
|
error: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type DataToSend = {
|
||||||
|
whowas: string;
|
||||||
|
idleTime: number;
|
||||||
|
logonTime: number;
|
||||||
|
logon: number;
|
||||||
|
idle: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isDataError = (data: any): data is DataError => {
|
||||||
|
return data.error !== undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isDataToSend = (data: any): data is DataToSend => {
|
||||||
|
return !isDataError(data);
|
||||||
|
};
|
||||||
|
|
||||||
const input: PluginInputHandler = function ({irc}, chan, cmd, args) {
|
const input: PluginInputHandler = function ({irc}, chan, cmd, args) {
|
||||||
if (args.length === 1) {
|
const client = this;
|
||||||
// This queries server of the other user and not of the current user, which
|
const target = args[0];
|
||||||
// does not know idle time.
|
const targetNick = args[1] ? args[1] : target;
|
||||||
// See http://superuser.com/a/272069/208074.
|
|
||||||
irc.raw("WHOIS", args[0], args[0]);
|
const sendToClient = (data: DataError | DataToSend) => {
|
||||||
} else {
|
if (!isDataToSend(data)) {
|
||||||
// Re-assembling the command parsed in client.js
|
chan.pushMessage(
|
||||||
irc.raw(`${cmd} ${args.join(" ")}`);
|
client,
|
||||||
|
new Msg({
|
||||||
|
type: MessageType.ERROR,
|
||||||
|
error: data.error,
|
||||||
|
nick: targetNick,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Absolute datetime in milliseconds since nick is idle
|
||||||
|
data.idleTime = Date.now() - data.idle * 1000;
|
||||||
|
// Absolute datetime in milliseconds when nick logged on.
|
||||||
|
data.logonTime = data.logon * 1000;
|
||||||
|
chan.pushMessage(
|
||||||
|
client,
|
||||||
|
new Msg({
|
||||||
|
type: MessageType.WHOIS,
|
||||||
|
whois: data,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
sendToClient({
|
||||||
|
error: `/${cmd} needs a target nick`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case "whois":
|
||||||
|
// @ts-ignore
|
||||||
|
irc.whois(target, targetNick, sendToClient);
|
||||||
|
break;
|
||||||
|
case "whowas":
|
||||||
|
irc.whowas(target, (data: any) => {
|
||||||
|
data.whowas = true;
|
||||||
|
sendToClient(data);
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
import {IrcEventHandler} from "../../client";
|
|
||||||
import {ChanType} from "../../models/chan";
|
|
||||||
|
|
||||||
import Msg, {MessageType} from "../../models/msg";
|
|
||||||
|
|
||||||
export default <IrcEventHandler>function (irc, network) {
|
|
||||||
const client = this;
|
|
||||||
|
|
||||||
irc.on("whois", handleWhois);
|
|
||||||
|
|
||||||
irc.on("whowas", (data) => {
|
|
||||||
data.whowas = true;
|
|
||||||
|
|
||||||
handleWhois(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleWhois(data) {
|
|
||||||
let chan = network.getChannel(data.nick);
|
|
||||||
|
|
||||||
if (typeof chan === "undefined") {
|
|
||||||
// Do not create new windows for errors as they may contain illegal characters
|
|
||||||
if (data.error) {
|
|
||||||
chan = network.channels[0];
|
|
||||||
} else {
|
|
||||||
chan = client.createChannel({
|
|
||||||
type: ChanType.QUERY,
|
|
||||||
name: data.nick,
|
|
||||||
});
|
|
||||||
|
|
||||||
client.emit("join", {
|
|
||||||
shouldOpen: true,
|
|
||||||
network: network.uuid,
|
|
||||||
chan: chan.getFilteredClone(true),
|
|
||||||
index: network.addChannel(chan),
|
|
||||||
});
|
|
||||||
chan.loadMessages(client, network);
|
|
||||||
client.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let msg;
|
|
||||||
|
|
||||||
if (data.error) {
|
|
||||||
msg = new Msg({
|
|
||||||
type: MessageType.ERROR,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
||||||
text: "No such nick: " + data.nick,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Absolute datetime in milliseconds since nick is idle
|
|
||||||
data.idleTime = Date.now() - data.idle * 1000;
|
|
||||||
// Absolute datetime in milliseconds when nick logged on.
|
|
||||||
data.logonTime = data.logon * 1000;
|
|
||||||
msg = new Msg({
|
|
||||||
type: MessageType.WHOIS,
|
|
||||||
whois: data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
chan.pushMessage(client, msg);
|
|
||||||
}
|
|
||||||
};
|
|
Loading…
Reference in a new issue