williamkapke / irc-connect

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

parseOption gets called at least twice, therefore deleting vars will force default settings after 1st call #8

Closed coderofsalvation closed 8 years ago

coderofsalvation commented 8 years ago

couldnt get the example to work without doing this fix

williamkapke commented 8 years ago

Oh yeah, that's an error on my part. Good catch.

I built off your commit to eliminate the double parse and simplify it a bit. Can you test it out and see if it works for you?

branch coderofsalvation-master

ScottKaye commented 8 years ago

I ran into this same issue - seems that removing the call to parseOptions on line 165 of connect.js fixes the issue for me.

williamkapke commented 8 years ago

@ScottKaye Can you confirm if the changes in coderofsalvation-master work for you and I'll merge/publish it?

ScottKaye commented 8 years ago

Hmm, it seems to be close! I first get the following error message using the coderofsalvation fork:

...\path\node_modules\irc-connect\connect.js:88
                        host: options.host || 'localhost',
                              ^

ReferenceError: options is not defined
    at Client.connect (...\path\node_modules\irc-connect\connect.js:88:10)
    at Object.module.exports.connect (...\path\node_modules\irc-connect\connect.js:164:10)
    ...

Seems this is just a quick fix though, replacing options with the local opt:

connect: function(){
    var client = this;
    var opt = client.options;
    var connection = {
        host: opt.host || 'localhost',
        port: +opt.port || (opt.secure?6697:6667),
        rejectUnauthorized: !!(opt.secure && opt.lazyCA)
    };
    client.socket = (opt.secure?tls:net).connect(connection, function() {
        ....

With this update, using this boilerplate code, it gets this far:

>node server.js

Server started on port 3000.
NOTICE: *** Looking up your hostname...
NOTICE: *** Checking Ident
NOTICE: *** Found your hostname
NOTICE: *** No Ident response
Your nick is now: Nickname
Welcome to the freenode Internet Relay Chat Network Nickname
X:\project\node_modules\irc-connect\nick.js:24
                this.once(auth_errors[i], error);
                     ^

TypeError: this.once is not a function
    at sendNick (X:\project\node_modules\irc-connect\nick.js:24:8)
    at Client.auth (X:\project\node_modules\irc-connect\nick.js:52:2)
    at Client.client.identify (X:\project\node_modules\irc-connect\nick.js:68:9)
    at Client.client.nick (X:\project\node_modules\irc-connect\nick.js:73:20)
    at Client.<anonymous> (X:\project\server.js:53:14)
    at emitOne (events.js:90:13)
    at Client.emit (events.js:182:7)
    at Client.<anonymous> (X:\project\node_modules\irc-connect\connect.js:113:9)
    at Client.g (events.js:273:16)
    at emitOne (events.js:95:20)

I think I fixed this by changing sendNick(nick,cb,authd); to sendNick.call(this,nick,cb,authd); in nick.js at the end of the auth function. After these changes, I'm error-free!

And just for completeness:

>node -v
v5.5.0

>npm -v
3.5.3