Guest User

Untitled

a guest
Sep 18th, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 83.24 KB | None | 0 0
  1. let SteamUser = require("steam-user"),
  2. SteamTotp = require("steam-totp"),
  3. TradeOfferManager = require("steam-tradeoffer-manager"),
  4. SteamCommunity = require("steamcommunity"),
  5. Utils = require("./utils.js"),
  6. CONFIG = require("./SETTINGS/config.js"),
  7. allCards = {},
  8. botSets = {},
  9. fs = require("fs"),
  10. users = {},
  11. userMsgs = {},
  12. SID64REGEX = new RegExp(/^[0-9]{17}$/),
  13. chatLogs = "",
  14. userLogs = {},
  15. totalBotSets = 0,
  16. setsThatShouldntBeSent = [];
  17.  
  18.  
  19. let client = new SteamUser(),
  20. manager = new TradeOfferManager({
  21. "steam": client,
  22. "language": "en",
  23. "pollInterval": "10000",
  24. "cancelTime": "7200000" // 2 hours in ms
  25. }),
  26. community = new SteamCommunity();
  27.  
  28. fs.readFile("./UserData/Users.json", (ERR, DATA) => {
  29. if (ERR) {
  30. console.log("## An error occurred while getting Users: " + ERR);
  31. } else {
  32. users = JSON.parse(DATA);
  33. }
  34. });
  35.  
  36. Utils.getCardsInSets((ERR, DATA) => {
  37. if (!ERR) {
  38. allCards = DATA;
  39. console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
  40. } else {
  41. console.log("An error occurred while getting cards: " + ERR);
  42. }
  43. });
  44.  
  45. setInterval(() => {
  46. for (let i = 0; i < Object.keys(users).length; i++) {
  47. if (users[Object.keys(users)[i]].idleforhours >= CONFIG.MAXHOURSADDED) {
  48. client.chatMessage(Object.keys(users)[i], "Hi, you have been inactive on my friends list for too long. If you wish to use this bot again re-add it.");
  49. client.removeFriend(Object.keys(users)[i]);
  50. delete users[Object.keys(users)[i]];
  51. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  52. if (ERR) {
  53. console.log("## An error occurred while writing UserData file: " + ERR);
  54. }
  55. });
  56. } else {
  57. users[Object.keys(users)[i]].idleforhours += 1;
  58. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  59. if (ERR) {
  60. console.log("## An error occurred while writing UserData file: " + ERR);
  61. }
  62. });
  63. }
  64. }
  65. }, 1000 * 60 * 60);
  66.  
  67. setInterval(() => {
  68. for (let i = 0; i < Object.keys(userMsgs).length; i++) {
  69. if (userMsgs[Object.keys(userMsgs)[i]] > CONFIG.MAXMSGPERSEC) {
  70. client.chatMessage(Object.keys(userMsgs)[i], "You have been removed for spamming. Another offense will get you blocked.");
  71. client.removeFriend(Object.keys(userMsgs)[i]);
  72. for (let j = 0; j < CONFIG.ADMINS.length; j++) {
  73. client.chatMessage(CONFIG.ADMINS[j], "User #" + Object.keys(userMsgs)[i] + " has been removed for spamming. To block him use !block [STEAMID64]");
  74. }
  75. }
  76. }
  77. userMsgs = {};
  78. }, 1000);
  79.  
  80. client.logOn({
  81. accountName: CONFIG.USERNAME,
  82. password: CONFIG.PASSWORD,
  83. twoFactorCode: SteamTotp.getAuthCode(CONFIG.SHAREDSECRET)
  84. });
  85.  
  86. client.on("loggedOn", (details, parental) => {
  87. client.getPersonas([client.steamID], (personas) => {
  88. console.log("## Logged in as #" + client.steamID + " (" + personas[client.steamID].player_name + ")");
  89. });
  90. client.setPersona(1);
  91. });
  92.  
  93. client.on("webSession", (sessionID, cookies) => {
  94. manager.setCookies(cookies, (ERR) => {
  95. if (ERR) {
  96. console.log("## An error occurred while setting cookies.");
  97. } else {
  98. console.log("## Websession created and cookies set.");
  99. }
  100. });
  101. // Add people that added the bot while it was online.
  102. for (let i = 0; i < Object.keys(client.myFriends).length; i++) {
  103. if (client.myFriends[Object.keys(client.myFriends)[i]] == 2) {
  104. client.addFriend(Object.keys(client.myFriends)[i]);
  105. }
  106. }
  107. community.setCookies(cookies);
  108. community.startConfirmationChecker(10000, CONFIG.IDENTITYSECRET);
  109. client.blockUser("76561198337312992"); // Some people have tried to either crash the bot or buy it not directly from me, I'm going to make bots block them just in case. :)
  110. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  111. console.log("DEBUG#INVLOADED");
  112. if (!ERR) {
  113. let s = DATA;
  114. Utils.getSets(s, allCards, (ERR, DATA) => {
  115. console.log("DEBUG#SETSLOADED");
  116. if (!ERR) {
  117. botSets = DATA;
  118. console.log("## Bot's sets loaded.");
  119. let botNSets = 0;
  120. for (let i = 0; i < Object.keys(botSets).length; i++) {
  121. botNSets += botSets[Object.keys(botSets)[i]].length;
  122. }
  123. totalBotSets = botNSets;
  124. let playThis = CONFIG.PLAYGAMES;
  125. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  126. playThis[0] = parseString(playThis[0], totalBotSets);
  127. }
  128. client.gamesPlayed(playThis);
  129. } else {
  130. console.log("## An error occurred while getting bot sets: " + ERR);
  131. process.exit();
  132. }
  133. });
  134. } else {
  135. console.log("## An error occurred while getting bot inventory: " + ERR);
  136. }
  137. });
  138. });
  139.  
  140. community.on("sessionExpired", (ERR) => {
  141. console.log("## Session Expired. Relogging.");
  142. client.webLogOn();
  143. });
  144.  
  145. client.on("friendMessage", (SENDER, MSG) => {
  146. if (userLogs[SENDER.getSteamID64()]) {
  147. userLogs[SENDER.getSteamID64()].push(MSG);
  148. } else {
  149. userLogs[SENDER.getSteamID64()] = [];
  150. userLogs[SENDER.getSteamID64()].push(MSG);
  151. }
  152. fs.writeFile("./ChatLogs/UserLogs/" + SENDER.getSteamID64() + "-log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".json", JSON.stringify({ logs: userLogs[SENDER.getSteamID64()] }), (ERR) => {
  153. if (ERR) {
  154. console.log("## An error occurred while writing UserLogs file: " + ERR);
  155. }
  156. });
  157. chatLogs += SENDER.getSteamID64() + " : " + MSG + "\n";
  158. fs.writeFile("./ChatLogs/FullLogs/log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".txt", chatLogs, (ERR) => {
  159. if (ERR) {
  160. console.log("## An error occurred while writing FullLogs file: " + ERR);
  161. }
  162. });
  163. if (Object.keys(users).indexOf(SENDER.getSteamID64()) < 0) {
  164. users[SENDER.getSteamID64()] = {};
  165. users[SENDER.getSteamID64()].idleforhours = 0;
  166. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  167. if (ERR) {
  168. console.log("## An error occurred while writing UserData file: " + ERR);
  169. }
  170. });
  171. } else {
  172. users[SENDER.getSteamID64()].idleforhours = 0;
  173. }
  174. if (userMsgs[SENDER.getSteamID64()]) {
  175. userMsgs[SENDER.getSteamID64()]++;
  176. } else {
  177. userMsgs[SENDER.getSteamID64()] = 1;
  178. }
  179. /*if (MSG.toUpperCase() == "!STOCK") {
  180. for (let i = 0; i < botSets.length; i++) {
  181. //
  182. }
  183. } else */
  184. if (MSG.toUpperCase().indexOf("!LEVEL") >= 0) {
  185. let n = parseInt(MSG.toUpperCase().replace("!LEVEL ", ""));
  186. if (!isNaN(n) && parseInt(n) > 0) {
  187. if (n <= CONFIG.MESSAGES.MAXLEVEL) {
  188. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA, CURRENTLEVEL, XPNEEDED) => {
  189. if (!ERR) {
  190. if (DATA) {
  191. if (n > CURRENTLEVEL) {
  192. let s = 0,
  193. l = 0;
  194. for (let i = 0; i < (n - CURRENTLEVEL); i++) {
  195. s += parseInt((CURRENTLEVEL + l) / 10) + 1;
  196. l++;
  197. }
  198. client.chatMessage(SENDER, "To get to level " + n + " you will need " + (s - Math.floor(XPNEEDED / 100)) + " sets. That would cost " + parseInt((s - Math.floor(XPNEEDED / 100)) / CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS * 100) / 100 + " keys.");
  199. } else {
  200. client.chatMessage(SENDER, "Please provide a valid level.");
  201. }
  202. } else {
  203. client.chatMessage(SENDER, "Your level could not be retrieved. Make sure your Steam Profile is public and try again.");
  204. }
  205. } else {
  206. console.log("## An error occurred while getting badge data: " + ERR);
  207. client.chatMessage(SENDER, "An error occurred while loading your badges. Please try again later.");
  208. }
  209. });
  210. } else {
  211. client.chatMessage(SENDER, "Please try a lower level.");
  212. }
  213. } else {
  214. client.chatMessage(SENDER, "Please provide a valid level.");
  215. }
  216. } else if (MSG.toUpperCase() === "!HELP") {
  217. client.chatMessage(SENDER, CONFIG.MESSAGES.HELP);
  218. if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64()) < 0) {
  219. client.chatMessage(SENDER, CONFIG.MESSAGES.SELLHELP);
  220. }
  221. } else if (MSG.toUpperCase().indexOf("!BUYONECHECK") >= 0) {
  222. client.chatMessage(SENDER, "Loading badges...");
  223. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  224. if (!ERR) {
  225. let b = {}; // List with badges that CAN still be crafted
  226. if (DATA) {
  227. for (let i = 0; i < Object.keys(DATA).length; i++) {
  228. if (DATA[Object.keys(DATA)[i]] < 6) {
  229. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  230. }
  231. }
  232. } else {
  233. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  234. }
  235. // console.log(b);
  236. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  237. // 1: GET BOTS CARDS. DONE
  238. // 2: GET PLAYER's BADGES. DONE
  239. // 3: MAGIC
  240. let hisMaxSets = 0,
  241. botNSets = 0;
  242. // Loop for sets he has partially completed
  243. for (let i = 0; i < Object.keys(b).length; i++) {
  244. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  245. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  246. }
  247. }
  248. // Loop for sets he has never crafted
  249. for (let i = 0; i < Object.keys(botSets).length; i++) {
  250. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  251. if (botSets[Object.keys(botSets)[i]].length >= 1) {
  252. hisMaxSets += 1;
  253. }
  254. }
  255. botNSets += botSets[Object.keys(botSets)[i]].length;
  256. }
  257. totalBotSets = botNSets;
  258. let playThis = CONFIG.PLAYGAMES;
  259. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  260. playThis[0] = parseString(playThis[0], totalBotSets);
  261. }
  262. client.gamesPlayed(playThis);
  263. client.chatMessage(SENDER, "There are currently sets from " + Object.keys(botSets).length + " different games, of which you have not crafted " + hisMaxSets + ". This would cost " + parseInt(hisMaxSets / CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS * 100) / 100 + " keys.");
  264. } else {
  265. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  266. console.log("An error occurred while getting badges: " + ERR);
  267. }
  268. });
  269. } else if (MSG.toUpperCase().indexOf("!SELLCHECK") >= 0 && (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64().toString()) < 0 || CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(parseInt(SENDER.getSteamID64())) < 0)) {
  270. let n = parseInt(MSG.toUpperCase().replace("!SELLCHECK ", ""));
  271. client.chatMessage(SENDER, "Loading inventory...");
  272.  
  273. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  274. console.log("DEBUG#INVLOADED");
  275. if (!ERR) {
  276. let s = DATA;
  277. Utils.getSets(s, allCards, (ERR, DATA) => {
  278. console.log("DEBUG#SETSLOADED");
  279. if (!ERR) {
  280.  
  281. // console.log(b);
  282. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  283. // 1: GET BOTS CARDS. DONE
  284. // 2: GET PLAYER's BADGES. DONE
  285. // 3: MAGIC
  286. let hisMaxSets = 0,
  287. botNSets = 0;
  288. // Loop for sets he has partially completed
  289. // Loop for sets he has never crafted
  290. for (let i = 0; i < Object.keys(DATA).length; i++) {
  291. if (DATA[Object.keys(DATA)[i]].length >= 5) {
  292. hisMaxSets += 5;
  293. } else {
  294. hisMaxSets += DATA[Object.keys(DATA)[i]].length;
  295. }
  296. botNSets += DATA[Object.keys(DATA)[i]].length;
  297. }
  298. totalBotSets = botNSets;
  299. let playThis = CONFIG.PLAYGAMES;
  300. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  301. playThis[0] = parseString(playThis[0], totalBotSets);
  302. }
  303. client.gamesPlayed(playThis);
  304. client.chatMessage(SENDER, "You currently have " + botNSets + " sets available which the bot can buy. For all of them the bot will pay you " + parseInt(botNSets / CONFIG.CARDS.GIVE1KEYPERAMOUNTOFSETS * 100) / 100 + " keys.");
  305. } else {
  306. console.log("## An error occurred while getting user sets: " + ERR);
  307. }
  308. });
  309. } else {
  310. console.log("## An error occurred while getting user inventory: " + ERR);
  311. }
  312. });
  313. } else if (MSG.toUpperCase().indexOf("!CHECK") >= 0) {
  314. let n = parseInt(MSG.toUpperCase().replace("!CHECK ", ""));
  315. if (!isNaN(n) && parseInt(n) > 0) {
  316. client.chatMessage(SENDER, "With " + n + " keys you can get " + n * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS + " sets.");
  317. } else {
  318. if (Object.keys(botSets).length > 0) {
  319. client.chatMessage(SENDER, "Loading badges...");
  320. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  321. if (!ERR) {
  322. let b = {}; // List with badges that CAN still be crafted
  323. if (DATA) {
  324. for (let i = 0; i < Object.keys(DATA).length; i++) {
  325. if (DATA[Object.keys(DATA)[i]] < 6) {
  326. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  327. }
  328. }
  329. } else {
  330. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  331. }
  332. // console.log(b);
  333. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  334. // 1: GET BOTS CARDS. DONE
  335. // 2: GET PLAYER's BADGES. DONE
  336. // 3: MAGIC
  337. let hisMaxSets = 0,
  338. botNSets = 0;
  339. // Loop for sets he has partially completed
  340. for (let i = 0; i < Object.keys(b).length; i++) {
  341. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  342. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  343. }
  344. }
  345. // Loop for sets he has never crafted
  346. for (let i = 0; i < Object.keys(botSets).length; i++) {
  347. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  348. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  349. hisMaxSets += 5;
  350. } else {
  351. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  352. }
  353. }
  354. botNSets += botSets[Object.keys(botSets)[i]].length;
  355. }
  356. totalBotSets = botNSets;
  357. let playThis = CONFIG.PLAYGAMES;
  358. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  359. playThis[0] = parseString(playThis[0], totalBotSets);
  360. }
  361. client.gamesPlayed(playThis);
  362. client.chatMessage(SENDER, "There are currently " + hisMaxSets + "/" + botNSets + " sets available which you have not fully crafted yet. Buying all of them will cost you " + parseInt(hisMaxSets / CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS * 100) / 100 + " keys.");
  363. } else {
  364. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  365. console.log("An error occurred while getting badges: " + ERR);
  366. }
  367. });
  368. } else {
  369. client.chatMessage(SENDER, "Please try again later.");
  370. }
  371. }
  372. } else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
  373. if (botSets) {
  374. if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64().toString()) < 0 || CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(parseInt(SENDER.getSteamID64())) < 0) {
  375. let n = parseInt(MSG.toUpperCase().replace("!SELL ", "")),
  376. amountofsets = n * CONFIG.CARDS.GIVE1KEYPERAMOUNTOFSETS;
  377. if (!isNaN(n) && parseInt(n) > 0) {
  378. if (n <= CONFIG.MESSAGES.MAXSELL) {
  379. client.chatMessage(SENDER, "Processing your request.");
  380. let botKeys = [],
  381. t = manager.createOffer(SENDER.getSteamID64());
  382. t.getUserDetails((ERR, ME, THEM) => {
  383. if (ERR) {
  384. console.log("## An error occurred while getting trade holds: " + ERR);
  385. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  386. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  387. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  388. if (ERR) {
  389. console.log("## An error occurred while getting bot inventory: " + ERR);
  390. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  391. } else {
  392. for (let i = 0; i < INV.length; i++) {
  393. if (botKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  394. botKeys.push(INV[i]);
  395. }
  396. }
  397. if (botKeys.length != n) {
  398. client.chatMessage(SENDER, "The bot does not have enough keys.");
  399. } else {
  400. let amountofB = amountofsets;
  401. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  402. if (!ERR) {
  403. let s = DATA;
  404. Utils.getSets(s, allCards, (ERR, DDATA) => {
  405. if (!ERR) {
  406. sortSetsByAmountB(s, (DATA) => {
  407. let setsSent = {};
  408. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  409. console.log(setsSent);
  410. console.log(DATA[i]);
  411. if (DDATA[DATA[i]]) {
  412. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  413. if (amountofB > 0) {
  414. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.MAXSETSELL) || !setsSent[DATA[i]]) {
  415. t.addTheirItems(DDATA[DATA[i]][j]);
  416. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  417. amountofB--;
  418. if (!setsSent[DATA[i]]) {
  419. setsSent[DATA[i]] = 1;
  420. } else {
  421. setsSent[DATA[i]] += 1;
  422. }
  423. } else {
  424. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  425. continue firsttLoop;
  426. }
  427. } else {
  428. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  429. continue firsttLoop;
  430. }
  431. }
  432. } else {
  433. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  434. continue firsttLoop;
  435. }
  436. }
  437. });
  438. if (amountofB > 0) {
  439. client.chatMessage(SENDER, "You do not have enough sets, (this bot only accepts " + CONFIG.CARDS.MAXSETSELL + " sets per set type at a time). Please try again later.");
  440. } else {
  441. console.log("DEBUG#SENDING");
  442. t.addMyItems(botKeys);
  443. t.data("commandused", "Sell");
  444. t.data("amountofsets", amountofsets.toString());
  445. t.data("amountofkeys", n);
  446. t.send((ERR, STATUS) => {
  447. if (ERR) {
  448. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  449. console.log("## An error occurred while sending trade: " + ERR);
  450. } else {
  451. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  452. console.log("## Trade offer sent!");
  453. }
  454. });
  455. }
  456. } else {
  457. console.log("## An error occurred while getting bot sets: " + ERR);
  458. }
  459. });
  460. } else {
  461. console.log("## An error occurred while getting user inventory: " + ERR);
  462. }
  463. });
  464. }
  465. }
  466. });
  467. } else {
  468. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  469. }
  470. });
  471. } else {
  472. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  473. }
  474. } else {
  475. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  476. }
  477. } else {
  478. client.chatMessage(SENDER, "You are not able to sell sets.");
  479. }
  480. } else {
  481. client.chatMessage(SENDER, "Please try again later.");
  482. }
  483. } else if (MSG.toUpperCase().indexOf("!BUYONE") >= 0) {
  484. if (botSets) {
  485. let n = MSG.toUpperCase().replace("!BUYONE ", ""),
  486. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  487. if (!isNaN(n) && parseInt(n) > 0) {
  488. if (n <= CONFIG.MESSAGES.MAXBUY) {
  489. let t = manager.createOffer(SENDER.getSteamID64());
  490. t.getUserDetails((ERR, ME, THEM) => {
  491. if (ERR) {
  492. console.log("## An error occurred while getting trade holds: " + ERR);
  493. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  494. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  495. n = parseInt(n);
  496. let theirKeys = [];
  497. client.chatMessage(SENDER, "Processing your request.");
  498. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  499. if (ERR) {
  500. console.log("## An error occurred while getting inventory: " + ERR);
  501. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  502. } else {
  503. console.log("DEBUG#INV LOADED");
  504. if (!ERR) {
  505. console.log("DEBUG#INV LOADED NOERR");
  506. for (let i = 0; i < INV.length; i++) {
  507. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  508. theirKeys.push(INV[i]);
  509. }
  510. }
  511. if (theirKeys.length != n) {
  512. client.chatMessage(SENDER, "You do not have enough keys.");
  513. } else {
  514. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  515. if (!ERR) {
  516. console.log("DEBUG#BADGE LOADED");
  517. if (!ERR) {
  518. let b = {}; // List with badges that CAN still be crafted
  519. if (DATA) {
  520. for (let i = 0; i < Object.keys(DATA).length; i++) {
  521. if (DATA[Object.keys(DATA)[i]] < 6) {
  522. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  523. }
  524. }
  525. } else {
  526. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  527. }
  528. console.log(DATA);
  529. console.log(b);
  530. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  531. // 1: GET BOTS CARDS. DONE
  532. // 2: GET PLAYER's BADGES. DONE
  533. // 3: MAGIC
  534. let hisMaxSets = 0,
  535. botNSets = 0;
  536. // Loop for sets he has partially completed
  537. for (let i = 0; i < Object.keys(b).length; i++) {
  538. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  539. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  540. }
  541. }
  542. console.log("DEBUG#LOOP 1 DONE");
  543. // Loop for sets he has never crafted
  544. for (let i = 0; i < Object.keys(botSets).length; i++) {
  545. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  546. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  547. hisMaxSets += 5;
  548. } else {
  549. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  550. }
  551. }
  552. botNSets += botSets[Object.keys(botSets)[i]].length;
  553. }
  554. totalBotSets = botNSets;
  555. let playThis = CONFIG.PLAYGAMES;
  556. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  557. playThis[0] = parseString(playThis[0], totalBotSets);
  558. }
  559. client.gamesPlayed(playThis);
  560. console.log("DEBUG#LOOP 2 DONE");
  561. // HERE
  562. if (amountofsets <= hisMaxSets) {
  563. hisMaxSets = amountofsets;
  564. console.log("DEBUG#TRADE CREATED");
  565. sortSetsByAmount(botSets, (DATA) => {
  566. console.log("DEBUG#" + DATA);
  567. console.log("DEBUG#SETS SORTED");
  568. firstLoop: for (let i = 0; i < DATA.length; i++) {
  569. if (b[DATA[i]] == 0) {
  570. continue firstLoop;
  571. } else {
  572. console.log("DEBUG#" + i);
  573. console.log("DEBUG#FOR LOOP ITEMS");
  574. if (hisMaxSets > 0) {
  575. console.log("DEBUG#MAXSETSMORETHAN1");
  576. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  577. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  578. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  579. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  580. t.addMyItems(botSets[DATA[i]][j]);
  581. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  582. hisMaxSets--;
  583. continue firstLoop;
  584. } else {
  585. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  586. continue firstLoop;
  587. }
  588. }
  589. }
  590. } else {
  591. console.log("DEBUG#RETURN");
  592. break firstLoop;
  593. }
  594. }
  595. }
  596. if (hisMaxSets > 0) {
  597. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  598. } else {
  599. console.log("DEBUG#SENDING");
  600. t.addTheirItems(theirKeys);
  601. t.data("commandused", "BuyOne");
  602. t.data("amountofkeys", n);
  603. t.data("amountofsets", amountofsets.toString());
  604. t.data("index", setsThatShouldntBeSent.length);
  605. setsThatShouldntBeSent.push(t.itemsToGive);
  606. t.send((ERR, STATUS) => {
  607. if (ERR) {
  608. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  609. console.log("## An error occurred while sending trade: " + ERR);
  610. } else {
  611. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  612. console.log("## Trade offer sent");
  613. }
  614. });
  615. }
  616. });
  617. } else {
  618. client.chatMessage(SENDER, "There are currently not enough sets that you have not used in stock for this amount of keys. Please try again later. If you want the bot to ignore your current badges use !buyany.");
  619. }
  620. // TO HERE
  621. } else {
  622. console.log("An error occurred while getting badges: " + ERR);
  623. }
  624. } else {
  625. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  626. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  627. }
  628. });
  629. }
  630. } else {
  631. console.log("## An error occurred while getting inventory: " + ERR);
  632. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  633. }
  634. }
  635. });
  636. } else {
  637. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  638. }
  639. });
  640. } else {
  641. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  642. }
  643. } else {
  644. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  645. }
  646. } else {
  647. client.chatMessage(SENDER, "Please try again later.");
  648. }
  649. } else if (MSG.toUpperCase().indexOf("!BUYANY") >= 0) {
  650. if (botSets) {
  651. let n = MSG.toUpperCase().replace("!BUYANY ", ""),
  652. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  653. if (!isNaN(n) && parseInt(n) > 0) {
  654. if (n <= CONFIG.MESSAGES.MAXBUY) {
  655. let t = manager.createOffer(SENDER.getSteamID64());
  656. n = parseInt(n);
  657. let theirKeys = [];
  658. t.getUserDetails((ERR, ME, THEM) => {
  659. if (ERR) {
  660. console.log("## An error occurred while getting trade holds: " + ERR);
  661. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  662. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  663. client.chatMessage(SENDER, "Processing your request.");
  664. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  665. if (ERR) {
  666. console.log("## An error occurred while getting inventory: " + ERR);
  667. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  668. } else {
  669. let amountofB = amountofsets;
  670. for (let i = 0; i < INV.length; i++) {
  671. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  672. theirKeys.push(INV[i]);
  673. }
  674. }
  675. if (theirKeys.length != n) {
  676. client.chatMessage(SENDER, "You do not have enough keys.");
  677. } else {
  678. sortSetsByAmount(botSets, (DATA) => {
  679. let setsSent = {};
  680. firstLoop: for (let i = 0; i < DATA.length; i++) {
  681. console.log(setsSent);
  682. console.log(DATA[i]);
  683. if (botSets[DATA[i]]) {
  684. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  685. if (amountofB > 0) {
  686. if ((setsSent[DATA[i]] && setsSent[DATA[i]] > -1) || !setsSent[DATA[i]]) {
  687. t.addMyItems(botSets[DATA[i]][j]);
  688. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  689. amountofB--;
  690. if (!setsSent[DATA[i]]) {
  691. setsSent[DATA[i]] = 1;
  692. } else {
  693. setsSent[DATA[i]] += 1;
  694. }
  695. } else {
  696. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  697. continue firstLoop;
  698. }
  699. } else {
  700. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  701. continue firstLoop;
  702. }
  703. }
  704. } else {
  705. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  706. continue firstLoop;
  707. }
  708. }
  709. });
  710. }
  711. if (amountofB > 0) {
  712. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  713. } else {
  714. console.log("DEBUG#SENDING");
  715. t.addTheirItems(theirKeys);
  716. t.data("commandused", "BuyAny");
  717. t.data("amountofsets", amountofsets.toString());
  718. t.data("amountofkeys", n);
  719. t.data("index", setsThatShouldntBeSent.length);
  720. setsThatShouldntBeSent.push(t.itemsToGive);
  721. t.send((ERR, STATUS) => {
  722. if (ERR) {
  723. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  724. console.log("## An error occurred while sending trade: " + ERR);
  725. } else {
  726. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  727. console.log("## Trade offer sent!");
  728. }
  729. });
  730. }
  731. }
  732. });
  733. } else {
  734. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  735. }
  736. });
  737. } else {
  738. client.chatMessage(SENDER, "Please try a lower amount of keys");
  739. }
  740. } else {
  741. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  742. }
  743. } else {
  744. client.chatMessage(SENDER, "Please try again later.");
  745. }
  746. } else if (MSG.toUpperCase().indexOf("!BUY") >= 0) {
  747. if (botSets) {
  748. let n = MSG.toUpperCase().replace("!BUY ", ""),
  749. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  750. if (!isNaN(n) && parseInt(n) > 0) {
  751. if (n <= CONFIG.MESSAGES.MAXBUY) {
  752. let t = manager.createOffer(SENDER.getSteamID64());
  753. t.getUserDetails((ERR, ME, THEM) => {
  754. if (ERR) {
  755. console.log("## An error occurred while getting trade holds: " + ERR);
  756. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  757. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  758. n = parseInt(n);
  759. let theirKeys = [];
  760. client.chatMessage(SENDER, "Processing your request.");
  761. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  762. if (ERR) {
  763. console.log("## An error occurred while getting inventory: " + ERR);
  764. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  765. } else {
  766. console.log("DEBUG#INV LOADED");
  767. if (!ERR) {
  768. console.log("DEBUG#INV LOADED NOERR");
  769. for (let i = 0; i < INV.length; i++) {
  770. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  771. theirKeys.push(INV[i]);
  772. }
  773. }
  774. if (theirKeys.length != n) {
  775. client.chatMessage(SENDER, "You do not have enough keys.");
  776. } else {
  777. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  778. if (!ERR) {
  779. console.log("DEBUG#BADGE LOADED");
  780. if (!ERR) {
  781. let b = {}; // List with badges that CAN still be crafted
  782. if (DATA) {
  783. for (let i = 0; i < Object.keys(DATA).length; i++) {
  784. if (DATA[Object.keys(DATA)[i]] < 6) {
  785. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  786. }
  787. }
  788. } else {
  789. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  790. }
  791. console.log(DATA);
  792. console.log(b);
  793. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  794. // 1: GET BOTS CARDS. DONE
  795. // 2: GET PLAYER's BADGES. DONE
  796. // 3: MAGIC
  797. let hisMaxSets = 0,
  798. botNSets = 0;
  799. // Loop for sets he has partially completed
  800. for (let i = 0; i < Object.keys(b).length; i++) {
  801. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  802. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  803. }
  804. }
  805. console.log("DEBUG#LOOP 1 DONE");
  806. // Loop for sets he has never crafted
  807. for (let i = 0; i < Object.keys(botSets).length; i++) {
  808. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  809. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  810. hisMaxSets += 5;
  811. } else {
  812. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  813. }
  814. }
  815. botNSets += botSets[Object.keys(botSets)[i]].length;
  816. }
  817. console.log("DEBUG#LOOP 2 DONE");
  818. // HERE
  819. if (amountofsets <= hisMaxSets) {
  820. hisMaxSets = amountofsets;
  821. console.log("DEBUG#TRADE CREATED");
  822. sortSetsByAmount(botSets, (DATA) => {
  823. console.log("DEBUG#" + DATA);
  824. console.log("DEBUG#SETS SORTED");
  825. firstLoop: for (let i = 0; i < DATA.length; i++) {
  826. if (b[DATA[i]] == 0) {
  827. continue firstLoop;
  828. } else {
  829. console.log("DEBUG#" + i);
  830. console.log("DEBUG#FOR LOOP ITEMS");
  831. if (hisMaxSets > 0) {
  832. console.log("DEBUG#MAXSETSMORETHAN1");
  833. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  834. // BOT HAS ENOUGH SETS OF THIS KIND
  835. console.log("DEBUG#LOOP #1");
  836. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  837. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  838. console.log("DEBUG#LOOP #1: ITEM ADD");
  839. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  840. t.addMyItems(botSets[DATA[i]][j]);
  841. hisMaxSets--;
  842. console.log(hisMaxSets);
  843. } else {
  844. console.log("DEBUG#LOOP #1: RETURN");
  845. continue firstLoop;
  846. }
  847. }
  848. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  849. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  850. console.log("DEBUG#LOOP #1 CONTINUE");
  851. continue; // *
  852. } else if (!b[DATA[i]] && botSets[DATA[i]].length < 5 && botSets[DATA[i]].length - b[DATA[i]] > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  853. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  854. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  855. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  856. t.addMyItems(botSets[DATA[i]][j]);
  857. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  858. hisMaxSets--;
  859. } else {
  860. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  861. continue firstLoop;
  862. }
  863. }
  864. }
  865. else if (hisMaxSets < 5) {
  866. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  867. console.log("DEBUG#LOOP #2");
  868. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  869. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  870. t.addMyItems(botSets[DATA[i]][j]);
  871. console.log("DEBUG#LOOP #2: ITEM ADD");
  872. hisMaxSets--;
  873. console.log(hisMaxSets);
  874. } else {
  875. console.log("DEBUG#LOOP #2: RETURN");
  876. continue firstLoop;
  877. }
  878. }
  879. } else {
  880. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  881. console.log("DEBUG#LOOP #2");
  882. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  883. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  884. t.addMyItems(botSets[DATA[i]][j]);
  885. console.log("DEBUG#LOOP #2: ITEM ADD");
  886. hisMaxSets--;
  887. console.log(hisMaxSets);
  888. } else {
  889. console.log("DEBUG#LOOP #2: RETURN");
  890. continue firstLoop;
  891. }
  892. }
  893. }
  894. } else {
  895. console.log("DEBUG#RETURN");
  896. break firstLoop;
  897. }
  898. }
  899. }
  900. if (hisMaxSets > 0) {
  901. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  902. } else {
  903. console.log("DEBUG#SENDING");
  904. t.addTheirItems(theirKeys);
  905. t.data("commandused", "Buy");
  906. t.data("amountofkeys", n);
  907. t.data("amountofsets", amountofsets.toString());
  908. t.data("index", setsThatShouldntBeSent.length);
  909. setsThatShouldntBeSent.push(t.itemsToGive);
  910. t.send((ERR, STATUS) => {
  911. if (ERR) {
  912. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  913. console.log("## An error occurred while sending trade: " + ERR);
  914. } else {
  915. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  916. console.log("## Trade offer sent");
  917. }
  918. });
  919. }
  920. });
  921. } else {
  922. client.chatMessage(SENDER, "There are currently not enough sets that you have not used in stock for this amount of keys. Please try again later. If you want the bot to ignore your current badges use !buyany.");
  923. }
  924. // TO HERE
  925. } else {
  926. console.log("An error occurred while getting badges: " + ERR);
  927. }
  928. } else {
  929. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  930. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  931. }
  932. });
  933. }
  934. } else {
  935. console.log("## An error occurred while getting inventory: " + ERR);
  936. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  937. }
  938. }
  939. });
  940. } else {
  941. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  942. }
  943. });
  944. } else {
  945. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  946. }
  947. } else {
  948. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  949. }
  950. } else {
  951. client.chatMessage(SENDER, "Please try again later.");
  952. }
  953. } else if (MSG.toUpperCase() == "!PROOF") {
  954. client.chatMessage(SENDER, "This bot was made by www.steamcommunity.com/id/timandyouknow");
  955. } else if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
  956. // Admin commands.
  957. if (MSG.toUpperCase().indexOf("!BLOCK") >= 0) {
  958. let n = MSG.toUpperCase().replace("!BLOCK ", "").toString();
  959. if (SID64REGEX.test(n)) {
  960. client.chatMessage(SENDER, "User blocked.");
  961. client.blockUser(n);
  962. } else {
  963. client.chatMessage(SENDER, "Please provide a valid SteamID64");
  964. }
  965. } else if (MSG.toUpperCase().indexOf("!USERCHECK") >= 0) {
  966. let n = MSG.toUpperCase().replace("!USERCHECK ", "").toString();
  967. if (SID64REGEX.test(n)) {
  968. if (Object.keys(botSets).length > 0) {
  969. client.chatMessage(SENDER, "Loading badges...");
  970. Utils.getBadges(n, (ERR, DATA) => {
  971. if (!ERR) {
  972. let b = {}; // List with badges that CAN still be crafted
  973. if (DATA) {
  974. for (let i = 0; i < Object.keys(DATA).length; i++) {
  975. if (DATA[Object.keys(DATA)[i]] < 6) {
  976. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  977. }
  978. }
  979. } else {
  980. client.chatMessage(SENDER.getSteamID64(), n + "'s badges are empty, sending an offer without checking badges.");
  981. }
  982. // console.log(b);
  983. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  984. // 1: GET BOTS CARDS. DONE
  985. // 2: GET PLAYER's BADGES. DONE
  986. // 3: MAGIC
  987. let hisMaxSets = 0,
  988. botNSets = 0;
  989. // Loop for sets he has partially completed
  990. for (let i = 0; i < Object.keys(b).length; i++) {
  991. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  992. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  993. }
  994. }
  995. // Loop for sets he has never crafted
  996. for (let i = 0; i < Object.keys(botSets).length; i++) {
  997. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  998. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  999. hisMaxSets += 5;
  1000. } else {
  1001. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1002. }
  1003. }
  1004. botNSets += botSets[Object.keys(botSets)[i]].length;
  1005. }
  1006. client.chatMessage(SENDER, "There are currently " + hisMaxSets + "/" + botNSets + " sets available which " + n + " has not fully crafted yet. Buying all of them will cost " + parseInt(hisMaxSets / CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS * 100) / 100 + " keys.");
  1007. } else {
  1008. client.chatMessage(SENDER, "An error occurred while getting " + n + "'s badges. Please try again.");
  1009. console.log("An error occurred while getting badges: " + ERR);
  1010. }
  1011. });
  1012. } else {
  1013. client.chatMessage(SENDER, "Please try again later.");
  1014. }
  1015. } else {
  1016. client.chatMessage(SENDER, "Please provide a valid SteamID64.");
  1017. }
  1018. }
  1019.  
  1020.  
  1021. /*
  1022. else if (MSG.toUpperCase() == "!KEYS") {
  1023. manager.getInventoryContents(CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  1024. if (ERR) {
  1025. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory.");
  1026. console.log("## An error occurred while getting inventory: " + ERR);
  1027. } else {
  1028. let t = manager.createOffer(SENDER);
  1029. for (let i = 0; i < INV.length; i++) {
  1030. if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1031. t.addMyItem(INV[i]);
  1032. }
  1033. t.send();
  1034. }
  1035. }
  1036. });
  1037. }
  1038. */
  1039. else if (MSG.toUpperCase() == "!DEPOSIT") {
  1040. t = manager.createOffer(SENDER.getSteamID64());
  1041. t.getUserDetails((ERR, ME, THEM) => {
  1042. if (ERR) {
  1043. console.log("## An error occurred while getting trade holds: " + ERR);
  1044. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  1045. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1046. if (ERR) {
  1047. console.log("## An error occurred while getting bot inventory: " + ERR);
  1048. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  1049. } else {
  1050. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  1051. if (!ERR) {
  1052. let s = DATA;
  1053. Utils.getSets(s, allCards, (ERR, DDATA) => {
  1054. if (!ERR) {
  1055. sortSetsByAmountB(s, (DATA) => {
  1056. let setsSent = {};
  1057. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  1058. console.log(setsSent);
  1059. console.log(DATA[i]);
  1060. if (DDATA[DATA[i]]) {
  1061. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  1062. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.MAXSETSELL) || !setsSent[DATA[i]]) {
  1063. t.addTheirItems(DDATA[DATA[i]][j]);
  1064. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1065. if (!setsSent[DATA[i]]) {
  1066. setsSent[DATA[i]] = 1;
  1067. } else {
  1068. setsSent[DATA[i]] += 1;
  1069. }
  1070. } else {
  1071. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1072. continue firsttLoop;
  1073. }
  1074. }
  1075. } else {
  1076. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  1077. continue firsttLoop;
  1078. }
  1079. }
  1080. });
  1081. console.log("DEBUG#SENDING");
  1082. t.data("commandused", "Deposit");
  1083. t.send((ERR, STATUS) => {
  1084. if (ERR) {
  1085. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1086. console.log("## An error occurred while sending trade: " + ERR);
  1087. } else {
  1088. client.chatMessage(t.partner, "Trade confirmed! Click here to accept it: https://www.steamcommunity.com/tradeoffer/" + t.id);
  1089. console.log("## Trade offer sent!");
  1090. }
  1091. });
  1092. } else {
  1093. console.log("## An error occurred while getting bot sets: " + ERR);
  1094. }
  1095. });
  1096. } else {
  1097. console.log("## An error occurred while getting user inventory: " + ERR);
  1098. }
  1099. });
  1100. }
  1101. } else {
  1102. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1103. }
  1104. });
  1105. } else {
  1106. client.chatMessage(SENDER, "Command not recognized.");
  1107. }
  1108. } else {
  1109. client.chatMessage(SENDER, "Command not recognized. Use !help to see how this bot works.");
  1110. }
  1111. });
  1112.  
  1113. client.on("friendRelationship", (SENDER, REL) => {
  1114. if (REL === 2) {
  1115. client.addFriend(SENDER);
  1116. } else if (REL === 3) {
  1117. if (CONFIG.INVITETOGROUPID) {
  1118. client.inviteToGroup(SENDER, CONFIG.INVITETOGROUPID);
  1119. }
  1120. client.chatMessage(SENDER, CONFIG.MESSAGES.WELCOME);
  1121. }
  1122. });
  1123.  
  1124. // manager.on("unknownOfferSent", (o, os) => {
  1125. // if (o.state == 9) {
  1126. // console.log("## OFFER SENT LIST");
  1127. // community.checkConfirmations();
  1128. // }
  1129. // });
  1130.  
  1131. // community.on("newConfirmation", (CONF) => {
  1132. // console.log("## New confirmation.");
  1133. // community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id);
  1134. // });
  1135.  
  1136. manager.on("sentOfferChanged", (OFFER, OLDSTATE) => {
  1137. if (OFFER.state == 2) {
  1138. client.chatMessage(OFFER.partner, "Trade confirmed! Click here to accept it: https://www.steamcommunity.com/tradeoffer/" + OFFER.id);
  1139. } else if (OFFER.state == 3) {
  1140. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  1141. if (!ERR) {
  1142. let s = DATA;
  1143. Utils.getSets(s, allCards, (ERR, DATA) => {
  1144. if (!ERR) {
  1145. botSets = DATA;
  1146. console.log("## Bot's sets loaded.");
  1147. } else {
  1148. console.log("## An error occurred while getting bot sets: " + ERR);
  1149. }
  1150. let botNSets = 0;
  1151. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1152. botNSets += botSets[Object.keys(botSets)[i]].length;
  1153. }
  1154. totalBotSets = botNSets;
  1155. let playThis = CONFIG.PLAYGAMES;
  1156. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  1157. playThis[0] = parseString(playThis[0], totalBotSets);
  1158. }
  1159. client.gamesPlayed(playThis);
  1160. });
  1161. } else {
  1162. console.log("## An error occurred while getting bot inventory: " + ERR);
  1163. }
  1164. });
  1165. if (CONFIG.INVITETOGROUPID) {
  1166. client.inviteToGroup(OFFER.partner, CONFIG.INVITETOGROUPID);
  1167. }
  1168. let d = "" + OFFER.data("commandused") + "";
  1169. d += "\nSets: " + OFFER.data("amountofsets");
  1170. d += "\nKeys: " + OFFER.data("amountofkeys");
  1171. d += "\nSteamID: " + OFFER.partner.getSteamID64();
  1172. fs.writeFile("./TradesAccepted/" + OFFER.id + "-" + OFFER.partner.getSteamID64() + ".txt", d, (ERR) => {
  1173. if (ERR) {
  1174. console.log("## An error occurred while writing trade file: " + ERR);
  1175. }
  1176. });
  1177. community.getSteamUser(OFFER.partner, (ERR, USER) => {
  1178. if (ERR) {
  1179. console.log("## An error occurred while getting user profile: " + ERR);
  1180. client.chatMessage(OFFER.partner, "An error occurred while getting your profile (to comment).");
  1181. } else {
  1182. USER.comment(CONFIG.COMMENTAFTERTRADE, (ERR) => {
  1183. if (ERR) {
  1184. console.log("## An error occurred while commenting on user profile: " + ERR);
  1185. client.chatMessage(OFFER.partner, "An error occurred while getting commenting on your profile.");
  1186. } else {
  1187. client.chatMessage(OFFER.partner, "Thanks for trading! :D");
  1188. }
  1189. });
  1190. }
  1191. });
  1192. } else if (OFFER.state == 6) {
  1193. client.chatMessage(OFFER.partner, "Hey, you did not accept the offer. Please try again if you wish to receive sets!");
  1194. }
  1195. /* else if (OFFER.state == 9) {
  1196. community.checkConfirmations();
  1197. }*/
  1198. });
  1199.  
  1200. manager.on("newOffer", (OFFER) => {
  1201. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(OFFER.partner.getSteamID64())) >= 0) {
  1202. OFFER.getUserDetails((ERR, ME, THEM) => {
  1203. if (ERR) {
  1204. console.log("## An error occurred while getting trade holds: " + ERR);
  1205. client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again");
  1206. OFFER.decline((ERR) => {
  1207. if (ERR) {
  1208. console.log("## An error occurred while declining trade: " + ERR);
  1209. }
  1210. });
  1211. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1212. OFFER.accept((ERR) => {
  1213. if (ERR) {
  1214. console.log("## An error occurred while declining trade: " + ERR);
  1215. OFFER.decline((ERR) => {
  1216. if (ERR) {
  1217. console.log("## An error occurred while declining trade: " + ERR);
  1218. }
  1219. });
  1220. } else {
  1221. client.chatMessage(OFFER.partner, "Offer accepted!");
  1222. }
  1223. });
  1224. } else {
  1225. client.chatMessage(OFFER.partner, "Please make sure you don't have a trade hold!");
  1226. OFFER.decline((ERR) => {
  1227. if (ERR) {
  1228. console.log("## An error occurred while declining trade: " + ERR);
  1229. }
  1230. });
  1231. }
  1232. });
  1233. } else if (OFFER.itemsToGive.length == 0) {
  1234. OFFER.accept((ERR) => {
  1235. console.log("DONATION ACCEPT");
  1236. if (ERR) {
  1237. console.log("## An error occurred while declining trade: " + ERR);
  1238. }
  1239. });
  1240. } else {
  1241. OFFER.decline((ERR) => {
  1242. if (ERR) {
  1243. console.log("## An error occurred while declining trade: " + ERR);
  1244. }
  1245. });
  1246. }
  1247. });
  1248.  
  1249. community.on("newConfirmation", (CONF) => {
  1250. console.log("## New confirmation.");
  1251. community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id, (ERR) => {
  1252. if (ERR) {
  1253. console.log("## An error occurred while accepting confirmation: " + ERR);
  1254. } else {
  1255. console.log("## Confirmation accepted.");
  1256. }
  1257. });
  1258. });
  1259.  
  1260. function sortSetsByAmount(SETS, callback) {
  1261. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length).reverse());
  1262. }
  1263.  
  1264. function sortSetsByAmountB(SETS, callback) {
  1265. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length));
  1266. }
  1267.  
  1268. function parseString(INPUT, SETS) {
  1269. return INPUT.replace(":sets:", SETS);
  1270. }
Add Comment
Please, Sign In to add comment