Advertisement
Guest User

bot.js

a guest
Sep 13th, 2018
245
0
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. const TeamFortress2 = require('tf2');
  6.  
  7.  
  8. const Prices = require('./prices.json');
  9. const config = require('./config.json');
  10.  
  11. const client = new SteamUser();
  12. const tf2 = new TeamFortress2(client);
  13. const community = new SteamCommunity();
  14. const manager = new TradeOfferManager ({
  15.     steam: client,
  16.     community: community,
  17.     language: 'en'
  18. });
  19.  
  20. const logOnOptions = {
  21.     accountName: config.username,
  22.     password: config.password,
  23.     twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  24. };
  25.  
  26. client.logOn(logOnOptions);
  27.  
  28.     console.log('succesfully logged on.');
  29. client.on('loggedOn', () => {
  30.     client.setPersona(SteamUser.Steam.EPersonaState.Online);
  31.     client.gamesPlayed([440, "Bot Uptime"]);
  32. });
  33.  
  34. client.on("friendMessage", function(steamID, message) {
  35.     if (message == "sfjgsfjgtuaffg") {
  36.         client.chatMessage(steamID, "hello, im just a bot, why bother? If you need to speek to the owner of the bot, please add and send a message to this account: https://steamcommunity.com/id/sanlys/ or leave a comment on the same profile, thanks!");
  37.     }
  38. });
  39.  
  40. client.on('webSession', (sessionid, cookies) => {
  41.     manager.setCookies(cookies);
  42.  
  43.     community.setCookies(cookies);
  44.     community.startConfirmationChecker(20000, config.identitySecret);
  45. });
  46.  
  47. function acceptOffer(offer) {
  48.     offer.accept((err) => {
  49.         community.checkConfirmations();
  50.         console.log("We Accepted an offer");
  51.         if (err) console.log("There was an error accepting the offer.");
  52.     });
  53. }
  54.  
  55. function declineOffer(offer) {
  56.     offer.decline((err) => {
  57.         console.log("We Declined an offer");
  58.         if (err) console.log("There was an error declining the offer.");
  59.     });
  60. }
  61.  
  62. function processOffer(offer) {
  63.     if (offer.isGlitched() || offer.state === 11) {
  64.         console.log("Offer was glitched, declining.");
  65.         declineOffer(offer);
  66.     } else if (offer.partner.getSteamID64() === config.ownerID) {
  67.         acceptOffer(offer);
  68.     } else {
  69.         var ourItems = offer.itemsToGive;
  70.         var theirItems = offer.itemsToReceive;
  71.         var ourValue = 0;
  72.         var theirValue = 0;
  73.         for (var i in ourItems) {
  74.             var item = ourItems[i].market_name;
  75.             if(Prices[item]) {
  76.                 ourValue += Prices[item].sell;
  77.             } else {
  78.                 console.log("Invalid Value.");
  79.                 ourValue += 99999;
  80.             }
  81.         }
  82.         for(var i in theirItems) {
  83.             var item= theirItems[i].market_name;
  84.             if(Prices[item]) {
  85.                 theirValue += Prices[item].buy;
  86.             } else {
  87.             console.log("Their value was different.")
  88.             }
  89.         }
  90.    
  91.     console.log("Our value: "+ourValue);
  92.     console.log("Their value: "+theirValue);
  93.  
  94.     if (ourValue <= theirValue) {
  95.         acceptOffer(offer);
  96.     } else {
  97.         declineOffer(offer);
  98.     }
  99.     }
  100. }
  101.  
  102. client.setOption("promptSteamGuardCode", false);
  103.  
  104. manager.on('newOffer', (offer) => {
  105.      processOffer(offer);
  106. });
  107.  
  108. /* Crafting */
  109.  
  110. var scrapAmt = 25;
  111. var pollCraft = 30;
  112.  
  113. tf2.on('connectedToGC', function() {
  114.     console.log("Connected to tf2 game server.");
  115. });
  116.  
  117. tf2.on('backpackLoaded', function () {
  118.     console.log("Backpack is loaded");
  119. });
  120.  
  121. function craftS(amtNeedScrap) {
  122.     if (tf2.backpack == undefined) {
  123.         console.log("The bot could not connect to the team fortress 2 backpack, unable to craft change in metal");
  124.         return
  125.     } else {
  126.         console.log("attempting to craft...");
  127.         var amtOfScrap = 0;
  128.         for (var i = 0; i <tf2.backpack.length; i++) {
  129.             if (tf2.backpack[i].defIndex === 5000) {
  130.                 amtOfScrap++;
  131.             }
  132.         }
  133.         for (var i = 0; i <tf2.backpack.length; i++) {
  134.             if (tf2.backpack[i].defIndex === 5002) {
  135.                 amtOfScrap +=9;
  136.                 var beep = new Array;
  137.                 beep.push(parseInt(tf2.backpack[i].id));
  138.                 tf2.craft(beep);
  139.  
  140.     } else if (tf2.backpack[i].defIndex === 5001) {
  141.                 amtOfScrap +=3;
  142.                 var beep = new Array;
  143.                 beep.push(parseInt(tf2.backpack[i].id));
  144.                 tf2.craft(beep);
  145.             }
  146.             if (amtOfScrap >= amtNeedScrap) {
  147.                 break;
  148.             }
  149.         }
  150.            
  151.  
  152.     }
  153. }
  154.  
  155. tf2.on('craftingComplete', function(e) {
  156.     console.log("Crafting was succesfull.");
  157. });
  158.  
  159. client.on('friendMessage#'+config.ownerID, function(steamID, message) {
  160.     if (message == "craft") {
  161.         craftS(scrapAmt);
  162.         console.log("Recieved order to craft from admin.")
  163.     } else {
  164.         console.log("craft error.")
  165.     }
  166. });
  167.  
  168. setInterval(function() {
  169.     craftS(scrapAmt);
  170. }, 1000 * 60 * pollCraft)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement