steamutils 1.3.5 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/SteamClient.js +39 -12
  2. package/index.js +11 -13
  3. package/package.json +2 -1
package/SteamClient.js CHANGED
@@ -108,6 +108,7 @@ function SteamClient({
108
108
  let lastTimePartySearch = 0
109
109
  const appsPlayed = []
110
110
  const ownedApps = []
111
+ let logOffEvent = null
111
112
 
112
113
  const onAnyCallbacks = []
113
114
 
@@ -487,7 +488,10 @@ function SteamClient({
487
488
 
488
489
  if (['ServiceUnavailable', 'NoConnection'].includes(msg) && autoReconnect && !isLogOff) {
489
490
  async function relogin(retry) {
490
- if (retry <= 0) {
491
+ if (isLogOff) {
492
+ console.error("Cannot relogin (logoff)")
493
+ return false
494
+ } else if (retry <= 0) {
491
495
  console.error("Cannot relogin")
492
496
  return false
493
497
  } else {
@@ -500,21 +504,44 @@ function SteamClient({
500
504
  console.log("Relogin success")
501
505
  return true
502
506
  } else {
503
- await sleep(120000)
507
+ const isLogOff = await new Promise((resolve, reject) => {
508
+ logOffEvent = resolve
509
+ setTimeout(resolve, 120000)
510
+ })
511
+ logOffEvent = null
512
+ if (isLogOff === true) {
513
+ return false
514
+ }
504
515
  return await relogin(retry - 1)
505
516
  }
506
517
  } else {
507
- await sleep(120000)
518
+ const isLogOff = await new Promise((resolve, reject) => {
519
+ logOffEvent = resolve
520
+ setTimeout(resolve, 120000)
521
+ })
522
+ logOffEvent = null
523
+ if (isLogOff === true) {
524
+ return false
525
+ }
508
526
  return await relogin(retry - 1)
509
527
  }
510
528
  }
511
529
  }
512
530
 
513
- await sleep(60000)
514
- const isSuccess = await relogin(50)
515
- if (!isSuccess) {
531
+ const isLogOff = await new Promise((resolve, reject) => {
532
+ logOffEvent = resolve
533
+ setTimeout(resolve, 60000)
534
+ })
535
+ logOffEvent = null
536
+ if (isLogOff === true) {
516
537
  offAllEvent()
517
538
  doClearIntervals()
539
+ } else {
540
+ const isSuccess = await relogin(50)
541
+ if (!isSuccess) {
542
+ offAllEvent()
543
+ doClearIntervals()
544
+ }
518
545
  }
519
546
  } else {
520
547
  offAllEvent()
@@ -1407,7 +1434,7 @@ function SteamClient({
1407
1434
 
1408
1435
  async function logOff() {
1409
1436
  isLogOff = true
1410
-
1437
+ logOffEvent?.(true)
1411
1438
  steamClient.logOff()
1412
1439
  }
1413
1440
 
@@ -1764,10 +1791,10 @@ function SteamClient({
1764
1791
  return steamClient
1765
1792
  },
1766
1793
  getAccountInfoName,
1767
- async getPlayersProfile(steamId, retry = 3){
1794
+ async getPlayersProfile(steamId, retry = 3) {
1768
1795
  for (let i = 0; i < retry; i++) {
1769
1796
  const profile = await getPlayersProfile(steamId)
1770
- if(profile){
1797
+ if (profile) {
1771
1798
  return profile
1772
1799
  }
1773
1800
  }
@@ -1873,13 +1900,13 @@ function SteamClient({
1873
1900
  } catch (e) {
1874
1901
  }
1875
1902
  },
1876
- getLastTimePartyRegister(){
1903
+ getLastTimePartyRegister() {
1877
1904
  return lastTimePartyRegister
1878
1905
  },
1879
- getLastTimePartySearch(){
1906
+ getLastTimePartySearch() {
1880
1907
  return lastTimePartySearch
1881
1908
  },
1882
- getLicenses(){
1909
+ getLicenses() {
1883
1910
  return steamClient.licenses
1884
1911
  const exampleLicenses = [{
1885
1912
  package_id: 303386,
package/index.js CHANGED
@@ -16,6 +16,7 @@ import axios from 'axios'
16
16
  import * as cheerio from 'cheerio'
17
17
  import fs from "fs";
18
18
  import FormData from "form-data";
19
+ import {StringUtils} from "alpha-common-utils/src";
19
20
 
20
21
  const MAX_RETRY = 10
21
22
  let requestTimestamp = 0
@@ -998,7 +999,7 @@ class SteamUser {
998
999
  const text = $(line).text()
999
1000
  $(line).remove()
1000
1001
  return text
1001
- }).concat(profileBanStatusEl.text()).map(text => text?.replaceAll(/[\t\n\r]/gi, ' ')?.replaceAll(/\s+/gi, ' ')?.trim()).filter(Boolean)
1002
+ }).concat(profileBanStatusEl.text()).map(text => StringUtils.cleanSpace(text)).filter(Boolean)
1002
1003
  const GameBan = SteamUser.parseGameBanType(gameBanFull)
1003
1004
  let dayLastBan = null
1004
1005
  if (GameBan && GameBan.daysSinceLastBan !== null) {
@@ -2357,10 +2358,10 @@ class SteamUser {
2357
2358
 
2358
2359
  const isNickname = !!friendBlockContent.find('.player_nickname_hint').length
2359
2360
 
2360
- const game = friendBlockContent.find(`.friend_game_link, .linkFriend_in-game`).text().replaceAll(/\s+/g, ' ').trim().removePrefix('In-Game').trim()
2361
+ const game = StringUtils.cleanSpace(friendBlockContent.find(`.friend_game_link, .linkFriend_in-game`).text()).removePrefix('In-Game').trim()
2361
2362
  friendBlockContent.find(`.friend_small_text, .friendSmallText`).remove()
2362
2363
 
2363
- const lastOnline = friendBlockContent.find(`.friend_last_online_text`).text().replaceAll(/\s+/g, ' ').trim()
2364
+ const lastOnline = StringUtils.cleanSpace(friendBlockContent.find(`.friend_last_online_text`).text())
2364
2365
  friendBlockContent.find(`.friend_last_online_text`).remove()
2365
2366
 
2366
2367
  let username = friendBlockContent.text().trim()
@@ -5532,6 +5533,7 @@ class SteamUser {
5532
5533
  "You listed an item on the Community Market.",
5533
5534
  "You canceled a listing on the Community Market. The item was returned to you.",
5534
5535
  "Crafted",
5536
+ "Expired",
5535
5537
  "Earned a new rank and got a drop",
5536
5538
  "Got an item drop",
5537
5539
  "Random item drop",
@@ -5603,7 +5605,7 @@ class SteamUser {
5603
5605
  for (const tradehistory_items_el of querySelectorAll($, '.tradehistory_items', tradehistoryrow_el)) {
5604
5606
  const plusminus = tradehistory_items_el.find('.tradehistory_items_plusminus').text().trim()
5605
5607
  for (const itemEl of querySelectorAll($, '.tradehistory_items_group > .history_item', tradehistory_items_el)) {
5606
- const text = plainText(itemEl.text())//You did not receive any items in this trade.
5608
+ const text = StringUtils.cleanSpace(itemEl.text())//You did not receive any items in this trade.
5607
5609
  const appID = itemEl.attr('data-appid')
5608
5610
  const classid = itemEl.attr('data-classid')
5609
5611
  const instanceid = itemEl.attr('data-instanceid')
@@ -5837,7 +5839,7 @@ class SteamUser {
5837
5839
  const playerAvatar = $1.find('.playerAvatar')
5838
5840
  const avatar = playerAvatar.find('img')?.attr('src')
5839
5841
  const link = playerAvatar.find('a')?.attr('href')
5840
- const header = $1.find('.tradeoffer_header').text().replaceAll(/\t/g, ' ').replaceAll(/\s+/g, ' ').trim()
5842
+ const header = StringUtils.cleanSpace($1.find('.tradeoffer_header').text())
5841
5843
  const active = $1.find('.tradeoffer_items_ctn').hasClass("active")
5842
5844
 
5843
5845
  tradeOffers.push({
@@ -5989,12 +5991,12 @@ class SteamUser {
5989
5991
  const market_headertip_container_warning_el = $('.market_headertip_container_warning')
5990
5992
  const market_warning_header_el = market_headertip_container_warning_el.find('#market_warning_header')
5991
5993
  if (market_headertip_container_warning_el.length && market_warning_header_el.length) {
5992
- const market_warning_header = market_warning_header_el.text().replaceAll(/\t/g, ' ').replaceAll(/\s+/g, ' ').trim()
5994
+ const market_warning_header = StringUtils.cleanSpace(market_warning_header_el.text())
5993
5995
  const market_restrictions = []
5994
5996
  market_headertip_container_warning_el.find('ul.market_restrictions > li').each(function () {
5995
5997
  const el = $(this);
5996
5998
  el.find('a').remove()
5997
- market_restrictions.push(el.text().replaceAll(/\t/g, ' ').replaceAll(/\s+/g, ' ').trim())
5999
+ market_restrictions.push(StringUtils.cleanSpace(el.text()))
5998
6000
  })
5999
6001
  return {
6000
6002
  market_warning_header,
@@ -6013,7 +6015,7 @@ class SteamUser {
6013
6015
  return null
6014
6016
  }
6015
6017
  const $ = cheerio.load(response)
6016
- const text = $('.help_event_limiteduser .help_event_limiteduser_spend').text().replaceAll(/[\t\n\r]/gi, ' ').replaceAll(/\s+/g, ' ').trim()
6018
+ const text = StringUtils.cleanSpace($('.help_event_limiteduser .help_event_limiteduser_spend').text())
6017
6019
  if (text?.startsWith("Amount Spent on Steam")) {
6018
6020
  return text
6019
6021
  } else {
@@ -6091,7 +6093,7 @@ class SteamUser {
6091
6093
  const receive_price = parseInt($1.find(`.market_listing_price span[title="This is how much you will receive."]`).text().replaceAll(`(`, '').replaceAll(`)`, '').replaceAll(`₫`, '').replaceAll(`.`, '').replaceAll(`,`, '').trim())
6092
6094
  const item_name = $1.find('.market_listing_item_name_link').text()
6093
6095
  const game_name = $1.find('.market_listing_game_name').text()
6094
- const date_combined = $1.find('.market_listing_listed_date_combined').text().replaceAll(`Listed:`, '').replaceAll(/[\t\n\r]/gi, ' ').replaceAll(/\s+/gi, ' ').trim()
6096
+ const date_combined = StringUtils.cleanSpace($1.find('.market_listing_listed_date_combined').text().replaceAll(`Listed:`, ''))
6095
6097
  list.push({
6096
6098
  listingid,
6097
6099
  appid,
@@ -6113,10 +6115,6 @@ class SteamUser {
6113
6115
  }
6114
6116
  }
6115
6117
 
6116
- function plainText(text) {
6117
- return text?.replaceAll(/[\t\n\r]/gi, ' ')?.replaceAll(/\s+/g, ' ')?.trim()
6118
- }
6119
-
6120
6118
  function querySelectorAll($, selector, root) {
6121
6119
  try {
6122
6120
  if (root) {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.3.05",
3
+ "version": "1.3.07",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
+ "alpha-common-utils": "^1.0.4",
6
7
  "axios": "^1.5.1",
7
8
  "cheerio": "^1.0.0-rc.12",
8
9
  "crypto-js": "^4.1.1",