steamutils 1.3.59 → 1.3.60

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 +30 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -220,7 +220,7 @@ export default class SteamUser {
220
220
  try {
221
221
  const result = (
222
222
  await request({
223
- url: "https://steamcommunity.com/profiles/" + steamId,
223
+ url: `https://steamcommunity.com/profiles/${steamId}?l=english`,
224
224
  headers: { ...(cookie && { cookie }) },
225
225
  })
226
226
  ).data;
@@ -319,10 +319,13 @@ export default class SteamUser {
319
319
  }
320
320
 
321
321
  let memberSince;
322
- if ((memberSince = moment.utc(`November 3, 2016`, ["MMMM DD, YYYY", "MMMM D, YYYY", "MMMM DD", "MMMM D"], true)).isValid()) {
323
- memberSince = memberSince.valueOf();
324
- } else {
325
- memberSince = _profile.memberSince;
322
+ const formats = ["MMMM DD, YYYY", "MMMM D, YYYY", "MMMM DD", "MMMM D"];
323
+ for (const format of formats) {
324
+ const memberSinceMoment = moment(_profile.memberSince, format, true);
325
+ if (memberSinceMoment.isValid()) {
326
+ memberSince = moment(_profile.memberSince, format, true).valueOf();
327
+ break;
328
+ }
326
329
  }
327
330
 
328
331
  const avatarHash = SteamUser.GetAvatarHashFromMultipleURL([_profile.avatarIcon, _profile.avatarFull]);
@@ -1056,9 +1059,12 @@ export default class SteamUser {
1056
1059
  .filter(Boolean);
1057
1060
  if (!queryList.some((q) => q.toLowerCase().startsWith("sessionid".toLowerCase()))) {
1058
1061
  queryList.push(`sessionid=${this.getSessionid()}`);
1059
- const protocol = urlObject.protocol ? `${urlObject.protocol}//${urlObject.host}` : "";
1060
- params.url = `${protocol}${urlObject.pathname}?${queryList.join("&")}`;
1061
1062
  }
1063
+ if (!queryList.some((q) => q.toLowerCase().startsWith("l".toLowerCase()))) {
1064
+ queryList.push(`l=english`);
1065
+ }
1066
+ const protocol = urlObject.protocol ? `${urlObject.protocol}//${urlObject.host}` : "";
1067
+ params.url = `${protocol}${urlObject.pathname}?${queryList.join("&")}`;
1062
1068
 
1063
1069
  if (!(params.headers instanceof Header)) {
1064
1070
  params.headers = new Header(params.headers);
@@ -1513,7 +1519,7 @@ export default class SteamUser {
1513
1519
  if (result instanceof ResponseError) {
1514
1520
  return result;
1515
1521
  }
1516
- if (!result.data) {
1522
+ if (!result?.data) {
1517
1523
  return;
1518
1524
  }
1519
1525
  let g_rgProfileData = JSON_parse(result.data.substringBetweenOrNull("g_rgProfileData = ", '"};') + '"}');
@@ -6384,6 +6390,22 @@ export default class SteamUser {
6384
6390
  //example 13 June, 2023
6385
6391
  return friendSince;
6386
6392
  }
6393
+
6394
+ async getWalletBalance() {
6395
+ const result = await this._httpRequest(`my?l=english`);
6396
+ if (result instanceof ResponseError) {
6397
+ return result;
6398
+ }
6399
+ const html = result?.data;
6400
+ if (!html || typeof html !== "string") {
6401
+ return;
6402
+ }
6403
+ const $ = cheerio.load(html);
6404
+ const headerEl = $("#header_wallet_balance");
6405
+ try {
6406
+ return headerEl[0].children.map((el) => $(el).text().trim()).filter(Boolean);
6407
+ } catch (e) {}
6408
+ }
6387
6409
  }
6388
6410
 
6389
6411
  SteamUser.MAX_RETRY = 10;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.3.59",
3
+ "version": "1.3.60",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",