thelounge/server/plugins/irc-events/topic.ts

47 lines
998 B
TypeScript
Raw Normal View History

import {IrcEventHandler} from "../../client";
import Msg, {MessageType} from "../../models/msg";
2014-09-13 21:29:45 +00:00
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("topic", function (data) {
const chan = network.getChannel(data.channel);
2014-09-13 21:29:45 +00:00
if (typeof chan === "undefined") {
return;
}
const msg = new Msg({
2016-03-12 09:36:55 +00:00
time: data.time,
type: MessageType.TOPIC,
2017-11-19 16:30:10 +00:00
from: data.nick && chan.getUser(data.nick),
text: data.topic,
self: data.nick === irc.user.nick,
2014-09-13 21:29:45 +00:00
});
chan.pushMessage(client, msg);
chan.topic = data.topic;
2014-10-10 20:05:25 +00:00
client.emit("topic", {
chan: chan.id,
topic: chan.topic,
2014-10-10 20:05:25 +00:00
});
2014-09-13 21:29:45 +00:00
});
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),
2016-03-20 17:18:43 +00:00
when: new Date(data.when * 1000),
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
});
2014-09-13 21:29:45 +00:00
};