2015-05-29 72 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) 

讓我知道如果你找到更好的解決方案,祝你好運