Closed wntjq6902 closed 7 years ago
Testcase?
windows 7 64 bit (no sp) node.js 7.3.0
tftrade.js: var fs = require('fs'); var Steam = require('steam'); var admin = '76561198056988602';
var logOnOptions = { account_name: 'wbot01', password: '---------------' };
var crypto = require('crypto'); var SteamWebLogOn = require('steam-weblogon'); var getSteamAPIKey = require('steam-web-api-key'); var SteamTradeOffers = require('steam-tradeoffers'); var steamTrading = new Steam.SteamTrading(steamClient); var SteamTrade = require('steam-trade'); var steamTrade = new SteamTrade();
var sentryFileName = 'sentry'; // steam guard data file name
try { logOnOptions.sha_sentryfile = getSHA1(fs.readFileSync(sentryFileName)); } catch (e) { if (authCode !== '') { logOnOptions.auth_code = authCode; } }
if (fs.existsSync('servers')) { Steam.servers = JSON.parse(fs.readFileSync('servers')); }
var steamClient = new Steam.SteamClient(); var steamUser = new Steam.SteamUser(steamClient); var steamFriends = new Steam.SteamFriends(steamClient);
steamClient.connect(); steamClient.on('connected', function() { steamUser.logOn({ account_name: 'wbot01', password: '721016wntjq' }); });
steamClient.on('logOnResponse', function(logonResp) { if (logonResp.eresult == Steam.EResult.OK) { console.info('Logged in!'); steamFriends.setPersonaState(Steam.EPersonaState.Online); // to display your bot's status as "Online" steamFriends.setPersonaName('Error Bot #01 [TFITEM]'); // to change its nickname steamWebLogOn.webLogOn(function(sessionID, newCookie) { getSteamAPIKey({ sessionID: sessionID, webCookie: newCookie }, function(err, APIKey) { offers.setup({ sessionID: sessionID, webCookie: newCookie, APIKey: APIKey }); handleOffers(); }); }); } });
steamFriends.on('chatInvite', function(chatRoomID, chatRoomName, patronID) { console.info('Got an invite to ' + chatRoomName + ' from ' + steamFriends.personaStates[patronID].player_name); steamFriends.joinChat(chatRoomID); // autojoin on invite fs.writeFile('servers', JSON.stringify(servers)); });
steamFriends.on('message', function(source, message, type, chatter) {
// respond to both chat room and private messages
console.info('Received message: ' + message);
if (message == 'echo') {
steamFriends.sendMessage(source, 'Hello, World!', Steam.EChatEntryType.ChatMsg); // ChatMsg by default
}else if (message == 'price') {
steamFriends.sendMessage(source, '>>buy<< <
} }); steamUser.on('updateMachineAuth', function(sentry, callback) { fs.writeFileSync(sentryFileName, sentry.bytes); callback({ sha_file: getSHA1(sentry.bytes) }); });
steamUser.on('tradeOffers', function(number) { if (number > 0) { handleOffers(); } });
function handleOffers() { offers.getOffers({ get_received_offers: 1, active_only: 1, time_historical_cutoff: Math.round(Date.now() / 1000), get_descriptions: 1 }, function(error, body) { if (error) { return log(error); }
if (
body
&& body.response
&& body.response.trade_offers_received
) {
var descriptions = {};
body.response.descriptions = body.response.descriptions || [];
body.response.descriptions.forEach(function (desc) {
descriptions[
desc.appid + ';' + desc.classid + ';' + desc.instanceid
] = desc;
});
body.response.trade_offers_received.forEach(function (offer) {
if (offer.trade_offer_state !== 2) {
return;
}
var offerMessage = 'Got an offer ' + offer.tradeofferid +
' from ' + offer.steamid_other + '\n';
if (offer.items_to_receive) {
offerMessage += 'Items to receive: ' +
offer.items_to_receive.map(function (item) {
var desc = descriptions[
item.appid + ';' + item.classid + ';' + item.instanceid
];
return desc.name + ' (' + desc.type + ')';
}).join(', ') + '\n';
}
if (offer.items_to_give) {
offerMessage += 'Items to give: ' +
offer.items_to_give.map(function (item) {
var desc = descriptions[
item.appid + ';' + item.classid + ';' + item.instanceid
];
return desc.name + ' (' + desc.type + ')';
}).join(', ') + '\n';
}
if (offer.message && offer.message !== '') {
offerMessage += 'Message: ' + offer.message;
}
log(offerMessage);
if (offer.steamid_other === admin || !offer.items_to_give) {
offers.acceptOffer({
tradeOfferId: offer.tradeofferid,
partnerSteamId: offer.steamid_other
}, function (error, result) {
if (error) {
return log(error);
}
log('Offer ' + offer.tradeofferid + ' accepted');
offers.getOffer({
tradeofferid: offer.tradeofferid
}, function (error, result) {
if (error) {
return log(error);
}
if (result
&& result.response
&& result.response.offer
&& result.response.offer.tradeid
) {
offers.getItems({
tradeId: result.response.offer.tradeid
}, function (error, result) {
if (error) {
return log(error);
}
var items = 'Got items:\n' +
result.map(function (item) {
return 'http://steamcommunity.com/profiles/' +
item.owner + '/inventory/#' +
item.appid + '_' + item.contextid + '_' + item.id;
}).join('\n');
log(items);
});
}
});
});
} else {
offers.declineOffer({
tradeOfferId: offer.tradeofferid
}, function (error, result) {
if (error) {
return log(error);
}
log('Offer ' + offer.tradeofferid + ' declined');
});
}
});
}
}); }
function log (message) { console.log(new Date().toString() + ' - ' + message); steamFriends.sendMessage(admin, message.toString()); }
function getSHA1 (bytes) { var shasum = crypto.createHash('sha1'); shasum.end(bytes); return shasum.read(); }
yes, my code are bad, i'm still learning js
undefined
to the SteamTrading constructor because steamClient
wasn't initialized at that point.
G:\node.js\custom_steambot>node tftrade.js G:\node.js\custom_steambot\node_modules\steam\lib\handlers\trading\index.js:10 this._client.on('message', function(header, body, callback) { ^
TypeError: Cannot read property 'on' of undefined at new SteamTrading (G:\node.js\custom_steambot\node_modules\steam\lib\handl ers\trading\index.js:10:15) at Object. (G:\node.js\custom_steambot\tftrade.js:14:20)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:420:7)
at startup (bootstrap_node.js:139:9)