martynsmith / node-irc

NodeJS IRC client library
GNU General Public License v3.0
1.33k stars 424 forks source link

How to multiple server connections at the same time #434

Closed MTRNord closed 8 years ago

MTRNord commented 8 years ago

Hi I want to have the client connected to multiple servers without writing the hole handling stuff all over again. Are there any ways to do so?

del6597 commented 8 years ago

The current implementation handles 1 server per client created. If you create another client in your code, then you'll have two bots connected to two servers.

MTRNord commented 8 years ago

@del6597 yeah that did I see but how can I make that both clients can use the same function? Is this in any way possible?

jirwin commented 8 years ago

@MTRNord You could just make your own addListener function that iterates your list of clients and adds the listener function to each of your clients.

Something like this maybe:

var client1 = Client(...);
var client2 = Client(...);
var clients = [client1, client2];

function addListener(event, callback) {
  clients.forEach(function(client) {
    client.addListener(event, callback);
  });
}
MTRNord commented 8 years ago

@jirwin i will try that :) thanks for the idea

MTRNord commented 8 years ago

@jirwin seems to work but hackint.org is sadly kicking the bot sometimes with "quit: Excess Flood" :/

jirwin commented 8 years ago

@MTRNord try enabling the floodControl option in the config.

MTRNord commented 8 years ago

@jirwin that seems to help :) hopefully i can speed up the forEach. it slows the bot extremly down

jirwin commented 8 years ago

@MTRNord do you have a code snippet you can share? I wouldn't expect things to slow dow much(other than flood control doing its thing)

MTRNord commented 8 years ago

@jirwin https://github.com/MTRNord/nordlab-hackerspace-door/blob/v0.0.2/handlers/irc.js this is my code for the bot. I know that there are also other things that are slowing the bot down.

jirwin commented 8 years ago

Closing this.