Guest User

Untitled

a guest
Jun 12th, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Initalizing packages
  3. */
  4. const SteamUser = require('steam-user');
  5. const TradeOfferManager = require('steam-tradeoffer-manager');
  6. const SteamTotp = require('steam-totp');
  7. const SteamCommunity = require('steamcommunity');
  8. const fs = require('fs');
  9. const request = require('request');
  10. const config = require('./configmultilevel.json');
  11.  
  12. const community = new SteamCommunity();
  13. const client = new SteamUser();
  14. const manager = new TradeOfferManager({
  15.    
  16.     steam: client,
  17.     domain: 'example.com',
  18.     language: 'en'
  19. });
  20.  
  21. /*
  22.     Polling Steam and Logging On
  23. */
  24. client.logOn({
  25.     accountName: config.username,
  26.     password: config.password,
  27.     twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  28. });
  29.  
  30. /*
  31.     Getting prices
  32. */
  33. const priceUrl = 'https://api.steamapi.io/market/prices/'+config.options.appid+'?key='+config.options.apikey;
  34.  
  35. function getPriceList() {
  36.     request(priceUrl, (error, response, body) => {
  37.         if (error || response.statusCode !== 200) return console.log(`Error: ${error} - Status Code: ${response.statusCode}`);
  38.         fs.writeFile('prices.json', body);
  39.     });
  40. }
  41.  
  42. function priceItemsInOffer(offer) {
  43.     let offerValue = 0;
  44.     if (offer) {
  45.         const prices = require('./prices.json'); //Requiring price file
  46.         //Loop through offer and get total price
  47.         for (var x in offer) {
  48.             if (prices[offer[x].market_hash_name] <= config.options.minPricePerItem) {
  49.                 offerValue += (prices[offer[x].market_hash_name] * 0.1)
  50.             }
  51.             else if (prices[offer[x].market_hash_name] <= config.options.minPricePerItem2) {
  52.                 offerValue += (prices[offer[x].market_hash_name] * 0.3)
  53.                 }
  54.             else if (prices[offer[x].market_hash_name] <= config.options.minPricePerItem3) {
  55.                 offerValue += (prices[offer[x].market_hash_name] * 0.8)
  56.             }
  57.             else offerValue += prices[offer[x].market_hash_name]
  58.         }
  59.     }
  60.     return offerValue;
  61. }
  62.  
  63. //Make the first price request
  64. getPriceList();
  65. //Auto Refresh price
  66. setInterval(getPriceList, config.options.priceRefreshInterval * 1000);
  67.  
  68. /*
  69.     Friend requests and chat
  70. */
  71. // Accepting friends requests.
  72. client.on("friendRelationship", (steamid, reletionship) => {
  73.     if (reletionship === 2) {
  74.         community.getGroupMembers('103582791458524004', function(err, members) {
  75.         if (members.indexOf(steamid) > -1) {
  76.         client.addFriend(steamid);
  77.         client.chatMessage(steamid, `Thank you for adding me!`);
  78.         console.log(`Friends request accepted, is group member. SteamID:  ${steamid}`);
  79.         } else if (err){
  80.             console.log(err);
  81.     } else {
  82.         client.removeFriend(steamid);
  83.         console.log(`Ignored friends request, not in the group. SteamID: ${steamid}`);
  84.     }
  85.     });
  86.     }  
  87. });
  88.  
  89. client.on('friendMessage', (steamID, message) => {
  90.     console.log(config.options.chatResponse.commands[message]);
  91.     if (config.options.chatResponse.commands[message]) {
  92.         client.chatMessage(steamID, config.options.chatResponse.commands[message]);
  93.     }
  94.     else {
  95.         client.chatMessage(steamID, config.options.chatResponse.unknownCommand);
  96.     }
  97. });
  98.  
  99. /*
  100.     Offer handling
  101. */
  102. function isInArray(value, array) {
  103.   return array.indexOf(value) > -1;
  104. }
  105. function acceptOffer(offer) {
  106.     offer.accept((err) => {
  107.         if (err) console.log(`Unable to accept offer: ${err.message}`);
  108.         community.checkConfirmations();
  109.     });
  110. }
  111.  
  112. function declineOffer(offer) {
  113.     offer.decline((err) => {
  114.         if (err) return console.log(`Unable to decline offer: ${err.message}`);
  115.     });
  116. }
  117.  
  118. manager.on('newOffer', function(offer) {
  119.     const partnerid = offer.partner.getSteamID64();
  120.  
  121.     offer.getUserDetails((err, me, them) => {
  122.         if(err) return console.log(err);
  123.  
  124.         if(them.escrowDays > 0) {
  125.             console.log('Trade is in escrow. Declining.');
  126.             declineOffer(offer);
  127.         }
  128.     });
  129.  
  130.     console.log(`New offer # ${offer.id} from ${partnerid}`);
  131.  
  132.     if (isInArray(partnerid, config.adminIDs)) {
  133.         client.chatMessage(partnerid, config.options.chatResponse.adminTrade);
  134.         acceptOffer(offer);
  135.  
  136.     } else if (!offer.itemsToGive.length) {
  137.         console.log(`${partnerid} just donated us items.`);
  138.         client.chatMessage(partnerid, config.options.chatResponse.donation); //Sending message for donations
  139.         acceptOffer(offer);
  140.     }else if (priceItemsInOffer(offer.itemsToReceive) < config.options.minimumprice1) {
  141.         client.chatMessage(partnerid, config.options.chatResponse.tradeDeclined);
  142.         declineOffer(offer);
  143.     } else if (priceItemsInOffer(offer.itemsToGive) <= priceItemsInOffer(offer.itemsToReceive) * config.options.percentamountlv) {
  144.         client.chatMessage(partnerid, config.options.chatResponse.tradeAccepted);
  145.         acceptOffer(offer);
  146.     }else if (priceItemsInOffer(offer.itemsToReceive) < config.options.minimumprice) {
  147.         client.chatMessage(partnerid, config.options.chatResponse.tradeDeclined);
  148.         declineOffer(offer);
  149.     }else if (priceItemsInOffer(offer.itemsToGive) <= priceItemsInOffer(offer.itemsToReceive) * config.options.percentamount) {
  150.         client.chatMessage(partnerid, config.options.chatResponse.tradeAccepted);
  151.         acceptOffer(offer);
  152.     }else {
  153.         client.chatMessage(partnerid, config.options.chatResponse.tradeDeclined);
  154.         declineOffer(offer);
  155. }});
  156.  
  157.  
  158.  
  159. //Refresh polldata.json
  160. manager.on('pollData', function(pollData) {
  161.     fs.writeFile('polldata.json', JSON.stringify(pollData));
  162. });
  163.  
  164. if (fs.existsSync('polldata.json')) {
  165.     manager.pollData = JSON.parse(fs.readFileSync('polldata.json'));
  166. }
  167.  
  168. client.on('loggedOn', function(details) {
  169.     console.log(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`);
  170.     client.setPersona(SteamUser.Steam.EPersonaState.Online,config.botname);
  171.     client.gamesPlayed([000])
  172. });
  173.  
  174. client.on('webSession', function(sessionID, cookies) {
  175.     manager.setCookies(cookies, function(err) {
  176.         if (err) return console.log(err);
  177.         console.log(`Got API key: ${manager.apiKey}`);
  178.     });
  179.     community.setCookies(cookies);
  180.     community.startConfirmationChecker(config.options.confirmationInterval, config.identitySecret);
  181. });
Add Comment
Please, Sign In to add comment