Advertisement
Guest User

Steam Bot

a guest
Dec 7th, 2017
4,457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. const SteamUser = require('steam-user');
  2. const SteamTotp = require('steam-totp');
  3. const SteamCommunity = require('steamcommunity');
  4. const TradeOdderManager = require('steam-tradeoffer-manager');
  5. const TeamFortress2 = require('tf2');
  6.  
  7. const Prices = require('./prices.json');
  8. const config = require('./config.json');
  9.  
  10. const client = new SteamUser();
  11. const tf2 = new TeamFortress2(client);
  12. const commuinty = new SteamCommunity();
  13. const manager = new TradeOdderManager({
  14. steam: client,
  15. commuinty: commuinty,
  16. language: 'en'
  17. });
  18.  
  19. const logOnOptions = {
  20. accountName: config.username,
  21. password: config.password,
  22. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  23. };
  24.  
  25. client.logOn(logOnOptions);
  26.  
  27. client.on('loggedOn', () => {
  28. console.log('Logged on.');
  29. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  30. client.gamesPlayed(["Oi",440]);
  31. });
  32.  
  33. client.on("friendMessage", function(steamID, message) {
  34. if (message == "hi") {
  35. client.chatMessage(steamID, "hello, this works.");
  36. }
  37. });
  38.  
  39. client.on('webSession', (sessionid, cookies) => {
  40. manager.setCookies(cookies);
  41.  
  42. commuinty.setCookies(cookies);
  43. commuinty.startConfirmationChecker(20000, config.identitySecret);
  44. });
  45.  
  46. function acceptOffer(offer) {
  47. offer.accept((err) => {
  48. commuinty.checkConfirmations();
  49. console.log("We accept an offer.")
  50. if (err) console.log("There was a error.");
  51. });
  52. }
  53.  
  54. function declineOffer(offer) {
  55. offer.decline((err) => {
  56. console.log("We declined an offer.")
  57. if (err) console.log("There was a error.");
  58. });
  59. }
  60.  
  61. function processOffer(offer) {
  62. if (offer.isGlitched() || offer.state === 11) {
  63. console.log("Offer was glitched, declining.");
  64. declineOffer(offer);
  65. } else if (offer.partner.getSteamID64() === config.ownerID) {
  66. acceptOffer(offer);
  67. } else {
  68. var ourItems = offer.itemsToGive;
  69. var theirItems = offer.itemsToReceive;
  70. var ourValue = 0;
  71. var theirValue = 0;
  72. for (var i in ourItems) {
  73. var item = ourItems[i].market_name;
  74. if(Prices[item]) {
  75. ourValue += Prices[item].sell;
  76. } else {
  77. console.log("Invalid Value.");
  78. ourValue += 99999;
  79. }
  80. }
  81. for(var i in theirItems) {
  82. var item= theirItems[i].market_name;
  83. if(Prices[item]) {
  84. theirValue += Prices[item].buy;
  85. } else {
  86. console.log("Their value was different.")
  87. }
  88. }
  89.  
  90. console.log("Our value: "+ourValue);
  91. console.log("Their value: "+theirValue);
  92.  
  93. if (ourValue <= theirValue) {
  94. acceptOffer(offer);
  95. } else {
  96. declineOffer(offer);
  97. }
  98. }
  99. }
  100.  
  101. client.setOption("promtSteamGuardCode", false);
  102.  
  103. manager.on('newOffer', (offer) => {
  104. processOffer(offer);
  105. });
  106.  
  107. client.on('friendRelationship', function(sid, relationship) {
  108. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  109. console.log("We got a request from "+sid);
  110. client.addFriend(sid, function (err, name) {
  111. if (err) {
  112. console.log(err);
  113. return;
  114. }
  115. console.log("Accepted user with the name of "+name)
  116. })
  117. }
  118.  
  119. })
  120.  
  121. client.on('groupRelationship', function(sid, relationship) {
  122. if (relationship == SteamUser.EClanRelationship.Invited) {
  123. console.log("Clan #"+sid);
  124. client.respondToGroupInvite(sid, true);
  125. }
  126. })
  127.  
  128. client.on('friendsList', function() {
  129. for (var sid in client.myFriends);
  130. var relationship = client.myFriends[sid]
  131. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  132. console.log("We got a request from"+sid);
  133. client.addFriend(sid, function (err, name) {
  134. if (err) {
  135. console.log(err);
  136. return;
  137. }
  138. console.log("Accepted user with the name of "+name)
  139. })
  140. }
  141. })
  142.  
  143. client.on('groupList', function() {
  144. for (var sid in client.myGroups);
  145. var relationship = client.myGroups[sid]
  146. if (relationship == SteamUser.EClanRelationship.Invited) {
  147. console.log("Clan #"+sid);
  148. client.respondToGroupInvite(sid, true);
  149. }
  150. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement