Skip to content

Commit

Permalink
Add /isup command (close #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Spronck committed Jun 23, 2016
1 parent 2b5d26b commit 4597e49
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"nedb": "^1.8.0",
"node-geocoder": "^3.12.0",
"request": "^2.72.0"
},
"devDependencies": {
"typings": "^1.3.0"
}
}
2 changes: 2 additions & 0 deletions src/CommandList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Emote } from './Commands/Emote';
import { Forecast } from './Commands/Forecast';
import { HelloWorld } from './Commands/HelloWorld';
import { Info } from './Commands/Info';
import { Isup } from './Commands/Isup';
import { Joke } from './Commands/Joke';
import { Stats } from './Commands/Stats';

Expand All @@ -27,6 +28,7 @@ export class CommandList{
new Forecast(process.env.FORECAST_API, process.env.GEOCODE_PROVIDER, process.env.GEOCODE_APIKEY),
new HelloWorld(),
new Info(),
new Isup(),
new Joke(),
new Stats(db)
];
Expand Down
33 changes: 33 additions & 0 deletions src/Commands/Isup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ICommand } from './ICommand';
import * as Request from 'request';

export class Isup implements ICommand {
command = /isup$/;
help = "Checks if a website is up/down.";
usage = "Usage: /isup [url]";


private IsUp(url: string, callback: (isup: boolean) => void): void {
var SERVER_URL = 'http://isup.me/';
Request(SERVER_URL + url, function(error, response, body) {
callback(body.indexOf('It\'s just you') !== -1);
});
}

// Displays hello world
exec(msg, reply): void {
var args: string = msg.args();
if (args.trim().length == 0) {
reply.text(this.usage);
return;
}

this.IsUp(args, (isup: boolean) => {
if(isup){
reply.markdown(`*${args}* looks *up* from here.`);
}else{
reply.markdown(`*${args}* looks *down* from here.`);
}
});
}
}
2 changes: 1 addition & 1 deletion typings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"globalDependencies": {
"dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
"nedb": "registry:dt/nedb#0.0.0+20160505185910",
"node": "registry:env/node#6.0.0+20160610031852"
"node": "registry:env/node#6.0.0+20160622202520"
}
}

0 comments on commit 4597e49

Please sign in to comment.