Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. const SteamUser = require('steam-user');
  2. const SteamTotp = require('steam-totp')
  3. const SteamCommunity = require('steamcommunity');
  4. const TradeOfferManager = require('steam-tradeoffer-manager');
  5.  
  6. const Prices = require('./prices.json')
  7. const config = require('./config.json');
  8.  
  9. const client = new SteamUser();
  10. const community = new SteamCommunity();
  11. const manager = new TradeOfferManager({
  12. steam: client,
  13. community: community,
  14. language: 'en'
  15. });
  16.  
  17. const logOnOptions = {
  18. accountName: config.username,
  19. password: config.password,
  20. twoFactorcode: SteamTotp.generateAuthCode(config.sharedSecret)
  21. };
  22.  
  23. client.logOn(logOnOptions);
  24.  
  25. client.on('loggedOn', () => {
  26. console.log('succesfully logged on.')
  27. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  28. client.gamesPlayed(["730",Trading]);
  29. });
  30.  
  31. client.on("friendMessage", function(steamID, message) {
  32. if (message == "hi") {
  33. client.chatMessage(steamID, "hello, i am arrays trade bot. feel free to send me an offer. if its a good offer my bot will auto accept it.");
  34. }
  35. });
  36.  
  37. client.on('webSession', (sessionid, cookies) => {
  38. manager.setCookies(cookies);
  39.  
  40. community.setCookies(cookies);
  41. community.startConfirmationChecker(15000, config.identitySecret);
  42. });
  43.  
  44. function acceptOffer(offer) {
  45. offer.accept((err) => {
  46. community.checkConfirmations();
  47. console.log("We Accepted an offer");
  48. if (err) console.log("There was an error accepting the offer.");
  49. });
  50. }
  51.  
  52. function declineOffer(offer) {
  53. offer.decline((err) => {
  54. console.log("We Declined an offer");
  55. if (err) console.log("There was an error declining the offer.");
  56. });
  57. }
  58.  
  59. function processOffer(offer) {
  60. if (offer.isGlitched() || offer.state === 11) {
  61. console.log("Offer was glitched, declining.");
  62. declineOffer(offer);
  63. } else if (offer.partner.getSteamID64() === config.ownerID) {
  64. acceptOffer(offer);
  65. } else {
  66. var ourItems = offer.itemsToGive;
  67. var theirItems = offer.itemsToRecieve;
  68. var ourValue = 0;
  69. var theirValue = 0;
  70. for (var i in ourItems) {
  71. var item = ourItems[i].market_name;
  72. if (Prices[item]) {
  73. ourValue += Prices[item].sell;
  74. } else {
  75. console.log("Invalid Value.");
  76. ourValue += 99999;
  77. }
  78. }
  79. for(var i in theirItems) {
  80. var item= theirItems[i].market_name;
  81. if(Prices[item]) {
  82. theirValue += Prices[item].buy;{
  83. }
  84. } else {
  85. console.log("Their value was differant.")
  86. }
  87. }
  88. } console.log("Our value: "+ourValue);
  89. console.log("Their value: "+theirValue)
  90.  
  91. if (ourValue <= theirValue) {
  92. acceptOffer(offer);
  93. } else {
  94. declineOffer(offer);
  95. }
  96. }
  97. }
  98.  
  99. manager.on('newOffer', (offer) => {
  100.  
  101. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement