Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. module.exports = {
  2.  
  3. bot: function(username, password, sharedSecret, identitySecret) {
  4.  
  5. const SteamUser = require('steam-user');
  6. const TradeOfferManager = require('steam-tradeoffer-manager');
  7. const SteamTotp = require('steam-totp');
  8. const SteamCommunity = require('steamcommunity');
  9. const SteamID = require('steamid');
  10. const config = require('./config.json');
  11. const acceptedCases = ["Operation Breakout Weapon Case", "Chroma 2 Case", "Chroma 3 Case", "Operation Wildfire Case", "Gamma Case", "Shadow Case", "Gamma 2 Case", "Spectrum Case"];
  12. const acceptedKeys = ["Shadow Case Key"]
  13.  
  14. const community = new SteamCommunity();
  15. const client = new SteamUser();
  16. const manager = new TradeOfferManager({
  17. steam: client,
  18. domain: 'example.com',
  19. language: 'en'
  20. });
  21.  
  22. const logOnOptions = {
  23. accountName: username,
  24. password: password,
  25. twoFactorCode: SteamTotp.generateAuthCode(sharedSecret)
  26. };
  27.  
  28. client.logOn(logOnOptions);
  29.  
  30. client.on('loggedOn', function(details) {
  31. console.log(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`); //online then play tf2
  32. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  33. client.gamesPlayed([440])
  34. });
  35.  
  36. client.on('webSession', function(sessionID, cookies) {
  37. manager.setCookies(cookies, function(err) {
  38. if (err) return console.log(err);
  39. console.log(`Got API key: ${manager.apiKey}`);
  40. });
  41.  
  42. community.setCookies(cookies);
  43. community.startConfirmationChecker(4000, identitySecret);
  44. });
  45.  
  46. function keyAmountGood(keyAmount) {
  47. if (Math.floor(1000 / config.casesForKey) < keyAmount) {
  48. return false;
  49. }
  50. }
  51.  
  52. function loadInv(steamID) {
  53. return new Promise((resolve, reject) => {
  54. manager.loadUserInventory(steamID, 730, 2, true, (err, inv) => {
  55. if (err) {
  56. console.log(err.message)
  57. return reject(err.message)
  58. }
  59. resolve(inv);
  60. })
  61. })
  62. }
  63.  
  64. function GetCaseStock() {
  65. let cases = 0;
  66. console.log(cases);
  67. for (var i = 0; i < config.storageBotIds.length; i++) {
  68. loadInv(config.storageBotIds[i]).then(inv => {
  69. for (var i = 0; i < inv.length; i++) {
  70. if (acceptedCases.includes(inv[i].market_hash_name)) {
  71. cases++;
  72. console.log(cases);
  73. }
  74. }
  75. });
  76. }
  77. }
  78.  
  79. function makeOffer(steamID, neededCases, keyAmount) {
  80. var offer = manager.createOffer(steamID);
  81. let ourCases = [];
  82. let thereKeys = [];
  83.  
  84. loadInv(steamID).then(thereInv => {
  85. loadInv(config.mainBot64).then(myInv => {
  86.  
  87. for (let i = 0; i < myInv.length; i++) {
  88. if (acceptedCases.includes(myInv[i].market_hash_name) && neededCases > ourCases.length) {
  89. ourCases.push(myInv[i].assetid);
  90. }
  91. }
  92.  
  93. for (var i = 0; i < thereInv.length; i++) {
  94. if (acceptedKeys.includes(myInv[i].market_hash_name) && neededCases > ourCases.length) {
  95. thereKeys.push(thereInv[i].assetid);
  96. }
  97. }
  98.  
  99. if (thereKeys < keyAmount) {
  100. client.chatMessage(steamID, "oh no it appears you do not have enough keys, you have " + thereKeys.length + " keys and you need " + keyAmount + " keys sorry");
  101. return;
  102. }
  103.  
  104. });
  105. });
  106. }
  107.  
  108. client.on('friendMessage', (steamID, message) => {
  109. let keyAmount = parseInt(message.split("!buy")[1])
  110. if (keyAmountGood(keyAmount) == false) {
  111. client.chatMessage(steamID, "oh no your trying to trade to many keys, we can only trade " + Math.floor(1000 / config.casesForKey) + " keys at a time!");
  112. } else {
  113. let neededCases = keyAmount * config.casesForKey;
  114.  
  115. var offer = manager.createOffer(steamID);
  116. let ourCases = [];
  117. let thereKeys = [];
  118.  
  119. loadInv(steamID).then(thereInv => {
  120. loadInv(config.mainBot64).then(myInv => {
  121.  
  122. for (let i = 0; i < myInv.length; i++) {
  123. if (acceptedCases.includes(myInv[i].market_hash_name) && neededCases > ourCases.length) {
  124. ourCases.push(myInv[i].assetid);
  125. }
  126. }
  127.  
  128. for (var i = 0; i < thereInv.length; i++) {
  129. if (acceptedKeys.includes(myInv[i].market_hash_name) && neededCases > ourCases.length) {
  130. thereKeys.push(thereInv[i].assetid);
  131. }
  132. }
  133.  
  134. if (thereKeys < keyAmount) {
  135. client.chatMessage(steamID, "oh no it appears you do not have enough keys, you have " + thereKeys.length + " keys and you need " + keyAmount + " keys sorry");
  136. return;
  137. }
  138.  
  139. });
  140. });
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. if (GetCaseStock() <= neededCases) {
  151. }
  152. }
  153. });
  154.  
  155.  
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement