SHARE
TWEET

Untitled

a guest Apr 21st, 2018 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const SteamUser = require('steam-user');
  2. const SteamTotp = require('steam-totp');
  3. const SteamCommunity = require('steamcommunity');
  4. const TradeOfferManager = require('steam-tradeoffer-manager');
  5.  
  6. const Prices = require('./prices.json');
  7. const config = require('./config.json');
  8.  
  9. const client = new SteamUser();
  10. const community = new SteamCommunity();
  11. const manager = new TradeOfferManager ({
  12.     steam: client,
  13.     community: community,
  14.     language: 'en'
  15. });
  16.  
  17. const logOnOptions = {
  18.     accountName: config.username,
  19.     password: config.password,
  20.     twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  21. };
  22.  
  23. client.logOn(logOnOptions);
  24.  
  25. client.on('loggedOn', () => {
  26.     console.log('succesfully logged on.');
  27.     client.setPersona(SteamUser.Steam.EPersonaState.Online);
  28.     client.gamesPlayed(["Custom Game",440]);
  29. });
  30.  
  31. client.on("friendMessage", function(steamID, message) {
  32.     if (message == "hi") {
  33.         client.chatMessage(steamID, "hello, this works.");
  34.     }
  35. });
  36.  
  37. client.on('webSession', (sessionid, cookies) => {
  38.     manager.setCookies(cookies);
  39.  
  40.     community.setCookies(cookies);
  41.     community.startConfirmationChecker(20000, config.identitySecret);
  42. });
  43.  
  44. function acceptOffer(offer) {
  45.     offer.accept((err) => {
  46.         community.checkConfirmations();
  47.         console.log("We Accepted an offer");
  48.         if (err) console.log("There was an error accepting the offer.");
  49.     });
  50. }
  51.  
  52. function declineOffer(offer) {
  53.     offer.decline((err) => {
  54.         console.log("We Declined an offer");
  55.         if (err) console.log("There was an error declining the offer.");
  56.     });
  57. }
  58.  
  59. function processOffer(offer) {
  60.     if (offer.isGlitched() || offer.state === 11) {
  61.         console.log("Offer was glitched, declining.");
  62.         declineOffer(offer);
  63.     } else if (offer.partner.getSteamID64() === config.ownerID) {
  64.         acceptOffer(offer);
  65.     } else {
  66.         var ourItems = offer.itemsToGive;
  67.         var theirItems = offer.itemsToReceive;
  68.         var ourValue = 0;
  69.         var theirValue = 0;
  70.         for (var i in ourItems) {
  71.             var item = ourItems[i].market_name;
  72.             if(Prices[item]) {
  73.                 ourValue += Prices[item].sell;
  74.             } else {
  75.                 console.log("Invalid Value.");
  76.                 ourValue += 99999;
  77.             }
  78.         }
  79.         for(var i in theirItems) {
  80.             var item= theirItems[i].market_name;
  81.             if(Prices[item]) {
  82.                 theirValue += Prices[item].buy;
  83.             } else {
  84.             console.log("Their value was different.")
  85.             }
  86.         }
  87.     }
  88.     console.log("Our value: "+ourValue);
  89.     console.log("Their value: "+theirValue);
  90.  
  91.     if (ourValue <= theirValue) {
  92.         acceptOffer(offer);
  93.     } else {
  94.         declineOffer(offer);
  95.     }
  96. }
  97.  
  98. client.setOption("promptSteamGuardCode", false);
  99.  
  100. manager.on('newOffer', (offer) => {
  101.      processOffer(offer);
  102. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top