Advertisement
Guest User

Untitled

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