Jump to content
McKay Development

Recommended Posts

Posted

Hi, i've been trying to send trade offers in loop every time it blows.

 

Here is what im doing in theory:

 

im reading some valuables from local text file such as my items assetid, tradelinks and market hash name of item that i want to add trade.

then im creating offers in loop and sending them. i tried to sleep in loop and so many things every time it gives error.

 

in code : 

var SteamUser = require('steam-user');
var SteamCommunity = require('steamcommunity');
var SteamTotp = require('steam-totp');
var TradeOfferManager = require('steam-tradeoffer-manager');
var fs = require('fs');
var client = new SteamUser();
var manager = new TradeOfferManager({	"steam": client, 	"domain": "google.com","language": "en" });
var community = new SteamCommunity();
// Steam logon options
var logOnOptions = {	"accountName": "***",	"password": "****",	"twoFactorCode": SteamTotp.getAuthCode("sharedSecret")};
var lineReader = require('readline').createInterface({  input: require('fs').createReadStream('trd.txt')});
var lines=[];
var i,text,q;
var itmName,myitmid;
i = 0;
q=0;
// so far so good
lineReader.on('line', function (line) {lines[i]=line;console.log(i+". trd :"+lines[i]);i++;});
lineReader2 = require('readline').createInterface({  input: require('fs').createReadStream('nm.txt')});
lineReader2.on('line',function (line2){	itmName =line2;	console.log("itmName :"+itmName);});
lineReader3 = require('readline').createInterface({  input: require('fs').createReadStream('myitm.txt')});
lineReader3.on('line',function (line3){	myitmid =line3;console.log("myitmid :"+myitmid);});
//end reading
if (fs.existsSync('polldata.json')) {	manager.pollData = JSON.parse(fs.readFileSync('polldata.json'));}
client.logOn(logOnOptions);
client.on('loggedOn', function() {	console.log("Logged into Steam");});
client.on('webSession', function(sessionID, cookies) //right here it begins
{
  for(q = 0; q<lines.length-1;q++)//creating loop
  {
    manager.setCookies(cookies, function(err)
    {
      console.log("//////////");
      console.log("q : "+q);
      console.log(lines[q]);
      console.log("\\\\\\\\\\");
//used this because it reads all links but tries to send just lastone
      if (err){console.log(err);process.exit(1);return;}
      var linqs = getstID(lines[q]);//getting the userid from tradelink
      cItmId = getInv(linqs);//getting asset id of item
      if(cItmId !== false && cItmId !== "undefined")//checking the value before send offer
      {
      sndTrade(myitmid,cItmId,lines[q]);
      }
      else
      {
      console.log("false");
      }
    });
    community.setCookies(cookies);
  }
});
manager.on('sentOfferChanged', function(offer, oldState){console.log(`Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`);});
manager.on('pollData', function(pollData){fs.writeFile('polldata.json', JSON.stringify(pollData));});
function getstID(st)//that function gets the userid from tradelink
{
  var ll = st.substring(st.indexOf("=")+1,st.indexOf("&"));
  ll = "[U:1:"+ll+"]";
  return ll;
}
function getInv(sTeamID)//that func returns the assetid
{
  manager.loadUserInventory(sTeamID,730,2,false,function(err,inventory)
  {
    console.log("envanter yükleniyor");
    if(err)
    {
      console.log("[WARNING]: Couldn't load inventory of " + sTeamID + "!");
    }
    else
    {
      console.log(sTeamID+"envanteri yüklendi");
      for (var p = 0;p<inventory.length;p++)
      {
        if(inventory[p].market_hash_name == itmName)
        {
          console.log("item bulundu");
          return inventory[p].assetid;
        }
        else
        {
          console.log(sTeamID+"Item bulunamadı");
          return false;
        }
      }
    }
  })
}
function sndTrade(mnItm,cItm,trdLink)//that creates the offer.
{
    var offer = manager.createOffer(trdLink);
    offer.addMyItem({"assetid":mnItm,"appid":730,"contextid":2});
    offer.addTheirItem({"assetid":cItm,"appid":730,"contextid":2});
    offer.send(function(err,status)
    {
      if (err) {console.log(err);return;}
      if (status == "pending"){console.log("offer #${offer.id} sent, but reqires confirmation.");}
    });
}

i've tried without/with functions, tried to log every value to check up.

 

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...