-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.js
64 lines (53 loc) · 1.53 KB
/
events.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
require('dotenv').config()
const arma3syncLib = require('arma3sync-lib')
const axios = require('axios')
const operationsUrl = 'https://www.anrop.se/api/operations'
const templatesUrl = 'https://playwithsix.anrop.se/templates'
function getJSON (url) {
return axios.get(url).then(res => res.data)
}
function createOperationEvents (operations) {
return operations.filter(function (operation) {
return operation.pws && operation.pws.length > 0
}).map(function (operation) {
const addons = {}
operation.pws.forEach(function (addon) {
addons[addon.name] = false
})
return {
name: 'Operation - ' + operation.title,
description: operation.datetime,
addonNames: addons,
userconfigFolderNames: {}
}
})
}
function createTemplateEvents (templates) {
return templates.map(function (template) {
const addons = {}
template.mods.forEach(function (mod) {
addons[mod] = false
})
return {
name: 'Template - ' + template.title,
description: '',
addonNames: addons,
userconfigFolderNames: {}
}
})
}
function writeEvents (events) {
return arma3syncLib.a3sDirectory.setEvents({ list: events })
}
Promise.all([
getJSON(operationsUrl),
getJSON(templatesUrl)
]).then(([operations, templates]) => {
const operationEvents = createOperationEvents(operations)
const templateEvents = createTemplateEvents(templates)
const events = operationEvents.concat(templateEvents)
return writeEvents(events)
}).catch((err) => {
console.error(err)
process.exit(1)
})