Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var config = require('./config.js');
- var SteamUser = require('steam-user');
- var client = new SteamUser();
- var SteamTotp = require('steam-totp');
- var mobilecode = SteamTotp.getAuthCode(config.sharedsecret);
- var TradeOfferManager = require('steam-tradeoffer-manager');
- var manager = new TradeOfferManager({
- "steam": client,
- "domain": "http://localhost",
- "language": "en",
- "cancelTime": "600000", // 10 minutes
- "pollInterval": "5000"
- });
- var login = {
- accountName: config.username,
- password: config.password,
- twoFactorCode: mobilecode
- };
- client.logOn(login);
- client.on('loggedOn', function(details) {
- client.getPersonas([client.steamID], function(personas) {
- console.log('Logged in as ' + client.steamID + ' (' + personas[client.steamID]["player_name"] + ')');
- console.log();
- });
- console.log();
- client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
- setInterval(function() { client.webLogOn(); }, 1000 * 60); // Refreshes session every 10 minutes
- });
- client.on('webSession', function(sessionID, cookies) {
- manager.setCookies(cookies, function(err) {
- if (err) { console.log("Couldn\'t set cookies! Error: " + err); }
- });
- });
- client.on('error', function(e) {
- console.log(e);
- process.exit(1);
- });
- manager.on('newOffer', function(offer) { // When a new offer is received do the stuff below
- offer.getUserDetails(function(err, me, them) { // Get errors, an object containing the escrow days left and the inventory of the bot and the partner
- if (err) { // If there is an error log it
- console.log('Error getting user information: ' + err);
- } else if (me.escrowDays == 0 && them.escrowDays == 0) { // If there is no error, and if neither the bot nor the partner has a ESCROW cooldown do this
- if (offer.itemsToGive.length == 0 || offer.partner.getSteamID64() == config.admin) { // Check if the trade doesn't require the bot to give out any items or if the trade is coming from an admin set in the config file
- offer.accept(function(err, status) { // Accept the offer if the statement above is true
- if (err) { // If there was an error accepting the trade log it
- console.log("Error accepting trade: " + err + ". Trying to accept offer again.");
- manager.getOffer(offer.id, function(err, offer) {
- offer.accept(function(err, status) {
- if (err) {
- console("Error accepting trade: " + err + ". Trying again.");
- var timer = setInterval(function() {
- offer.accept(function(err, status) {
- if (err) {
- console("Error accepting trade: " + err + ". Trying again.");
- }
- if (status == 'accepted') {
- console.log("Trade " + offer.id + " accepted");
- console.log();
- clearInterval(timer);
- }
- });
- }, 20000);
- }
- if (status == 'accepted') { // If the trade was successfully accepted log it
- console.log("Trade " + offer.id + " accepted");
- console.log();
- }
- });
- });
- }
- if (status == 'accepted') { // If the trade was successfully accepted log it
- console.log("Trade " + offer.id + " accepted");
- console.log();
- }
- });
- } else { // If the trade does require the bot to give out items and the trade is not coming from the admin decline the offer and log it
- console.log("Offer is not a donation! Declining it.");
- offer.decline(function(err) {
- if (err) { // If there was an error declining the trade log it
- console.log('Couldn\'t decline offer. Error: ' + err);
- }
- console.log("");
- });
- }
- } else { // If either the bot or the partner has an ESCROW cooldown log it and decline the offer
- console.log("Your or your trade partner have an ESCROW cooldown! Declining trade.");
- offer.decline(function(err) {
- if (err) { // If there was an error declining the trade log it
- console.log('Couldn\'t decline offer. Error: ' + err);
- }
- console.log("");
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement