-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
159 lines (139 loc) · 4.7 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const axios = require('axios');
function login(config) {
axios.defaults.headers.common['Authorization'] = config.token
}
axios.defaults.baseURL = 'https://api.battlemetrics.com';
axios.defaults.headers.post['Content-Type'] = 'application/json';
async function getServerInfoByName(serverName, game) {
let info = [];
await axios.get(`/servers?filter[search]='${serverName}&filter[game]=${game}`).then(res => {
res.data.data.forEach(el => {
var attributes = el.attributes;
let data = {
Id: attributes.id,
Name: attributes.name,
Players: attributes.players,
MaxPlayers: attributes.maxPlayers,
Country: attributes.country,
Rank: attributes.rank,
Description: attributes.details.rust_description
}
info.push(data);
});
})
return info;
}
async function getServerInfoById(serverId) {
let info = [];
await axios.get(`/servers/${serverId}`).then(res => {
var attributes = res.data.data.attributes;
let data = {
Id: attributes.id,
Name: attributes.name,
Players: attributes.players,
MaxPlayers: attributes.maxPlayers,
Country: attributes.country,
Rank: attributes.rank,
ServerFPS: attributes.details.rust_fps,
Description: attributes.details.rust_description
}
info.push(data);
})
return info;
}
async function getGameInfo(game) {
let info = [];
await axios.get(`/games/${game}`).then(res => {
var attributes = res.data.data.attributes;
let data = {
AppID: attributes.metadata.appid,
Players: attributes.players,
Servers: attributes.servers,
MinPlayers24H: attributes.minPlayers24H,
MaxPlayers24H: attributes.maxPlayers24H,
MinPlayers7D: attributes.minPlayers7D,
MaxPlayers7D: attributes.maxPlayers7D,
MinPlayers30D: attributes.minPlayers30D,
MaxPlayers30D: attributes.maxPlayers30D
}
info.push(data);
})
return info;
}
async function getServerID(serverName, game) {
let info = [];
await axios.get(`/servers?filter[search]='${serverName}&filter[game]=${game}`).then(res => {
res.data.data.forEach(el => {
var attributes = el.attributes;
let data = {
Id: attributes.id,
Name: attributes.name,
}
info.push(data);
});
})
return info;
}
async function getPlayTimeHistory(playerId, serverId, startTime, stopTime) {
let info = [];
await axios.get(`https://api.battlemetrics.com/players/${playerId}/time-played-history/${serverId}?start=${startTime}T12%3A00%3A00Z&stop=${stopTime}T12%3A00%3A00Z`).then(res => {
info.push(res.data.data);
})
return info;
}
async function getServerPlayerInfo(playerId, serverId) {
let info = [];
await axios.get(`https://api.battlemetrics.com/players/${playerId}/servers/${serverId}`).then(res => {
var attributes = res.data.data.attributes;
let data = {
FirstSeen: attributes.firstSeen,
LastSeen: attributes.lastSeen,
TimePlayed: attributes.timePlayed,
Online: attributes.online
}
info.push(data)
})
return info;
}
async function getPlayerInfo(playerId) {
let info = [];
await axios.get(`https://api.battlemetrics.com/players/${playerId}`).then(res => {
var attributes = res.data.data.attributes;
let data = {
Name: attributes.name,
Private: attributes.private,
PossitiveMatch: attributes.positiveMatch,
CreatedAt: attributes.createdAt,
UpdatedAt: attributes.updatedAt
}
info.push(data);
})
return servers;
}
async function getBanInfo(banid) {
let info;
await axios.get(`/bans/${banid}`).then(res => {
let data = res.data.data;
info = data;
})
return info;
}
async function getBans() {
let info = [];
await axios.get(`/bans`).then(res => {
res.data.data.forEach(el => {
info.push(el);
})
})
return info;
}
module.exports.getGameInfo = getGameInfo;
module.exports.getServerInfoByName = getServerInfoByName;
module.exports.getServerInfoById = getServerInfoById;
module.exports.getServerID = getServerID;
module.exports.getPlayTimeHistory = getPlayTimeHistory;
module.exports.getServerPlayerInfo = getServerPlayerInfo;
module.exports.getPlayerInfo = getPlayerInfo;
module.exports.login = login;
module.exports.getBanInfo = getBanInfo;
module.exports.getBans = getBans;