steamutils 1.3.14 → 1.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +78 -78
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1744,6 +1744,17 @@ class SteamUser {
1744
1744
  return response
1745
1745
  }
1746
1746
 
1747
+ async _httpMyRequest(params) {
1748
+ if (typeof params === "string") {
1749
+ return await this._httpRequest(`${this.getMyProfileURL()}/${_.trimStart(params, '/')}`)
1750
+ } else {
1751
+ return await this._httpRequest({
1752
+ ...params,
1753
+ url: `${this.getMyProfileURL()}/${_.trimStart(params.url, '/')}`
1754
+ })
1755
+ }
1756
+ }
1757
+
1747
1758
  async _httpRequestAjax(params) {
1748
1759
  params = this._formatHttpRequest(params)
1749
1760
  const headers = params.headers instanceof Header ? params.headers : new Header(_.cloneDeep(params.headers))
@@ -1755,6 +1766,17 @@ class SteamUser {
1755
1766
  return await this._httpRequest(params)
1756
1767
  }
1757
1768
 
1769
+ async _httpMyRequestAjax(params) {
1770
+ if (typeof params === "string") {
1771
+ return await this._httpRequestAjax(`${this.getMyProfileURL()}/${_.trimStart(params, '/')}`)
1772
+ } else {
1773
+ return await this._httpRequestAjax({
1774
+ ...params,
1775
+ url: `${this.getMyProfileURL()}/${_.trimStart(params.url, '/')}`
1776
+ })
1777
+ }
1778
+ }
1779
+
1758
1780
  static RequestXML_TooManyRequests = 0
1759
1781
 
1760
1782
  static async _httpRequestXML(link) {
@@ -2460,7 +2482,7 @@ class SteamUser {
2460
2482
  }
2461
2483
 
2462
2484
  async getPendingFriendList() {
2463
- const result = await this._httpRequest(`${this._myProfile}/friends/pending`)
2485
+ const result = await this._httpMyRequest(`friends/pending`)
2464
2486
  if (!result?.data || typeof result._$ !== 'function') return null
2465
2487
  const sentInvites = this._parsePendingFriendList(result.data, '#search_results_sentinvites > div')
2466
2488
  const receiveInvites = this._parsePendingFriendList(result.data, '#search_results > div')
@@ -2474,7 +2496,7 @@ class SteamUser {
2474
2496
  if (!matchHistoryType) {
2475
2497
  return
2476
2498
  }
2477
- let result = await this._httpRequest(`${this.getMyProfileURL()}/gcpd/${AppID_CSGO}/?tab=${matchHistoryType}`)
2499
+ let result = await this._httpMyRequestAjax(`gcpd/${AppID_CSGO}/?tab=${matchHistoryType}`)
2478
2500
  if (result?.data) {
2479
2501
  const matches = this._parseMatchHistory(result?.data)
2480
2502
  const continue_token = result.data.substringBetweenOrNull('var g_sGcContinueToken =', ';').trim().removeSurrounding('\'').trim()
@@ -2527,8 +2549,8 @@ class SteamUser {
2527
2549
  let result,
2528
2550
  i = MAX_RETRY
2529
2551
  while (result?.data?.success !== true && i--) {
2530
- result = await _self._httpRequest(
2531
- `${this.getMyProfileURL()}/gcpd/${AppID_CSGO}?ajax=1&tab=${matchHistoryType}${token ? `&continue_token=${token}` : ''}&sessionid=${_self._sessionid}`)
2552
+ result = await _self._httpMyRequest(
2553
+ `gcpd/${AppID_CSGO}?ajax=1&tab=${matchHistoryType}${token ? `&continue_token=${token}` : ''}&sessionid=${_self._sessionid}`)
2532
2554
  }
2533
2555
  if (!result.data) {
2534
2556
  return null
@@ -2809,8 +2831,8 @@ class SteamUser {
2809
2831
  formData.append('steamids[]', steamID.toString())
2810
2832
  })
2811
2833
 
2812
- const {data} = await this._httpRequestAjax({
2813
- url: `${this.getMyProfileURL()}/friends/action`,
2834
+ const {data} = await this._httpMyRequestAjax({
2835
+ url: `friends/action`,
2814
2836
  method: 'POST',
2815
2837
  data: formData,
2816
2838
  })
@@ -2913,8 +2935,8 @@ class SteamUser {
2913
2935
  }
2914
2936
 
2915
2937
  async acceptFriendRequest(steamID) {
2916
- const {data} = await this._httpRequest({
2917
- url: `${this.getMyProfileURL()}/friends/action`,
2938
+ const {data} = await this._httpMyRequest({
2939
+ url: `friends/action`,
2918
2940
  data: {
2919
2941
  steamid: this._steamid_user,
2920
2942
  ajax: 1,
@@ -2992,8 +3014,8 @@ class SteamUser {
2992
3014
  getPreviousAliases = this.getNameHistory
2993
3015
 
2994
3016
  async clearPreviousAliases() {
2995
- const {data} = await this._httpRequestAjax({
2996
- url: `${this.getMyProfileURL()}/ajaxclearaliashistory/`,
3017
+ const {data} = await this._httpMyRequestAjax({
3018
+ url: `ajaxclearaliashistory/`,
2997
3019
  method: 'POST',
2998
3020
  headers: {
2999
3021
  'Content-Type': 'multipart/form-data',
@@ -3003,7 +3025,7 @@ class SteamUser {
3003
3025
  }
3004
3026
 
3005
3027
  async setupProfile() {
3006
- const profile = await this._httpRequest(`${this._myProfile}/edit?welcomed=1`)
3028
+ const profile = await this._httpMyRequest(`edit?welcomed=1`)
3007
3029
  if (!profile.data) {
3008
3030
  return false
3009
3031
  }
@@ -3019,7 +3041,7 @@ class SteamUser {
3019
3041
  summary = null,
3020
3042
  hide_profile_awards = null,
3021
3043
  }) {
3022
- const existProfile = await this._httpRequest(`${this.getMyProfileURL()}/edit/info`)
3044
+ const existProfile = await this._httpMyRequest(`edit/info`)
3023
3045
  if (!existProfile.data) {
3024
3046
  return
3025
3047
  }
@@ -3029,8 +3051,8 @@ class SteamUser {
3029
3051
  return
3030
3052
  }
3031
3053
 
3032
- const {data} = await this._httpRequestAjax({
3033
- url: `${this.getMyProfileURL()}/edit/`,
3054
+ const {data} = await this._httpMyRequestAjax({
3055
+ url: `edit/`,
3034
3056
  method: 'POST',
3035
3057
  data: {
3036
3058
  type: 'profileSave',
@@ -3066,8 +3088,8 @@ class SteamUser {
3066
3088
  }
3067
3089
 
3068
3090
  async setPersonaName(name) {
3069
- const result = await this._httpRequestAjax({
3070
- url: `${this.getMyProfileURL()}/ajaxsetpersonaname/`,
3091
+ const result = await this._httpMyRequestAjax({
3092
+ url: `ajaxsetpersonaname/`,
3071
3093
  method: 'POST',
3072
3094
  data: {
3073
3095
  persona: name,
@@ -3137,9 +3159,7 @@ class SteamUser {
3137
3159
  }
3138
3160
 
3139
3161
  async getPrivacySettings() {
3140
- const result = await this._httpRequest({
3141
- url: `${this.getMyProfileURL()}/edit/settings`,
3142
- })
3162
+ const result = await this._httpMyRequest(`edit/settings`)
3143
3163
 
3144
3164
  if (!result.data) {
3145
3165
  return
@@ -3246,8 +3266,8 @@ class SteamUser {
3246
3266
 
3247
3267
  const {
3248
3268
  data,
3249
- } = await this._httpRequestAjax({
3250
- url: `${this.getMyProfileURL()}/ajaxsetprivacy`,
3269
+ } = await this._httpMyRequestAjax({
3270
+ url: `ajaxsetprivacy`,
3251
3271
  method: 'POST',
3252
3272
  data: {
3253
3273
  Privacy: JSON.stringify(privacyValue.PrivacySettings),
@@ -3399,7 +3419,7 @@ class SteamUser {
3399
3419
  return
3400
3420
  }
3401
3421
  const _self = this
3402
- const result = await this._httpRequest(`${this.getMyProfileURL()}/friendsthatplay/${appID}`)
3422
+ const result = await this._httpMyRequest(`friendsthatplay/${appID}`)
3403
3423
  const data = {
3404
3424
  YourOwnPlaytime: [],//Your own playtime _
3405
3425
  FriendsCurrentlyPlaying: [],//Friends currently playing Counter-Strike: Global Offensive_
@@ -3503,7 +3523,7 @@ class SteamUser {
3503
3523
  }
3504
3524
 
3505
3525
  async getOwnedAppsDetail() {
3506
- const response = await this._httpRequest(`${this.getMyProfileURL()}/games/?tab=all`)
3526
+ const response = await this._httpMyRequest(`games/?tab=all`)
3507
3527
 
3508
3528
  let rgGames = response?.data?.substringBetweenOrNull('var rgGames = ', 'var rgChangingGames = []')?.trim()?.removeSuffix(';')?.trim()
3509
3529
  if (!rgGames) {
@@ -3668,8 +3688,8 @@ class SteamUser {
3668
3688
  }
3669
3689
 
3670
3690
  async _respondToGroupInvite(groupSteamID, accept) {
3671
- const {data} = await this._httpRequestAjax({
3672
- url: `${this.getMyProfileURL()}/friends/action`,
3691
+ const {data} = await this._httpMyRequestAjax({
3692
+ url: `friends/action`,
3673
3693
  data: {
3674
3694
  steamid: this.getSteamidUser(),
3675
3695
  ajax: 1,
@@ -3717,8 +3737,8 @@ class SteamUser {
3717
3737
  }
3718
3738
 
3719
3739
  async leaveGroup(groupSteamID) {
3720
- const {data} = await this._httpRequestAjax({
3721
- url: `${this.getMyProfileURL()}/friends/action`,
3740
+ const {data} = await this._httpMyRequestAjax({
3741
+ url: `friends/action`,
3722
3742
  data: {
3723
3743
  steamid: this.getSteamidUser(),
3724
3744
  ajax: 1,
@@ -4291,7 +4311,7 @@ class SteamUser {
4291
4311
  }
4292
4312
 
4293
4313
  async getNotifications() {
4294
- const {data} = await this._httpRequest(`/actions/GetNotificationCounts`)
4314
+ const {data} = await this._httpRequest(`actions/GetNotificationCounts`)
4295
4315
  if (!data) {
4296
4316
  return
4297
4317
  }
@@ -4402,9 +4422,7 @@ class SteamUser {
4402
4422
  requestFreeLicense = this.addFreeLicense
4403
4423
 
4404
4424
  async getCurrentSteamLogin() {
4405
- const result = await this._httpRequest({
4406
- url: `${this.getMyProfileURL()}/games/?tab=all`,
4407
- })
4425
+ const result = await this._httpMyRequest(`games/?tab=all`)
4408
4426
  const $ = result._$()
4409
4427
  return $('.clientConnMachineText').text()?.trim()?.substringBeforeLast('|')?.trim()
4410
4428
  }
@@ -4495,9 +4513,7 @@ class SteamUser {
4495
4513
 
4496
4514
  //Personal Game Data
4497
4515
  async getCompetitiveCooldownLevel() {
4498
- const result = await this._httpRequest({
4499
- url: `${this.getMyProfileURL()}/gcpd/730/?tab=matchmaking`,
4500
- })
4516
+ const result = await this._httpMyRequest(`gcpd/730/?tab=matchmaking`)
4501
4517
  const $ = result._$()
4502
4518
 
4503
4519
  const $table = $('table.generic_kv_table')
@@ -4575,9 +4591,7 @@ class SteamUser {
4575
4591
  }
4576
4592
 
4577
4593
  async getPersonalGameDataAccountInformation() {
4578
- const result = await this._httpRequest({
4579
- url: `${this.getMyProfileURL()}/gcpd/730/?tab=accountmain`,
4580
- })
4594
+ const result = await this._httpMyRequest(`gcpd/730/?tab=accountmain`)
4581
4595
  if (!result?.data) {
4582
4596
  return
4583
4597
  }
@@ -4782,9 +4796,7 @@ class SteamUser {
4782
4796
  }
4783
4797
 
4784
4798
  async getSteamGuardStatus() {
4785
- const result = await this._httpRequest({
4786
- url: `https://store.steampowered.com/twofactor/manage_action`,
4787
- })
4799
+ const result = await this._httpRequest(`https://store.steampowered.com/twofactor/manage_action`)
4788
4800
  const $ = cheerio.load(result?.data || '')
4789
4801
 
4790
4802
  if ($('#steam_authenticator_form #steam_authenticator_check[checked]')?.length) {
@@ -5014,9 +5026,7 @@ class SteamUser {
5014
5026
  }
5015
5027
 
5016
5028
  async removePhoneNumber() {
5017
- const result = await this._httpRequest({
5018
- url: `https://help.steampowered.com/en/wizard/HelpRemovePhoneNumber?redir=store/account`,
5019
- })
5029
+ const result = await this._httpRequest(`https://help.steampowered.com/en/wizard/HelpRemovePhoneNumber?redir=store/account`)
5020
5030
  let href = null
5021
5031
  const $ = result._$()
5022
5032
  $('a').each(function (index, el) {
@@ -5077,9 +5087,7 @@ class SteamUser {
5077
5087
  gamepad: 0,
5078
5088
  }
5079
5089
 
5080
- const result = await this._httpRequest({
5081
- url: `https://help.steampowered.com/en/wizard/AjaxVerifyAccountRecoveryCode?` + Object.keys(params).map(k => `${k}=${params[k]}`).join('&'),
5082
- })
5090
+ const result = await this._httpRequest(`https://help.steampowered.com/en/wizard/AjaxVerifyAccountRecoveryCode?` + Object.keys(params).map(k => `${k}=${params[k]}`).join('&'))
5083
5091
 
5084
5092
  if (result.data.errorMsg) {
5085
5093
  return {
@@ -5256,8 +5264,7 @@ class SteamUser {
5256
5264
  async getInventoryTrading(appID, contextid = 2) {
5257
5265
  const steamId = this.getSteamidUser()
5258
5266
  for (let i = 0; i < 10; i++) {
5259
- const url = `${this.getMyProfileURL()}/inventory/json/${appID}/${contextid}?l=english&trading=1`;
5260
- const _result = (await this._httpRequestAjax(url))?.data
5267
+ const _result = (await this._httpMyRequestAjax(`inventory/json/${appID}/${contextid}?l=english&trading=1`))?.data
5261
5268
  if (!_result) {
5262
5269
  await sleep(5000)
5263
5270
  } else if (_result.success !== true) {
@@ -5480,10 +5487,10 @@ class SteamUser {
5480
5487
  query['cursor[time_frac]'] = cursor.time_frac
5481
5488
  query['cursor[time]'] = cursor.time
5482
5489
  }
5483
- const url = `${this.getMyProfileURL()}/inventoryhistory/?${Object.keys(query).map(k => `${encodeURIComponent(k)}=${encodeURIComponent(query[k])}`).join('&')}`;
5484
5490
  let _result
5491
+ const params = Object.keys(query).map(k => `${encodeURIComponent(k)}=${encodeURIComponent(query[k])}`);
5485
5492
  try {
5486
- _result = (await this._httpRequestAjax({url}))?.data
5493
+ _result = (await this._httpMyRequestAjax(`inventoryhistory/?${params.join('&')}`))?.data
5487
5494
  } catch (e) {
5488
5495
  }
5489
5496
  if (!_result) {
@@ -5491,7 +5498,6 @@ class SteamUser {
5491
5498
  } else if (typeof _result === "string") {
5492
5499
 
5493
5500
  } else if (_result.success !== true) {
5494
- console.error(url)
5495
5501
  console.error(_result)
5496
5502
  await sleep(5000)
5497
5503
  } else {
@@ -5698,7 +5704,7 @@ class SteamUser {
5698
5704
  }
5699
5705
 
5700
5706
  async getTradeURL() {
5701
- const result = await this._httpRequest(`${this.getMyProfileURL()}/tradeoffers/privacy`)
5707
+ const result = await this._httpMyRequest(`tradeoffers/privacy`)
5702
5708
  const $ = cheerio.load(result?.data || '')
5703
5709
  const trade_offer_access_url = $('#trade_offer_access_url').attr('value')
5704
5710
  return trade_offer_access_url
@@ -5758,9 +5764,7 @@ class SteamUser {
5758
5764
  async acceptTradeOffer(tradeOfferID, partnerSteamId) {
5759
5765
  if (!partnerSteamId) {
5760
5766
  try {
5761
- partnerSteamId = (await this._httpRequest({
5762
- url: `tradeoffer/${tradeOfferID}`,
5763
- }))?.data?.split(`var g_ulTradePartnerSteamID = '`)?.[1]?.split(`';`)[0]
5767
+ partnerSteamId = (await this._httpRequest(`tradeoffer/${tradeOfferID}`))?.data?.split(`var g_ulTradePartnerSteamID = '`)?.[1]?.split(`';`)[0]
5764
5768
  } catch (e) {
5765
5769
  }
5766
5770
  }
@@ -5786,10 +5790,7 @@ class SteamUser {
5786
5790
  }
5787
5791
 
5788
5792
  async getTradeOffer() {
5789
- const result = await this._httpRequest({
5790
- url: `${this._myProfile}/tradeoffers/`,
5791
- method: 'GET',
5792
- })
5793
+ const result = await this._httpMyRequest(`tradeoffers/`)
5793
5794
  if (!result?.data) {
5794
5795
  return
5795
5796
  }
@@ -5942,9 +5943,7 @@ class SteamUser {
5942
5943
  }
5943
5944
 
5944
5945
  async getMiniprofile(steamId = this._steamid_user) {
5945
- const response = await this._httpRequestAjax({
5946
- url: `miniprofile/${SteamUser.steamID642Miniprofile(steamId)}/json/?origin=https://steamcommunity.com/`
5947
- })
5946
+ const response = await this._httpRequestAjax(`miniprofile/${SteamUser.steamID642Miniprofile(steamId)}/json/?origin=https://steamcommunity.com/`)
5948
5947
  const miniProfile = response.data;
5949
5948
  const avatar_hash = SteamUser.GetAvatarHashFromURL(miniProfile?.avatar_url) || ''
5950
5949
  return {
@@ -5981,9 +5980,7 @@ class SteamUser {
5981
5980
  }
5982
5981
 
5983
5982
  async getMarketUnavailable() {
5984
- const response = (await this._httpRequest({
5985
- url: `market`,
5986
- }))?.data
5983
+ const response = (await this._httpRequest(`market`))?.data
5987
5984
  if (!response) {
5988
5985
  return null
5989
5986
  }
@@ -6008,9 +6005,7 @@ class SteamUser {
6008
6005
  }
6009
6006
 
6010
6007
  async getAmountSpentOnSteam() {
6011
- const response = (await this._httpRequest({
6012
- url: `https://help.steampowered.com/en/`,
6013
- }))?.data
6008
+ const response = (await this._httpRequest(`https://help.steampowered.com/en/`))?.data
6014
6009
  if (!response) {
6015
6010
  return null
6016
6011
  }
@@ -6121,9 +6116,7 @@ class SteamUser {
6121
6116
  ajax: 1,
6122
6117
  ...(!!token && {continue_token: token})
6123
6118
  }
6124
- const data = (await this._httpRequestAjax({
6125
- url: `my/gcpd/730?${Object.keys(param).map(k => `${k}=${param[k]}`).join('&')}`,
6126
- }))?.data
6119
+ const data = (await this._httpMyRequestAjax(`gcpd/730?${Object.keys(param).map(k => `${k}=${param[k]}`).join('&')}`))?.data
6127
6120
  if (data.success !== true) {
6128
6121
  return
6129
6122
  }
@@ -6160,14 +6153,21 @@ class SteamUser {
6160
6153
  },
6161
6154
  reportContents,
6162
6155
  })
6163
- //gdfgkdgf
6164
- //gdfgkdgf
6165
- //gdfgkdgf
6166
- //gdfgkdgf
6167
- //gdfgkdgf
6168
- //gdfgkdgf
6169
6156
  })
6170
- return reports;
6157
+ return {
6158
+ reports,
6159
+ token: continue_token,
6160
+ text: continue_text
6161
+ };
6162
+ }
6163
+
6164
+ async getAllPlayerReports(onPageCb) {
6165
+ let token = null
6166
+ do {
6167
+ const result = await this.getPlayerReports(token)
6168
+ token = result.token
6169
+ onPageCb?.(result)
6170
+ } while (token)
6171
6171
  }
6172
6172
  }
6173
6173
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.3.14",
3
+ "version": "1.3.17",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.5",