Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 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.  
  7. const community = new SteamCommunity();
  8. const client = new SteamUser();
  9. const manager = new TradeOfferManager({
  10. steam: client,
  11. domain: 'example.com',
  12. language: 'en'
  13. });
  14.  
  15. const logOnOptions = {
  16. accountName: config.username,
  17. password: config.password,
  18. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  19. };
  20. //log on
  21. client.logOn(logOnOptions);
  22.  
  23. client.on('loggedOn', function(details) {
  24. console.log(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`); //online then play tf2
  25. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  26. client.gamesPlayed(["B>Cards: 0.11 | S>Cards: 0.33",440])
  27. });
  28.  
  29. client.on('webSession', function(sessionID, cookies) {
  30. manager.setCookies(cookies, function(err) {
  31. if (err) return console.log(err);
  32. console.log(`Got API key: ${manager.apiKey}`);
  33. });
  34.  
  35. community.setCookies(cookies);
  36. community.startConfirmationChecker(10000, config.identitySecret);
  37. });
  38.  
  39. client.on('friendRelationship', (steamid, relationship) => {
  40. // Code to run when our relationship with `steamid` changes
  41. });
  42.  
  43. client.on('friendRelationship', (steamid, relationship) => {
  44. if (relationship === 2) {
  45. // Code to run when we get a `PendingInvitee`
  46. }
  47. });
  48.  
  49. client.on('friendRelationship', (steamid, relationship) => {
  50. if (relationship === 2) {
  51. client.addFriend(steamid);
  52. client.chatMessage(steamid, 'Hello there! Thanks for adding me!I buy and sell Steam Trading Cards/Backgrounds/Emoticons for TF2 metal!Just sent me a trade offer and i will accept it!');
  53. }
  54. });
  55.  
  56. function Get_Cards(offer, price) {
  57.  
  58. var Vaule = 0;
  59.  
  60. offer.forEach(function(item) {
  61. if (item.tags) {
  62. item.tags.forEach(function(tag) {
  63. if (tag.name && tag.name == "Trading Card") {
  64. Vaule += Math.round(price * 9);
  65. }
  66. });
  67. }
  68. });
  69. return Vaule;
  70. }
  71.  
  72. function Get_Cards(offer, price) {
  73.  
  74. var Vaule = 0;
  75.  
  76. offer.forEach(function(item) {
  77. if (item.tags) {
  78. item.tags.forEach(function(tag) {
  79. if (tag.name && tag.name == "Trading Card") {
  80. Vaule += Math.round(price * 9);
  81. }
  82. });
  83. }
  84. });
  85. return Vaule;
  86. }
  87.  
  88. function Get_backround(offer, price) {
  89.  
  90. var Vaule = 0;
  91.  
  92. offer.forEach(function(item) {
  93. if (item.tags) {
  94. item.tags.forEach(function(tag) {
  95. if (tag.name && tag.name == "Profile Background") {
  96. Vaule += Math.round(price * 9);
  97. }
  98. });
  99. }
  100. });
  101. return Vaule;
  102. }
  103.  
  104. function Get_emoticons(offer, price) {
  105.  
  106. var Vaule = 0;
  107.  
  108. offer.forEach(function(item) {
  109. if (item.tags) {
  110. item.tags.forEach(function(tag) {
  111. if (tag.name && tag.name == "Emoticon") {
  112. Vaule += Math.round(price * 9);
  113. }
  114. });
  115. }
  116. });
  117. return Vaule;
  118. }
  119.  
  120.  
  121.  
  122. function Get_Metal(offer) {
  123.  
  124. var Vaule = 0;
  125.  
  126. for (i = 0; i < offer.length; i++) {
  127. if (offer[i].market_hash_name.includes('Refined Metal')) {
  128. Vaule+=9;
  129. } else {
  130. if (offer[i].market_hash_name.includes('Reclaimed Metal')) {
  131. Vaule+=3;
  132. } else {
  133. if (offer[i].market_hash_name.includes('Scrap Metal')) {
  134. Vaule++;
  135. }
  136. }
  137. }
  138. }
  139. return Vaule;
  140. }
  141.  
  142.  
  143.  
  144.  
  145. function acceptOffer(offer, partnerID) {
  146. offer.accept((err) => {
  147. if (err) console.log(`Unable to accept offer: ${err.message}`);
  148. community.checkConfirmations();
  149. client.inviteToGroup(partnerID, config.groupSteamID);
  150. });
  151. }
  152.  
  153.  
  154.  
  155.  
  156. function declineOffer(offer) {
  157. offer.decline((err) => {
  158. if (err) return console.log(`Unable to decline offer: ${err.message}`);
  159. });
  160. }
  161.  
  162. manager.on('newOffer', function(offer) {
  163.  
  164. var partnerID = offer.partner.getSteamID64();
  165.  
  166. var OurCardVaule = Get_Cards(offer.itemsToGive, config.CardsSellPrice);
  167. var OurMetal = Get_Metal(offer.itemsToGive);
  168. var OurBackroundVaule = Get_backround(offer.itemsToGive, config.BackroundSellPrice)
  169. var OurEmoticonVaule = Get_emoticons(offer.itemsToGive, config.EmoticonSellPrice)
  170. var VauleToGive = OurCardVaule + OurMetal + OurEmoticonVaule + OurBackroundVaule;
  171.  
  172. var ThereCardVaule = Get_Cards(offer.itemsToReceive,config.CardsBuyPrice);
  173. var ThereMetal = Get_Metal(offer.itemsToReceive);
  174. var ThereBackroundVaule = Get_backround(offer.itemsToReceive, config.BackroundBuyPrice);
  175. var ThereEmoticonVaule = Get_emoticons(offer.itemsToReceive, config.EmoticonBuyPrice);
  176. var VauleToReceive = ThereCardVaule + ThereMetal + ThereBackroundVaule + ThereEmoticonVaule;
  177.  
  178.  
  179. if(VauleToReceive >= VauleToGive) {
  180. acceptOffer(offer, partnerID);
  181. console.log("accepted offer");
  182. console.log("invited to group");
  183. }else{
  184. declineOffer(offer);
  185. console.log("declined offer");
  186. }
  187. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement