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