martynsmith / node-irc

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

How to get current server. #453

Closed MTRNord closed 8 years ago

MTRNord commented 8 years ago

Since I am using the code snippet from @jirwin that he gave me in #434 I need to know from which server a meassage is send. Is there a way to get this value?

jirwin commented 8 years ago

@MTRNord you could include the client in your listeners, so in your function you always have the appropriate client available.

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

function eventHandler(callback) {
  console.log("Now when this function is called, 'this' is equal to the client that received the message");
};

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

that is not working :/ now the bot is not working anymore :/ i will better leave it as before. (the function is triggered but bot is not responding anymore.