-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (57 loc) · 1.47 KB
/
server.js
File metadata and controls
63 lines (57 loc) · 1.47 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
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 8080;
var router = express.Router();
router.get('/roll', function (req, res) {
var max;
switch (req.query.text) {
case "":
max = 20;
break;
case "d4":
max = 4;
break;
case "d6":
max = 6;
break;
case "d8":
max = 8;
break;
case "d10":
max = 10;
break;
case "d12":
max = 12;
break;
case "d20":
max = 20;
break;
case "help":
res.json({
"response_type": "ephemeral",
"text": "usage: /roll {d6|d8|d10|d12|d20}"
});
return;
default:
max = -1;
break;
}
if (max == -1) {
res.json({
"response_type": "ephemeral",
"text": "invalid dice type, accepted types: {d6|d8|d10|d12|d20}"
})
} else {
var randomRoll = Math.floor(Math.random() * max + 1);
res.json({
"response_type": "in_channel",
"text": randomRoll
})
}
});
app.use('/', router);
app.listen(port);
console.log("Magic happens on port " + port);