mirror of
https://github.com/thelounge/thelounge.git
synced 2026-07-31 23:25:50 -04:00
Relies on https://github.com/kiwiirc/irc-framework/pull/411 https://ircv3.net/specs/client-tags/reply.html Design feedback very welcome <img width="1718" height="278" alt="Screenshot 2026-04-11 at 21-00-22 #thelounge — The Lounge" src="https://github.com/user-attachments/assets/ba6e7c69-2477-4a7b-b196-901d19ca9cba" /> 1. we lack a 'thread' view (irccloud, slack, etc). can be a followup if we do want it 2. need to test scrolling to messages outside of the current buffer 3. due to lack of client support, i opted to auto prefill the input with \`<targetNick>: \` so people can follow along even without reply support 4. CSS can definitely be improved (once a design is settled on) --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
134 lines
3.0 KiB
TypeScript
134 lines
3.0 KiB
TypeScript
import {PluginInputHandler} from "./index";
|
|
import Msg from "../../models/msg";
|
|
import Chan from "../../models/chan";
|
|
import {MessageType} from "../../../shared/types/msg";
|
|
import {ChanType} from "../../../shared/types/chan";
|
|
|
|
const commands = ["query", "msg", "say"];
|
|
|
|
function getTarget(cmd: string, args: string[], chan: Chan) {
|
|
switch (cmd) {
|
|
case "msg":
|
|
case "query":
|
|
return args.shift();
|
|
default:
|
|
return chan.name;
|
|
}
|
|
}
|
|
|
|
const input: PluginInputHandler = function (network, chan, cmd, args, extras) {
|
|
let targetName = getTarget(cmd, args, chan);
|
|
|
|
if (cmd === "query") {
|
|
if (!targetName) {
|
|
chan.pushMessage(
|
|
this,
|
|
new Msg({
|
|
type: MessageType.ERROR,
|
|
text: "You cannot open a query window without an argument.",
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
const target = network.getChannel(targetName);
|
|
|
|
if (typeof target === "undefined") {
|
|
const char = targetName[0];
|
|
|
|
if (
|
|
network.irc.network.options.CHANTYPES &&
|
|
network.irc.network.options.CHANTYPES.includes(char)
|
|
) {
|
|
chan.pushMessage(
|
|
this,
|
|
new Msg({
|
|
type: MessageType.ERROR,
|
|
text: "You can not open query windows for channels, use /join instead.",
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
for (let i = 0; i < network.irc.network.options.PREFIX.length; i++) {
|
|
if (network.irc.network.options.PREFIX[i].symbol === char) {
|
|
chan.pushMessage(
|
|
this,
|
|
new Msg({
|
|
type: MessageType.ERROR,
|
|
text: "You can not open query windows for names starting with a user prefix.",
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
const newChan = this.createChannel({
|
|
type: ChanType.QUERY,
|
|
name: targetName,
|
|
});
|
|
|
|
this.emit("join", {
|
|
network: network.uuid,
|
|
chan: newChan.getFilteredClone(true),
|
|
shouldOpen: true,
|
|
index: network.addChannel(newChan),
|
|
});
|
|
this.save();
|
|
newChan.loadMessages(this, network);
|
|
}
|
|
}
|
|
|
|
if (args.length === 0) {
|
|
return true;
|
|
}
|
|
|
|
if (!targetName) {
|
|
return true;
|
|
}
|
|
|
|
const msg = args.join(" ");
|
|
|
|
if (msg.length === 0) {
|
|
return true;
|
|
}
|
|
|
|
const replyTo = extras?.replyTo;
|
|
const replyTags =
|
|
replyTo && network.serverOptions.supportsReply ? {"+reply": replyTo} : undefined;
|
|
network.irc.say(targetName, msg, replyTags);
|
|
|
|
// If the IRCd does not support echo-message, simulate the message
|
|
// being sent back to us.
|
|
if (!network.irc.network.cap.isEnabled("echo-message")) {
|
|
const parsedTarget = network.irc.network.extractTargetGroup(targetName);
|
|
let targetGroup: string | undefined = undefined;
|
|
|
|
if (parsedTarget) {
|
|
targetName = parsedTarget.target;
|
|
targetGroup = parsedTarget.target_group;
|
|
}
|
|
|
|
const channel = network.getChannel(targetName);
|
|
|
|
if (typeof channel !== "undefined") {
|
|
network.irc.emit("privmsg", {
|
|
nick: network.irc.user.nick,
|
|
ident: network.irc.user.username,
|
|
hostname: network.irc.user.host,
|
|
target: targetName,
|
|
group: targetGroup,
|
|
message: msg,
|
|
tags: replyTo ? {"+reply": replyTo} : undefined,
|
|
});
|
|
}
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
export default {
|
|
commands,
|
|
input,
|
|
};
|