Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.38 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) {
  270. let n = parseInt(MSG.toUpperCase().replace("!SELLCHECK ", ""));
  271. client.chatMessage(SENDER, "Loading inventory...");
  272. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  273. console.log("DEBUG#INVLOADED");
  274. if (!ERR) {
  275. let s = DATA;
  276. Utils.getSets(s, allCards, (ERR, DATA) => {
  277. console.log("DEBUG#SETSLOADED");
  278. if (!ERR) {
  279.  
  280. // console.log(b);
  281. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  282. // 1: GET BOTS CARDS. DONE
  283. // 2: GET PLAYER's BADGES. DONE
  284. // 3: MAGIC
  285. let hisMaxSets = 0,
  286. botNSets = 0;
  287. // Loop for sets he has partially completed
  288. // Loop for sets he has never crafted
  289. for (let i = 0; i < Object.keys(DATA).length; i++) {
  290. if (DATA[Object.keys(DATA)[i]].length >= 5) {
  291. hisMaxSets += 5;
  292. } else {
  293. hisMaxSets += DATA[Object.keys(DATA)[i]].length;
  294. }
  295. botNSets += DATA[Object.keys(DATA)[i]].length;
  296. }
  297. totalBotSets = botNSets;
  298. let playThis = CONFIG.PLAYGAMES;
  299. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  300. playThis[0] = parseString(playThis[0], totalBotSets);
  301. }
  302. client.gamesPlayed(playThis);
  303. 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.");
  304. } else {
  305. console.log("## An error occurred while getting user sets: " + ERR);
  306. }
  307. });
  308. } else {
  309. console.log("## An error occurred while getting user inventory: " + ERR);
  310. }
  311. });
  312. } else if (MSG.toUpperCase().indexOf("!CHECK") >= 0) {
  313. let n = parseInt(MSG.toUpperCase().replace("!CHECK ", ""));
  314. if (!isNaN(n) && parseInt(n) > 0) {
  315. client.chatMessage(SENDER, "With " + n + " keys you can get " + n * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS + " sets.");
  316. } else {
  317. if (Object.keys(botSets).length > 0) {
  318. client.chatMessage(SENDER, "Loading badges...");
  319. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  320. if (!ERR) {
  321. let b = {}; // List with badges that CAN still be crafted
  322. if (DATA) {
  323. for (let i = 0; i < Object.keys(DATA).length; i++) {
  324. if (DATA[Object.keys(DATA)[i]] < 6) {
  325. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  326. }
  327. }
  328. } else {
  329. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  330. }
  331. // console.log(b);
  332. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  333. // 1: GET BOTS CARDS. DONE
  334. // 2: GET PLAYER's BADGES. DONE
  335. // 3: MAGIC
  336. let hisMaxSets = 0,
  337. botNSets = 0;
  338. // Loop for sets he has partially completed
  339. for (let i = 0; i < Object.keys(b).length; i++) {
  340. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  341. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  342. }
  343. }
  344. // Loop for sets he has never crafted
  345. for (let i = 0; i < Object.keys(botSets).length; i++) {
  346. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  347. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  348. hisMaxSets += 5;
  349. } else {
  350. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  351. }
  352. }
  353. botNSets += botSets[Object.keys(botSets)[i]].length;
  354. }
  355. totalBotSets = botNSets;
  356. let playThis = CONFIG.PLAYGAMES;
  357. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  358. playThis[0] = parseString(playThis[0], totalBotSets);
  359. }
  360. client.gamesPlayed(playThis);
  361. 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.");
  362. } else {
  363. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  364. console.log("An error occurred while getting badges: " + ERR);
  365. }
  366. });
  367. } else {
  368. client.chatMessage(SENDER, "Please try again later.");
  369. }
  370. }
  371. } else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
  372. if (botSets) {
  373. //if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64().toString()) >= 0 || CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
  374. let n = parseInt(MSG.toUpperCase().replace("!SELL ", "")),
  375. amountofsets = n * CONFIG.CARDS.GIVE1KEYPERAMOUNTOFSETS;
  376. if (!isNaN(n) && parseInt(n) > 0) {
  377. if (n <= CONFIG.MESSAGES.MAXSELL) {
  378. client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  379. let botKeys = [],
  380. t = manager.createOffer(SENDER.getSteamID64());
  381. t.getUserDetails((ERR, ME, THEM) => {
  382. if (ERR) {
  383. console.log("## An error occurred while getting trade holds: " + ERR);
  384. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please check is your inventory public.");
  385. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  386. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  387. if (ERR) {
  388. console.log("## An error occurred while getting bot inventory: " + ERR);
  389. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  390. } else {
  391. for (let i = 0; i < INV.length; i++) {
  392. if (botKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  393. botKeys.push(INV[i]);
  394. }
  395. }
  396. if (botKeys.length != n) {
  397. client.chatMessage(SENDER, "The bot does not have enough keys.");
  398. } else {
  399. let amountofB = amountofsets;
  400. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  401. if (!ERR) {
  402. let s = DATA;
  403. Utils.getSets(s, allCards, (ERR, DDATA) => {
  404. if (!ERR) {
  405. sortSetsByAmountB(s, (DATA) => {
  406. let setsSent = {};
  407. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  408. console.log(setsSent);
  409. console.log(DATA[i]);
  410. if (DDATA[DATA[i]]) {
  411. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  412. if (amountofB > 0) {
  413. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.MAXSETSELL) || !setsSent[DATA[i]]) {
  414. t.addTheirItems(DDATA[DATA[i]][j]);
  415. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  416. amountofB--;
  417. if (!setsSent[DATA[i]]) {
  418. setsSent[DATA[i]] = 1;
  419. } else {
  420. setsSent[DATA[i]] += 1;
  421. }
  422. } else {
  423. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  424. continue firsttLoop;
  425. }
  426. } else {
  427. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  428. continue firsttLoop;
  429. }
  430. }
  431. } else {
  432. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  433. continue firsttLoop;
  434. }
  435. }
  436. });
  437. if (amountofB > 0) {
  438. 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.");
  439. } else {
  440. console.log("DEBUG#SENDING");
  441. t.addMyItems(botKeys);
  442. t.data("commandused", "Sell");
  443. t.data("amountofsets", amountofsets.toString());
  444. t.data("amountofkeys", n);
  445. t.send((ERR, STATUS) => {
  446. if (ERR) {
  447. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  448. console.log("## An error occurred while sending trade: " + ERR);
  449. } else {
  450. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  451. console.log("## Trade offer sent!");
  452. }
  453. });
  454. }
  455. } else {
  456. console.log("## An error occurred while getting bot sets: " + ERR);
  457. }
  458. });
  459. } else {
  460. console.log("## An error occurred while getting user inventory: " + ERR);
  461. }
  462. });
  463. }
  464. }
  465. });
  466. } else {
  467. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  468. }
  469. });
  470. } else {
  471. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  472. }
  473. } else {
  474. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  475. }
  476. //else {
  477. //client.chatMessage(SENDER, "You are not able to sell sets.");
  478. //}
  479. } else {
  480. client.chatMessage(SENDER, "Please try again later.");
  481. }
  482. } else if (MSG.toUpperCase().indexOf("!BUYONE") >= 0) {
  483. if (botSets) {
  484. let n = MSG.toUpperCase().replace("!BUYONE ", ""),
  485. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  486. if (!isNaN(n) && parseInt(n) > 0) {
  487. if (n <= CONFIG.MESSAGES.MAXBUY) {
  488. let t = manager.createOffer(SENDER.getSteamID64());
  489. t.getUserDetails((ERR, ME, THEM) => {
  490. if (ERR) {
  491. console.log("## An error occurred while getting trade holds: " + ERR);
  492. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  493. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  494. n = parseInt(n);
  495. let theirKeys = [];
  496. client.chatMessage(SENDER, "Processing your request.");
  497. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  498. if (ERR) {
  499. console.log("## An error occurred while getting inventory: " + ERR);
  500. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  501. } else {
  502. console.log("DEBUG#INV LOADED");
  503. if (!ERR) {
  504. console.log("DEBUG#INV LOADED NOERR");
  505. for (let i = 0; i < INV.length; i++) {
  506. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  507. theirKeys.push(INV[i]);
  508. }
  509. }
  510. if (theirKeys.length != n) {
  511. client.chatMessage(SENDER, "You do not have enough keys.");
  512. } else {
  513. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  514. if (!ERR) {
  515. console.log("DEBUG#BADGE LOADED");
  516. if (!ERR) {
  517. let b = {}; // List with badges that CAN still be crafted
  518. if (DATA) {
  519. for (let i = 0; i < Object.keys(DATA).length; i++) {
  520. if (DATA[Object.keys(DATA)[i]] < 6) {
  521. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  522. }
  523. }
  524. } else {
  525. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  526. }
  527. console.log(DATA);
  528. console.log(b);
  529. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  530. // 1: GET BOTS CARDS. DONE
  531. // 2: GET PLAYER's BADGES. DONE
  532. // 3: MAGIC
  533. let hisMaxSets = 0,
  534. botNSets = 0;
  535. // Loop for sets he has partially completed
  536. for (let i = 0; i < Object.keys(b).length; i++) {
  537. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  538. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  539. }
  540. }
  541. console.log("DEBUG#LOOP 1 DONE");
  542. // Loop for sets he has never crafted
  543. for (let i = 0; i < Object.keys(botSets).length; i++) {
  544. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  545. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  546. hisMaxSets += 5;
  547. } else {
  548. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  549. }
  550. }
  551. botNSets += botSets[Object.keys(botSets)[i]].length;
  552. }
  553. totalBotSets = botNSets;
  554. let playThis = CONFIG.PLAYGAMES;
  555. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  556. playThis[0] = parseString(playThis[0], totalBotSets);
  557. }
  558. client.gamesPlayed(playThis);
  559. console.log("DEBUG#LOOP 2 DONE");
  560. // HERE
  561. if (amountofsets <= hisMaxSets) {
  562. hisMaxSets = amountofsets;
  563. console.log("DEBUG#TRADE CREATED");
  564. sortSetsByAmount(botSets, (DATA) => {
  565. console.log("DEBUG#" + DATA);
  566. console.log("DEBUG#SETS SORTED");
  567. firstLoop: for (let i = 0; i < DATA.length; i++) {
  568. if (b[DATA[i]] == 0) {
  569. continue firstLoop;
  570. } else {
  571. console.log("DEBUG#" + i);
  572. console.log("DEBUG#FOR LOOP ITEMS");
  573. if (hisMaxSets > 0) {
  574. console.log("DEBUG#MAXSETSMORETHAN1");
  575. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  576. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  577. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  578. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  579. t.addMyItems(botSets[DATA[i]][j]);
  580. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  581. hisMaxSets--;
  582. continue firstLoop;
  583. } else {
  584. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  585. continue firstLoop;
  586. }
  587. }
  588. }
  589. } else {
  590. console.log("DEBUG#RETURN");
  591. break firstLoop;
  592. }
  593. }
  594. }
  595. if (hisMaxSets > 0) {
  596. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  597. } else {
  598. console.log("DEBUG#SENDING");
  599. t.addTheirItems(theirKeys);
  600. t.data("commandused", "BuyOne");
  601. t.data("amountofkeys", n);
  602. t.data("amountofsets", amountofsets.toString());
  603. t.data("index", setsThatShouldntBeSent.length);
  604. setsThatShouldntBeSent.push(t.itemsToGive);
  605. t.send((ERR, STATUS) => {
  606. if (ERR) {
  607. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  608. console.log("## An error occurred while sending trade: " + ERR);
  609. } else {
  610. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  611. console.log("## Trade offer sent");
  612. }
  613. });
  614. }
  615. });
  616. } else {
  617. 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.");
  618. }
  619. // TO HERE
  620. } else {
  621. console.log("An error occurred while getting badges: " + ERR);
  622. }
  623. } else {
  624. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  625. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  626. }
  627. });
  628. }
  629. } else {
  630. console.log("## An error occurred while getting inventory: " + ERR);
  631. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  632. }
  633. }
  634. });
  635. } else {
  636. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  637. }
  638. });
  639. } else {
  640. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  641. }
  642. } else {
  643. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  644. }
  645. } else {
  646. client.chatMessage(SENDER, "Please try again later.");
  647. }
  648. } else if (MSG.toUpperCase().indexOf("!BUYANY") >= 0) {
  649. if (botSets) {
  650. let n = MSG.toUpperCase().replace("!BUYANY ", ""),
  651. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  652. if (!isNaN(n) && parseInt(n) > 0) {
  653. if (n <= CONFIG.MESSAGES.MAXBUY) {
  654. let t = manager.createOffer(SENDER.getSteamID64());
  655. n = parseInt(n);
  656. let theirKeys = [];
  657. t.getUserDetails((ERR, ME, THEM) => {
  658. if (ERR) {
  659. console.log("## An error occurred while getting trade holds: " + ERR);
  660. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  661. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  662. client.chatMessage(SENDER, "Processing your request.");
  663. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  664. if (ERR) {
  665. console.log("## An error occurred while getting inventory: " + ERR);
  666. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  667. } else {
  668. let amountofB = amountofsets;
  669. for (let i = 0; i < INV.length; i++) {
  670. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  671. theirKeys.push(INV[i]);
  672. }
  673. }
  674. if (theirKeys.length != n) {
  675. client.chatMessage(SENDER, "You do not have enough keys.");
  676. } else {
  677. sortSetsByAmount(botSets, (DATA) => {
  678. let setsSent = {};
  679. firstLoop: for (let i = 0; i < DATA.length; i++) {
  680. console.log(setsSent);
  681. console.log(DATA[i]);
  682. if (botSets[DATA[i]]) {
  683. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  684. if (amountofB > 0) {
  685. if ((setsSent[DATA[i]] && setsSent[DATA[i]] > -1) || !setsSent[DATA[i]]) {
  686. t.addMyItems(botSets[DATA[i]][j]);
  687. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  688. amountofB--;
  689. if (!setsSent[DATA[i]]) {
  690. setsSent[DATA[i]] = 1;
  691. } else {
  692. setsSent[DATA[i]] += 1;
  693. }
  694. } else {
  695. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  696. continue firstLoop;
  697. }
  698. } else {
  699. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  700. continue firstLoop;
  701. }
  702. }
  703. } else {
  704. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  705. continue firstLoop;
  706. }
  707. }
  708. });
  709. }
  710. if (amountofB > 0) {
  711. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  712. } else {
  713. console.log("DEBUG#SENDING");
  714. t.addTheirItems(theirKeys);
  715. t.data("commandused", "BuyAny");
  716. t.data("amountofsets", amountofsets.toString());
  717. t.data("amountofkeys", n);
  718. t.data("index", setsThatShouldntBeSent.length);
  719. setsThatShouldntBeSent.push(t.itemsToGive);
  720. t.send((ERR, STATUS) => {
  721. if (ERR) {
  722. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  723. console.log("## An error occurred while sending trade: " + ERR);
  724. } else {
  725. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  726. console.log("## Trade offer sent!");
  727. }
  728. });
  729. }
  730. }
  731. });
  732. } else {
  733. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  734. }
  735. });
  736. } else {
  737. client.chatMessage(SENDER, "Please try a lower amount of keys");
  738. }
  739. } else {
  740. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  741. }
  742. } else {
  743. client.chatMessage(SENDER, "Please try again later.");
  744. }
  745. } else if (MSG.toUpperCase().indexOf("!BUY") >= 0) {
  746. if (botSets) {
  747. let n = MSG.toUpperCase().replace("!BUY ", ""),
  748. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  749. if (!isNaN(n) && parseInt(n) > 0) {
  750. if (n <= CONFIG.MESSAGES.MAXBUY) {
  751. let t = manager.createOffer(SENDER.getSteamID64());
  752. t.getUserDetails((ERR, ME, THEM) => {
  753. if (ERR) {
  754. console.log("## An error occurred while getting trade holds: " + ERR);
  755. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  756. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  757. n = parseInt(n);
  758. let theirKeys = [];
  759. client.chatMessage(SENDER, "Processing your request.");
  760. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  761. if (ERR) {
  762. console.log("## An error occurred while getting inventory: " + ERR);
  763. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  764. } else {
  765. console.log("DEBUG#INV LOADED");
  766. if (!ERR) {
  767. console.log("DEBUG#INV LOADED NOERR");
  768. for (let i = 0; i < INV.length; i++) {
  769. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  770. theirKeys.push(INV[i]);
  771. }
  772. }
  773. if (theirKeys.length != n) {
  774. client.chatMessage(SENDER, "You do not have enough keys.");
  775. } else {
  776. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  777. if (!ERR) {
  778. console.log("DEBUG#BADGE LOADED");
  779. if (!ERR) {
  780. let b = {}; // List with badges that CAN still be crafted
  781. if (DATA) {
  782. for (let i = 0; i < Object.keys(DATA).length; i++) {
  783. if (DATA[Object.keys(DATA)[i]] < 6) {
  784. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  785. }
  786. }
  787. } else {
  788. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  789. }
  790. console.log(DATA);
  791. console.log(b);
  792. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  793. // 1: GET BOTS CARDS. DONE
  794. // 2: GET PLAYER's BADGES. DONE
  795. // 3: MAGIC
  796. let hisMaxSets = 0,
  797. botNSets = 0;
  798. // Loop for sets he has partially completed
  799. for (let i = 0; i < Object.keys(b).length; i++) {
  800. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  801. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  802. }
  803. }
  804. console.log("DEBUG#LOOP 1 DONE");
  805. // Loop for sets he has never crafted
  806. for (let i = 0; i < Object.keys(botSets).length; i++) {
  807. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  808. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  809. hisMaxSets += 5;
  810. } else {
  811. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  812. }
  813. }
  814. botNSets += botSets[Object.keys(botSets)[i]].length;
  815. }
  816. console.log("DEBUG#LOOP 2 DONE");
  817. // HERE
  818. if (amountofsets <= hisMaxSets) {
  819. hisMaxSets = amountofsets;
  820. console.log("DEBUG#TRADE CREATED");
  821. sortSetsByAmount(botSets, (DATA) => {
  822. console.log("DEBUG#" + DATA);
  823. console.log("DEBUG#SETS SORTED");
  824. firstLoop: for (let i = 0; i < DATA.length; i++) {
  825. if (b[DATA[i]] == 0) {
  826. continue firstLoop;
  827. } else {
  828. console.log("DEBUG#" + i);
  829. console.log("DEBUG#FOR LOOP ITEMS");
  830. if (hisMaxSets > 0) {
  831. console.log("DEBUG#MAXSETSMORETHAN1");
  832. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  833. // BOT HAS ENOUGH SETS OF THIS KIND
  834. console.log("DEBUG#LOOP #1");
  835. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  836. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  837. console.log("DEBUG#LOOP #1: ITEM ADD");
  838. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  839. t.addMyItems(botSets[DATA[i]][j]);
  840. hisMaxSets--;
  841. console.log(hisMaxSets);
  842. } else {
  843. console.log("DEBUG#LOOP #1: RETURN");
  844. continue firstLoop;
  845. }
  846. }
  847. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  848. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  849. console.log("DEBUG#LOOP #1 CONTINUE");
  850. continue; // *
  851. } 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
  852. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  853. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  854. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  855. t.addMyItems(botSets[DATA[i]][j]);
  856. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  857. hisMaxSets--;
  858. } else {
  859. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  860. continue firstLoop;
  861. }
  862. }
  863. }
  864. else if (hisMaxSets < 5) {
  865. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  866. console.log("DEBUG#LOOP #2");
  867. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  868. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  869. t.addMyItems(botSets[DATA[i]][j]);
  870. console.log("DEBUG#LOOP #2: ITEM ADD");
  871. hisMaxSets--;
  872. console.log(hisMaxSets);
  873. } else {
  874. console.log("DEBUG#LOOP #2: RETURN");
  875. continue firstLoop;
  876. }
  877. }
  878. } else {
  879. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  880. console.log("DEBUG#LOOP #2");
  881. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  882. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  883. t.addMyItems(botSets[DATA[i]][j]);
  884. console.log("DEBUG#LOOP #2: ITEM ADD");
  885. hisMaxSets--;
  886. console.log(hisMaxSets);
  887. } else {
  888. console.log("DEBUG#LOOP #2: RETURN");
  889. continue firstLoop;
  890. }
  891. }
  892. }
  893. } else {
  894. console.log("DEBUG#RETURN");
  895. break firstLoop;
  896. }
  897. }
  898. }
  899. if (hisMaxSets > 0) {
  900. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  901. } else {
  902. console.log("DEBUG#SENDING");
  903. t.addTheirItems(theirKeys);
  904. t.data("commandused", "Buy");
  905. t.data("amountofkeys", n);
  906. t.data("amountofsets", amountofsets.toString());
  907. t.data("index", setsThatShouldntBeSent.length);
  908. setsThatShouldntBeSent.push(t.itemsToGive);
  909. t.send((ERR, STATUS) => {
  910. if (ERR) {
  911. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  912. console.log("## An error occurred while sending trade: " + ERR);
  913. } else {
  914. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  915. console.log("## Trade offer sent");
  916. }
  917. });
  918. }
  919. });
  920. } else {
  921. 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.");
  922. }
  923. // TO HERE
  924. } else {
  925. console.log("An error occurred while getting badges: " + ERR);
  926. }
  927. } else {
  928. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  929. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  930. }
  931. });
  932. }
  933. } else {
  934. console.log("## An error occurred while getting inventory: " + ERR);
  935. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  936. }
  937. }
  938. });
  939. } else {
  940. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  941. }
  942. });
  943. } else {
  944. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  945. }
  946. } else {
  947. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  948. }
  949. } else {
  950. client.chatMessage(SENDER, "Please try again later.");
  951. }
  952. } else if (MSG.toUpperCase() == "!PROOF") {
  953. client.chatMessage(SENDER, "This bot was made by www.steamcommunity.com/id/timandyouknow");
  954. } else if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
  955. // Admin commands.
  956. if (MSG.toUpperCase().indexOf("!BLOCK") >= 0) {
  957. let n = MSG.toUpperCase().replace("!BLOCK ", "").toString();
  958. if (SID64REGEX.test(n)) {
  959. client.chatMessage(SENDER, "User blocked.");
  960. client.blockUser(n);
  961. } else {
  962. client.chatMessage(SENDER, "Please provide a valid SteamID64");
  963. }
  964. } else if (MSG.toUpperCase().indexOf("!USERCHECK") >= 0) {
  965. let n = MSG.toUpperCase().replace("!USERCHECK ", "").toString();
  966. if (SID64REGEX.test(n)) {
  967. if (Object.keys(botSets).length > 0) {
  968. client.chatMessage(SENDER, "Loading badges...");
  969. Utils.getBadges(n, (ERR, DATA) => {
  970. if (!ERR) {
  971. let b = {}; // List with badges that CAN still be crafted
  972. if (DATA) {
  973. for (let i = 0; i < Object.keys(DATA).length; i++) {
  974. if (DATA[Object.keys(DATA)[i]] < 6) {
  975. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  976. }
  977. }
  978. } else {
  979. client.chatMessage(SENDER.getSteamID64(), n + "'s badges are empty, sending an offer without checking badges.");
  980. }
  981. // console.log(b);
  982. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  983. // 1: GET BOTS CARDS. DONE
  984. // 2: GET PLAYER's BADGES. DONE
  985. // 3: MAGIC
  986. let hisMaxSets = 0,
  987. botNSets = 0;
  988. // Loop for sets he has partially completed
  989. for (let i = 0; i < Object.keys(b).length; i++) {
  990. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  991. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  992. }
  993. }
  994. // Loop for sets he has never crafted
  995. for (let i = 0; i < Object.keys(botSets).length; i++) {
  996. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  997. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  998. hisMaxSets += 5;
  999. } else {
  1000. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1001. }
  1002. }
  1003. botNSets += botSets[Object.keys(botSets)[i]].length;
  1004. }
  1005. 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.");
  1006. } else {
  1007. client.chatMessage(SENDER, "An error occurred while getting " + n + "'s badges. Please try again.");
  1008. console.log("An error occurred while getting badges: " + ERR);
  1009. }
  1010. });
  1011. } else {
  1012. client.chatMessage(SENDER, "Please try again later.");
  1013. }
  1014. } else {
  1015. client.chatMessage(SENDER, "Please provide a valid SteamID64.");
  1016. }
  1017. } else if (MSG.toUpperCase() == "!KEYS") {
  1018. manager.getInventoryContents(CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
  1019. if (ERR) {
  1020. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory.");
  1021. console.log("## An error occurred while getting inventory: " + ERR);
  1022. } else {
  1023. let t = manager.createOffer(SENDER);
  1024. for (let i = 0; i < INV.length; i++) {
  1025. if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1026. t.addMyItem(INV[i]);
  1027. }
  1028. t.send();
  1029. }
  1030. }
  1031. });
  1032. } else {
  1033. client.chatMessage(SENDER, "Command not recognized.");;
  1034. }
  1035. } else {
  1036. client.chatMessage(SENDER, "Command not recognized. Use !help to see how this bot works.");
  1037. }
  1038. });
  1039.  
  1040. client.on("friendRelationship", (SENDER, REL) => {
  1041. if (REL === 2) {
  1042. client.addFriend(SENDER);
  1043. } else if (REL === 3) {
  1044. if (CONFIG.INVITETOGROUPID) {
  1045. client.inviteToGroup(SENDER, CONFIG.INVITETOGROUPID);
  1046. }
  1047. client.chatMessage(SENDER, CONFIG.MESSAGES.WELCOME);
  1048. }
  1049. });
  1050.  
  1051. // manager.on("unknownOfferSent", (o, os) => {
  1052. // if (o.state == 9) {
  1053. // console.log("## OFFER SENT LIST");
  1054. // community.checkConfirmations();
  1055. // }
  1056. // });
  1057.  
  1058. // community.on("newConfirmation", (CONF) => {
  1059. // console.log("## New confirmation.");
  1060. // community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id);
  1061. // });
  1062.  
  1063. manager.on("sentOfferChanged", (OFFER, OLDSTATE) => {
  1064. if (OFFER.state == 2) {
  1065. client.chatMessage(OFFER.partner, "Trade confirmed! Click here to accept it: https://www.steamcommunity.com/tradeoffer/" + OFFER.id);
  1066. } else if (OFFER.state == 3) {
  1067. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  1068. if (!ERR) {
  1069. let s = DATA;
  1070. Utils.getSets(s, allCards, (ERR, DATA) => {
  1071. if (!ERR) {
  1072. botSets = DATA;
  1073. console.log("## Bot's sets loaded.");
  1074. } else {
  1075. console.log("## An error occurred while getting bot sets: " + ERR);
  1076. }
  1077. let botNSets = 0;
  1078. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1079. botNSets += botSets[Object.keys(botSets)[i]].length;
  1080. }
  1081. totalBotSets = botNSets;
  1082. let playThis = CONFIG.PLAYGAMES;
  1083. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  1084. playThis[0] = parseString(playThis[0], totalBotSets);
  1085. }
  1086. client.gamesPlayed(playThis);
  1087. });
  1088. } else {
  1089. console.log("## An error occurred while getting bot inventory: " + ERR);
  1090. }
  1091. });
  1092. if (CONFIG.INVITETOGROUPID) {
  1093. client.inviteToGroup(OFFER.partner, CONFIG.INVITETOGROUPID);
  1094. }
  1095. let d = "" + OFFER.data("commandused") + "";
  1096. d += "\nSets: " + OFFER.data("amountofsets");
  1097. d += "\nKeys: " + OFFER.data("amountofkeys");
  1098. d += "\nSteamID: " + OFFER.partner.getSteamID64();
  1099. fs.writeFile("./TradesAccepted/" + OFFER.id + "-" + OFFER.partner.getSteamID64() + ".txt", d, (ERR) => {
  1100. if (ERR) {
  1101. console.log("## An error occurred while writing trade file: " + ERR);
  1102. }
  1103. });
  1104. community.getSteamUser(OFFER.partner, (ERR, USER) => {
  1105. if (ERR) {
  1106. console.log("## An error occurred while getting user profile: " + ERR);
  1107. client.chatMessage(OFFER.partner, "An error occurred while getting your profile (to comment).");
  1108. } else {
  1109. USER.comment(CONFIG.COMMENTAFTERTRADE, (ERR) => {
  1110. if (ERR) {
  1111. console.log("## An error occurred while commenting on user profile: " + ERR);
  1112. client.chatMessage(OFFER.partner, "An error occurred while getting commenting on your profile.");
  1113. } else {
  1114. client.chatMessage(OFFER.partner, "Thanks for trading! :D");
  1115. }
  1116. });
  1117. }
  1118. });
  1119. } else if (OFFER.state == 6) {
  1120. client.chatMessage(OFFER.partner, "Hey, you did not accept the offer. Please try again if you wish to receive sets!");
  1121. }
  1122. /* else if (OFFER.state == 9) {
  1123. community.checkConfirmations();
  1124. }*/
  1125. });
  1126.  
  1127. manager.on("newOffer", (OFFER) => {
  1128. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(OFFER.partner.getSteamID64())) >= 0) {
  1129. OFFER.getUserDetails((ERR, ME, THEM) => {
  1130. if (ERR) {
  1131. console.log("## An error occurred while getting trade holds: " + ERR);
  1132. client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again");
  1133. OFFER.decline((ERR) => {
  1134. if (ERR) {
  1135. console.log("## An error occurred while declining trade: " + ERR);
  1136. }
  1137. });
  1138. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1139. OFFER.accept((ERR) => {
  1140. if (ERR) {
  1141. console.log("## An error occurred while declining trade: " + ERR);
  1142. OFFER.decline((ERR) => {
  1143. if (ERR) {
  1144. console.log("## An error occurred while declining trade: " + ERR);
  1145. }
  1146. });
  1147. } else {
  1148. client.chatMessage(OFFER.partner, "Offer accepted!");
  1149. }
  1150. });
  1151. } else {
  1152. client.chatMessage(OFFER.partner, "Please make sure you don't have a trade hold!");
  1153. OFFER.decline((ERR) => {
  1154. if (ERR) {
  1155. console.log("## An error occurred while declining trade: " + ERR);
  1156. }
  1157. });
  1158. }
  1159. });
  1160. } else if (OFFER.itemsToGive.length == 0) {
  1161. OFFER.accept((ERR) => {
  1162. console.log("DONATION ACCEPT");
  1163. if (ERR) {
  1164. console.log("## An error occurred while declining trade: " + ERR);
  1165. }
  1166. });
  1167. } else {
  1168. OFFER.decline((ERR) => {
  1169. if (ERR) {
  1170. console.log("## An error occurred while declining trade: " + ERR);
  1171. }
  1172. });
  1173. }
  1174. });
  1175.  
  1176. community.on("newConfirmation", (CONF) => {
  1177. console.log("## New confirmation.");
  1178. community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id, (ERR) => {
  1179. if (ERR) {
  1180. console.log("## An error occurred while accepting confirmation: " + ERR);
  1181. } else {
  1182. console.log("## Confirmation accepted.");
  1183. }
  1184. });
  1185. });
  1186.  
  1187. function sortSetsByAmount(SETS, callback) {
  1188. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length).reverse());
  1189. }
  1190.  
  1191. function sortSetsByAmountB(SETS, callback) {
  1192. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length));
  1193. }
  1194.  
  1195. function parseString(INPUT, SETS) {
  1196. return INPUT.replace(":sets:", SETS);
  1197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement