Jump to content
McKay Development

Recommended Posts

Posted

Hey, I've been using Steam Trade Offer Manager for years, but it stopped working recently. What am I missing? I've tried reading around but got lost with all the recent updates, attaching my code.

 

const SteamUser = require("steam-user");
const SteamCommunity = require("steamcommunity");
const TradeOfferManager = require("steam-tradeoffer-manager");

const { getAuthCode } = require("../authenticators/steamAuthenticator");
const { initiateSleep } = require("../functions/global");
const { logger } = require("../logger/winstonLogger");

const client = new SteamUser();

const manager = new TradeOfferManager({
  steam: client,
  domain: "example.com",
  language: "en",
});

const community = new SteamCommunity();

const logOnOptions = {
  accountName: process.env.SteamUsername,
  password: process.env.SteamPassword,
  twoFactorCode: getAuthCode(),
};

async function setUpTradeHandler() {
  await new Promise((resolve, reject) => {
    client.logOn(logOnOptions);
    client.on("loggedOn", () => {
      logger.trade("Logged into Steam");
    });
    client.on("webSession", async (sessionID, cookies) => {
      manager.setCookies(cookies, async (err) => {
        if (err) {
          console.log(err);
          process.exit(1); // Fatal error since we couldn't get our API key
        }
        await manager.apiKey;
        logger.trade("Got API key: " + manager.apiKey);
      });

      community.setCookies(cookies);
      await initiateSleep(5000);
      resolve("Logged in");
    });
  });
  return 1;
}

manager.on("newOffer", function (offer) {
  logger.trade("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
  if (offer.itemsToGive.length === 0) {
    offer.accept(function (err, status) {
      if (err) {
        logger.trade("Unable to accept offer: " + err.message);
        if (err.message === "Malformed JSON response") {
          offer.accept();
        } else if (err.message === "Not Logged In") {
          client.webLogOn();
        }
      } else {
        logger.trade("Offer accepted: " + status);
        if (status == "pending") {
          community.acceptConfirmationForObject(process.env.SteamSecret, offer.id, function (err) {
            if (err) {
              logger.trade("Can't confirm trade offer: " + err.message);
            } else {
              logger.trade("Trade offer " + offer.id + " confirmed");
            }
          });
        }
      }
    });
  }
});

community.on("sessionExpired", function (err) {
  logger.info("Session was expired, refreshing connection");
  client.webLogOn(); //relogin to Steam or refresh tradeoffer-manager cookies }
});

module.exports = { client, manager, community, setUpTradeHandler };

 

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...