Guest User

Untitled

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