Advertisement
maximilianmaliar

GT2king's trade bot - edited by maximilian maliar

Jul 8th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //need to install aditional package  - npm install fs
  2.  
  3. 'use strict';
  4.  
  5. const SteamUser = require('steam-user');
  6. const SteamTotp = require('steam-totp');
  7. const SteamCommunity = require('steamcommunity');
  8. const TradeOfferManager = require('steam-tradeoffer-manager');
  9.  
  10. const Prices = require('./prices.json');
  11. const config = require('./config.json');
  12. const fs = require("fs");
  13.  
  14. const client = new SteamUser();
  15. const community = new SteamCommunity();
  16. const manager = new TradeOfferManager({
  17.     steam: client,
  18.     community: community,
  19.     language: 'en'
  20. });
  21.  
  22. const logOnOptions = {
  23.     accountName: config.username,
  24.     password: config.password,
  25.     twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  26. };
  27. var offerNumber = 0;
  28.  
  29. client.logOn(logOnOptions);
  30.  
  31. client.on('loggedOn', function (){
  32.     console.log('succesfully logged on.');
  33.     client.setPersona(SteamUser.Steam.EPersonaState.Online);
  34.     client.gamesPlayed([440]);
  35. });
  36.  
  37. client.on("friendMessage", function (steamID, message) {
  38.     if (message == "hi") {
  39.         client.chatMessage(steamID, "hello, this works.");
  40.     }
  41. });
  42.  
  43. client.on('webSession', function (sessionid, cookies) {
  44.     manager.setCookies(cookies);
  45.  
  46.     community.setCookies(cookies);
  47.     community.startConfirmationChecker(20000, config.identitySecret);
  48. });
  49.  
  50. function acceptOffer(offer) {
  51.     offer.accept(function(err){
  52.         community.checkConfirmations();
  53.         if (err) console.log("There was an error accepting the offer.");
  54.     });
  55. }
  56.  
  57. function declineOffer(offer) {
  58.     offer.decline(function (err){
  59.         if (err) console.log("There was an error declining the offer.");
  60.     });
  61. }
  62.  
  63. function processOffer(offer) {
  64.     offerNumber++;
  65.     fs.writeFile("offers/offer" + offerNumber + ".json", JSON.stringify(offer));
  66.     if (offer.isGlitched() || offer.state === 11) {
  67.         console.log("Offer was glitched, declining.");
  68.         declineOffer(offer);
  69.     }
  70.     else if (offer.partner.getSteamID64() === config.ownerID) {
  71.         console.log("trade with owner");
  72.         acceptOffer(offer);
  73.     }
  74.     else {
  75.         var ourItems = offer.itemsToGive;
  76.         var theirItems = offer.itemsToReceive;
  77.         var ourValue = 0;
  78.         var theirValue = 0;
  79.         for (var i in ourItems) {
  80.             var item = ourItems[i].market_name;
  81.             if (Prices[item]) {
  82.                 ourValue += Prices[item].sell;
  83.             } else {
  84.                 console.log("Invalid Item. Declining");
  85.                 declineOffer(offer);
  86.                 return;
  87.             }
  88.         }
  89.         for (var i in theirItems) {
  90.             var item = theirItems[i].market_name;
  91.             if (Prices[item]) {
  92.                 theirValue += Prices[item].buy;
  93.             } else {
  94.                 console.log("Invalid Item. Declining");
  95.                 declineOffer(offer);
  96.                 return;
  97.             }
  98.         }
  99.         console.log("Our value: " + ourValue);
  100.         console.log("Their value: " + theirValue);
  101.  
  102.         if (ourValue <= theirValue) {
  103.             console.log("offer was accepted");
  104.             acceptOffer(offer);
  105.         } else {
  106.             console.log("Payng under price, declining");
  107.             declineOffer(offer);
  108.         }
  109.     }
  110.  
  111. }
  112.  
  113. client.setOption("promptSteamGuardCode", false);
  114.  
  115. manager.on('newOffer', function (offer) {
  116.     processOffer(offer);
  117. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement