steamutils 1.5.18 → 1.5.19

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 +63 -74
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3966,98 +3966,87 @@ export default class SteamUser {
3966
3966
  }
3967
3967
 
3968
3968
  async getFriendActivity(params) {
3969
- let { start, url, filter = {} } = params || {};
3970
- if (!params) {
3971
- start = Math.round(new Date().getTime() / 1000);
3972
- } else if (typeof params === "string") {
3973
- if (params.startsWith("http")) {
3974
- url = params;
3975
- } else {
3976
- start = params;
3977
- }
3969
+ let start,
3970
+ url,
3971
+ filter = {};
3972
+ if (typeof params === "string") {
3973
+ params.startsWith("http") ? (url = params) : (start = params);
3978
3974
  } else if (typeof params === "number") {
3979
3975
  start = params;
3980
- } else if (typeof params === "object") {
3981
- //do nothing
3976
+ } else if (params && typeof params === "object") {
3977
+ ({ start, url, filter = {} } = params);
3982
3978
  }
3983
3979
 
3984
- //start or next_request
3980
+ start = start || Math.floor(Date.now() / 1000);
3985
3981
  url = url || `${this.getMyProfileURL()}/ajaxgetusernews/?start=${start}`; //use my, not profiles/76561197977736539 getMySteamUserProfileURL
3982
+
3986
3983
  const _self = this;
3987
3984
  const activity = [];
3988
- let next_request_timestart = null;
3989
- let next_request = null;
3990
3985
  const result = await this._httpRequestAjax(url);
3991
3986
  if (result instanceof ResponseError) {
3992
3987
  return result;
3993
3988
  }
3994
3989
  const data = result?.data;
3995
- if (data?.success) {
3996
- next_request = data.next_request || null;
3997
- next_request_timestart = parseInt(next_request.substringAfterLast("?start=")) || null;
3998
- const $ = cheerio.load(data.blotter_html.replaceAll(/[\t\n\r]/gi, "").trim());
3999
- $(".blotter_day").each(function () {
4000
- const blotter_day = $(this);
4001
- const timestamp = parseInt(blotter_day.attr("id").substringAfter("blotter_day_"));
4002
- const header_date = blotter_day.find(".blotter_day_header_date").text();
4003
-
4004
- let _activity = [];
4005
-
4006
- const activityType = {
4007
- daily_rollup(blotterBlockEl) {
4008
- return _self._parseBlotterDailyRollup($, blotterBlockEl);
4009
- },
4010
- gamepurchase(blotterBlockEl) {
4011
- return _self._parseBlotterGamepurchase($, blotterBlockEl);
4012
- },
4013
- workshopitempublished() {},
4014
- recommendation() {},
4015
- userstatus() {},
4016
- screenshot() {
4017
- //screenshot_fullscreen
4018
- },
4019
- videopublished() {},
4020
- };
3990
+ if (!data?.success) return { activity, next_request_timestart: null, next_request: null };
3991
+
3992
+ const next_request = data.next_request || "";
3993
+ const next_request_timestart = parseInt(next_request.substringAfterLast("?start=")) || null;
3994
+ const $ = cheerio.load(data.blotter_html.replaceAll(/[\t\n\r]/gi, "").trim());
3995
+ const activityTypeHandlers = {
3996
+ daily_rollup(blotterBlockEl) {
3997
+ return _self._parseBlotterDailyRollup($, blotterBlockEl);
3998
+ },
3999
+ gamepurchase(blotterBlockEl) {
4000
+ return _self._parseBlotterGamepurchase($, blotterBlockEl);
4001
+ },
4002
+ workshopitempublished() {},
4003
+ recommendation() {},
4004
+ userstatus() {},
4005
+ screenshot() {
4006
+ //screenshot_fullscreen
4007
+ },
4008
+ videopublished() {},
4009
+ };
4021
4010
 
4022
- blotter_day.find(".blotter_block").each(function (index, blotterBlockEl) {
4023
- blotterBlockEl = $(blotterBlockEl);
4024
- let type = [];
4025
- blotterBlockEl.children().each(function () {
4026
- const classList = $(this).attr("class")?.replaceAll("blotter_entry", "")?.trim();
4027
- if (classList) {
4028
- type = type.concat(classList.split(" ").map((_class) => _class?.removePrefix("blotter_")));
4029
- }
4030
- });
4011
+ $(".blotter_day").each(function (_, dayElement) {
4012
+ const dayEl = $(dayElement);
4013
+ const timestamp = parseInt(dayEl.attr("id").substringAfter("blotter_day_"));
4014
+ const header_date = dayEl.find(".blotter_day_header_date").text();
4015
+
4016
+ dayEl.find(".blotter_block").each(function (index, blotterBlockEl) {
4017
+ blotterBlockEl = $(blotterBlockEl);
4018
+ const types = Array.from(
4019
+ new Set(
4020
+ blotterBlockEl
4021
+ .children()
4022
+ .map((_, child) => $(child).attr("class")?.replace("blotter_entry", "").trim())
4023
+ .get()
4024
+ .flatMap((cls) => cls?.split(" ").map((c) => c.replace("blotter_", "")) || []),
4025
+ ),
4026
+ );
4031
4027
 
4032
- let excute;
4033
- if ((excute = type.find((_class) => Object.hasOwn(activityType, _class)))) {
4034
- const __activity = activityType[excute](blotterBlockEl);
4035
- if (__activity instanceof Array) {
4036
- __activity.forEach((___activity) => {
4037
- if (!___activity.type) {
4038
- ___activity.type = excute;
4039
- }
4028
+ const handlerKey = types.find((type) => activityTypeHandlers[type]);
4029
+ if (!handlerKey) {
4030
+ const html = blotterBlockEl.html();
4031
+ console.log(html);
4032
+ return;
4033
+ }
4040
4034
 
4041
- const activityID = [___activity.type, ___activity.author?.steamId, (___activity.apps?.map?.((app) => app.id) || []).sort().join("|"), (___activity.players?.map?.((p) => p.steamId) || []).sort().join("|"), (___activity.achieved?.map?.((p) => p.title.replaceAll(/\s/gi, "").toLowerCase()) || []).sort().join("|"), (___activity.groups?.map?.((p) => p.URL) || []).sort().join("|")].filter(Boolean);
4042
- _activity.push(___activity);
4043
- });
4044
- }
4045
- } else {
4046
- const html = blotterBlockEl.html();
4047
- console.log(html);
4048
- }
4049
- });
4050
- _activity.forEach((ac) => {
4051
- ac.timestamp = timestamp;
4052
- ac.header_date = header_date;
4035
+ const parsedActivities = activityTypeHandlers[handlerKey](blotterBlockEl) || [];
4036
+ if (Array.isArray([parsedActivities])) {
4037
+ for (const parsedActivity of parsedActivities) {
4038
+ parsedActivity.type ||= handlerKey;
4039
+ parsedActivity.timestamp = timestamp;
4040
+ parsedActivity.header_date = header_date;
4053
4041
 
4054
- if (filter?.type && filter.type !== ac.type) {
4055
- return;
4042
+ if (filter?.type && filter.type !== parsedActivity.type) {
4043
+ continue;
4044
+ }
4045
+ activity.push(parsedActivity);
4056
4046
  }
4057
- activity.push(ac);
4058
- });
4047
+ }
4059
4048
  });
4060
- }
4049
+ });
4061
4050
 
4062
4051
  return {
4063
4052
  activity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.5.18",
3
+ "version": "1.5.19",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",