thelounge/server/plugins/irc-events/topic.ts
Reto Brunner 3eb19135f5 wip: msg
2024-04-21 15:10:41 +02:00

48 lines
1 KiB
TypeScript

import {IrcEventHandler} from "../../client";
import Msg from "../../models/msg";
import {MessageType} from "../../../shared/types/msg";
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("topic", function (data) {
const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
return;
}
const msg = new Msg({
time: data.time,
type: MessageType.TOPIC,
from: data.nick && chan.getUser(data.nick),
text: data.topic,
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
chan.topic = data.topic;
client.emit("topic", {
chan: chan.id,
topic: chan.topic,
});
});
irc.on("topicsetby", function (data) {
const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
return;
}
const msg = new Msg({
type: MessageType.TOPIC_SET_BY,
from: chan.getUser(data.nick),
when: new Date(data.when * 1000),
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
});
};