usercaching (who)

This commit is contained in:
Flummi 2017-11-09 17:04:30 +01:00
parent f38d449c1e
commit df5f5cb767

View File

@ -20,15 +20,17 @@ class irc {
this.channels = this.options.channels || []; this.channels = this.options.channels || [];
this.server = { this.server = {
motd: "", motd: "",
me: {} me: {},
channel: [],
user: []
}; };
this.socket = (this.options.ssl ? tls : net).connect({ this.socket = (this.options.ssl ? tls : net).connect({
host: this.options.host, host: this.options.host,
port: this.options.port, port: this.options.port,
rejectUnauthorized: !this.options.selfSigned rejectUnauthorized: !this.options.selfSigned
}, () => { }, () => {
this.send("NICK ", this.nickname); this.send(`NICK ${this.nickname}`);
this.send("USER ", this.username, ' 0 * :', this.realname); this.send(`USER ${this.username} 0 * : ${this.realname}`);
}); });
this.socket.setEncoding('utf-8'); this.socket.setEncoding('utf-8');
this.socket.on('data', msg => { this.socket.on('data', msg => {
@ -39,6 +41,18 @@ class irc {
this.join(this.options.channels); this.join(this.options.channels);
this.emit('data', ['connected', msg.params[1]]); this.emit('data', ['connected', msg.params[1]]);
break; break;
case "352": // who_entry
if(!this.server.channel[msg.params[1]])
this.server.channel[msg.params[1]] = new Map();
this.server.channel[msg.params[1]].set(msg.params[5], { // chan
nick: msg.params[5],
username: msg.params[2],
hostname: msg.params[3]
});
break;
case "315": // who_end
console.log(this.server.channel);
break;
case "372": // motd case "372": // motd
this.server.motd += `${msg.params[1]}\n`; this.server.motd += `${msg.params[1]}\n`;
break; break;
@ -51,10 +65,16 @@ class irc {
break; break;
case "464": // Password required case "464": // Password required
if (this.options.password.length > 0) if (this.options.password.length > 0)
this.send("PASS ", this.options.password); // pwd this.send(`PASS ${this.options.password}`); // pwd
break; break;
case "PING": case "PING":
this.send("PONG ", msg.params.join``); this.send(`PONG ${msg.params.join``}`);
break;
case "JOIN":
this.send(`WHO ${msg.params[0]}`);
break;
case "PART":
delete this.server.user[msg.params[0]];
break; break;
case "PRIVMSG": case "PRIVMSG":
if (msg.params[1] === "\u0001VERSION\u0001") if (msg.params[1] === "\u0001VERSION\u0001")
@ -70,8 +90,6 @@ class irc {
break; break;
} }
}); });
//if(this.network === "n0xy")
// setTimeout(() => { console.log(this.server.me) }, 5000);
} }
send() { send() {
for (let i = 0; i < arguments.length; i++) for (let i = 0; i < arguments.length; i++)
@ -127,6 +145,8 @@ class irc {
replyNotice: msg => { replyNotice: msg => {
this.send(`NOTICE ${tmp.params[0]} :${msg}`); this.send(`NOTICE ${tmp.params[0]} :${msg}`);
}, },
// act chan
_chan: this.server.channel[tmp.params[0]],
// commands // commands
join: chan => this.join(chan), join: chan => this.join(chan),
part: (chan, msg) => this.part(chan, msg), part: (chan, msg) => this.part(chan, msg),
@ -137,7 +157,7 @@ class irc {
this.send(`JOIN ${(typeof channel === "object") ? channel.join(',') : channel}`); this.send(`JOIN ${(typeof channel === "object") ? channel.join(',') : channel}`);
} }
part(channel, msg=false) { part(channel, msg=false) {
this.send(`PART ${(typeof channel === "object") ? channel.join(',') : channel}${msg ? " " + msg : "part"}`); this.send(`PART ${(typeof channel === "object") ? channel.join(',') : channel}${msg ? " " + msg : " part"}`);
} }
} }