Node Js Steam Trade提供Bot项目

时间:2015-08-16 19:41:39

标签: javascript node.js steam steam-web-api steambot

此机器人接受所有交易,但它只需要接受包含itemToReceive中[type:'Consumer Grade SMG']项目的交易要约。我试图做类似的事情:如果itemsToReceive包含消费级SMG,那么accpet提供其他取消优惠但我失败了。我是新手,我不知道该怎么做。 抱歉我的英语不好。

我的输出控制台:

New offer #644673626 from [U:1:205839253]
    [ { appid: 730,
        contextid: { low: 2, high: 0, unsigned: true },
        assetid: '3142560367',
        classid: '310777708',
        instanceid: '302028390',
        amount: 1,
        missing: true,
        id: '3142560367',
        icon_url: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHL
    bXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FBRw7ODYYzxb08-3moS0m_7zO6-fxzNQ65J03L2Vo
    9-sigzj_kU6Mmr6LIKVdwNvZVHTqVTqxri8jZS4tYOJlyVoTeLjug',
        icon_url_large: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4o
    FJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FBRw7ODYYzxb08-3moS0m_7zO6_ummpD78A
    _27HA9tvw3gDg_UBlMWH0IYDDIwU3aVzQ_1Tvxefs1pPou8uawXBnsz5iuyjoOPjz8g',
        icon_drag_url: '',
        name: 'P90 | Sand Spray',
        market_hash_name: 'P90 | Sand Spray (Minimal Wear)',
        market_name: 'P90 | Sand Spray (Minimal Wear)',
        name_color: 'D2D2D2',
        background_color: '',
        type: 'Consumer Grade SMG',
        tradable: true,
        marketable: true,
        commodity: false,
        market_tradable_restriction: 7,
        fraudwarnings: '',
        descriptions:
         { '0': [Object],
           '1': [Object],
           '2': [Object],
           '3': [Object],
           '4': [Object],
           '5': [Object] },
        owner_descriptions: '',
        actions: { '0': [Object] },
        market_actions: { '0': [Object] },
        tags:
         { '0': [Object],
           '1': [Object],
           '2': [Object],
           '3': [Object],
           '4': [Object],
           '5': [Object] } } ]
    Offer accepted
    Offer #644673626 changed: Active -Accepted
    Received: P90 | Sand Spray

和机器人代码:

/**
 * STOREHOUSE - node-steam
 * 
 * Uses node-steam-user for notifications and accepts all incoming trade offers
 */

var SteamUser = require('steam-user');
var TradeOfferManager = require('../lib/index.js'); // use require('steam-tradeoffer-manager') in production
var fs = require('fs');

var client = new SteamUser();
var manager = new TradeOfferManager({
	"steam": client, // Polling every 30 seconds is fine since we get notifications from Steam
	"domain": "example.com", // Our domain is example.com
	"language": "en" // We want English item descriptions
});

// Steam logon options
var logOnOptions = {
	"accountName": "xxxxx",
	"password": "xxxxx"
};

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) {
	manager.setCookies(cookies, function(err) {
		if(err) {
			console.log(err);
			process.exit(1); // Fatal error since we couldn't get our API key
			return;
		}

		console.log("Got API key: " + manager.apiKey);
	});
});
manager.on('newOffer', function(offer) {
	console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
	console.log(offer.itemsToReceive);
	offer.accept(function(err) {
		if(err) {
			console.log("Unable to accept offer: " + err.message);
		} else {
			console.log("Offer accepted");
		}
	});
});

manager.on('receivedOfferChanged', function(offer, oldState) {
	console.log("Offer #" + offer.id + " changed: " + TradeOfferManager.getStateName(oldState) + " -> " + TradeOfferManager.getStateName(offer.state));
	
	if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
		offer.getReceivedItems(function(err, items) {
			if(err) {
				console.log("Couldn't get received items: " + err);
			} else {
				var names = items.map(function(item) {
					return item.name;
				});
				
				console.log("Received: " + names.join(', '));
			}
		});
	}
});

manager.on('pollData', function(pollData) {
	fs.writeFile('polldata.json', JSON.stringify(pollData));
});

1 个答案:

答案 0 :(得分:0)

试试。

manager.on('newOffer', function(offer) {
    console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
    console.log(offer.itemsToReceive);
    for(var i = 0; i > offer.itemsToReceive.length)
    {   
        if(offer.itemsToReceive[i]['type'] != "Consumer Grade SMG")
        {
            return;

            if(i == offer.itemsToReceive.length)
            {
                offer.accept(function(err){
                    if(err){
                        console.log("Unable to accept offer: " + err.message);
                    } 
                    else{
                        console.log("Offer accepted");
                    }
                });
            }
        }   
    }
});