112 lines
4.5 KiB
JavaScript
112 lines
4.5 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.scrapeBanStatus = exports.fetchProfileData = void 0;
|
|
const axios_1 = __importDefault(require("axios"));
|
|
const cheerio = __importStar(require("cheerio"));
|
|
const AXIOS_CONFIG = {
|
|
timeout: 10000,
|
|
headers: {
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
}
|
|
};
|
|
const fetchProfileData = async (identifier, steamLoginSecure) => {
|
|
let url = '';
|
|
// Clean identifier
|
|
const cleanId = identifier.replace(/https?:\/\/steamcommunity\.com\/(profiles|id)\//, '').replace(/\/$/, '');
|
|
if (cleanId.match(/^\d+$/)) {
|
|
url = `https://steamcommunity.com/profiles/${cleanId}?xml=1`;
|
|
}
|
|
else {
|
|
url = `https://steamcommunity.com/id/${cleanId}?xml=1`;
|
|
}
|
|
const headers = { ...AXIOS_CONFIG.headers };
|
|
if (steamLoginSecure) {
|
|
headers['Cookie'] = steamLoginSecure;
|
|
}
|
|
try {
|
|
const response = await axios_1.default.get(url, { ...AXIOS_CONFIG, headers });
|
|
const $ = cheerio.load(response.data, { xmlMode: true });
|
|
const steamId = $('steamID64').first().text().trim();
|
|
const personaName = $('steamID').first().text().trim();
|
|
const avatarRaw = $('avatarFull').first().text().trim();
|
|
// Robustly extract the first URL if concatenated
|
|
let avatar = avatarRaw;
|
|
const urls = avatarRaw.match(/https?:\/\/[^\s"'<>]+/g);
|
|
if (urls && urls.length > 0) {
|
|
avatar = urls[0];
|
|
}
|
|
// Ensure https
|
|
if (avatar && avatar.startsWith('http:')) {
|
|
avatar = avatar.replace('http:', 'https:');
|
|
}
|
|
const profileUrl = steamId
|
|
? `https://steamcommunity.com/profiles/${steamId}`
|
|
: (cleanId.match(/^\d+$/) ? `https://steamcommunity.com/profiles/${cleanId}` : `https://steamcommunity.com/id/${cleanId}`);
|
|
return {
|
|
steamId: steamId || cleanId,
|
|
personaName: personaName || 'Unknown',
|
|
avatar: avatar || 'https://avatars.akamai.steamstatic.com/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb_full.jpg',
|
|
profileUrl
|
|
};
|
|
}
|
|
catch (error) {
|
|
throw new Error(`Failed to fetch profile: ${error.message}`);
|
|
}
|
|
};
|
|
exports.fetchProfileData = fetchProfileData;
|
|
const scrapeBanStatus = async (profileUrl, steamLoginSecure) => {
|
|
try {
|
|
const headers = { ...AXIOS_CONFIG.headers };
|
|
if (steamLoginSecure) {
|
|
headers['Cookie'] = steamLoginSecure;
|
|
}
|
|
const response = await axios_1.default.get(profileUrl, { ...AXIOS_CONFIG, headers });
|
|
const $ = cheerio.load(response.data);
|
|
const banText = $('.profile_ban').text().toLowerCase();
|
|
const vacBanned = banText.includes('vac ban');
|
|
const gameBansMatch = banText.match(/(\d+)\s+game\s+ban/);
|
|
const gameBans = gameBansMatch ? parseInt(gameBansMatch[1]) : 0;
|
|
return { vacBanned, gameBans };
|
|
}
|
|
catch (error) {
|
|
return { vacBanned: false, gameBans: 0 };
|
|
}
|
|
};
|
|
exports.scrapeBanStatus = scrapeBanStatus;
|