-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (28 loc) · 1000 Bytes
/
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
const express = require('express');
const webhook = require('webhook-discord');
const dotenv = require('dotenv').config();
const hook = new webhook.Webhook(process.env.WEBHOOK_URL);
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
app.post('/', (req, res) => {
res.header('Access-Control-Allow-Origin', '*');
var infos = req.body.attacks;
var msg = '';
console.log('Updating attack information!');
for (var i = 0; i < infos.length; i++) {
console.log(
`Recieved info from ${infos[i].nome}, is recieving ${infos[i].numAtaques} attacks!`
);
msg += `O jogador ${infos[i].nome} está a levar ${infos[i].numAtaques} ataques!\n`;
}
hook.info('VT@', msg);
});
app.listen(PORT, (req, res) => {
console.log('Server is up');
console.log(`Pinging to webhook server: ${process.env.WEBHOOK_URL}`);
});