Comparing version 1.3.4 to 1.3.5
@@ -5,3 +5,3 @@ { | ||
"main": "index.js", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"keywords": [ | ||
@@ -31,2 +31,2 @@ "steam", | ||
"homepage": "https://github.com/lloti/node-steamapi#readme" | ||
} | ||
} |
const fetch = require('./Fetch'); | ||
const { version } = require('../package.json'); | ||
const appReg = /^\d+$/; | ||
const idReg = /^\d{17}$/; | ||
const ipReg = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?::\d+)?$/; | ||
@@ -34,8 +32,4 @@ class SteamAPI { | ||
*/ | ||
get(path) { | ||
return new Promise((resolve, reject) => { | ||
fetch(`${this.baseURL}${path}${path.includes('?') ? '&' : '?'}key=${this.key}`, this.headers) | ||
.then(resolve) | ||
; | ||
}); | ||
async get(path) { | ||
return await fetch(`${this.baseURL}${path}${path.includes('?') ? '&' : '?'}key=${this.key}`, this.headers); | ||
} | ||
@@ -48,29 +42,30 @@ | ||
*/ | ||
resolve(info) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!info) return reject('no info provided'); | ||
let steamID, steamURL; | ||
if (/^(?:\/?profiles\/)?\d{17}.*$/.test(info)) { | ||
steamID = info.replace(/^(?:\/?profiles\/)?(\d{17}).*$/, '$1'); | ||
} else if (/^(?:\/?id\/)?\w{2,32}.*$/.test(info)) { | ||
steamURL = info.replace(/^(?:\/?id\/)?(\w{2,32}).*$/, '$1'); | ||
} else { | ||
const url = parse(info); | ||
if (url.hostname === 'steamcommunity.com') { | ||
if (url.path.startsWith('/id/')) { | ||
steamURL = url.path.replace(/\/id\//, ''); | ||
} else if (url.path.startsWith('/profiles/')) { | ||
steamID = url.path.replace(/\/profiles\//, ''); | ||
} else { | ||
return reject('Invalid profile link/id'); | ||
} | ||
async resolve(info) { | ||
if (!info) throw new Error('no info provided'); | ||
let steamID, steamURL; | ||
if (/^(?:\/?profiles\/)?\d{17}.*$/.test(info)) { | ||
steamID = info.replace(/^(?:\/?profiles\/)?(\d{17}).*$/, '$1'); | ||
} else if (/^(?:\/?id\/)?\w{2,32}.*$/.test(info)) { | ||
steamURL = info.replace(/^(?:\/?id\/)?(\w{2,32}).*$/, '$1'); | ||
} else { | ||
const url = parse(info); | ||
if (url.hostname === 'steamcommunity.com') { | ||
if (url.path.startsWith('/id/')) { | ||
steamURL = url.path.replace(/\/id\//, ''); | ||
} else if (url.path.startsWith('/profiles/')) { | ||
steamID = url.path.replace(/\/profiles\//, ''); | ||
} else { | ||
throw new Error('Invalid profile link/id'); | ||
} | ||
} | ||
if (steamURL) { | ||
steamID = await fetch(`${this.baseURL}/ISteamUser/ResolveVanityURL/v1?key=${this.key}&vanityurl=${steamURL}`, this.headers) | ||
.then(json => json.response.success === 1 ? json.response.steamid : reject('Invalid profile link/id')) | ||
; | ||
} | ||
if (steamURL) { | ||
const json = await fetch(`${this.baseURL}/ISteamUser/ResolveVanityURL/v1?key=${this.key}&vanityurl=${steamURL}`, this.headers); | ||
if (json.response.success) { | ||
steamID = json.response.steamid | ||
} else { | ||
throw new Error('Invalid profile link/id') | ||
} | ||
resolve(steamID); | ||
}); | ||
} | ||
return steamID; | ||
} | ||
@@ -82,7 +77,5 @@ | ||
*/ | ||
getAppList() { | ||
return new Promise(async (resolve, reject) => { | ||
const json = await fetch(`${this.baseURL}/ISteamApps/GetAppList/v2`, this.headers); | ||
resolve(json.applist.apps); | ||
}); | ||
async getAppList() { | ||
const json = await fetch(`${this.baseURL}/ISteamApps/GetAppList/v2`, this.headers); | ||
return json.applist.apps; | ||
} | ||
@@ -94,7 +87,5 @@ | ||
*/ | ||
getFeaturedCategories() { | ||
return new Promise(async (resolve, reject) => { | ||
const json = await fetch('https://store.steampowered.com/api/featuredcategories', this.headers); | ||
resolve(json); | ||
}); | ||
async getFeaturedCategories() { | ||
const json = await fetch('https://store.steampowered.com/api/featuredcategories', this.headers); | ||
return Object.values(json); | ||
} | ||
@@ -106,7 +97,5 @@ | ||
*/ | ||
getFeaturedGames() { | ||
return new Promise(async (resolve, reject) => { | ||
const json = await fetch('https://store.steampowered.com/api/featured', this.headers); | ||
resolve(json); | ||
}); | ||
async getFeaturedGames() { | ||
const json = await fetch('https://store.steampowered.com/api/featured', this.headers); | ||
return json; | ||
} | ||
@@ -119,8 +108,6 @@ | ||
*/ | ||
getGameAchievements(app) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v2?gameid=${app}`, this.headers); | ||
resolve(json.achievementpercentages.achievements); | ||
}); | ||
async getGameAchievements(app) { | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v2?gameid=${app}`, this.headers); | ||
return json.achievementpercentages.achievements; | ||
} | ||
@@ -135,22 +122,20 @@ | ||
*/ | ||
getGameDetails(app, force) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
app = app.toString(); | ||
if (this.options.enabled) { | ||
if (force || (this.cache.has(app) && this.cache.get(app).expires <= Date.now()) || !this.cache.has(app)) { | ||
const json = await fetch(`https://store.steampowered.com/api/appdetails?appids=${app}`, this.headers); | ||
if (!json[app].success) return reject('no app found'); | ||
this.cache.set(app, { | ||
data: json[app].data, | ||
expires: Date.now() + this.options.expires | ||
}); | ||
} | ||
} else { | ||
async getGameDetails(app, force) { | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
app = app.toString(); | ||
if (this.options.enabled) { | ||
if (force || (this.cache.has(app) && this.cache.get(app).expires <= Date.now()) || !this.cache.has(app)) { | ||
const json = await fetch(`https://store.steampowered.com/api/appdetails?appids=${app}`, this.headers); | ||
if (!json[app].success) return reject('no app found'); | ||
return resolve(json[app].data); | ||
if (!json[app].success) throw new Error('no app found'); | ||
this.cache.set(app, { | ||
data: json[app].data, | ||
expires: Date.now() + this.options.expires | ||
}); | ||
} | ||
resolve(this.cache.get(app).data); | ||
}); | ||
} else { | ||
const json = await fetch(`https://store.steampowered.com/api/appdetails?appids=${app}`, this.headers); | ||
if (!json[app].success) throw new Error('no app found'); | ||
return json[app].data; | ||
} | ||
return this.cache.get(app).data; | ||
} | ||
@@ -163,9 +148,7 @@ | ||
*/ | ||
getGameNews(app) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamNews/GetNewsForApp/v2?appid=${app}`, this.headers); | ||
if (json.appnews.count === 0) return reject('no news found'); | ||
resolve(json.appnews.newsitems); | ||
}); | ||
async getGameNews(app) { | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamNews/GetNewsForApp/v2?appid=${app}`, this.headers); | ||
if (json.appnews.count === 0) throw new Error('no news found'); | ||
return json.appnews.newsitems; | ||
} | ||
@@ -178,9 +161,7 @@ | ||
*/ | ||
getGamePlayers(app) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetNumberOfCurrentPlayers/v1?appid=${app}`, this.headers); | ||
if (json.response.result !== 1) return reject('invalid app id'); | ||
resolve(json.response.player_count); | ||
}); | ||
async getGamePlayers(app) { | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetNumberOfCurrentPlayers/v1?appid=${app}`, this.headers); | ||
if (json.response.result !== 1) throw new Error('invalid app id'); | ||
return json.response.player_count; | ||
} | ||
@@ -193,33 +174,29 @@ | ||
*/ | ||
getGameSchema(app) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetSchemaForGame/v2?key=${this.key}&appid=${app}`, this.headers); | ||
if (!json.game) return reject('game not found'); | ||
resolve(json.game); | ||
}); | ||
async getGameSchema(app) { | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetSchemaForGame/v2?key=${this.key}&appid=${app}`, this.headers); | ||
if (!json.game) throw new Error('game not found'); | ||
return json.game; | ||
} | ||
/** | ||
* Get every server associated with ip | ||
* @param {string} ip IP to request | ||
* Get every server associated with host | ||
* @param {string} host Host to request | ||
* @returns {Promise<Array<Object>>} Objects consisting of server info | ||
*/ | ||
getServers(ip) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!ipReg.test(ip)) return reject('no ip provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamApps/GetServersAtAddress/v1?addr=${ip}`, this.headers); | ||
if (!json.response.success) return reject('invalid ip'); | ||
resolve(json.response.servers.map(server => ({ | ||
address: server.addr, | ||
appID: server.appid, | ||
game: server.gamedir, | ||
gmsindex: server.gmsindex, | ||
lan: server.lan, | ||
port: server.gameport, | ||
region: server.region, | ||
secure: server.secure, | ||
specPort: server.specPort | ||
}))); | ||
}); | ||
async getServers(host) { | ||
if (!host) throw new Error('no host provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamApps/GetServersAtAddress/v1?addr=${host}`, this.headers); | ||
if (!json.response.success) throw new Error('invalid host'); | ||
return json.response.servers.map(server => ({ | ||
address: server.addr, | ||
appID: server.appid, | ||
game: server.gamedir, | ||
gmsindex: server.gmsindex, | ||
lan: server.lan, | ||
port: server.gameport, | ||
region: server.region, | ||
secure: server.secure, | ||
specPort: server.specPort | ||
})); | ||
} | ||
@@ -233,19 +210,17 @@ | ||
*/ | ||
getUserAchievements(id, app) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no user id provided'); | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetPlayerAchievements/v1?key=${this.key}&steamid=${id}&appid=${app}`, this.headers); | ||
const stats = json.playerstats; | ||
if (!stats.success) return reject('error getting achievements'); | ||
resolve({ | ||
gameName: stats.gameName, | ||
steamID: stats.steamID, | ||
achievements: stats.achievements.map(achievement => ({ | ||
api: achievement.apiname, | ||
achieved: achievement.achieved ? true : false, | ||
unlockTime: achievement.unlocktime | ||
})) | ||
}); | ||
}); | ||
async getUserAchievements(id, app) { | ||
if (!idReg.test(id)) throw new Error('no user id provided'); | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetPlayerAchievements/v1?key=${this.key}&steamid=${id}&appid=${app}`, this.headers); | ||
const stats = json.playerstats; | ||
if (!stats.success) throw new Error('error getting achievements'); | ||
return { | ||
gameName: stats.gameName, | ||
steamID: stats.steamID, | ||
achievements: stats.achievements.map(achievement => ({ | ||
api: achievement.apiname, | ||
achieved: achievement.achieved ? true : false, | ||
unlockTime: achievement.unlocktime | ||
})) | ||
}; | ||
} | ||
@@ -258,17 +233,15 @@ | ||
*/ | ||
getUserBadges(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetBadges/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
resolve(json.response.badges.map(badge => ({ | ||
appID: badge.appid, | ||
badgeID: badge.badgeid, | ||
borderColor: badge.border_color, | ||
communityItemID: badge.communityitemid, | ||
completionTime: badge.completion_time, | ||
level: badge.level, | ||
scarcity: badge.scarcity, | ||
xp: badge.xp | ||
}))); | ||
}); | ||
async getUserBadges(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetBadges/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
return json.response.badges.map(badge => ({ | ||
appID: badge.appid, | ||
badgeID: badge.badgeid, | ||
borderColor: badge.border_color, | ||
communityItemID: badge.communityitemid, | ||
completionTime: badge.completion_time, | ||
level: badge.level, | ||
scarcity: badge.scarcity, | ||
xp: badge.xp | ||
})); | ||
} | ||
@@ -281,17 +254,15 @@ | ||
*/ | ||
getUserBans(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetPlayerBans/v1?key=${this.key}&steamids=${id}`, this.headers); | ||
const ban = json.players[0]; | ||
resolve({ | ||
communityBanned: ban.CommunityBanned, | ||
daysSinceLastBan: ban.DaysSinceLastBan, | ||
economyBan: ban.EconomyBan, | ||
numberOfVACBans: ban.NumberOfVACBans, | ||
numberOfGameBans: ban.NumberOfGameBans, | ||
steamID: ban.SteamID, | ||
VACBanned: ban.VACBanned | ||
}); | ||
}); | ||
async getUserBans(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetPlayerBans/v1?key=${this.key}&steamids=${id}`, this.headers); | ||
const ban = json.players[0]; | ||
return { | ||
communityBanned: ban.CommunityBanned, | ||
daysSinceLastBan: ban.DaysSinceLastBan, | ||
economyBan: ban.EconomyBan, | ||
numberOfVACBans: ban.NumberOfVACBans, | ||
numberOfGameBans: ban.NumberOfGameBans, | ||
steamID: ban.SteamID, | ||
VACBanned: ban.VACBanned | ||
}; | ||
} | ||
@@ -304,17 +275,10 @@ | ||
*/ | ||
getUserFriends(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetFriendList/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
const friends = json.friendslist.friends; | ||
const newFriends = []; | ||
for (const friend of friends) { | ||
newFriends.push({ | ||
steamID: friend.steamid, | ||
relationship: friend.relationship, | ||
friendSince: friend.friend_since | ||
}); | ||
} | ||
resolve(newFriends); | ||
}); | ||
async getUserFriends(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetFriendList/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
return json.friendslist.friends.map(friend => ({ | ||
steamID: friend.steamid, | ||
relationship: friend.relationship, | ||
friendSince: friend.friend_since | ||
})); | ||
} | ||
@@ -327,9 +291,7 @@ | ||
*/ | ||
getUserGroups(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetUserGroupList/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
if (!json.response.success) return reject('failed'); | ||
resolve(json.response.groups.map(group => group.gid)); | ||
}); | ||
async getUserGroups(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetUserGroupList/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
if (!json.response.success) throw new Error('failed'); | ||
return json.response.groups.map(group => group.gid); | ||
} | ||
@@ -342,8 +304,6 @@ | ||
*/ | ||
getUserLevel(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetSteamLevel/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
resolve(json.response.player_level); | ||
}); | ||
async getUserLevel(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetSteamLevel/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
return json.response.player_level; | ||
} | ||
@@ -356,12 +316,10 @@ | ||
*/ | ||
getUserOwnedGames(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetOwnedGames/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
resolve(json.response.games.map(game => ({ | ||
appID: game.appid, | ||
playTime: game.playtime_forever, | ||
playTime2: game.playtime_2weeks || null | ||
}))); | ||
}); | ||
async getUserOwnedGames(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetOwnedGames/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
return json.response.games.map(game => ({ | ||
appID: game.appid, | ||
playTime: game.playtime_forever, | ||
playTime2: game.playtime_2weeks || null | ||
})); | ||
} | ||
@@ -374,15 +332,13 @@ | ||
*/ | ||
getUserRecentGames(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetRecentlyPlayedGames/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
resolve(json.response.games.map(game => ({ | ||
appID: game.appid, | ||
logoURL: `https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/${game.appid}/${game.img_logo_url}.jpg`, | ||
name: game.name, | ||
iconURL: `https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/${game.appid}/${game.img_icon_url}.jpg`, | ||
playTime: game.playtime_forever, | ||
playTime2: game.playtime_2weeks | ||
}))); | ||
}); | ||
async getUserRecentGames(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/IPlayerService/GetRecentlyPlayedGames/v1?key=${this.key}&steamid=${id}`, this.headers); | ||
return json.response.games.map(game => ({ | ||
appID: game.appid, | ||
logoURL: `https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/${game.appid}/${game.img_logo_url}.jpg`, | ||
name: game.name, | ||
iconURL: `https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/${game.appid}/${game.img_icon_url}.jpg`, | ||
playTime: game.playtime_forever, | ||
playTime2: game.playtime_2weeks | ||
})); | ||
} | ||
@@ -396,22 +352,20 @@ | ||
*/ | ||
getUserServers(hide = false, key = this.key) { | ||
return new Promise(async (resolve, reject) => { | ||
const json = await fetch(`${this.baseURL}/IGameServersService/GetAccountList/v1?key=${key}`, this.headers); | ||
const response = json.response; | ||
resolve({ | ||
actor: response.actor, | ||
expires: response.expires, | ||
banned: response.is_banned, | ||
lastActionTime: response.last_action_time, | ||
servers: response.servers.filter(server => hide && !(server.is_deleted || server.is_expired)).map(server => ({ | ||
appID: server.appid, | ||
deleted: server.is_deleted, | ||
expired: server.is_expired, | ||
lastLoginTime: server.rt_last_logon, | ||
memo: server.memo, | ||
steamID: server.steamid, | ||
token: server.login_token | ||
})) | ||
}); | ||
}); | ||
async getUserServers(hide = false, key = this.key) { | ||
const json = await fetch(`${this.baseURL}/IGameServersService/GetAccountList/v1?key=${key}`, this.headers); | ||
const response = json.response; | ||
return { | ||
actor: response.actor, | ||
expires: response.expires, | ||
banned: response.is_banned, | ||
lastActionTime: response.last_action_time, | ||
servers: response.servers.filter(server => hide && !(server.is_deleted || server.is_expired)).map(server => ({ | ||
appID: server.appid, | ||
deleted: server.is_deleted, | ||
expired: server.is_expired, | ||
lastLoginTime: server.rt_last_logon, | ||
memo: server.memo, | ||
steamID: server.steamid, | ||
token: server.login_token | ||
})) | ||
}; | ||
} | ||
@@ -425,10 +379,8 @@ | ||
*/ | ||
getUserStats(id, app) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no user id provided'); | ||
if (!appReg.test(app)) return reject('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetUserStatsForGame/v2?key=${this.key}&steamid=${id}&appid=${app}`, this.headers); | ||
if (!json.playerstats) return reject('game not found for user'); | ||
resolve(json.playerstats); | ||
}); | ||
async getUserStats(id, app) { | ||
if (!idReg.test(id)) throw new Error('no user id provided'); | ||
if (isNaN(app)) throw new Error('no appid provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUserStats/GetUserStatsForGame/v2?key=${this.key}&steamid=${id}&appid=${app}`, this.headers); | ||
if (!json.playerstats) throw new Error('game not found for user'); | ||
return json.playerstats; | ||
} | ||
@@ -441,27 +393,25 @@ | ||
*/ | ||
getUserSummary(id) { | ||
return new Promise(async (resolve, reject) => { | ||
if (!idReg.test(id)) return reject('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetPlayerSummaries/v2?key=${this.key}&steamids=${id}`, this.headers); | ||
const player = json.response.players[0]; | ||
if (!player) return reject('invalid id'); | ||
resolve({ | ||
avatar: { | ||
small: player.avatar, | ||
medium: player.avatarmedium, | ||
large: player.avatarfull | ||
}, | ||
commentPermission: player.commentpermission, | ||
created: player.timecreated, | ||
lastLogOff: player.lastlogoff, | ||
nickname: player.personaname, | ||
personaState: player.personastate, | ||
personaStateFlags: player.personastateflags, | ||
primaryGroupID: player.primaryclanid, | ||
profileState: player.profilestate, | ||
profileURL: player.profileurl, | ||
steamID: player.steamid, | ||
visibilityState: player.communityvisibilitystate | ||
}); | ||
}); | ||
async getUserSummary(id) { | ||
if (!idReg.test(id)) throw new Error('no id provided'); | ||
const json = await fetch(`${this.baseURL}/ISteamUser/GetPlayerSummaries/v2?key=${this.key}&steamids=${id}`, this.headers); | ||
const player = json.response.players[0]; | ||
if (!player) throw new Error('invalid id'); | ||
return { | ||
avatar: { | ||
small: player.avatar, | ||
medium: player.avatarmedium, | ||
large: player.avatarfull | ||
}, | ||
commentPermission: player.commentpermission, | ||
created: player.timecreated, | ||
lastLogOff: player.lastlogoff, | ||
nickname: player.personaname, | ||
personaState: player.personastate, | ||
personaStateFlags: player.personastateflags, | ||
primaryGroupID: player.primaryclanid, | ||
profileState: player.profilestate, | ||
profileURL: player.profileurl, | ||
steamID: player.steamid, | ||
visibilityState: player.communityvisibilitystate | ||
}; | ||
} | ||
@@ -468,0 +418,0 @@ } |
18087
399