Advertisement
Guest User

testbotsteam

a guest
Jun 22nd, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. username = 'testbot'; // Username of bot
  2. password = 'testbot123'; // Password of bot
  3.  
  4. // included variables
  5. var steam = require('steam');
  6. var steamtrade = require('steam-trade');
  7. var winston = require('winston');
  8. var readline = require('readline');
  9. var fs = require('fs');
  10. // application id helper
  11. var appid = { TF2: 440, Steam: 753 };
  12. // context id helper
  13. var contextid = { TF2: 2, Steam: 6 }
  14. // So we only enter one trade at a time
  15. var inTrade = false;
  16. // Make inventory global
  17. var myBackpack;
  18. // Used for steamguard codes
  19. var rl = readline.createInterface({ input: process.stdin, output: process.stdout });
  20. // Sets logging to console
  21. var logger = new (winston.Logger)({
  22.     transports: [
  23.         new (winston.transports.Console)({
  24.             colorize: true,
  25.             level: 'debug'
  26.         }),
  27.         new (winston.transports.File)({
  28.             level: 'info',
  29.             timestamp: true,
  30.             filename: 'cratedump.log',
  31.             json: false
  32.         })
  33.     ]
  34. });
  35. // starts Steam client and trading library
  36. var client = new steam.SteamClient();
  37. var trade = new steamtrade();
  38. // Library of steam servers
  39. if(fs.existsSync('servers.json')) {
  40.     steam.servers = JSON.parse(fs.readFileSync('servers.json'));
  41. }
  42. // Uses saved sentry file if there is one
  43. var sentryfile;
  44. if(fs.existsSync('sentryfile.' + username + '.hash')) {
  45.     sentryfile = fs.readFileSync('sentryfile.' + username + '.hash');
  46. }
  47. // Logs in
  48. client.logOn({
  49.     accountName: username,
  50.     password: password,
  51.     shaSentryfile: sentryfile // If null, a new Steam Guard code will be requested
  52. });
  53. // If Steam returns an error it is emitted
  54. client.on('error', function(e) {
  55. // Error code for invalid Steam Guard code
  56.     if (e.eresult == steam.EResult.AccountLogonDenied) {
  57.     // Prompt the user for Steam Guard code
  58.     rl.question('Steam Guard Code: ', function(code) {
  59.     // Attempt to log in again
  60.         client.logOn({
  61.         accountName: username,
  62.         password: password,
  63.         authCode: code
  64.     });
  65. });
  66. } else { // For simplicity, we'll just log anything else.
  67. logger.error('Steam Error: ' + e.eresult);
  68. // Steam sometimes returns InvalidPassword (5) for valid passwords
  69. // Just try logging in again, that usually corrects this issue
  70. }
  71. });
  72. // If a Steam Guard code is entered, sentry event goes off.
  73. client.on('sentry', function(sentry) {
  74.     logger.info('Got new sentry file hash from Steam. Saving.');
  75.     fs.writeFile('sentryfile.' + username + '.hash', sentry);
  76. });
  77. // following a successful login
  78. client.on('loggedOn', function() {
  79.     logger.info('Logged on to Steam');
  80.     // Rename bot on login if you want
  81.     client.setPersonaName("CrateDumpBot");
  82.     // Doesn't show as online until ready
  83.     client.setPersonaState(steam.EPersonaState.Offline);
  84. });
  85. /* Now you should be logged in but set to show as offline
  86. * We haven't logged into the web yet * Steam hands us an ID before we can use the API.
  87. * Our Trading library requires the session ID and cookie,
  88. * so we have to wait for the following event to be emitted.
  89. */
  90. client.on('webSessionID', function(sessionid) {
  91.      trade.sessionID = sessionid; // Shares session between libraries
  92.      client.webLogOn(function(cookie) {
  93.          cookie.forEach(function(part) { // Shares cookies between libraries
  94.             trade.setCookie(part.trim()); // Now we can start trading!
  95.         });
  96.         logger.info('Logged into web'); // You will appear as online now
  97.         client.setPersonaState(steam.EPersonaState.LookingToTrade);
  98.      });
  99. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement