Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. const SteamUser = require('steam-user');
  2. const TradeOfferManager = require('steam-tradeoffer-manager');
  3. const SteamTotp = require('steam-totp');
  4. const SteamCommunity = require('steamcommunity');
  5. const config = require('./config.json');
  6. const winston = require('winston');
  7.  
  8. const community = new SteamCommunity();
  9. const client = new SteamUser();
  10. const manager = new TradeOfferManager({
  11. steam: client,
  12. domain: 'example.com',
  13. language: 'en'
  14. });
  15.  
  16.  
  17.  
  18. /*
  19. edit these to add and remove listings
  20. SellPrices = Price to sell items at in keys
  21. BuyPrices = Price to buy items at in keys
  22.  
  23. edit tutorial
  24. to add a listing to the bot simply follow the exsamples below
  25.  
  26. var exsample = {'name':11, 'name 2':6, 'name3':75}
  27. var exsample2 = {'name':11, 'name 2':6}
  28.  
  29. make sure to leave a comma and a space as can be seen between 'name1' and 'name2' but keep in mind do not do this at the end
  30.  
  31. you can have as many as you like!
  32.  
  33. bot aacepts all keys ask me if you want something diffrent
  34.  
  35. */
  36.  
  37. //edit these
  38. var SellPrices = {'Reclaimed Metal':1, 'placeholder':1};
  39. var BuyPrices = {'placeholder1':1, 'placeholder':1};
  40. var acceptedKeys = ['Scrap Metal', 'Rainy Day Cosmetic Case']
  41. //end editing here
  42.  
  43.  
  44. winston.add(winston.transports.File, {
  45. filename: 'events.log'
  46. });
  47. winston.remove(winston.transports.Console);
  48.  
  49.  
  50.  
  51. const logOnOptions = {
  52. accountName: config.username,
  53. password: config.password,
  54. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  55. };
  56. //log on
  57. client.logOn(logOnOptions);
  58.  
  59. client.on('loggedOn', function(details) {
  60. console.log(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`); //online then play tf2
  61. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  62. client.gamesPlayed([440])
  63. });
  64.  
  65. client.on('webSession', function(sessionID, cookies) {
  66. manager.setCookies(cookies, function(err) {
  67. if (err) return console.log(err);
  68. console.log(`Got API key: ${manager.apiKey}`);
  69. });
  70.  
  71. community.setCookies(cookies);
  72. community.startConfirmationChecker(10000, config.identitySecret);
  73. });
  74.  
  75. client.on('friendRelationship', (steamID, relationship) => { //freind requests
  76. if (relationship == 2) {
  77. client.addFriend(steamID);
  78. client.chatMessage(steamID, config.welcomeMessage);
  79. }
  80. });
  81.  
  82. client.on('friendMessage', (steamID, message) => {
  83. if (message.startsWith("!buy prices")) {
  84. var Msg = JSON.stringify(BuyPrices) //converting buy array to a string
  85. var Msg = Msg.replace('{',''); //removing '{'
  86. var Msg = Msg.replace('}',''); //removing '}'
  87. client.chatMessage(steamID, Msg);
  88. }else {
  89. if (message.startsWith("!sell prices")) {
  90. var Msg = JSON.stringify(SellPrices) //converting buy array to a string
  91. var Msg = Msg.replace('{',''); //removing '{'
  92. var Msg = Msg.replace('}','');
  93. client.chatMessage(steamID, Msg);
  94. }
  95. }
  96. });
  97.  
  98. function Get_Item_Vaule(offer, price) {
  99. var name;
  100. var Vaule = 0;
  101.  
  102. for (i = 0; i < offer.length; i++) {
  103. name = offer[i].market_hash_name;
  104. if (price[name]) {
  105. Vaule += price[name]
  106. }
  107. }
  108. return Vaule;
  109. }
  110.  
  111. function Get_keys(offer, acceptedKeys) {
  112. var name;
  113. var Keys = 0;
  114.  
  115. for (i = 0; i < offer.length; i++) {
  116. name = offer[i].market_hash_name;
  117. if (acceptedKeys.includes(name)){
  118. Keys += 1
  119. }
  120. }
  121. return Keys;
  122. }
  123.  
  124.  
  125. function acceptOffer(offer) {
  126. offer.accept((err) => {
  127. if (err) winston.info(`Unable to accept offer: ${err.message}`);
  128. community.checkConfirmations();
  129. });
  130. }
  131.  
  132. function declineOffer(offer) {
  133. offer.decline((err) => {
  134. if (err) return winston.info(`Unable to decline offer: ${err.message}`);
  135. });
  136. }
  137.  
  138. manager.on('newOffer', function(offer) {
  139. const partnerID = offer.partner.getSteamID64();
  140. winston.info("offer incoming from " + partnerID);
  141. var ThereItemVaule = Get_Item_Vaule(offer.itemsToReceive, BuyPrices);
  142. var ThereKeys = Get_keys(offer.itemsToReceive, acceptedKeys);
  143. var ThereTotalVaule = ThereKeys + ThereItemVaule;
  144. console.log(ThereTotalVaule);
  145.  
  146. var OurItemVaule = Get_Item_Vaule(offer.itemsToGive, SellPrices);
  147. console.log(OurItemVaule);
  148. var OurKeys = Get_keys(offer.itemsToGive, acceptedKeys);
  149. console.log(OurKeys);
  150. var OurTotalVaule = OurKeys + OurItemVaule;
  151. console.log(OurTotalVaule);
  152.  
  153. if (OurTotalVaule <= ThereTotalVaule) {
  154. acceptOffer(offer);
  155. winston.info("accepted offer from " + partnerID + " we made profit!");
  156. }else{
  157. declineOffer(offer);
  158. winston.info("declined offer from " + partnerID + " we would have lost money");
  159. }
  160. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement