Node-steam-trade,如何获取商品名称?

时间:2015-05-29 17:30:46

标签: steam steam-web-api

我正在制作一个steamBot,它从用户那里获取物品,我需要获取这些物品的名称,以及在我的网站上发送它的价格。 我应该如何获取items数组中每个项目的名称? 我已经知道了物品[i] .appid assetid和其他人,但我怎么能得到名字和平均价格?

 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!");
            }
          }
        });
      }
    });
  }
});

1 个答案:

答案 0 :(得分:0)

我仍然在寻找更好的方法,但与此同时,你可以这样做:

交易要约对象中包括&#34; steamid_other&#34;您可以使用它来查询他们的库存:

'http://steamcommunity.com/profiles/' + steamid_other + '/inventory/json/730/2/?l=english'
然后,您可以将交易中的项目与其库存中的项目进行匹配,并访问&#34; market_hash_name&#34;这可用于查询价格信息,如下所示:

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

如果您找到更好的解决方案,请告诉我,祝您好运