-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (64 loc) · 2.32 KB
/
app.js
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
80
81
import {registerAction} from './registerAction';
import PlayerManager from './PlayerManager';
import Player from './Player';
const BootBot = require('bootbot');
export let playerManager = new PlayerManager();
let express = require('express');
let bodyParser = require('body-parser');
export let bot = new BootBot({
accessToken: 'EAANFAiEgluIBAIvo0PH2sNnU0eO00uYDCnmxgKjWTIczBdiW6bP5fvaA6toXEA3v6B5wZCM9RaPzflZAiNbB9It0qIg9xHlp2qMCsuWUMKsrqySiDignlyojg2xOpIAzvOGpqlnZASBEb3swH8qZBfxZAdCZBd4rGDqaFFZBHMuXwZDZD',
verifyToken: 'vnts0937227240',
appSecret: '77adfd6c33b94de68265d88305ae343c'
});
let app = bot.app;
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function (req, res) {
res.send('App is running...');
res.end();
});
app.get('/getallplayer', function (req, res) {
res.setHeader('Content-Type', 'application/json');
let listPlayer = playerManager.getPlayers();
res.send(JSON.stringify(listPlayer) + "\n");
res.end();
});
app.get('/deleteallplayer', function (req, res) {
res.setHeader('Content-Type', 'application/json');
playerManager.reset();
console.log(playerManager);
let msg = {status: "success"};
res.send(JSON.stringify(msg) + "\n");
res.end();
});
app.post('/sendmessage', function (req, res) {
console.log(req.body);
res.setHeader('Content-Type', 'application/json');
bot.say(req.body.id, 'In this game, you are "' + req.body.character + '"');
let msg = {status: "success"};
res.send(JSON.stringify(msg) + "\n");
res.end();
});
app.post('/notify', function (req, res) {
console.log(req.body);
playerManager.sendEach(req.body.msg);
res.setHeader('Content-Type', 'application/json');
let msg = {status: "success"};
res.send(JSON.stringify(msg) + "\n");
res.end();
});
app.post('/postallplayer', function (req, res) {
console.log(req.params);
});
app.post('/addplayer', function (req, res) {
console.log("REQUEST POST: -------------------", req.body);
let player = new Player(req.body.id, req.body.name);
playerManager.addPlayer(player);
res.setHeader('Content-Type', 'application/json');
let msg = {status: "success"};
res.send(JSON.stringify(msg) + "\n");
res.end();
// console.log(playerManager);
});
registerAction(bot);
bot.start();