matthewoak Posted February 17, 2025 Report Posted February 17, 2025 Ive notice on the odd ocassion, the newOffer event has triggered multiple times for the same trade offer. Maybe my sign-in logic is bad. I start listening to the events in another file> Please if anyone can explain why I get duplicate events sometimes. Thanks. async function startNewOffersListener() { if (newOffersListenerStarted) { console.log("⚠️ New offers listener is already running."); return; } newOffersListenerStarted = true; // Prevent duplicate starts console.log("✅ New offers listener started."); // Listen for new offers steamOffManagerInstance.manager.on('newOffer', offer => { //console.log('new trade offer', offer); let skinMarketName = null; let assetId = null; let actionsLink = null; let isCommodity = null; (async () => { try { offer.itemsToReceive.forEach((item, index) => { skinMarketName = item.market_hash_name; assetId = item.assetid; isCommodity = item.commodity; console.log(`newOffer`); console.log(`Item ${index + 1}:`); console.log(`Name: ${item.name}`); console.log(`Market Hash Name: ${item.market_hash_name}`); console.log(`AssetId: ${item.assetid}`); console.log(`Commodity: ${item.commodity}`); console.log(`PartnerId: ${offer.partner}`); console.log(`Actions:`); class SteamOfferManagerInstance { constructor(account) { this.account = account; this.hasWebLogOnBeenCalled = false; this.hasbeenUsed = false; this.init = false; this.firstTimeLog = false; this.access_token = ''; this.waitingForSteamGuard = false; // Track Steam Guard input state // Conditionally set proxy for client and community this.client = proxy ? new SteamUser({ debug: true, autoRelogin: true, httpProxy: proxy }) : new SteamUser(); this.community = proxy ? new SteamCommunity({ request: request.defaults({ proxy: proxy }) }) : new SteamCommunity(); this.manager = new steam_offer_manager({ "steam": this.client, "communinty": this.community, "domain": "localhost", "language": "en", "useAccessToken": true, }); //test commit for workflow this.logOnOptions = { "accountName": account.name, "password": account.password, "logonID": Date.now().toString().slice(-5), "twoFactorCode": SteamTotp.generateAuthCode(sharedSecret) }; // Handle other events this.client.on('loggedOn', () => { console.log('Successfully logged into Steam as', this.account.name); console.log('Logged in on IP', this.client.publicIP); }); this.client.on('webSession', async (sessionID, cookies) => { this.manager.setCookies(cookies, function(err) { if (err) { throw err; } }); this.community.setCookies(cookies); const [key, value] = cookies[0].split('='); this.access_token = value.split('%7C%7C')[1]; this.init = true; }); this.setRelogin(); } setRelogin() { if (!this.hasWebLogOnBeenCalled) { this.hasWebLogOnBeenCalled = true; this.isLogged = false; this.logOnOptions.logonID = Date.now().toString().slice(-5); try { if (this.firstTimeLog) { this.client.webLogOn(); } else { this.client.logOn(this.logOnOptions); this.firstTimeLog = true; } } catch (err) { if (err.message === "Already logged on, cannot log on again") { this.isLogged = true; } else { console.log('Login Error:', err.message); } } } if (this.hasWebLogOnBeenCalled) { setTimeout(() => { this.hasWebLogOnBeenCalled = false; }, 360000); } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.