Jump to content
McKay Development

Andrei Elvis

Member
  • Posts

    14
  • Joined

  • Last visited

Posts posted by Andrei Elvis

  1. Hello!

    I've been facing an issue. The bot was used to work before, but now it is not working. I've also tried to create a new code from scratch (maybe the old code was wrong) but still, the same result. There is no console log, nothing, about the `sentOfferChanged` event..

    Here is my code:

    // Required packages
    const SteamTotp = require('steam-totp');
    const SteamCommunity = require('steamcommunity');
    const TradeOfferManager = require('steam-tradeoffer-manager');
    
    // Steam credentials
    const username = 'xxx';
    const password = 'xxx';
    const sharedSecret = 'xxx';
    
    // Target trade link (replace with the actual trade offer link of the user)
    const tradeOfferURL = 'https://steamcommunity.com/tradeoffer/new/?partner=xxx&token=xxx';
    
    // SteamCommunity and TradeOfferManager instances
    const community = new SteamCommunity();
    const manager = new TradeOfferManager({
      community: community,
      domain: 'localhost',
      language: 'en',
      pollInterval: 10000
    });
    
    // Steam App ID and Context ID for CS:GO
    const appid = 730;
    const contextid = 2;
    
    // Log in and send a trade offer
    function loginAndSendTradeOffer() {
      console.log("Logging in to Steam...");
    
      const authCode = SteamTotp.generateAuthCode(sharedSecret);
    
      community.login({
        accountName: username,
        password: password,
        twoFactorCode: authCode
      }, (err, sessionID, cookies, steamguard) => {
        if (err) {
          console.log("Failed to login:", err);
          return;
        }
    
        console.log("Successfully logged in!");
    
        manager.on('debug', console.log)
    
        manager.setCookies(cookies, (err) => {
          if (err) {
            console.log("Failed to set cookies:", err);
            return;
          }
    
          console.log("Cookies set, fetching inventory...");
    
          manager.getUserInventoryContents('xxx', appid, contextid, true, (err, inventory) => {
            if (err) {
              console.log("Failed to fetch partner's inventory:", err);
              return;
            }
    
            if (inventory.length === 0) {
              console.log("Partner's inventory is empty, no items to trade.");
              return;
            }
    
            console.log(`Found ${inventory.length} items in partner's inventory. Picking the first item...`);
    
            const firstItem = inventory[0];
    
            const offer = manager.createOffer(tradeOfferURL);
    
            offer.addTheirItem({
              appid: appid,
              contextid: contextid,
              assetid: firstItem.assetid
            });
    
            offer.send((err, status) => {
              if (err) {
                console.log("Failed to send offer:", err);
                return;
              }
    
              console.log("Trade offer sent successfully! Status:", status);
            });
          });
        });
      });
    }
    
    manager.on('sentOfferChanged', (offer, oldState) => {
      console.log(`Trade offer #${offer.id} changed from ${oldState} to ${offer.state}.`);
    
      switch (offer.state) {
        case TradeOfferManager.ETradeOfferState.Accepted:
          console.log('The trade offer was accepted!');
          break;
        case TradeOfferManager.ETradeOfferState.Declined:
          console.log('The trade offer was declined.');
          break;
        case TradeOfferManager.ETradeOfferState.Canceled:
          console.log('The trade offer was canceled.');
          break;
        case TradeOfferManager.ETradeOfferState.InvalidItems:
          console.log('The trade offer contained invalid items.');
          break;
        case TradeOfferManager.ETradeOfferState.Countered:
          console.log('The trade offer was countered by the other party.');
          break;
        default:
          console.log('Trade offer status updated.');
          break;
      }
    });
    
    loginAndSendTradeOffer();

    And these are my logs, after having it running for few time ( after I've declined the offer )

    Logging in to Steam...
    Successfully logged in!
    Doing trade offer poll since 1 (full update)
    Cookies set, fetching inventory...
    Trade offer poll succeeded in 361 ms
    Found 39 items in partner's inventory. Picking the first item...
    Trade offer sent successfully! Status: sent
    Doing trade offer poll since 0
    Trade offer poll succeeded in 260 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 230 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 257 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 241 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 246 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 247 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 266 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 416 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 235 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 228 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 281 ms
    Doing trade offer poll since 1 (full update)
    Trade offer poll succeeded in 294 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 245 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 236 ms
    Doing trade offer poll since 0
    Trade offer poll succeeded in 378 ms

     

    What's wrong?

    I've used another steam account for this and it's the same result. It is like I am doing something wrong.. what am I doing wrong? Thanks!!

  2.  

    Hi Echo,

     

    I don't think it's possible to extract a image by the market name (without scraping the market), I do know you used to be able to get it using the classid of an item;

    I'm not sure if it still is a valid way of doing this but I remember I used to be using,

    https://steamcommunity-a.akamaihd.net/economy/image/class/730/<classid>/150fx125f
    

     

    It is useless with classid... as I have an array with the skin names :P, but thanks for reply.

    I had the script to get the image of a skin name, it was requesting the steam market with the skin name given and it were getting the skin image.

    But I do not have the code and I do not have any idea how to make it right now :'(

  3. Hello,

     

    I've saw that there's an error when the bot tries to reconnect after a session expires

    [ERROR] default - Error: Cannot log onto steamcommunity.com without first being connected to Steam network
        at SteamUser.webLogOn (/var/www/node_modules/steam-user/components/web.js:9:9)
        at SteamCommunity.<anonymous> (/var/www/socket/main.js:1453:29)
        at emitOne (events.js:96:13)
        at SteamCommunity.emit (events.js:188:7)
        at SteamCommunity._notifySessionExpired (/var/www/node_modules/steamcommunity/components/http.js:85:7)
        at /var/www/node_modules/steamcommunity/components/confirmations.js:21:10
        at /var/www/node_modules/steamcommunity/components/confirmations.js:272:4
        at SteamCommunity._checkHttpError (/var/www/node_modules/steamcommunity/components/http.js:90:3)
        at Request._callback (/var/www/node_modules/steamcommunity/components/http.js:50:61)
        at self.callback (/var/www/node_modules/request/request.js:186:22)
    

    And I want to know if there's a callback, so when an error comes in to just 

    return;

    Can I do like:

    client.webLogOn(function(err) {
        if(err) return;
    });
    

    Or something like this?

    Please help me.

    Thanks!

  4. When you add items to the offer (with .addMyItem and .addTheirItem) you need to specify appid and contextid of items.

    So, instead of

    offer.addMyItem(myItem);
    

    Replace with:

    offer.addMyItem({
        'assetid': myItem.assetid,
        'appid': appid,
        'contextid': contextid
    });
    

    Same for

    offer.addTheirItem(theirItem);
    

    Replace with:

    offer.addTheirItem({
        'assetid': theirItem.assetid,
        'appid': appid,
        'contextid': contextid
    });
    
  5. That processOffer should be like this:

    function processOffer(offer, oldstate) {
        if (offer.isGlitched() || (offer.state === 11 && oldstate == 2)) {
            //console.log("Offer was glitched, declining.");
            declineOffer(offer);
        } else if (offer.partner.getSteamID64() === config.ownerID) {
            acceptOffer(offer);
            var item = ourItems[i].market_name;
        } else {
    
         //my_code
    
        }
    

    And at the event 'sentOfferChanged' you should put the function:

    processOffer(offer, oldstate);

    Note: On the event 'sentOfferChanged' put the oldstate to be same as on the processOffer function.

  6. It should look like this:

    function acceptOffer(offer) {
        offer.accept((err) => {
            community.checkConfirmations();
            if (err) console.log("There was an error accepting the offer.");
            manager.getOffer(offer.id, function(er, of) {
                if(er) throw er;
    
                var itemsReceived = of.itemsToReceive;
                var newOffer = manager.createOffer(SOMEID);
                newOffer.addMyItem(itemsReceived[0]);
                newOffer.send(function(err, status) {console.log('error: '+err+' status: '+status)});
                console.log(newOffer.state);
            });
        });
    };

    Hope it works! :P

×
×
  • Create New...