Advertisement
MagneticaMusic

BTC Bot

Feb 29th, 2016
2,745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. const ADD = 0;
  2. var stock = 0;
  3.  
  4. var config;
  5. try {
  6. config = JSON.parse(fs.readFileSync('./config.json'));
  7. } catch (err) {
  8. log("Error: unable to parse config.json.");
  9. log("Error details: " + err.message);
  10. process.exit(1);
  11. }
  12.  
  13. var d = config.debugEnabled;
  14.  
  15. var block_io = new BlockIo(config.blockIOAPIKey, config.blockIOsecretPIN, 2);
  16. log("Logged into block.io wallet.")
  17.  
  18. var acceptedCSKeys = ["CS:GO Case Key", "Winter Offensive Case Key", "Operation Phoenix Case Key", "Huntsman Case Key", "eSports Key", "Operation Breakout Case Key", "Operation Vanguard Case Key", "Chroma Case Key", "Chroma 2 Case Key", "Falchion Case Key", "Shadow Case Key", "Revolver Case Key"];
  19.  
  20. var currentTransaction;
  21. var lt = Date.now();
  22. var ticker;
  23. var doStock = false;
  24.  
  25. block_io.get_current_price({
  26. 'price_base': 'USD'
  27. }, (err, data) => {
  28. if (!data || data.data.error_message) {
  29. ticker = 375.31;
  30. } else {
  31. ticker = Number(data.data.prices[0].price);
  32. }
  33. });
  34.  
  35.  
  36. process.stdin.setEncoding('utf8');
  37. var commands = {
  38. "UNKNOWN_COMMAND": function() {
  39. return "Unknown command. Type `help` for help.";
  40. },
  41. "stop": function() {
  42. log("Stopping bot...");
  43. if (currentTransaction) {
  44. log("WARNING: not stopping because there is a transaction in process!");
  45. log("To force stop bot, type `forcestop` (WARNING: NOT GOOD UNLESS YOU ARE TESTING! DO NOT DO THIS IN STANDARD USE IF YOU DON'T KNOW WHAT YOU ARE DOING!)");
  46. } else {
  47. steam.chatLogoff();
  48. process.exit(0);
  49. }
  50. return "Bot successfully stopped, but if it actually did this message shouldn't show up.";
  51. },
  52. "help": function() {
  53. return "Command List:\nhelp - shows this menu\nstop - stops the bot\nforcestop - force-stops the bot\ningame - sets bot ingame";
  54. },
  55. "ingame": function() {
  56. user.gamesPlayed("Keys For BTC | Buy: " + config.keySalePrice + " Sell: " + config.keyBuyPrice);
  57. return "Entering non-steam game.";
  58. },
  59. "stock": function() {
  60. updateStock();
  61. setTimeout(function() {
  62. user.gamesPlayed("Selling " + stock + " keys @ $" + config.keySalePrice + "");
  63. log("Entering non-Steam game.");
  64. }, 2000);
  65. doStock = true;
  66. return "Please wait while I update stock...";
  67. },
  68. "forcestop": function() {
  69. log("Forcing bot to stop!");
  70. steam.chatLogoff();
  71. process.exit();
  72. }
  73. };
  74.  
  75.  
  76.  
  77. var logOnOptions = {
  78. 'accountName': config.username,
  79. 'password': config.password
  80. };
  81. var authCode = totp.generateAuthCode(config.sharedsecret);
  82.  
  83. if (config.manualAuthCode !== "") {
  84. authCode = config.manualAuthCode;
  85. }
  86. if (fs.existsSync('steamguard.txt')) {
  87. logOnOptions.steamguard = fs.readFileSync('steamguard.txt').toString('utf8');
  88. logOnOptions.twoFactorCode = authCode;
  89. } else if (authCode) {
  90. logOnOptions.twoFactorCode = authCode;
  91. }
  92.  
  93. steam.login(logOnOptions, function(err, sessionID, cookies, steamguard) {
  94. if (err) { //error handling
  95. log("Steam login falied. Error: " + err.message);
  96. process.exit(1);
  97. }
  98.  
  99. fs.writeFile('steamguard.txt', steamguard); //creates sentry
  100.  
  101. log("Logged into Steam as " + logOnOptions.accountName);
  102.  
  103. manager.setCookies(cookies, function(err) {
  104. if (err) {
  105. log(err);
  106. process.exit(1); // Fatal error since we couldn't get our API key
  107. return;
  108. }
  109. });
  110. steam.chatLogon();
  111. if (config.identitysecret) {
  112. steam.startConfirmationChecker(10000);
  113. }
  114. setTimeout(function() {
  115. log("Logging in using fake steam client.");
  116. user.logOn({
  117. 'accountName': config.username,
  118. 'password': config.password,
  119. 'twoFactorCode': totp.generateAuthCode(config.sharedsecret)
  120. });
  121. }, 30000);
  122. });
  123.  
  124. user.on('loggedOn', function() {
  125. log("Logged into Steam for friends list acceptor.");
  126. process.stdin.resume();
  127. log("Commands are now enabled.");
  128. process.stdin.on('data', (text) => {
  129. while (text.indexOf('\n') !== -1 || text.indexOf('\r') !== -1 || text.indexOf(' ') !== -1) {
  130. text = text.replace(/\n|\r|\t/, '').replace(/ /, ' ');
  131. }
  132. var args = text.split(' ');
  133. //call a function with args. Maybe make a function list or something?
  134. var command = args[0].toLowerCase();
  135. var trip = false;
  136. for (var key in commands) {
  137. if (key === command) {
  138. trip = true;
  139. stuff = commands[key](args[1], args[2], args[3]);
  140. if (Array.isArray(stuff)) {
  141. stuff.forEach(console.log);
  142. } else {
  143. console.log(stuff);
  144. }
  145. }
  146. }
  147. if (!trip) {
  148. stuff = commands.UNKNOWN_COMMAND();
  149. if (Array.isArray(stuff)) {
  150. for (var i = 0; i < stuff.length; i++) {
  151. console.log(stuff[i]);
  152. }
  153. } else {
  154. console.log(stuff);
  155. }
  156. }
  157. });
  158. user.setPersona(1);
  159. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement