usercaching (who)
This commit is contained in:
		@@ -20,15 +20,17 @@ class irc {
 | 
			
		||||
    this.channels = this.options.channels || [];
 | 
			
		||||
    this.server = {
 | 
			
		||||
      motd: "",
 | 
			
		||||
      me: {}
 | 
			
		||||
      me: {},
 | 
			
		||||
      channel: [],
 | 
			
		||||
      user: []
 | 
			
		||||
    };
 | 
			
		||||
    this.socket = (this.options.ssl ? tls : net).connect({
 | 
			
		||||
      host: this.options.host,
 | 
			
		||||
      port: this.options.port,
 | 
			
		||||
      rejectUnauthorized: !this.options.selfSigned
 | 
			
		||||
    }, () => {
 | 
			
		||||
      this.send("NICK ", this.nickname);
 | 
			
		||||
      this.send("USER ", this.username, ' 0 * :', this.realname);
 | 
			
		||||
      this.send(`NICK ${this.nickname}`);
 | 
			
		||||
      this.send(`USER ${this.username} 0 * : ${this.realname}`);
 | 
			
		||||
    });
 | 
			
		||||
    this.socket.setEncoding('utf-8');
 | 
			
		||||
    this.socket.on('data', msg => {
 | 
			
		||||
@@ -39,6 +41,18 @@ class irc {
 | 
			
		||||
          this.join(this.options.channels);
 | 
			
		||||
          this.emit('data', ['connected', msg.params[1]]);
 | 
			
		||||
          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
 | 
			
		||||
          this.server.motd += `${msg.params[1]}\n`;
 | 
			
		||||
          break;
 | 
			
		||||
@@ -51,10 +65,16 @@ class irc {
 | 
			
		||||
          break;
 | 
			
		||||
        case "464": // Password required
 | 
			
		||||
          if (this.options.password.length > 0)
 | 
			
		||||
            this.send("PASS ", this.options.password); // pwd
 | 
			
		||||
            this.send(`PASS ${this.options.password}`); // pwd
 | 
			
		||||
          break;
 | 
			
		||||
        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;
 | 
			
		||||
        case "PRIVMSG":
 | 
			
		||||
          if (msg.params[1] === "\u0001VERSION\u0001")
 | 
			
		||||
@@ -70,8 +90,6 @@ class irc {
 | 
			
		||||
          break;
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
    //if(this.network === "n0xy")
 | 
			
		||||
    //  setTimeout(() => { console.log(this.server.me) }, 5000);
 | 
			
		||||
  }
 | 
			
		||||
  send() {
 | 
			
		||||
    for (let i = 0; i < arguments.length; i++)
 | 
			
		||||
@@ -127,6 +145,8 @@ class irc {
 | 
			
		||||
      replyNotice: msg => {
 | 
			
		||||
        this.send(`NOTICE ${tmp.params[0]} :${msg}`);
 | 
			
		||||
      },
 | 
			
		||||
      // act chan
 | 
			
		||||
      _chan: this.server.channel[tmp.params[0]],
 | 
			
		||||
      // commands
 | 
			
		||||
      join: chan => this.join(chan),
 | 
			
		||||
      part: (chan, msg) => this.part(chan, msg),
 | 
			
		||||
@@ -137,7 +157,7 @@ class irc {
 | 
			
		||||
    this.send(`JOIN ${(typeof channel === "object") ? channel.join(',') : channel}`);
 | 
			
		||||
  }
 | 
			
		||||
  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"}`);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user