Advertisement
Guest User

Untitled

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