SHARE
TWEET

Untitled

a guest Jul 21st, 2017 63 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.         if(err){
  47.             console.log("There was an error accepting the offer.");
  48.             console.log(err);
  49.         }else{
  50.             community.checkConfirmations();
  51.             console.log(`We accepted an offer.`);
  52.         }
  53.  
  54. function declineOffer(offer) {
  55.     offer.decline((err) => {
  56.         if(err){
  57.             console.log("There was an error declining the offer.");
  58.             console.log(err);
  59.         }else{
  60.             console.log(`We declined an offer.`);
  61.         }
  62.  
  63. function processOffer(offer) {
  64.     if (offer.isGlitched() || offer.state === 11) {
  65.         console.log("Offer was glitched, declining.");
  66.         declineOffer(offer);
  67.     } else if (offer.partner.getSteamID64() === config.ownerID) {
  68.         acceptOffer(offer);
  69.     } else {
  70.         var ourItems = offer.itemsToGive;
  71.         var theirItems = offer.itemsToReceive;
  72.         var ourValue = 0;
  73.         var theirValue = 0;
  74.         for (var i in ourItems) {
  75.             var item = ourItems[i].market_name;
  76.             if(Prices[item]) {
  77.                 ourValue += Prices[item].sell;
  78.             } else {
  79.                 console.log("Invalid Value.");
  80.                 ourValue += 99999;
  81.             }
  82.         }
  83.         for(var i in theirItems) {
  84.             var item= theirItems[i].market_name;
  85.             if(Prices[item]) {
  86.                 theirValue += Prices[item].buy;
  87.             } else {
  88.             console.log("Their value was different.")
  89.             }
  90.         }
  91.     }
  92.     console.log("Our value: "+ourValue);
  93.     console.log("Their value: "+theirValue);
  94.  
  95.     if (ourValue <= theirValue) {
  96.         acceptOffer(offer);
  97.     } else {
  98.         declineOffer(offer);
  99.     }
  100. }
  101.  
  102. client.setOption("promptSteamGuardCode", false);
  103.  
  104. manager.on('newOffer', (offer) => {
  105.      processOffer(offer);
  106. });
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
 
Top