ircanywhere / irc-factory

A rebuilt irc-factory from simple-irc-socket and irc-message. Get support at #ircanywhere on freenode
https://ircanywhere.com
MIT License
60 stars 14 forks source link

api.createClient called through a function kills the script #25

Open cydrobolt opened 9 years ago

cydrobolt commented 9 years ago

Calling api.createClient through a function kills its host script. For instance...

var factory = require('irc-factory'),
    api = new factory.Api();
function factory () {
    var client = api.createClient('test', {
        nick : 'testIRCBot',
        user : 'testuser',
        server : 'irc.freenode.net',
        realname: 'realbot',
        port: 6667,
        secure: false
    });
    *** SCRIPT DIES HERE ***
    // create a client by giving it a unique key, and a config object
    // You can see more info on the config options and the client class at the bottom of the page

    api.hookEvent('test', '*', function(message) {
        console.log(message);
    });
    // hook to all events for our client and output them to console

    api.hookEvent('test', 'registered', function(message) {
        client.irc.join('##cydrobolt');
    });
}
factory();

However, when it is called like so:

var factory = require('irc-factory'),
    api = new factory.Api();

    var client = api.createClient('test', {
        nick : 'testIRCBot',
        user : 'testuser',
        server : 'irc.freenode.net',
        realname: 'realbot',
        port: 6667,
        secure: false
    });
    // create a client by giving it a unique key, and a config object
    // You can see more info on the config options and the client class at the bottom of the page

    api.hookEvent('test', '*', function(message) {
        console.log(message);
    });
    // hook to all events for our client and output them to console

    api.hookEvent('test', 'registered', function(message) {
        client.irc.join('##cydrobolt');
    });

everything works like normal.

rickihastings commented 9 years ago

Any errors?

cydrobolt commented 9 years ago

Nope

silverbucket commented 9 years ago

did you try wrapping the createClient in a try/catch block and console.loging the error? Sometimes scripts, due to their environment, can silently eat errors