Skip to content

Commit

Permalink
plenty of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Bell committed Aug 27, 2011
1 parent 70d7393 commit b7070b3
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 214 deletions.
68 changes: 34 additions & 34 deletions lib/bot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions lib/fortune.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
(function() {
var getFortune, http;
http = require('http');
http = require("http");
exports.getFortune = getFortune = function(callback) {
var opts, req;
var opts, request;
opts = {
host: 'www.fortunefortoday.com',
path: '/getfortuneonly.php'
host: "www.fortunefortoday.com",
path: "/getfortuneonly.php"
};
req = http.request(opts, function(resp) {
request = http.request(opts, function(response) {
var data;
data = '';
resp.on('data', function(chunk) {
data = "";
response.on("data", function(chunk) {
return data += chunk;
});
resp.on('end', function() {
response.on("end", function() {
var body;
data = data.replace(/(\r\n|\n|\r)/gm, '');
data = data.replace(/\s\s+/g, ' ');
data = data.replace(/(\r\n|\n|\r)/gm, "");
data = data.replace(/\s\s+/g, " ");
body = data;
if (!body) {
return callback('Could not find fortune');
return callback("Could not find fortune");
} else {
return callback(null, body);
}
});
return resp.on('error', function(err) {
return callback(err);
return response.on("error", function(error) {
return callback(error);
});
});
req.on('error', function(err) {
return callback(err);
request.on("error", function(error) {
return callback(error);
});
return req.end();
return request.end();
};
}).call(this);
24 changes: 12 additions & 12 deletions lib/github.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(function() {
var getLatestCommit, https;
https = require('https');
https = require("https");
exports.getLatestCommit = getLatestCommit = function(user, proj, callback) {
var opts, req;
var opts, request;
opts = {
host: 'api.github.com',
host: "api.github.com",
path: "/repos/" + user + "/" + proj + "/commits?per_page=1"
};
req = https.request(opts, function(resp) {
request = https.request(opts, function(response) {
var data;
data = '';
resp.on('data', function(chunk) {
data = "";
response.on("data", function(chunk) {
return data += chunk;
});
resp.on('end', function() {
response.on("end", function() {
var body, commit;
body = JSON.parse(data);
if (!body[0]) {
Expand All @@ -27,13 +27,13 @@
return callback(null, commit);
}
});
return resp.on('error', function(err) {
return callback(err);
return response.on("error", function(error) {
return callback(error);
});
});
req.on('error', function(err) {
return callback(err);
request.on("error", function(error) {
return callback(error);
});
return req.end();
return request.end();
};
}).call(this);
36 changes: 18 additions & 18 deletions lib/image.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
(function() {
var getImage, http;
http = require('http');
http = require("http");
exports.getImage = getImage = function(phrase, callback) {
var client, headers, host, path, req;
host = 'ajax.googleapis.com';
path = "/ajax/services/search/images?v=1.0&rsz=8&safe=active&q=" + phrase;
var client, headers, host, path, request;
host = "ajax.googleapis.com";
path = "/ajax/services/search/images?v=1.0&rsz=8&q=" + (encodeURI(phrase));
client = http.createClient(80, host);
headers = {
'Host': 'ajax.googleapis.com'
Host: "ajax.googleapis.com"
};
req = client.request('GET', path, headers);
req.on('response', function(resp) {
request = client.request("GET", path, headers);
request.on("response", function(response) {
var data;
if (resp.statusCode === 200) {
data = '';
resp.setEncoding('utf8');
resp.on('data', function(chunk) {
if (response.statusCode === 200) {
data = "";
response.setEncoding("utf8");
response.on("data", function(chunk) {
return data += chunk;
});
resp.on('end', function() {
response.on("end", function() {
var body, image, images;
body = JSON.parse(data);
images = body.responseData.results;
image = images[Math.floor(Math.random() * images.length)];
if (!image) {
return callback('Could not find results for phrase');
return callback("Could not find results for phrase");
} else {
return callback(null, image.unescapedUrl);
}
});
return resp.on('error', function(err) {
return callback(err);
return response.on("error", function(error) {
return callback(error);
});
}
});
req.on('error', function(err) {
return callback(err);
request.on("error", function(error) {
return callback(error);
});
return req.end();
return request.end();
};
}).call(this);
3 changes: 1 addition & 2 deletions lib/seen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
};
exports.getSeenUser = getSeenUser = function(user, callback) {
var seen;
user = user.toLowerCase();
seen = seen_list[user];
seen = seen_list[user.toLowerCase()];
if (!seen) {
return callback("not seen " + user + " yet, sorry");
} else {
Expand Down
Loading

0 comments on commit b7070b3

Please sign in to comment.