steamutils 1.1.97 → 1.1.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/SteamClient.js +20 -4
  2. package/index.js +28 -1
  3. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -87,10 +87,12 @@ function SteamClient({
87
87
  isPartyRegister = true,
88
88
  autoPlay = false,
89
89
  autoAcceptTradeRequest = false,
90
+ autoReconnect = true,
90
91
  }) {
91
92
  const steamClient = new SteamUser()
92
93
  let prime = null
93
94
  let state = 'Offline'//InGame, Online
95
+ let isLogOff = false
94
96
 
95
97
  const events = {
96
98
  user: [],
@@ -372,6 +374,12 @@ function SteamClient({
372
374
  log('disconnected', eresult, msg)
373
375
  doClearIntervals()
374
376
  callEvent(events.disconnected, {eresult, msg})
377
+
378
+ if (eresult === 3 && autoReconnect && !isLogOff) {
379
+ setTimeout(function () {
380
+ login(true)
381
+ }, 30000)
382
+ }
375
383
  })
376
384
  steamClient.on('error', async (e) => {
377
385
  let errorStr = ``
@@ -1040,21 +1048,28 @@ function SteamClient({
1040
1048
  }
1041
1049
  }
1042
1050
 
1043
- async function login() {
1051
+ async function login(reconnect = false) {
1044
1052
  if (cookie) {
1045
- log('login with cookie')
1053
+ log(reconnect ? 'reconnect with cookie' : 'login with cookie')
1046
1054
  const newCookie = await loginWithCookie(cookie)
1047
1055
  if (newCookie) {
1048
1056
  cookie = newCookie
1049
1057
  }
1050
1058
  } else if (username && password) {
1051
- log(`login with username ${username}`)
1059
+ log(reconnect ? `reconnect with username ${username}` : `login with username ${username}`)
1052
1060
  steamClient.logOn({
1053
1061
  accountName: username, password: password, rememberPassword: true, machineName: 'Natri',
1054
1062
  })
1055
1063
  }
1056
1064
  }
1057
1065
 
1066
+ async function logOff() {
1067
+ isLogOff = true
1068
+ offAllEvent()
1069
+ doClearIntervals()
1070
+ steamClient.logOff()
1071
+ }
1072
+
1058
1073
  function onCookie(callback) {
1059
1074
  if(getCookies() ){
1060
1075
  callback(getCookies())
@@ -1286,7 +1301,8 @@ function SteamClient({
1286
1301
  isPrime(){
1287
1302
  return prime === true
1288
1303
  },
1289
- getFriendList
1304
+ getFriendList,
1305
+ logOff,
1290
1306
  }
1291
1307
  }
1292
1308
 
package/index.js CHANGED
@@ -2318,6 +2318,33 @@ class SteamUser {
2318
2318
  return await this.getFollowingPlayersList(steamID)
2319
2319
  }
2320
2320
 
2321
+ async getSentFriendRequestList() {
2322
+ const result = await this._httpRequest(`${this._myProfile}/friends/pending`)
2323
+ if (!result?.data || typeof result._$ !== 'function') return null
2324
+ const $ = result._$()
2325
+
2326
+ const data = []
2327
+ $('#search_results_sentinvites > div').each(function () {
2328
+ const el = $(this)
2329
+ const steamId = el.attr('data-steamid')
2330
+ const accountid = parseInt(el.attr('data-accountid'))
2331
+ if (steamId && accountid) {
2332
+ const invite_block_nameEl = el.find('.invite_block_name > a.linkTitle')
2333
+ const name = invite_block_nameEl.text()
2334
+ const link = invite_block_nameEl.attr('href')
2335
+ const avatar = el.find('.playerAvatar a > img[data-miniprofile="' + accountid + '"]').attr('src')
2336
+ data.push({
2337
+ name,
2338
+ link,
2339
+ avatar,
2340
+ steamId,
2341
+ accountid,
2342
+ })
2343
+ }
2344
+ })
2345
+ return data
2346
+ }
2347
+
2321
2348
  async getMatchHistory_initial (matchHistoryType) {
2322
2349
  if (!matchHistoryType) {
2323
2350
  return
@@ -3244,7 +3271,7 @@ class SteamUser {
3244
3271
  FriendsPreviously: [],//Friends who have played Counter-Strike: Global Offensive previously _
3245
3272
  FriendsAddedLibrary: [],//Friends who have Counter-Strike: Global Offensive in their library _
3246
3273
  }
3247
- if (!result.data) {
3274
+ if (!result?.data) {
3248
3275
  return data
3249
3276
  }
3250
3277
  const $ = result._$()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.1.97",
3
+ "version": "1.1.99",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.3.4",