Zirak / SO-ChatBot

Other
124 stars 60 forks source link

Run-headless is not working #246

Closed allquixotic closed 9 years ago

allquixotic commented 9 years ago

I maintain the chatbot John Cavil in Root Access. For some time (I'm not sure how long; maybe a couple weeks?), the driver I wrote to start the chatbot in PhantomJS using Selenium/Java has not worked.

Thinking that maybe you guys hit a similar problem and fixed it, I then tried your run-headless.js script. I did edit the script to configure it for our room, but the bot never even shows up in our room.

var config = {
        email:    'my_email@gmail.com',
        password: 'my password',

        siteUrl: 'https://superuser.com',
        roomUrl: 'https://chat.stackexchange.com/rooms/118'
};

My specs:

Questions:

Console output, which looks suspicious but I'm not sure what exactly is wrong:

$ nodejs run-headless.js
Need to authenticate
Injected chatbot.
phantom stdout: SyntaxError: JSON Parse error: Unrecognized token '<'

phantom stdout:   https://raw.githubusercontent.com/allquixotic/SO-ChatBot/master/master.js:2653 in parse
  https://raw.githubusercontent.com/allquixotic/SO-ChatBot/master/master.js:2653 in finish
  https://raw.githubusercontent.com/allquixotic/SO-ChatBot/master/master.js:306

Should be done loading stuff.
You are now in a REPL with the remote page. Have fun!

In master.js:

//the input is not used by the bot directly, so you can implement it however
// you like
var polling = bot.adapter.in = {
    //used in the SO chat requests, dunno exactly what for, but guessing it's
    // the latest id or something like that. could also be the time last
    // sent, which is why I called it times at the beginning. or something.
    times : {},

    firstPoll : true,

    interval : 5000,

    init : function ( roomid ) {
        var that = this,
            providedRoomid = ( roomid !== undefined );
        roomid = roomid || bot.adapter.roomid;

        IO.xhr({
            url : '/ws-auth',
            data : fkey({
                roomid : roomid
            }),
            method : 'POST',
            complete : finish
        });

        function finish ( resp ) {
 ///The offending line is the following
            resp = JSON.parse( resp );
            bot.log( resp );

            that.openSocket( resp.url, providedRoomid );
        }
    },
rlemon commented 9 years ago

I ended up having to alter the script to add a few delays between inputs. Not sure if this is the root of the issue, but it did solve it for me.

function seLogin () {
    hound
        .type('#email', config.email)
        .wait()
        .type('#password', config.password)
        .wait()
        .click('#submit-button')
.....

note: I also changed the selectors. #se-login is now #se-login-form if you prefer to use the attribute selectors... but the inputs have id's so why not use them.

allquixotic commented 9 years ago

https://github.com/allquixotic/SO-ChatBot/commit/88d9eacdb446f20d0cd85a9fd58ca6654954b73f works for me. You guys can pull to Zirak master if you wish, but I've already pushed this to my fork.