Advertisement
Guest User

index.js

a guest
Sep 9th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.01 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/TRADES.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(SteamUser.Steam.EPersonaState.Online, BOTS[Object.keys(BOTS)[i]]["NAME"]);
  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. // BOT[i].COMMUNITY.getMarketItem(730, "P250 | Sand Dune (Factory New)", (ERR, ITEM) => { console.log(ITEM.medianSalePrices[0]);console.log(ITEM.medianSalePrices[ITEM.medianSalePrices.length-1]) });
  55. });
  56.  
  57. BOT[i].COMMUNITY.on("sessionExpired", (ERR) => {
  58. BOT[i].COMMUNITY.startConfirmationChecker();
  59. console.log(BOT[i].NAME + ": Session Expired, relogging.");
  60. BOT[i].CLIENT.webLogOn();
  61. });
  62.  
  63. BOT[i].CLIENT.on('friendRelationship', (steamid, relationship) => {
  64. if (relationship === 2) {
  65. BOT[i].CLIENT.addFriend(steamid);
  66. console.log(+ steamid.getSteamID64() + ` added the bot!`);
  67. BOT[i].CLIENT.chatMessage(steamid, `Welcome to my trade bot! You can send me a trade at ` +BOTS[Object.keys(BOTS)[i]]["URL"]); // optional, these can be removed/edited
  68. BOT[i].CLIENT.chatMessage(steamid, `If you have any questions contact my owner, King Ali, at http://steamcommunity.com/profiles/76561198110713513/`); // optional, these can be removed/edited
  69. } else if (relationship === 3) {
  70. if ("103582791460010606") {
  71. BOT[i].CLIENT.inviteToGroup(steamid, "103582791460010606");
  72. }
  73. BOT[i].CLIENT.chatMessage(steamid, "I invited you to our steam group! Feel free to join!");
  74. console.log( + steamid.getSteamID64() + ` Was invited to the steam group!`)
  75. }
  76. });
  77.  
  78. BOT[i].TRADES.on("newOffer", (OFFER) => {
  79. OFFER.itemsToReceive.forEach(function(item) {
  80. console.log(BOT[i].NAME + ` : New trade offer from ` + OFFER.partner.getSteamID64() + `. Sending : ` + item.market_hash_name);
  81. });
  82. OFFER.itemsToGive.forEach(function(item) {
  83. console.log(BOT[i].NAME + ` : New trade offer from ` + OFFER.partner.getSteamID64() + `. Giving : ` + item.market_hash_name);
  84. });
  85. OFFER.getUserDetails((ERR, ME, THEM) => {
  86. if (ME.escrowDays !== 0 || THEM.escrowDays !== 0) {
  87. OFFER.decline((ERR) => {
  88. if (ERR) {
  89. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  90. } else {
  91. console.log(BOT[i].NAME + `: Trade Declined from ` + OFFER.partner.getSteamID64() + ` because he doesn't have Mobile Auth.`);
  92. }
  93. });
  94. if (ERR) {
  95. console.log(BOT[i].NAME + ": There was an error getting user details: " + ERR);
  96. } else {
  97. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0) {
  98. OFFER.accept((ERR) => {
  99. if (ERR) {
  100. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  101. } else {
  102. console.log(`[!] THIS IS AN ADMIN TRADE [!] `+ BOT[i].NAME + `: Trade Accepted from ` + OFFER.partner.getSteamID64() + `.`);
  103. }
  104. });
  105. } else if (OFFER.itemsToGive.length == 0) {
  106. OFFER.accept((ERR) => {
  107. if (ERR) {
  108. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  109. } else {
  110. console.log(BOT[i].NAME + `: Donation Accepted from ` + OFFER.partner.getSteamID64() + `.`);
  111. }
  112. });
  113. } else {
  114. // Trade
  115. let OFFERDETAILS = {
  116. THEM: {
  117. ITEMWORTHINKEYS: 0,
  118. KEYS: 0,
  119. DONE: false
  120. },
  121. ME: {
  122. ITEMWORTHINKEYS: 0,
  123. KEYS: 0,
  124. DONE: false
  125. },
  126. VALID: true
  127. };
  128.  
  129.  
  130. for (let j = 0; j < OFFER.itemsToReceive.length; j++) {
  131. if (Object.keys(TRADES).indexOf(OFFER.itemsToReceive[j]["market_hash_name"]) >= 0) {
  132. BOT[i].COMMUNITY.getMarketItem(OFFER.itemsToReceive[j]["appid"], OFFER.itemsToReceive[j]["market_hash_name"], (ERR, ITEM) => {
  133. if (ERR) {
  134. console.log("## An error occured while getting item price: " + ERR);
  135. } else {
  136. console.log(ITEM.medianSalePrices[ITEM.medianSalePrices.length - 1 - 168].price + " PRICE WEEK AGO");
  137. console.log(ITEM.medianSalePrices[ITEM.medianSalePrices.length - 1].price + " PRICE NOW");
  138. console.log(TRADES[OFFER.itemsToReceive[j]["market_hash_name"]]["buyForKeys"] + " PRICE SET");
  139. if (ITEM.medianSalePrices[ITEM.medianSalePrices.length - 1 - 168].price * 1 - (CONFIG.INFLUENCEPERCENTAGE / 100) >= ((ITEM.medianSalePrices[ITEM.medianSalePrices.length - 1].price + ITEM.medianSalePrices[ITEM.medianSalePrices.length - 1].price) / 2)) {
  140. console.log("+" + TRADES[OFFER.itemsToReceive[j]["market_hash_name"]]["buyForKeys"]);
  141. OFFERDETAILS.THEM.ITEMWORTHINKEYS += TRADES[OFFER.itemsToReceive[j]["market_hash_name"]]["buyForKeys"];
  142. } else {
  143. console.log("## Item is currently being influenced. Marking it worthless.");
  144. }
  145. }
  146. if (j == OFFER.itemsToReceive.length - 1) {
  147. OFFERDETAILS.THEM.DONE = true;
  148. }
  149. });
  150. } else if (CONFIG.ACCEPTEDKEYS.indexOf(OFFER.itemsToReceive[j]["market_hash_name"]) >= 0) {
  151. OFFERDETAILS.THEM.KEYS++;
  152. } else {
  153. OFFERDETAILS.VALID = false;
  154. break;
  155. }
  156. }
  157.  
  158. for (let j = 0; j < OFFER.itemsToGive.length; j++) {
  159. if (Object.keys(TRADES).indexOf(OFFER.itemsToGive[j]["market_hash_name"]) >= 0) {
  160. console.log("+" + TRADES[OFFER.itemsToGive[j]["market_hash_name"]]["buyForKeys"]);
  161. OFFERDETAILS.ME.ITEMWORTHINKEYS += TRADES[OFFER.itemsToGive[j]["market_hash_name"]]["sellForKeys"];
  162. } else if (CONFIG.ACCEPTEDKEYS.indexOf(OFFER.itemsToGive[j]["market_hash_name"]) >= 0) {
  163. OFFERDETAILS.ME.KEYS++;
  164. } else {
  165. OFFERDETAILS.VALID = false;
  166. break;
  167. }
  168. if (j == OFFER.itemsToGive.length - 1) {
  169. OFFERDETAILS.ME.DONE = true;
  170. }
  171. }
  172. console.log(OFFERDETAILS);
  173. let intr = setInterval(() => {
  174. if (OFFERDETAILS.VALID && OFFERDETAILS.THEM.DONE && OFFERDETAILS.ME.DONE) {
  175. if (OFFERDETAILS.ME.KEYS > 0 && OFFERDETAILS.ME.ITEMWORTHINKEYS == 0 && OFFERDETAILS.THEM.ITEMWORTHINKEYS > 0 && OFFERDETAILS.THEM.KEYS == 0) {
  176. if (OFFERDETAILS.THEM.ITEMWORTHINKEYS >= OFFERDETAILS.ME.KEYS) {
  177. OFFER.accept((ERR) => {
  178. if (ERR) {
  179. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  180. } else {
  181. console.log(BOT[i].NAME + `: Trade Accepted from ` + OFFER.partner.getSteamID64() + `.`);
  182. }
  183. });
  184. } else {
  185. OFFER.decline((ERR) => {
  186. if (ERR) {
  187. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  188. } else {
  189. console.log(BOT[i].NAME + `: Trade Declined from` + OFFER.partner.getSteamID64() + `.`);
  190. }
  191. });
  192. }
  193. } else if (OFFERDETAILS.ME.KEYS == 0 && OFFERDETAILS.ME.ITEMWORTHINKEYS > 0 && OFFERDETAILS.THEM.ITEMWORTHINKEYS == 0 && OFFERDETAILS.THEM.KEYS > 0) {
  194. if (OFFERDETAILS.ME.ITEMWORTHINKEYS <= OFFERDETAILS.THEM.KEYS) {
  195. OFFER.accept((ERR) => {
  196. if (ERR) {
  197. console.log(BOT[i].NAME + ": An error occured while accepting error: " + ERR);
  198. } else {
  199. console.log(BOT[i].NAME + `: Trade Accepted from ` + OFFER.partner.getSteamID64() + `.`);
  200. }
  201. });
  202. } else {
  203. OFFER.decline((ERR) => {
  204. if (ERR) {
  205. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  206. } else {
  207. console.log(BOT[i].NAME + `: Trade Declined from ` + OFFER.partner.getSteamID64() + `.`);
  208. }
  209. });
  210. }
  211. } else {
  212. OFFER.decline((ERR) => {
  213. if (ERR) {
  214. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  215. } else {
  216. console.log(BOT[i].NAME + `: Trade Declined from ` + OFFER.partner.getSteamID64() + `.`);
  217. }
  218. });
  219. }
  220. } else {
  221. if (OFFERDETAILS.THEM.DONE || OFFERDETAILS.ME.DONE) {
  222. clearInterval(intr);
  223. OFFER.decline((ERR) => {
  224. if (ERR) {
  225. console.log(BOT[i].NAME + ": An error occured while declining error: " + ERR);
  226. } else {
  227. console.log(BOT[i].NAME + `: Trade Declined from ` + OFFER.partner.getSteamID64() + `.`);
  228. }
  229. });
  230. }
  231. }
  232. }, 1000 * 3);
  233. }
  234. }
  235. }
  236. });
  237. });
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement