Guest User

Untitled

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