Advertisement
Guest User

Untitled

a guest
Jul 9th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. //CONST
  2. const SteamUser = require('steam-user');
  3. const SteamTotp = require('steam-totp');
  4. const SteamCommunity = require('steamcommunity');
  5. const TradeOfferManager = require('steam-tradeoffer-manager');
  6. const config = require('./config.json');
  7. // const TeamFortress2 = require ('tf2');
  8. const Prices = require('./prices.json');
  9.  
  10. const client = new SteamUser();
  11. // const tf2 = new TeamFortress2(client);
  12. const community = new SteamCommunity();
  13. // CONST
  14.  
  15.  
  16.  
  17. //SKIT
  18. const manager = new TradeOfferManager ({
  19. steam: client,
  20. community: community,
  21. language: 'en'
  22. });
  23.  
  24.  
  25. const logOnOptions = {
  26. accountName: config.username,
  27. password: config.password,
  28. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  29. };
  30.  
  31. client.logOn(logOnOptions);
  32.  
  33. client.on('loggedOn', () => {
  34. console.log('Inloggad.');
  35. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  36. client.gamesPlayed([440]); // Custom game name HÄÄÄÄÄÄR!
  37. });
  38. //SKIT
  39.  
  40.  
  41.  
  42. // FRIEND MESSAGES
  43. client.on("friendMessage", function(steamID, message) {
  44. if (message == "help") {
  45. client.chatMessage(steamID, "Hi i am a bot programed by aethez (link on profile) and i simply accept and decline offers.");
  46. } else {
  47. client.chatMessage(steamID, "Mmm, i don't really understand that type help if you need anything.");
  48. }
  49. });
  50. //FRIEND MESSAGES
  51.  
  52.  
  53.  
  54.  
  55.  
  56. // TRADING
  57. client.on('webSession', (sessionid, cookies) => {
  58. manager.setCookies(cookies);
  59.  
  60. community.setCookies(cookies);
  61. community.startConfirmationChecker(20000, config.identitySecret);
  62. });
  63.  
  64. function acceptOffer(offer) {
  65. offer.accept((err) => {
  66. community.checkConfirmations();
  67. console.log("Jag accade ett trade offer");
  68. client.chatMessage(76561198403256399, "Jag gjorde ett trade!")
  69. if (err) console.log("There was an error accepting the offer.");
  70. });
  71. }
  72.  
  73. function declineOffer(offer) {
  74. offer.decline((err) => {
  75. console.log("Jag declinade ett trade offer");
  76. if (err) console.log("There was an error declining the offer.");
  77. });
  78. }
  79.  
  80. client.setOption("promptSteamGuardCode", false);
  81.  
  82. function processOffer(offer) {
  83. if (offer.isGlitched() || offer.state === 11) {
  84. console.log("Ett Trade offer var glitchad declinar traden på momangen.");
  85. declineOffer(offer);
  86. } else if (offer.partner.getSteamID64() === config.ownerID) {
  87. acceptOffer(offer);
  88. } else {
  89. var ourItems = offer.itemsToGive;
  90. var theirItems = offer.itemstoReceive;
  91. var ourValue = 0;
  92. var theirValue = 0;
  93. for (var i in ourItems) {
  94. var item = ourItems[i].market_name;
  95. if(Prices[item]) {
  96. ourValue += Prices[item].sell;
  97.  
  98. } else {
  99. console.log("Invalid Value.");
  100. ourValue += 99999;
  101. }
  102. }
  103. for(var i in theirItems) {
  104. var item= theirItems[i].market_name;
  105. if(Prices[item]) {
  106. theirValue += Prices[item].buy;
  107. } else {
  108. console.log("Their value was different.")
  109. }
  110. }
  111. }
  112. console.log("Our value: "+ourValue);
  113. console.log("Their Value: "+theirValue);
  114.  
  115. if (ourValue <= theirValue) {
  116. acceptOffer(offer);
  117. } else {
  118. declineOffer(offer);
  119. }
  120. }
  121.  
  122.  
  123. manager.on('newOffer', (offer) => {
  124. processOffer(offer);
  125. });
  126. //TRADING
  127.  
  128.  
  129.  
  130.  
  131.  
  132. //Friends!!!
  133. client.on('friendRelationship', function(sid, relationship) {
  134. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  135. console.log("We recieved a friend request from "+sid);
  136. client.addFriend(sid, function (err, name) {
  137. if (err) {
  138. console.log(err);
  139. return;
  140. }
  141. console.log("Accepted user with the name of "+name)
  142. client.chatMessage(sid, "Hi thanks for adding me, type help to get some information about me.");
  143. })
  144. }
  145.  
  146. })
  147.  
  148. client.on('groupRelationship', function(sid, relationship) {
  149. if (relationship == SteamUser.EClanRelationship.Invited) {
  150. console.log("We were asked to join steam group #"+sid);
  151. client.respondToGroupInvite(sid, false);
  152. }
  153. })
  154.  
  155. client.on('friendsList', function() {
  156. for (var sid in client.myFriends);
  157. var relationship = client.myFriends[sid]
  158. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  159. console.log("(offline) We recieved a friend request from "+sid);
  160. client.addFriend(sid, function (err, name) {
  161. if (err) {
  162. console.log(err);
  163. return;
  164. }
  165. console.log("(offline) Accepted user with the name of "+name)
  166. client.chatMessage(sid, "Hi thanks for adding me, type help to get some information about me.");
  167. })
  168. }
  169. })
  170.  
  171. client.on('groupList', function() {
  172. for (var sid in client.myGroups);
  173. var relationship = client.myGroups[sid];
  174. if (relationship == SteamUser.EClanRelationship.Invited) {
  175. console.log("(offline) We were asked to join steam group #"+sid);
  176. client.respondToGroupInvite(sid, false);
  177. }
  178. });
  179. //friends!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement