-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteamAPI.js
More file actions
61 lines (58 loc) · 2.19 KB
/
steamAPI.js
File metadata and controls
61 lines (58 loc) · 2.19 KB
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
const fetch = require("node-fetch")
const config = require("./config.json")
class WebApi {
constructor (apiKey) {
this.apiKey = apiKey
}
async getVanityUrl (vanity) {
let fetched = await fetch(`https://api.steampowered.com/ISteamUser/ResolveVanityURL/v1/?key=${this.apiKey}&vanityurl=${vanity}`)
let jsonized = await fetched.json()
return jsonized["response"]["steamid"]
}
async GetPlayerSummaries (player) {
let fetched = await fetch(`http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${this.apiKey}&steamids=${player}`)
let jsonized = await fetched.json()
return jsonized["response"]["players"][0]
}
async rawCheckBans (user) {
let fetched = await fetch(`http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=${this.apiKey}&steamids=${user}`)
let bans = await fetched.json()
let player = bans.players[0]
let outArray = []
if (player.NumberOfVACBans !== undefined) {
outArray.push(player.NumberOfVACBans)
}
else {
outArray.push(0)
}
if (player.NumberOfGameBans !== undefined) {
outArray.push(player.NumberOfGameBans)
}
else {
outArray.push(0)
}
return outArray
}
async checkBans (users) {
let outArray = []
let usersArray = users.map(it => it.dbRow.steamID).join(",")
let fetched = await fetch(`http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=${this.apiKey}&steamids=${usersArray}`)
try {
let bans = await fetched.json()
bans.players.forEach(element => {
if (element.NumberOfVACBans != undefined || element.NumberOfGameBans !== undefined) {
let info = users.find(it => it.dbRow.steamID == element.SteamId)
info.vacs = element.NumberOfVACBans
info.ows = element.NumberOfGameBans
outArray.push(info)
}
})
return outArray
}
catch(e) {
return users
}
}
}
const api = new WebApi(config.steamWebApiKey)
module.exports = {WebApi, api}