-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
79 lines (64 loc) · 2.18 KB
/
app.js
File metadata and controls
79 lines (64 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Server-side JS - Main file
*/
// Environment configurables
var port = process.env.OPENSHIFT_NODEJS_PORT || 5000;
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
// Dependencies
var config = require((process.env.OPENSHIFT_DATA_DIR || __dirname) + '/.config/config.json');
var Tbot = require('./Tbot');
var meetup = require('./meetup');
var express = require('express');
var app = express();
var http = require('http').Server(app);
// Use files from folder 'www'
// app.use(express.static('www'));
// Listen to <port>
http.listen(port, ipaddress, function(){
console.log('listening on ' + ipaddress + ':' + port);
});
// Route handlers
app.get('/',function(req, res){
res.send('Hi there!');
});
// Execute
var meetupBot = new Tbot(config['meetup'], meetup.parse, meetup.STRINGS);
var ksamiBot = new Tbot(config['ksami'], function(message){
var msg = message.text;
var returnMessage = '';
if(typeof msg !== 'undefined' && msg.charAt(0) === '/') {
text = msg.split(' ');
command = text[0];
if(command == '/start' || command == '/help'){
returnMessage += '/roll x - to obtain a number between 1 and x (eg. /roll 6)\n';
returnMessage += '/help to see this message again';
}
else if(command == '/ksami'){
returnMessage += 'ksami is cool, ksami is great, ksami is rated ten out of eight';
}
else if(command == '/haha'){
returnMessage += 'Haha yourself';
}
else if(command == '/roll'){
var max = parseInt(text[1]);
if(!isNaN(max) && max >= 1){
returnMessage += 'Rolling a ' + max + '-sided die...\n';
returnMessage += 'Result is: ';
returnMessage += (Math.floor((Math.random() * max) + 1)).toString();
}
else{
returnMessage += 'Please enter a number more than 0 (eg. /roll 6)';
}
}
else{
//unknown command
}
}
return returnMessage;
});
setInterval(function(){
meetupBot.getUpdates();
}, meetupBot.TIMEOUT*1000);
setInterval(function(){
ksamiBot.getUpdates();
}, ksamiBot.TIMEOUT*1000);