mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-01 21:32:17 +02:00
Merge edbc99915d
into da2572fe25
This commit is contained in:
commit
5427fb9b8a
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<span class="content">
|
<span class="content">
|
||||||
<p>
|
<p v-if="message.whois.nick">
|
||||||
<Username :user="{nick: message.whois.nick}" />
|
<Username :user="{nick: message.whois.nick}" />
|
||||||
<span v-if="message.whois.whowas"> is offline, last information:</span>
|
<span v-if="message.whois.whowas"> is offline, last information:</span>
|
||||||
</p>
|
</p>
|
||||||
|
@ -11,13 +11,15 @@
|
||||||
<dd>{{ message.whois.account }}</dd>
|
<dd>{{ message.whois.account }}</dd>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<dt>Host mask:</dt>
|
<template v-if="message.whois.ident && message.whois.hostname">
|
||||||
<dd class="hostmask">
|
<dt>Host mask:</dt>
|
||||||
<ParsedMessage
|
<dd class="hostmask">
|
||||||
:network="network"
|
<ParsedMessage
|
||||||
:text="message.whois.ident + '@' + message.whois.hostname"
|
:network="network"
|
||||||
/>
|
:text="message.whois.ident + '@' + message.whois.hostname"
|
||||||
</dd>
|
/>
|
||||||
|
</dd>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template v-if="message.whois.actual_hostname">
|
<template v-if="message.whois.actual_hostname">
|
||||||
<dt>Actual host:</dt>
|
<dt>Actual host:</dt>
|
||||||
|
|
|
@ -68,6 +68,7 @@ const builtInInputs = [
|
||||||
"raw",
|
"raw",
|
||||||
"rejoin",
|
"rejoin",
|
||||||
"topic",
|
"topic",
|
||||||
|
"who",
|
||||||
"whois",
|
"whois",
|
||||||
"mute",
|
"mute",
|
||||||
];
|
];
|
||||||
|
|
87
server/plugins/inputs/who.ts
Normal file
87
server/plugins/inputs/who.ts
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
import {ClientUser} from "../../../client/js/types";
|
||||||
|
import Msg, {MessageType} from "../../models/msg";
|
||||||
|
import {PluginInputHandler} from "./index";
|
||||||
|
|
||||||
|
const commands = ["who"];
|
||||||
|
|
||||||
|
const parseWhoxResponse = (user: ClientUser, args: string) => {
|
||||||
|
const parseFieldNameForLounge = (field: string) => {
|
||||||
|
switch (field) {
|
||||||
|
case "nickname":
|
||||||
|
return "nick";
|
||||||
|
case "username":
|
||||||
|
return "account";
|
||||||
|
case "realname":
|
||||||
|
return "real_name";
|
||||||
|
case "op":
|
||||||
|
return "operator";
|
||||||
|
default:
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const whoxFields = {
|
||||||
|
c: "channel",
|
||||||
|
u: "username",
|
||||||
|
h: "hostname",
|
||||||
|
s: "server",
|
||||||
|
n: "nickname",
|
||||||
|
f: "flags",
|
||||||
|
a: "account",
|
||||||
|
r: "realname",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!args) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredResponse = {};
|
||||||
|
|
||||||
|
for (const [token, fieldName] of Object.entries(whoxFields)) {
|
||||||
|
// TODO: throw on unknown field?
|
||||||
|
if (args.includes(token)) {
|
||||||
|
const expectedField = parseFieldNameForLounge(fieldName);
|
||||||
|
filteredResponse[expectedField] = user[expectedField];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredResponse;
|
||||||
|
};
|
||||||
|
|
||||||
|
const input: PluginInputHandler = function ({irc}, chan, cmd, args) {
|
||||||
|
if (args.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We use the callback instead of listening for `wholist` because
|
||||||
|
// irc-framework doesn't support filtering WHOX.
|
||||||
|
// This has the added benefit of easily showing it in the same buffer
|
||||||
|
// as the WHO command.
|
||||||
|
irc.who(args[0], (event) => {
|
||||||
|
if (!event.users.length) {
|
||||||
|
chan.pushMessage(
|
||||||
|
this,
|
||||||
|
new Msg({
|
||||||
|
type: MessageType.ERROR,
|
||||||
|
text: `The server returned no matching users for ${args[0]}`,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of event.users) {
|
||||||
|
const filteredResponse = parseWhoxResponse(user, args[1]);
|
||||||
|
chan.pushMessage(
|
||||||
|
this,
|
||||||
|
new Msg({
|
||||||
|
type: MessageType.WHOIS,
|
||||||
|
whois: filteredResponse,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
commands,
|
||||||
|
input,
|
||||||
|
};
|
Loading…
Reference in a new issue