Skip to content

Commit

Permalink
feat: Rework curator detection & curator clanid resolving to properly…
Browse files Browse the repository at this point in the history
… handle /publisher & /developer urls #266
  • Loading branch information
3urobeat committed Feb 16, 2025
1 parent 19da404 commit 3244047
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
48 changes: 37 additions & 11 deletions src/controller/helpers/handleSteamIdResolving.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2022-03-09 12:58:17
* Author: 3urobeat
*
* Last Modified: 2025-01-12 18:09:02
* Last Modified: 2025-02-16 15:55:33
* Modified By: 3urobeat
*
* Copyright (c) 2022 - 2025 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -147,20 +147,46 @@ Controller.prototype.handleSteamIdResolving = (str, expectedIdType, callback) =>
else callback(null, str, idType);
});

} else if (str.includes("store.steampowered.com/curator/")) {
logger("debug", "handleSteamIdResolving: User provided curator link...");
} else if (str.includes("store.steampowered.com/curator/") || str.includes("store.steampowered.com/developer/") || str.includes("store.steampowered.com/publisher/")) { // Apparently developer & publisher are also curators (https://github.com/3urobeat/steam-comment-service-bot/issues/266)
logger("debug", "handleSteamIdResolving: User provided curator link, resolving clanid from curator webpage...");

// Cut domain away
const split = str.replace("/?appid=", "").split("/"); // Remove any trailing app id, we don't exactly know what the user provided
if (split[split.length - 1] == "") split.pop(); // Remove trailing slash (which is now a space because of split("/"))
// Update idType and instantly abort if it doesn't match expectations
idType = "curator";

str = split[split.length - 1].split("-")[0];
if (expectedIdType && idType != expectedIdType) {
callback(`Received steamID of type ${idType} but expected ${expectedIdType}.`, null, null);
return;
}

// Update idType
idType = "curator";
// Resolve clanid from curator webpage
let output = "";

if (expectedIdType && idType != expectedIdType) callback(`Received steamID of type ${idType} but expected ${expectedIdType}.`, null, null);
else callback(null, str, idType);
require("https").get(str, (res) => {
res.setEncoding("utf8");

res.on("data", function (chunk) {
output += chunk;
});

res.on("end", () => {
try {
// Load result into cheerio
const $ = require("cheerio").load(output);

// Find follow_btn div child which has an id starting with "CuratorFollowBtn"
const CuratorFollowBtn = $(".follow_controls > .follow_btn [id^=\"CuratorFollowBtn\"]").attr("id");

if (!CuratorFollowBtn) return callback("Couldn't find follow button on curator page!", null, idType);

// Get the clanid from the follow button container id after an underscore: "CuratorFollowBtn_26299579"
callback(null, CuratorFollowBtn.split("_")[1], idType);
} catch (err) {
logger("error", "Failed to get clanid from curator page: " + err);
callback("Failed to get clanid from curator page!", null, idType);
return;
}
});
});

} else { // Doesn't seem to be an URL. We can ignore discussions & reviews as we need expect the user to provide the full URL.

Expand Down
2 changes: 1 addition & 1 deletion src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
{
"path": "src/controller/helpers/handleSteamIdResolving.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/controller/helpers/handleSteamIdResolving.js",
"checksum": "9af2534fd839007d192aa87b27c161da"
"checksum": "c9d0073bf2d421ae40c0b6b232bc3693"
},
{
"path": "src/controller/helpers/logger.js",
Expand Down

0 comments on commit 3244047

Please sign in to comment.