-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
82 lines (68 loc) · 2.02 KB
/
server.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
82
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const fs = require('fs')
app.use(bodyParser.json())
app.engine('html', require('ejs').renderFile)
// Discord helper
DISCORD = require("webhook-discord")
// Civ-handler logic
CIV = require('./civ-handler');
// Object for storing processed current POST request data
VARS = {}
// Port to bind the server to
APP_PORT = 80
APP_ALIVE_INTERVAL = 7200000
// Object to store sent messages for duplicate checking
SENT_MESSAGES = {}
ERRORS = {}
// Read old log.json entries from disk to memory
fs.readFile('log.json', 'utf-8', (err, data) => {
if (err) throw err;
try {
SENT_MESSAGES = JSON.parse(data.toString())
}
catch(e) {
console.error("Could not parse log.json, starting fresh.")
SENT_MESSAGES = {}
}
});
// Read old errors.json entries from disk to memory
fs.readFile('errors.json', 'utf-8', (err, data) => {
if (err) throw err;
try {
ERRORS = JSON.parse(data.toString())
}
catch(e) {
console.error("Could not parse log.json, starting fresh.")
ERRORS = {}
}
});
// toggle whether messages will actually be sent to discord, for debugging purposes
SENDING_ENABLED = true
// Displaying your bot messages with certain nick/color
BOT_NAME = "Dingding"
BOT_MSG_COLOR = "#ff6600"
// Steamnick -> discord user ID so that @mentions can work (enable dev mode in discord, right click user to copy his/her ID)
USER_MAP = {
// "steamnick" : "<@discordid>",
// "steamnick" : "<@discordid>",
// "steamnick" : "<@discordid>",
}
// Wbhook URLs from Discord, uses certain hook based on partial game name
HOOKS = [
// {
// name: "Partial gamename",
// hook: new DISCORD.Webhook("<<discordwebhookurl>>")
// },
]
// Handle posts requests to /, /civ, /new_turn, /civ/new_turn
app.post('/', CIV.handlePost)
app.post('/civ', CIV.handlePost)
app.post('/new_turn', CIV.handlePost)
app.post('/civ/new_turn', CIV.handlePost)
// Handle get requests to /, /alive
app.get('/', CIV.showLog)
app.get('/alive', CIV.handleAlive)
// Launch
CIV.startApp(app)