steamutils 1.1.89 → 1.1.91

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,8 @@
2
2
  <module type="WEB_MODULE" version="4">
3
3
  <component name="NewModuleRootManager">
4
4
  <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
5
  <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
7
  <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
8
  </content>
9
9
  <orderEntry type="inheritedJdk" />
package/.idea/vcs.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
5
  </component>
6
6
  </project>
package/index.js CHANGED
@@ -1045,6 +1045,37 @@ class SteamUser {
1045
1045
  }
1046
1046
  }
1047
1047
 
1048
+ static async getUsersSummaryByWebApiKey(webApiKey, steamIds) {
1049
+ if (!Array.isArray(steamIds)) {
1050
+ steamIds = [steamIds]
1051
+ }
1052
+ let response = await request(`https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${webApiKey}&steamids=${steamIds.join(',')}`)
1053
+ return response?.data?.response?.players || []
1054
+ const resultExample = [{
1055
+ "steamid": "76561199040402348",
1056
+ "communityvisibilitystate": 3,
1057
+ "profilestate": 1,
1058
+ "personaname": "Na",
1059
+ "commentpermission": 1,
1060
+ "profileurl": "https://steamcommunity.com/id/natri99/",
1061
+ "avatar": "https://avatars.steamstatic.com/834966fea6a0a8a3b7011db7f96d38b61ee0ba64.jpg",
1062
+ "avatarmedium": "https://avatars.steamstatic.com/834966fea6a0a8a3b7011db7f66d38b51ee0ba64_medium.jpg",
1063
+ "avatarfull": "https://avatars.steamstatic.com/834966fea6a0a8a3b7011db7f96e38b51ee0ba64_full.jpg",
1064
+ "avatarhash": "834966fea6a0a8a3b7011db7f96d38b51ee0ba64",
1065
+ "lastlogoff": 1685298425,
1066
+ "personastate": 0,
1067
+ "primaryclanid": "103582791470373577",
1068
+ "timecreated": 1585473529,
1069
+ "personastateflags": 0
1070
+ }]
1071
+ }
1072
+
1073
+ static async getUserFriendListByWebApiKey(webApiKey, steamId) {
1074
+ const response = await request(`http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=${webApiKey}&steamid=${steamId}&relationship=friend`);
1075
+ return response.data.friendslist.friends.map(({steamid}) => steamid) || []
1076
+ const resultExample = ["76561198112239954", "76561199239548264", "76561199446829671"]
1077
+ }
1078
+
1048
1079
  static async QueryLocations () {
1049
1080
  let response = await request(`https://steamcommunity.com//actions/QueryLocations/`)
1050
1081
  return response?.data || []
@@ -1506,6 +1537,7 @@ class SteamUser {
1506
1537
  let response = null
1507
1538
  let retry = 10
1508
1539
  let checkTooManyRequest = false
1540
+
1509
1541
  while (--retry) {
1510
1542
  const config = {
1511
1543
  baseURL: SteamcommunityURL,
@@ -1535,50 +1567,65 @@ class SteamUser {
1535
1567
  response = await axios.request(config)
1536
1568
 
1537
1569
  this._cookies.setCookies(response.headers["set-cookie"])
1538
- if (response.status === 302) {
1539
- redirectURL = response.headers.location
1540
1570
 
1541
- if (redirectURL?.startsWith('https://steamcommunity.com/id/')) {
1542
- const customURL = redirectURL.split('/')[4];
1543
- if (customURL) {
1544
- this._myProfile = `id/${customURL}`
1571
+ switch (response.status) {
1572
+ case 302: {
1573
+ redirectURL = response.headers.location
1574
+
1575
+ if (redirectURL?.startsWith('https://steamcommunity.com/id/')) {
1576
+ const customURL = redirectURL.split('/')[4];
1577
+ if (customURL) {
1578
+ this._myProfile = `id/${customURL}`
1579
+ }
1580
+ } else if (redirectURL?.startsWith('https://steamcommunity.com/login/')) {
1581
+ console.error('Login first', this._steamid_user)
1582
+ return null
1545
1583
  }
1546
- } else if (redirectURL?.startsWith('https://steamcommunity.com/login/')) {
1547
- console.error('Login first', this._steamid_user)
1548
- return null
1549
- }
1550
1584
 
1551
- console.log(`Redirect to ${redirectURL}`)
1552
- } else if (response.status === 200) {
1553
- if (response.data && typeof response.data === 'string') {
1554
- response._$ = function () {
1555
- return cheerio.load(response.data
1556
- .replaceAll(/[\t\n\r]/gi, '')
1557
- .trim())
1585
+ console.log(`Redirect ${config.url} to ${redirectURL}`)
1586
+ break
1587
+ }
1588
+ case 200: {
1589
+ if (response.data && typeof response.data === 'string') {
1590
+ response._$ = function () {
1591
+ return cheerio.load(response.data
1592
+ .replaceAll(/[\t\n\r]/gi, '')
1593
+ .trim())
1594
+ }
1558
1595
  }
1596
+ return response
1597
+ break
1559
1598
  }
1560
- break
1561
- } else if (response.status === 429) {
1562
- console.log('Too Many Requests', config.url)
1563
- tooManyRequestTimestamp = new Date().getTime()
1564
- checkTooManyRequest = true
1565
- await sleep(30000)
1566
- } else if (response.status === 401) {
1567
- console.log('Unauthorized', config.url)
1568
- if (params.method.toUpperCase() === 'POST') {
1569
- config.headers['Content-Type'] = config.headers['content-type'] = 'multipart/form-data'
1570
- retry = 1
1599
+ case 429: {
1600
+ console.log('Too Many Requests', config.url)
1601
+ tooManyRequestTimestamp = new Date().getTime()
1602
+ checkTooManyRequest = true
1603
+ await sleep(30000)
1604
+ break
1571
1605
  }
1572
- } else if (response.status === 400) {
1573
- console.log('Error', response.status, config.url)
1574
- if (params.method.toUpperCase() === 'POST') {
1575
- config.headers['Content-Type'] = config.headers['content-type'] = 'application/x-www-form-urlencoded'
1576
- retry = 1
1606
+ case 401: {
1607
+ console.log('Unauthorized', config.url)
1608
+ if (params.method.toUpperCase() === 'POST') {
1609
+ config.headers['Content-Type'] = config.headers['content-type'] = 'multipart/form-data'
1610
+ retry = 1
1611
+ }
1612
+ break
1613
+ }
1614
+ case 400: {
1615
+ console.log('Error', response.status, config.url)
1616
+ if (params.method.toUpperCase() === 'POST') {
1617
+ config.headers['Content-Type'] = config.headers['content-type'] = 'application/x-www-form-urlencoded'
1618
+ retry = 1
1619
+ }
1620
+ break
1621
+ }
1622
+ case 500: {
1623
+ console.log(response.status, response.statusText, config.url, response.data)
1624
+ break
1625
+ }
1626
+ default: {
1627
+ console.log(response.status, config.url);
1577
1628
  }
1578
- } else if (response.status === 500) {
1579
- console.log(response.status, response.statusText, config.url, response.data)
1580
- } else {
1581
- console.log(response.status, config.url);
1582
1629
  }
1583
1630
  }
1584
1631
  return response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.1.89",
3
+ "version": "1.1.91",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.3.4",
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
- </state>
5
- </component>