Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 5274f55

Browse files
author
Zirak
committed
Bot can now run headless!
See README for the know-how.
1 parent a69bb2c commit 5274f55

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
For usage info, on how to use the bot, see [here](https://github.com/Zirak/SO-ChatBot/wiki/Interacting-with-the-bot).
22

33
###Running the bot###
4+
45
The bot is currently a big dangle-on script running in your browser. **Run `bookmarklet.js`** in your browser to get it up an' running. For some tips on handling the bot, see [Bot Handling](https://github.com/Zirak/SO-ChatBot/wiki/Bot-Handling).
56

7+
If you wish, you can also run it headlessly on top of phantomjs and node:
8+
9+
* Install [phantomjs 2](http://phantomjs.org/) (yes, it has to be 2 and above). Differs from platform to platform.
10+
* Install nightmare: `npm install nightmare`
11+
* Edit your credentials into `run-headless.js`
12+
* Hit the road: `env DEBUG=nightmare node run-headless.js`
13+
614
###Building###
715

816
```sh

build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ var exec = require('child_process').exec;
159159

160160
var minifiers = [
161161
{
162-
name : 'uglify2',
162+
name : 'uglify',
163163
test : function ( success, fail ) {
164164
try {
165165
require.resolve( 'uglify-js' );

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "so-chatbot",
3+
"version": "0.1.0",
4+
"description": "A chatbot for StackOverflow.",
5+
"main": "run-headless.js",
6+
"dependencies": {
7+
"uglify-js": "^2.4.15",
8+
"nightmare": "^1.8.1"
9+
},
10+
"devDependencies": {},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/Zirak/SO-ChatBot.git"
14+
},
15+
"keywords": [
16+
"chatbot",
17+
"horse-lime",
18+
"goats"
19+
],
20+
"author": "Zirak",
21+
"license": "WTFPL",
22+
"bugs": {
23+
"url": "https://github.com/Zirak/SO-ChatBot/issues"
24+
},
25+
"homepage": "https://github.com/Zirak/SO-ChatBot#readme"
26+
}

run-headless.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var Nightmare = require('nightmare');
2+
var hound = new Nightmare();
3+
4+
/*********** Change me! ***********/
5+
var config = {
6+
email: 'you can guess',
7+
password: 'what these are'
8+
};
9+
10+
function once (fn) {
11+
var called = false, res;
12+
return function () {
13+
if (called) { return res; }
14+
15+
called = true;
16+
res = fn.apply(this, arguments);
17+
18+
return res;
19+
};
20+
}
21+
22+
hound
23+
.goto('https://stackoverflow.com/users/login/')
24+
.screenshot('pics/pre-login.png')
25+
.type('#se-login input[type="email"]', config.email)
26+
.type('#se-login input[type="password"]', config.password)
27+
.click('#se-login input[type="button"]')
28+
.wait()
29+
.screenshot('pics/login.png')
30+
.goto('https://chat.stackoverflow.com/rooms/76070')
31+
.screenshot('pics/chat.png')
32+
.evaluate(function () {
33+
var script = document.createElement('script');
34+
script.src = 'https://raw.github.com/Zirak/SO-ChatBot/master/master.js';
35+
script.onload = function() {
36+
console.log('Loaded bot');
37+
};
38+
document.head.appendChild(script);
39+
}, function () {
40+
console.log('Injected chatbot.');
41+
})
42+
.setup(function () {
43+
var self = hound;
44+
45+
setTimeout(next, 0);
46+
function next(err) {
47+
var item = self.queue.shift();
48+
if (!item) {
49+
console.log('Should be done loading stuff.');
50+
return;
51+
}
52+
53+
var method = item[0],
54+
args = item[1];
55+
args.push(once(next));
56+
method.apply(self, args);
57+
}
58+
});

0 commit comments

Comments
 (0)