williamkapke / irc-connect

Minimal IRC connection that simply emits event objects. Plugin modules can do the rest.
14 stars 5 forks source link

Instantiating Client before starting server #3

Closed MrJohz closed 10 years ago

MrJohz commented 10 years ago

The usage documentation uses the irc.connect function to immediately set the server in motion before adding handlers etc, but I was wondering if it were possible to use irc.Client and set up the client, to be later started using Client.connect().

In the source it looks like irc.connect is just a convenience method to do this, but when I try to instantiate the Client object like this:

this.server = irc.Client()

it just produces an error:

/home/jonathan/NS/project-squirrel/node_modules/irc-connect/connect.js:63
    this.use(require('./nick'));
         ^
TypeError: Object #<Object> has no method 'use'
    at Object.Client (/home/jonathan/NS/project-squirrel/node_modules/irc-connect/connect.js:63:7)
    at mainloop (/home/jonathan/NS/project-squirrel/lib/irc.js:31:25)
    at main (/home/jonathan/NS/project-squirrel/lib/main.js:20:19)
    at Object.<anonymous> (/home/jonathan/NS/project-squirrel/lib/main.js:23:3)
    at Object.<anonymous> (/home/jonathan/NS/project-squirrel/lib/main.js:25:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

If it is possible to instantiate the client object directly, could you advise on how to do that, and if it isn't, how hard would it be to add that feature?

Thanks!

williamkapke commented 10 years ago

I think you're just missing new

this.server = new irc.Client();

Hope that does the trick!

MrJohz commented 10 years ago

I'm really sorry, that may be the stupidest issue I've ever submitted. Thanks so much!

Spudz76 commented 10 years ago

I have supported this in PR #5. You pass your options into irc.create() which hands back the prepared Client reference like connect() did. Then, do whatever and wire things up, and when you're sure you want to connect, call irc.connect() with no arguments.