Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 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.  
  6. const Prices = require('./prices.json');
  7. const config = require('./config.json');
  8.  
  9. const client = new SteamUser();
  10. const community = new SteamCommunity();
  11. const manager = new TradeOfferManager ({
  12. steam: client,
  13. community: community,
  14. language: 'en'
  15. });
  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('succesfully logged on.');
  27. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  28. client.gamesPlayed(["Custom Game",440]);
  29. });
  30.  
  31. client.on("friendMessage", function(steamID, message) {
  32. if (message == "hi") {
  33. client.chatMessage(steamID, "hello, this works.");
  34. }
  35. });
  36.  
  37. client.on('webSession', (sessionid, cookies) => {
  38. manager.setCookies(cookies);
  39.  
  40. community.setCookies(cookies);
  41. community.startConfirmationChecker(20000, config.identitySecret);
  42. });
  43.  
  44. function acceptOffer(offer) {
  45. offer.accept((err) => {
  46. if(err){
  47. console.log("There was an error accepting the offer.");
  48. console.log(err);
  49. }else{
  50. community.checkConfirmations();
  51. console.log(`We accepted an offer.`);
  52. }
  53. });
  54. }
  55.  
  56. function declineOffer(offer) {
  57. offer.decline((err) => {
  58. if(err){
  59. console.log("There was an error declining the offer.");
  60. console.log(err);
  61. }else{
  62. console.log(`We declined an offer.`);
  63. }
  64. });
  65. }
  66.  
  67. function processOffer(offer) {
  68. if (offer.isGlitched() || offer.state === 11) {
  69. console.log("Offer was glitched, declining.");
  70. declineOffer(offer);
  71. } else if (offer.partner.getSteamID64() === config.ownerID) {
  72. acceptOffer(offer);
  73. } else {
  74. var ourItems = offer.itemsToGive;
  75. var theirItems = offer.itemsToReceive;
  76. var ourValue = 0;
  77. var theirValue = 0;
  78. for (var i in ourItems) {
  79. var item = ourItems[i].market_name;
  80. if(Prices[item]) {
  81. ourValue += Prices[item].sell;
  82. } else {
  83. console.log("Invalid Value.");
  84. ourValue += 99999;
  85. }
  86. }
  87. for(var i in theirItems) {
  88. var item= theirItems[i].market_name;
  89. if(Prices[item]) {
  90. theirValue += Prices[item].buy;
  91. } else {
  92. console.log("Their value was different.")
  93. }
  94. }
  95. }
  96. console.log("Our value: "+ourValue);
  97. console.log("Their value: "+theirValue);
  98.  
  99. if (ourValue <= theirValue) {
  100. acceptOffer(offer);
  101. } else {
  102. declineOffer(offer);
  103. }
  104. }
  105.  
  106. client.setOption("promptSteamGuardCode", false);
  107.  
  108. manager.on('newOffer', (offer) => {
  109. processOffer(offer);
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement