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