hardlounge/server/plugins/irc-events/join.ts
Max Leiter dd05ee3a65
TypeScript and Vue 3 (#4559)
Co-authored-by: Eric Nemchik <eric@nemchik.com>
Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
2022-06-18 17:25:21 -07:00

56 lines
1.3 KiB
TypeScript

import Msg, {MessageType} from "../../models/msg";
import User from "../../models/user";
import type {IrcEventHandler} from "../../client";
import {ChanState} from "../../models/chan";
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("join", function (data) {
let chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
chan = client.createChannel({
name: data.channel,
state: ChanState.JOINED,
});
client.emit("join", {
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});
client.save();
chan.loadMessages(client, network);
// Request channels' modes
network.irc.raw("MODE", chan.name);
} else if (data.nick === irc.user.nick) {
chan.state = ChanState.JOINED;
client.emit("channel:state", {
chan: chan.id,
state: chan.state,
});
}
const user = new User({nick: data.nick});
const msg = new Msg({
time: data.time,
from: user,
hostmask: data.ident + "@" + data.hostname,
gecos: data.gecos,
account: data.account,
type: MessageType.JOIN,
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
chan.setUser(new User({nick: data.nick}));
client.emit("users", {
chan: chan.id,
});
});
};