Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. var config = require('./config.js');
  2.  
  3. var SteamUser = require('steam-user');
  4. var client = new SteamUser();
  5.  
  6. var SteamTotp = require('steam-totp');
  7. var mobilecode = SteamTotp.getAuthCode(config.sharedsecret);
  8.  
  9. var TradeOfferManager = require('steam-tradeoffer-manager');
  10. var manager = new TradeOfferManager({
  11. "steam": client,
  12. "domain": "http://localhost",
  13. "language": "en",
  14. "cancelTime": "600000", // 10 minutes
  15. "pollInterval": "5000"
  16. });
  17.  
  18. var login = {
  19. accountName: config.username,
  20. password: config.password,
  21. twoFactorCode: mobilecode
  22. };
  23.  
  24. client.logOn(login);
  25.  
  26. client.on('loggedOn', function(details) {
  27. client.getPersonas([client.steamID], function(personas) {
  28. console.log('Logged in as ' + client.steamID + ' (' + personas[client.steamID]["player_name"] + ')');
  29. console.log();
  30. });
  31. console.log();
  32. client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
  33. setInterval(function() { client.webLogOn(); }, 1000 * 60); // Refreshes session every 10 minutes
  34. });
  35.  
  36. client.on('webSession', function(sessionID, cookies) {
  37. manager.setCookies(cookies, function(err) {
  38. if (err) { console.log("Couldn\'t set cookies! Error: " + err); }
  39. });
  40. });
  41.  
  42. client.on('error', function(e) {
  43. console.log(e);
  44. process.exit(1);
  45. });
  46.  
  47. manager.on('newOffer', function(offer) { // When a new offer is received do the stuff below
  48. offer.getUserDetails(function(err, me, them) { // Get errors, an object containing the escrow days left and the inventory of the bot and the partner
  49. if (err) { // If there is an error log it
  50. console.log('Error getting user information: ' + err);
  51. } else if (me.escrowDays == 0 && them.escrowDays == 0) { // If there is no error, and if neither the bot nor the partner has a ESCROW cooldown do this
  52. if (offer.itemsToGive.length == 0 || offer.partner.getSteamID64() == config.admin) { // Check if the trade doesn't require the bot to give out any items or if the trade is coming from an admin set in the config file
  53. offer.accept(function(err, status) { // Accept the offer if the statement above is true
  54. if (err) { // If there was an error accepting the trade log it
  55. console.log("Error accepting trade: " + err + ". Trying to accept offer again.");
  56. manager.getOffer(offer.id, function(err, offer) {
  57. offer.accept(function(err, status) {
  58. if (err) {
  59. console("Error accepting trade: " + err + ". Trying again.");
  60. var timer = setInterval(function() {
  61. offer.accept(function(err, status) {
  62. if (err) {
  63. console("Error accepting trade: " + err + ". Trying again.");
  64. }
  65. if (status == 'accepted') {
  66. console.log("Trade " + offer.id + " accepted");
  67. console.log();
  68. clearInterval(timer);
  69. }
  70. });
  71. }, 20000);
  72. }
  73. if (status == 'accepted') { // If the trade was successfully accepted log it
  74. console.log("Trade " + offer.id + " accepted");
  75. console.log();
  76. }
  77. });
  78. });
  79. }
  80. if (status == 'accepted') { // If the trade was successfully accepted log it
  81. console.log("Trade " + offer.id + " accepted");
  82. console.log();
  83. }
  84. });
  85. } else { // If the trade does require the bot to give out items and the trade is not coming from the admin decline the offer and log it
  86. console.log("Offer is not a donation! Declining it.");
  87. offer.decline(function(err) {
  88. if (err) { // If there was an error declining the trade log it
  89. console.log('Couldn\'t decline offer. Error: ' + err);
  90. }
  91. console.log("");
  92. });
  93. }
  94. } else { // If either the bot or the partner has an ESCROW cooldown log it and decline the offer
  95. console.log("Your or your trade partner have an ESCROW cooldown! Declining trade.");
  96. offer.decline(function(err) {
  97. if (err) { // If there was an error declining the trade log it
  98. console.log('Couldn\'t decline offer. Error: ' + err);
  99. }
  100. console.log("");
  101. });
  102. }
  103. });
  104. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement