Advertisement
Guest User

Untitled

a guest
Jul 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 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 == "!commands") {
  45. client.chatMessage(steamID, "My commands are:");
  46. client.chatMessage(steamID, "!stock to get my current stock");
  47. client.chatMessage(steamID, "!owner to know who my owner is.");
  48. client.chatMessage(steamID, "!how2trade to know how to trade with me")
  49. client.getPersonas([steamID], function(personas) {
  50. var persona = personas[steamID.getSteamID64()];
  51. var name = persona ? persona.player_name : (`['${steamID.getSteamID64()}']`); {
  52. console.log(`${name} (${steamID.getSteamID64()}) Skrev help`);
  53. }
  54. });
  55. }
  56. else if (message == "!stock") {
  57. manager.getInventoryContents(440, 2, true, function (err, inventory) {
  58. if (err) {
  59. client.chatMessage(steamID, "Oooopsi daisy that didn't work.")
  60. return;
  61. }
  62. var refined, reclaimed, scrap, keys = 0;
  63. for (var i = 0; i < inventory.length; i++) {
  64. var item = inventory [i];
  65. var name = item.market_hash_name;
  66. if (name == "Refined Metal") {
  67. refined++;
  68. } else if (name == "Reclaimed Metal") {
  69. reclaimed++;
  70. } else if (name == "Scrap Metal") {
  71. scrap++
  72. } else if (name == "Mann Co.Supply Crate Key") {
  73. keys++
  74. }
  75.  
  76. }
  77. client.chatMessage(steamID, "Stock is ", keys, refined, reclaimed, scrap)
  78. })
  79. } else if (message == "!how2trade") {
  80. client.chatMessage(steamID, "You basically send a trade offer with the correct amount, you can check my listings here https://backpack.tf/classifieds?steamid=76561198846789568")
  81. } else if (message == "!owner") {
  82. client.chatMessage(steamID, "I am coded by Aethez you can find his profile in my comments on my profile.")
  83. }
  84. })
  85.  
  86.  
  87.  
  88. //FRIEND MESSAGES
  89.  
  90.  
  91.  
  92.  
  93.  
  94. // TRADING
  95. client.on('webSession', (sessionid, cookies) => {
  96. manager.setCookies(cookies);
  97.  
  98. community.setCookies(cookies);
  99. community.startConfirmationChecker(20000, config.identitySecret);
  100. });
  101.  
  102. function acceptOffer(offer) {
  103. offer.accept((err) => {
  104. community.checkConfirmations();
  105. console.log("Jag accade ett trade offer");
  106. client.chatMessage(76561198403256399, "Jag gjorde ett trade!")
  107. if (err) console.log("There was an error accepting the offer.");
  108. });
  109. }
  110.  
  111. function declineOffer(offer) {
  112. offer.decline((err) => {
  113. console.log("Jag declinade ett trade offer");
  114. if (err) console.log("There was an error declining the offer.");
  115. });
  116. }
  117.  
  118. client.setOption("promptSteamGuardCode", false);
  119.  
  120. function processOffer(offer) {
  121. if (offer.isGlitched() || offer.state === 11) {
  122. console.log("Ett Trade offer var glitchad declinar traden på momangen.");
  123. declineOffer(offer);
  124. } else if (offer.partner.getSteamID64() === config.ownerID) {
  125. acceptOffer(offer);
  126. } else {
  127. var ourItems = offer.itemsToGive;
  128. var theirItems = offer.itemstoReceive;
  129. var ourValue = 0;
  130. var theirValue = 0;
  131. for (var i in ourItems) {
  132. var item = ourItems[i].market_name;
  133. if(Prices[item]) {
  134. ourValue += Prices[item].sell;
  135.  
  136. } else {
  137. console.log("Invalid Value.");
  138. ourValue += 99999;
  139. }
  140. }
  141. for(var i in theirItems) {
  142. var item= theirItems[i].market_name;
  143. if(Prices[item]) {
  144. theirValue += Prices[item].buy;
  145. } else {
  146. console.log("Their value was different.")
  147. }
  148. }
  149. }
  150. console.log("Our value: "+ourValue);
  151. console.log("Their Value: "+theirValue);
  152.  
  153. if (ourValue <= theirValue) {
  154. acceptOffer(offer);
  155. } else {
  156. declineOffer(offer);
  157. }
  158. }
  159.  
  160.  
  161. manager.on('newOffer', (offer) => {
  162. processOffer(offer);
  163. });
  164. //TRADING
  165.  
  166.  
  167.  
  168.  
  169.  
  170. //Friends!!!
  171. client.on('friendRelationship', function(sid, relationship) {
  172. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  173. console.log("We recieved a friend request from "+sid);
  174. client.addFriend(sid, function (err, name) {
  175. if (err) {
  176. console.log(err);
  177. return;
  178. } else {
  179. console.log("Accepted user with the name of "+name);
  180. client.chatMessage(config.ownerID, "Added 1 person, their name is: " +name);
  181. client.chatMessage(sid, "Hi thanks for adding me, type !commands to get my command list.");
  182. }
  183. });
  184. }
  185.  
  186. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement