Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  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 config = require('./config.json');
  6. const Prices = require('./prices.json');
  7.  
  8. const client = new SteamUser();
  9. const community = new SteamCommunity();
  10. const manager = new TradeOfferManager ({
  11. steam: client,
  12. community: community,
  13. language: 'en'
  14. });
  15. const testing = true;
  16.  
  17. const logOnOptions = {
  18. accountName: config.username,
  19. password: config.password,
  20. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  21. };
  22.  
  23. client.logOn(logOnOptions);
  24.  
  25. client.on('loggedOn', () => {
  26. console.log('Successfully logged into Steam.');
  27. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  28. client.gamesPlayed(440);
  29. });
  30.  
  31. client.on("friendMessage", function(steamID, message) {
  32. if (message == "hi") {
  33. client.chatMessage(steamID, "Hello! I am working.");
  34. }
  35. });
  36.  
  37. client.on('webSession', (sessionid, cookies) => {
  38. manager.setCookies(cookies);
  39. community.setCookies(cookies);
  40. community.startConfirmationChecker(10000, config.identitySecret);
  41. });
  42.  
  43. function acceptOffer(offer) {
  44. offer.accept((err) => {
  45. console.log("Accepted an Offer.");
  46. if (err) console.log("Error accepting a trade offer.");
  47. });
  48. }
  49.  
  50. function declineOffer(offer) {
  51. offer.decline((err) => {
  52. console.log("Declined an Offer.");
  53. if (err) console.log("Error declining a trade offer.");
  54. });
  55. }
  56.  
  57. function processOffer(offer) {
  58. if (offer.isGlitched() || offer.state === 11) {
  59. console.log("The offer was glitched, declining...");
  60. declineOffer(offer);
  61. } else if (!testing && offer.partner.getSteamID64() === config.ownerID) {
  62. acceptOffer(offer);
  63. } else {
  64. var ourItems = offer.itemsToGive;
  65. var theirItems = offer.itemsToReceive;
  66. var ourValue = 0;
  67. var theirValue = 0;
  68. var hasUnlistedItems;
  69. var i, name, item;
  70.  
  71. for ( i = 0; i < ourItems.length; i++) {
  72. name = ourItems[i].market_hash_name;
  73. item = Prices[name];
  74.  
  75. if (item) {
  76. ourValue += item.sell;
  77. } else {
  78. hasUnlistedItems = true;
  79. }
  80. }
  81. for (i = 0; i < theirItems.length; i++) {
  82. name = theirItems[i].market_hash_name;
  83. item = Prices[name];
  84.  
  85. if (item) {
  86. theirValue += item.buy;
  87. } else {
  88.  
  89. }
  90. }
  91.  
  92. console.log("Our value: "+ourValue);
  93. console.log("Their value: "+theirValue);
  94.  
  95. if (!hasUnlistedItems && theirValue >= ourValue) {
  96. acceptOffer(offer);
  97. } else {
  98. declineOffer(offer);
  99. }
  100. }
  101. }
  102.  
  103. manager.on('newOffer', (offer) => {
  104. processOffer(offer);
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement