2015-05-29 44 views
1

我正在做一个steamBot,从用户那里拿取物品,我需要得到这个物品的名称,并且它的价格是在我的网站上发送的。 我应该如何获取items数组中的每个项目的名称? 我有alreay知道项目[i] .appid assetid和其他人,但我怎么能得到名称和平均价格?Node-steam-trade,如何获取物品名称?

steam.on('tradeOffers', function(number) { 
    if (number > 0) { 
    offers.getOffers({ 
     get_received_offers: 1, 
     active_only: 1, 
     time_historical_cutoff: Math.round(Date.now()/1000) 
    }, function(error, body) { 
     if(body.response.trade_offers_received) { 
     body.response.trade_offers_received.forEach(function(offer) { 
      if (offer.trade_offer_state == 2) { 
      console.log(offer); 
      console.log('Recieved trade offer: ' + offer.tradeofferid); 

      var exception = false; 
      var items = offer.items_to_receive; 
      for(var i=0; i< items.length;i++) 
      { 
       if(items[i].appid != "730") 
       { 
        exception = true; 
        break; 
       } 
      } 
      var descriptionOfItems = ""; // assetid + classid 
      for(var i=0; i< items.length;i++) 
      { 
       appid += items[i].assetid + "-" + items[i].classid + " "; 
      } 


      if (!offer.items_to_give && !exception) { 
       offers.acceptOffer({tradeOfferId: offer.tradeofferid}); 
       console.log("Offer accepted"); 
       steam.sendMessage(offer.steamid_other, "Thanks you!"); 
       if (offer.steamid_other !== admin) { 
       steam.sendMessage(admin, offer.steamid_other+ " - " + descriptionOfItems + " just donated!"); 
       } 
      } else { 
       offers.declineOffer({tradeOfferId: offer.tradeofferid}); 
       console.log("Don't receive items from other's games!"); 
      } 
      } 
     }); 
     } 
    }); 
    } 
}); 

回答

0

我是我还在寻找更好的方式来做到这一点,但在此期间,你可以这样做:

包括在贸易优惠对象是“steamid_other”你可以用它来查询他们的库存:

'http://steamcommunity.com/profiles/' + steamid_other + '/inventory/json/730/2/?l=english' 

然后你可以匹配在贸易上的那些项目在他们的库存,并访问可用于查询价格信息,像这样的“market_hash_name”:

'http://steamcommunity.com/market/priceoverview/?appid=730&currency=3&market_hash_name=' + encodeURI(items[key].market_hash_name) 

让我知道如果你找到更好的解决方案,祝你好运