Advertisement
Guest User

Untitled

a guest
Feb 9th, 2018
3,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 156.84 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. blockedBuyUsers = {};
  17.  
  18.  
  19. let client = new SteamUser(),
  20. manager = new TradeOfferManager({
  21. "steam": client,
  22. "language": "en",
  23. "pollInterval": "10000",
  24. "cancelTime": "3600000" // 2 hours in ms
  25. }),
  26. community = new SteamCommunity();
  27.  
  28. fs.readFile("./UserData/blockedBuyUsers.json", (ERR, DATA) => {
  29. if (ERR) {
  30. console.log("[ DEBUG ] An error occurred while getting blockedBuyUsers from blockedBuyUsers.json : " + ERR);
  31. } else {
  32. blockedBuyUsers = JSON.parse(DATA);
  33. }
  34. });
  35.  
  36. fs.readFile("./UserData/Users.json", (ERR, DATA) => {
  37. if (ERR) {
  38. console.log("[ DEBUG ] An error occurred while getting UserData from Users.json : " + ERR);
  39. } else {
  40. users = JSON.parse(DATA);
  41. }
  42. });
  43.  
  44. Utils.getCardsInSets((ERR, DATA) => {
  45. if (!ERR) {
  46. allCards = DATA;
  47. console.log("[ DEBUG ] Card data loaded. [" + Object.keys(DATA).length + "]");
  48. } else {
  49. console.log("[ DEBUG ] An error occurred while getting cards: " + ERR);
  50. }
  51. });
  52.  
  53. setInterval(() => {
  54. for (let i = 0; i < Object.keys(users).length; i++) {
  55. if (users[Object.keys(users)[i]].idleforhours >= CONFIG.MAXHOURSADDED) {
  56. 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.");
  57. client.removeFriend(Object.keys(users)[i]);
  58. delete users[Object.keys(users)[i]];
  59. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  60. if (ERR) {
  61. console.log("[ DEBUG ] An error occurred while writing UserData file: " + ERR);
  62. }
  63. });
  64. } else {
  65. users[Object.keys(users)[i]].idleforhours += 1;
  66. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  67. if (ERR) {
  68. console.log("[ DEBUG ] An error occurred while writing UserData file: " + ERR);
  69. }
  70. });
  71. }
  72. }
  73. }, 1000 * 60 * 60);
  74.  
  75. setInterval(() => {
  76. for (let i = 0; i < Object.keys(userMsgs).length; i++) {
  77. if (userMsgs[Object.keys(userMsgs)[i]] > CONFIG.MAXMSGPERSEC) {
  78. client.chatMessage(Object.keys(userMsgs)[i], "You have been removed for spamming. Another offense will get you blocked.");
  79. client.removeFriend(Object.keys(userMsgs)[i]);
  80. for (let j = 0; j < CONFIG.ADMINS.length; j++) {
  81. client.chatMessage(CONFIG.ADMINS[j], "User #" + Object.keys(userMsgs)[i] + " has been removed for spamming. To block him use !block [STEAMID64]");
  82. }
  83. }
  84. }
  85. userMsgs = {};
  86. }, 1000);
  87.  
  88. client.logOn({
  89. accountName: CONFIG.USERNAME,
  90. password: CONFIG.PASSWORD,
  91. twoFactorCode: SteamTotp.getAuthCode(CONFIG.SHAREDSECRET)
  92. });
  93.  
  94. client.on("loggedOn", (details, parental) => {
  95. client.getPersonas([client.steamID], (personas) => {
  96. console.log("[ ACCOUNT ] Name: " + client.steamID + " (" + personas[client.steamID].player_name + ")");
  97. });
  98. client.setPersona(1);
  99. });
  100.  
  101. client.on("webSession", (sessionID, cookies) => {
  102. manager.setCookies(cookies, (ERR) => {
  103. if (ERR) {
  104. console.log("[ ACCOUNT ] An error occurred while setting cookies.");
  105. } else {
  106. console.log("[ ACCOUNT ] Websession created and cookies set.");
  107. }
  108. });
  109. community.setCookies(cookies);
  110. community.startConfirmationChecker(10000, CONFIG.IDENTITYSECRET);
  111. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  112. console.log("[ DEBUG ] Inventory loaded");
  113. if (!ERR) {
  114. let s = DATA;
  115. Utils.getSets(s, allCards, (ERR, DATA) => {
  116. console.log("[ DEBUG ] Sets loaded");
  117. if (!ERR) {
  118. botSets = DATA;
  119. console.log("[ DEBUG ] Bot's sets loaded.");
  120. let botNSets = 0;
  121. for (let i = 0; i < Object.keys(botSets).length; i++) {
  122. botNSets += botSets[Object.keys(botSets)[i]].length;
  123. }
  124. totalBotSets = botNSets;
  125. let playThis = CONFIG.PLAYGAMES;
  126. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  127. playThis[0] = parseString(playThis[0], totalBotSets);
  128. }
  129. client.gamesPlayed(playThis);
  130. } else {
  131. console.log("[ DEBUG ] An error occurred while getting bot sets: " + ERR);
  132. process.exit();
  133. }
  134. });
  135. } else {
  136. console.log("[ DEBUG ] An error occurred while getting bot inventory: " + ERR);
  137. }
  138. });
  139. });
  140.  
  141. community.on("sessionExpired", (ERR) => {
  142. console.log("[ ACCOUNT ] Session Expired. Relogging.");
  143. client.webLogOn();
  144. });
  145.  
  146. // Console will show us how much new Items we have
  147. client.on('newItems', function (count) {
  148. console.log("[ ACCOUNT ] We have " + count + " new Items in our Inventory");
  149. });
  150.  
  151. // Console will show the registred email from the Bot account
  152. client.on('emailInfo', function (address, validated) {
  153. console.log("[ ACCOUNT ] E-Mail: " + address + "");
  154. });
  155.  
  156. // Console will show our current account limitations (ex. when we would be tradebanned, or could not access the market due to steam restrictions)
  157. client.on('accountLimitations', function (limited, communityBanned, locked, canInviteFriends) {
  158. if(limited) {
  159. console.log("[ ACCOUNT ] Account is limited. Cannot send friend invites, use the market, open group chat, or access the web API.");
  160. }
  161. if(communityBanned){
  162. console.log("[ ACCOUNT ] Account is banned from Steam Community");
  163. }
  164. if(locked){
  165. console.log("[ ACCOUNT ] Account is locked. We cannot trade/gift/purchase items, play on VAC servers, or access Steam Community. Shutting down.");
  166. process.exit(1);
  167. }
  168. if(!canInviteFriends){
  169. console.log("[ ACCOUNT ] Account is unable to send friend requests.");
  170. }
  171. });
  172.  
  173. // Console will show the current Wallet Balance of the Steam Account
  174. client.on('wallet', function (hasWallet, currency, balance) {
  175. if(hasWallet){
  176. console.log("[ ACCOUNT ] Wallet: "+ SteamUser.formatCurrency(balance, currency) +" Steam Credit remaining");
  177. }
  178. else{
  179. console.log("[ ACCOUNT ] We do not have a Steam wallet.");
  180. }
  181. });
  182.  
  183. client.on("friendMessage", (SENDER, MSG) => {
  184. if (userLogs[SENDER.getSteamID64()]) {
  185. userLogs[SENDER.getSteamID64()].push(MSG);
  186. } else {
  187. userLogs[SENDER.getSteamID64()] = [];
  188. userLogs[SENDER.getSteamID64()].push(MSG);
  189. }
  190. fs.writeFile("./ChatLogs/UserLogs/" + SENDER.getSteamID64() + "-log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".json", JSON.stringify({ logs: userLogs[SENDER.getSteamID64()] }), (ERR) => {
  191. if (ERR) {
  192. console.log("[ DEBUG ] An error occurred while writing UserLogs file: " + ERR);
  193. }
  194. });
  195. chatLogs += SENDER.getSteamID64() + " : " + MSG + "\n";
  196. fs.writeFile("./ChatLogs/FullLogs/log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".txt", chatLogs, (ERR) => {
  197. if (ERR) {
  198. console.log("[ DEBUG ] An error occurred while writing FullLogs file: " + ERR);
  199. }
  200. });
  201. if (Object.keys(users).indexOf(SENDER.getSteamID64()) < 0) {
  202. users[SENDER.getSteamID64()] = {};
  203. users[SENDER.getSteamID64()].idleforhours = 0;
  204. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  205. if (ERR) {
  206. console.log("[ DEBUG ] An error occurred while writing UserLogs file: " + ERR);
  207. }
  208. });
  209. } else {
  210. users[SENDER.getSteamID64()].idleforhours = 0;
  211. }
  212. if (userMsgs[SENDER.getSteamID64()]) {
  213. userMsgs[SENDER.getSteamID64()]++;
  214. } else {
  215. userMsgs[SENDER.getSteamID64()] = 1;
  216. }
  217. /*if (MSG.toUpperCase() == "!STOCK") {
  218. for (let i = 0; i < botSets.length; i++) {
  219. //
  220. }
  221. } else */
  222. if (MSG.toUpperCase().indexOf("!LEVEL") >= 0) {
  223. let n = parseInt(MSG.toUpperCase().replace("!LEVEL ", ""));
  224. if (!isNaN(n) && parseInt(n) > 0) {
  225. if (n <= CONFIG.MESSAGES.MAXLEVEL) {
  226. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA, CURRENTLEVEL, XPNEEDED) => {
  227. if (!ERR) {
  228. if (DATA) {
  229. if (n > CURRENTLEVEL) {
  230. let s = 0,
  231. l = 0;
  232. for (let i = 0; i < (n - CURRENTLEVEL); i++) {
  233. s += parseInt((CURRENTLEVEL + l) / 10) + 1;
  234. l++;
  235. }
  236. 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)) / 18 * 100) / 100 + " CSGO keys.");
  237. } else {
  238. client.chatMessage(SENDER, "Please provide a valid level.");
  239. }
  240. } else {
  241. client.chatMessage(SENDER, "Your level could not be retrieved. Make sure your Steam Profile is public and try again.");
  242. }
  243. } else {
  244. console.log("[ Debug ] An error occurred while getting badge data: " + ERR);
  245. client.chatMessage(SENDER, "An error occurred while loading your badges. Please try again later.");
  246. }
  247. });
  248. } else {
  249. client.chatMessage(SENDER, "Please try a lower level.");
  250. }
  251. } else {
  252. client.chatMessage(SENDER, "Please provide a valid level.");
  253. }
  254. }
  255. else if (MSG.toUpperCase() == "!HELP") {
  256. client.chatMessage(SENDER, "All available commands:\n - \n :yellowbeat: !CHECK = Checking how many uncrafted sets you can buy from the current Bot. \n :yellowbeat: !CHECK [X] = Checking how many Cardsets you can buy for [X] CS:GO Keys. \n :yellowbeat: !BUYANY [X] = Buy any Cardsets for [X] CS:GO Keys. \n :yellowbeat: !BUY [X] = Buy uncrafted Cardsets for [X] CS:GO Keys. \n :yellowbeat: !SELLCHECK = Checking for Sets the Bot can buy from you. You recieve CS:GO Keys for your Cardsets. \n :yellowbeat: !SELL [X] = Sell Cardsets and get [X] CS:GO Keys. \n :yellowbeat: !LEVEL [X] = Will check how many Cardsets you need to reach Level [X].");
  257. }
  258. else if (MSG.toUpperCase() == "!KEYLIST") {
  259. client.chatMessage(SENDER, '\n We accept the following Keys: \n \n CS:GO Case Key \n Chroma Case Key \n Chroma 2 Case Key \n Chroma 3 Case Key \n eSports Key \n Falchion Case Key \n Gamma Case Key \n Gamma 2 Case Key \n Glove Case Key \n Huntsman Case Key \n Hydra Case Key \n Operation Breakout Case Key \n Operation Phoenix Case Key \n Operation Vanguard Case Key \n Operation Wildfire Case Key \n Revolver Case Key \n Shadow Case Key \n Spectrum Case Key \n Spectrum 2 Case Key \n Winter Offensive Case Key');
  260. }
  261. else if (MSG.toUpperCase() == "!WEBSITE") {
  262. client.chatMessage(SENDER, CONFIG.WEBSITE);
  263. }
  264. else if (MSG.toUpperCase() == "!OWNER") {
  265. client.chatMessage(SENDER, CONFIG.OWNER);
  266. }
  267. else if (MSG.toUpperCase() == "!INVITE") {
  268. client.inviteToGroup(SENDER.getSteamID64(),CONFIG.INVITETOGROUPID);
  269. console.log("[ UserChat ] INVITED:", SENDER.getSteamID64(), "TO:", CONFIG.INVITETOGROUPID);
  270. }
  271. else if (MSG.toUpperCase() == "!LVL") {
  272. client.chatMessage(SENDER, "You mean !level?");
  273. }
  274. else if (MSG.toUpperCase() == "!SHUTDOWN") {
  275. client.chatMessage(SENDER, "Please don't. :(");
  276. }
  277. else if (MSG.toUpperCase().indexOf("!BUYONECHECK") >= 0) {
  278. client.chatMessage(SENDER, "Loading badges...");
  279. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  280. if (!ERR) {
  281. let b = {}; // List with badges that CAN still be crafted
  282. if (DATA) {
  283. for (let i = 0; i < Object.keys(DATA).length; i++) {
  284. if (DATA[Object.keys(DATA)[i]] < 6) {
  285. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  286. }
  287. }
  288. } else {
  289. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  290. }
  291. // console.log(b);
  292. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  293. // 1: GET BOTS CARDS. DONE
  294. // 2: GET PLAYER's BADGES. DONE
  295. // 3: MAGIC
  296. let hisMaxSets = 0,
  297. botNSets = 0;
  298. // Loop for sets he has partially completed
  299. for (let i = 0; i < Object.keys(b).length; i++) {
  300. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  301. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  302. }
  303. }
  304. // Loop for sets he has never crafted
  305. for (let i = 0; i < Object.keys(botSets).length; i++) {
  306. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  307. if (botSets[Object.keys(botSets)[i]].length >= 1) {
  308. hisMaxSets += 1;
  309. }
  310. }
  311. botNSets += botSets[Object.keys(botSets)[i]].length;
  312. }
  313. totalBotSets = botNSets;
  314. let playThis = CONFIG.PLAYGAMES;
  315. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  316. playThis[0] = parseString(playThis[0], totalBotSets);
  317. }
  318. client.gamesPlayed(playThis);
  319. 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.");
  320. } else {
  321. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  322. console.log("[ DEBUG ] An error occurred while getting badges: " + ERR);
  323. }
  324. });
  325. } else if (MSG.toUpperCase().indexOf("!SET") >= 0) {
  326. if (botSets) {
  327. if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64().toString()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
  328. let n = MSG.toUpperCase().replace("!SET ", ""),
  329. amountofsets = parseInt(n) * 1;
  330. if (!isNaN(n) && parseInt(n) > 0) {
  331. if (n <= 999999999) {
  332. let t = manager.createOffer(SENDER.getSteamID64());
  333. t.getUserDetails((ERR, ME, THEM) => {
  334. if (ERR) {
  335. console.log("## An error occurred while getting trade holds: " + ERR);
  336. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  337. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  338. n = parseInt(n);
  339. let theirKeys = [];
  340. client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  341. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOID, 2, true, (ERR, INV, CURR) => {
  342. if (ERR) {
  343. console.log("## An error occurred while getting inventory: " + ERR);
  344. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  345. } else {
  346. console.log("DEBUG#INV LOADED");
  347. if (!ERR) {
  348. console.log("DEBUG#INV LOADED NOERR");
  349. for (let i = 0; i < INV.length; i++) {
  350. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  351. theirKeys.push(INV[i]);
  352. }
  353. }
  354. if (CONFIG.CSGOID == 1) {
  355. client.chatMessage(SENDER, "Error: You don't have enough keys. Feel free to come back when you collect more keys.");
  356. } else {
  357. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  358. if (!ERR) {
  359. console.log("DEBUG#BADGE LOADED");
  360. if (!ERR) {
  361. let b = {}; // List with badges that CAN still be crafted
  362. if (DATA) {
  363. for (let i = 0; i < Object.keys(DATA).length; i++) {
  364. if (DATA[Object.keys(DATA)[i]] < 6) {
  365. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  366. }
  367. }
  368. } else {
  369. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  370. }
  371. console.log(DATA);
  372. console.log(b);
  373. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  374. // 1: GET BOTS CARDS. DONE
  375. // 2: GET PLAYER's BADGES. DONE
  376. // 3: MAGIC
  377. let hisMaxSets = 0,
  378. botNSets = 0;
  379. // Loop for sets he has partially completed
  380. for (let i = 0; i < Object.keys(b).length; i++) {
  381. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  382. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  383. }
  384. }
  385. console.log("DEBUG#LOOP 1 DONE");
  386. // Loop for sets he has never crafted
  387. for (let i = 0; i < Object.keys(botSets).length; i++) {
  388. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  389. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  390. hisMaxSets += 5;
  391. } else {
  392. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  393. }
  394. }
  395. botNSets += botSets[Object.keys(botSets)[i]].length;
  396. }
  397. console.log("DEBUG#LOOP 2 DONE");
  398. // HERE
  399. if (amountofsets <= hisMaxSets) {
  400. hisMaxSets = amountofsets;
  401. console.log("DEBUG#TRADE CREATED");
  402. sortSetsByAmount(botSets, (DATA) => {
  403. console.log("DEBUG#" + DATA);
  404. console.log("DEBUG#SETS SORTED");
  405. firstLoop: for (let i = 0; i < DATA.length; i++) {
  406. if (b[DATA[i]] == 0) {
  407. continue firstLoop;
  408. } else {
  409. console.log("DEBUG#" + i);
  410. console.log("DEBUG#FOR LOOP ITEMS");
  411. if (hisMaxSets > 0) {
  412. console.log("DEBUG#MAXSETSMORETHAN1");
  413. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  414. // BOT HAS ENOUGH SETS OF THIS KIND
  415. console.log("DEBUG#LOOP #1");
  416. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  417. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  418. console.log("DEBUG#LOOP #1: ITEM ADD");
  419. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  420. t.addMyItems(botSets[DATA[i]][j]);
  421. hisMaxSets--;
  422. console.log(hisMaxSets);
  423. } else {
  424. console.log("DEBUG#LOOP #1: RETURN");
  425. continue firstLoop;
  426. }
  427. }
  428. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  429. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  430. console.log("DEBUG#LOOP #1 CONTINUE");
  431. continue; // *
  432. } 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
  433. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  434. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  435. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  436. t.addMyItems(botSets[DATA[i]][j]);
  437. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  438. hisMaxSets--;
  439. } else {
  440. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  441. continue firstLoop;
  442. }
  443. }
  444. }
  445. else if (hisMaxSets < 5) {
  446. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  447. console.log("DEBUG#LOOP #2");
  448. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  449. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  450. t.addMyItems(botSets[DATA[i]][j]);
  451. console.log("DEBUG#LOOP #2: ITEM ADD");
  452. hisMaxSets--;
  453. console.log(hisMaxSets);
  454. } else {
  455. console.log("DEBUG#LOOP #2: RETURN");
  456. continue firstLoop;
  457. }
  458. }
  459. } else {
  460. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  461. console.log("DEBUG#LOOP #2");
  462. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  463. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  464. t.addMyItems(botSets[DATA[i]][j]);
  465. console.log("DEBUG#LOOP #2: ITEM ADD");
  466. hisMaxSets--;
  467. console.log(hisMaxSets);
  468. } else {
  469. console.log("DEBUG#LOOP #2: RETURN");
  470. continue firstLoop;
  471. }
  472. }
  473. }
  474. } else {
  475. console.log("DEBUG#RETURN");
  476. break firstLoop;
  477. }
  478. }
  479. }
  480. if (hisMaxSets > 0) {
  481. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  482. } else {
  483. console.log("DEBUG#SENDING");
  484. t.addTheirItems(theirKeys);
  485. t.data("commandused", "Buy");
  486. t.data("amountofkeys", n);
  487. t.data("amountofsets", amountofsets.toString());
  488. t.send((ERR, STATUS) => {
  489. if (ERR) {
  490. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  491. console.log("## An error occurred while sending trade: " + ERR);
  492. } else {
  493. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  494. console.log("## Trade offer sent");
  495. }
  496. });
  497. }
  498. });
  499. } else {
  500. 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.");
  501. }
  502. // TO HERE
  503. } else {
  504. console.log("An error occurred while getting badges: " + ERR);
  505. }
  506. } else {
  507. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  508. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  509. }
  510. });
  511. }
  512. } else {
  513. console.log("## An error occurred while getting inventory: " + ERR);
  514. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  515. }
  516. }
  517. });
  518. } else {
  519. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  520. }
  521. });
  522. } else {
  523. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  524. }
  525. } else {
  526. client.chatMessage(SENDER, "Error: Please provide a valid amount of keys.");
  527. }
  528. }
  529. }
  530. }
  531. else if (MSG.toUpperCase().indexOf("!SELLCHECK") >= 0) {
  532. let n = parseInt(MSG.toUpperCase().replace("!SELLCHECK ",""));
  533. client.chatMessage(SENDER, "Loading your inventory...");
  534.  
  535. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  536. console.log("[ DEBUG ] Inventory loaded");
  537. if (!ERR) {
  538. let s = DATA;
  539. Utils.getSets(s, allCards, (ERR, DATA) => {
  540. console.log("[ DEBUG ] Sets loaded");
  541. if (!ERR) {
  542. // console.log(b);
  543. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  544. // 1: GET BOTS CARDS. DONE
  545. // 2: GET PLAYER's BADGES. DONE
  546. // 3: MAGIC
  547. let hisMaxSets = 0,
  548. botNSets = 0;
  549. // Loop for sets he has partially completed
  550. // Loop for sets he has never crafted
  551. for (let i = 0; i < Object.keys(DATA).length; i++) {
  552. if (DATA[Object.keys(DATA)[i]].length >= 5) {
  553. hisMaxSets += 5;
  554. }
  555. else {
  556. hisMaxSets += DATA[Object.keys(DATA)[i]].length;
  557. }
  558. botNSets += DATA[Object.keys(DATA)[i]].length;
  559. }
  560. totalBotSets = botNSets;
  561. let playThis = CONFIG.PLAYGAMES;
  562. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  563. playThis[0] = parseString(playThis[0], totalBotSets);
  564. }
  565. client.gamesPlayed(playThis);
  566. 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 / 20 * 100) / 100 + " CS:GO keys.");
  567. }
  568. else {
  569. console.log("[ DEBUG ] An error occurred while getting user sets: " + ERR);
  570. }
  571. });
  572. }
  573. else {
  574. console.log("[ DEBUG ] An error occurred while getting user inventory: " + ERR);
  575. }
  576. });
  577. } else if (MSG.toUpperCase().indexOf("!CHECK") >= 0) {
  578. let n = parseInt(MSG.toUpperCase().replace("!CHECK ", ""));
  579. if (!isNaN(n) && parseInt(n) > 0) {
  580. client.chatMessage(SENDER, " \n With " + n + " CSGO keys you can get " + n * 18 + " sets.");
  581. } else {
  582. if (Object.keys(botSets).length > 0) {
  583. client.chatMessage(SENDER, "Loading badges...");
  584. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  585. if (!ERR) {
  586. let b = {}; // List with badges that CAN still be crafted
  587. if (DATA) {
  588. for (let i = 0; i < Object.keys(DATA).length; i++) {
  589. if (DATA[Object.keys(DATA)[i]] < 6) {
  590. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  591. }
  592. }
  593. } else {
  594. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  595. }
  596. // console.log(b);
  597. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  598. // 1: GET BOTS CARDS. DONE
  599. // 2: GET PLAYER's BADGES. DONE
  600. // 3: MAGIC
  601. let hisMaxSets = 0,
  602. botNSets = 0;
  603. // Loop for sets he has partially completed
  604. for (let i = 0; i < Object.keys(b).length; i++) {
  605. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  606. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  607. }
  608. }
  609. // Loop for sets he has never crafted
  610. for (let i = 0; i < Object.keys(botSets).length; i++) {
  611. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  612. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  613. hisMaxSets += 5;
  614. } else {
  615. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  616. }
  617. }
  618. botNSets += botSets[Object.keys(botSets)[i]].length;
  619. }
  620. totalBotSets = botNSets;
  621. let playThis = CONFIG.PLAYGAMES;
  622. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  623. playThis[0] = parseString(playThis[0], totalBotSets);
  624. }
  625. client.gamesPlayed(playThis);
  626. client.chatMessage(SENDER, "There are currently " + hisMaxSets + " sets available which you have not fully crafted yet. Buying all of them will cost you " + parseInt(hisMaxSets / 18 * 100) / 100 + " CSGO keys.");
  627. } else {
  628. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  629. console.log("[ DEBUG ] An error occurred while getting badges: " + ERR);
  630. }
  631. });
  632. } else {
  633. client.chatMessage(SENDER, "Please try again later.");
  634. }
  635. }
  636. }
  637. else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
  638. if (botSets) {
  639. let n = parseInt(MSG.toUpperCase().replace("!SELL ","")),
  640. amountofsets = n * CONFIG.CARDS.SELLCSGO;
  641. if (!isNaN(n) && parseInt(n) > 0) {
  642. if (n <= CONFIG.MESSAGES.MAXSELL) {
  643. client.chatMessage(SENDER, "Processing your request.");
  644. let botKeys = [],
  645. t = manager.createOffer(SENDER.getSteamID64());
  646. t.getUserDetails((ERR, ME, THEM) => {
  647. if (ERR) {
  648. console.log("[ DEBUG ] An error occurred while getting trade holds: " + ERR);
  649. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  650. }
  651. else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  652. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.CSGOID, 2, true, (ERR, INV, CURR) => {
  653. if (ERR) {
  654. console.log("[ DEBUG ] An error occurred while getting bot inventory: " + ERR);
  655. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  656. }
  657. else {
  658. for (let i = 0; i < INV.length; i++) {
  659. if (botKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  660. botKeys.push(INV[i]);
  661. }
  662. }
  663. if (botKeys.length != n) {
  664. client.chatMessage(SENDER, "The bot does not have enough keys.");
  665. }
  666. else {
  667. let amountofB = amountofsets;
  668. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  669. if (!ERR) {
  670. let s = DATA;
  671. Utils.getSets(s, allCards, (ERR, DDATA) => {
  672. if (!ERR) {
  673. sortSetsByAmountB(s, (DATA) => {
  674. let setsSent = {};
  675. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  676. console.log(setsSent);
  677. console.log(DATA[i]);
  678. if (DDATA[DATA[i]]) {
  679. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  680. if (amountofB > 0) {
  681. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.SELLCSGO) || !setsSent[DATA[i]]) {
  682. t.addTheirItems(DDATA[DATA[i]][j]);
  683. console.log("[ DEBUG ] #2 CONTINUE: ITEM ADD");
  684. amountofB--;
  685. if (!setsSent[DATA[i]]) {
  686. setsSent[DATA[i]] = 1;
  687. }
  688. else {
  689. setsSent[DATA[i]] += 1;
  690. }
  691. }
  692. else {
  693. console.log("[ DEBUG ] #2 CONTINUE: RETURN");
  694. continue firsttLoop;
  695. }
  696. }
  697. else {
  698. console.log("[ DEBUG ] #2 CONTINUE: RETURN");
  699. continue firsttLoop;
  700. }
  701. }
  702. }
  703. else {
  704. console.log("[ DEBUG ] #2 CONTINUE: RETURN 2");
  705. continue firsttLoop;
  706. }
  707. }
  708. });
  709. if (amountofB > 0) {
  710. 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.");
  711. }
  712. else {
  713. console.log("[ DEBUG ] Sending Trade");
  714. t.addMyItems(botKeys);
  715. t.setMessage(CONFIG.MESSAGES.TRADEMSG);
  716. t.data("commandused", "Sell");
  717. t.data("amountofsets", amountofsets.toString());
  718. t.data("amountofkeys", n);
  719. t.send((ERR, STATUS) => {
  720. if (ERR) {
  721. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  722. console.log("[ DEBUG ] An error occurred while sending trade: " + ERR);
  723. }
  724. else {
  725. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  726. console.log("[ DEBUG ] Trade offer sent!");
  727. }
  728. });
  729. }
  730. }
  731. else {
  732. console.log("[ DEBUG ] An error occurred while getting bot sets: " + ERR);
  733. }
  734. });
  735. }
  736. else {
  737. console.log("[ DEBUG ] An error occurred while getting user inventory: " + ERR);
  738. }
  739. });
  740. }
  741. }
  742. });
  743. }
  744. else {
  745. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  746. }
  747. });
  748. }
  749. else {
  750. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  751. }
  752. }
  753. else {
  754. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  755. }
  756. }
  757. else {
  758. client.chatMessage(SENDER, "Please try again later.");
  759. }
  760. }
  761. else if (MSG.toUpperCase().indexOf("!BUYONE") >= 0) {
  762. if (botSets) {
  763. let n = MSG.toUpperCase().replace("!BUYONE ", ""),
  764. amountofsets = parseInt(n) * CONFIG.CARDS.BUYCSGO;
  765. if (!isNaN(n) && parseInt(n) > 0) {
  766. if (n <= CONFIG.MESSAGES.MAXBUY) {
  767. let t = manager.createOffer(SENDER.getSteamID64());
  768. t.getUserDetails((ERR, ME, THEM) => {
  769. if (ERR) {
  770. console.log("[ UserChat ] An error occurred while getting trade holds: " + ERR);
  771. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  772. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  773. n = parseInt(n);
  774. let theirKeys = [];
  775. client.chatMessage(SENDER, "Processing your request.");
  776. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOID, 2, true, (ERR, INV, CURR) => {
  777. if (ERR) {
  778. console.log("[ UserChat ] An error occurred while getting inventory: " + ERR);
  779. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  780. } else {
  781. console.log("DEBUG#INV LOADED");
  782. if (!ERR) {
  783. console.log("DEBUG#INV LOADED NOERR");
  784. for (let i = 0; i < INV.length; i++) {
  785. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  786. theirKeys.push(INV[i]);
  787. }
  788. }
  789. if (theirKeys.length != n) {
  790. client.chatMessage(SENDER, "You do not have enough keys.");
  791. } else {
  792. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  793. if (!ERR) {
  794. console.log("[ Debug ] Badge loaded without error");
  795. if (!ERR) {
  796. let b = {}; // List with badges that CAN still be crafted
  797. if (DATA) {
  798. for (let i = 0; i < Object.keys(DATA).length; i++) {
  799. if (DATA[Object.keys(DATA)[i]] < 6) {
  800. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  801. }
  802. }
  803. } else {
  804. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  805. }
  806. console.log(DATA);
  807. console.log(b);
  808. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  809. // 1: GET BOTS CARDS. DONE
  810. // 2: GET PLAYER's BADGES. DONE
  811. // 3: MAGIC
  812. let hisMaxSets = 0,
  813. botNSets = 0;
  814. // Loop for sets he has partially completed
  815. for (let i = 0; i < Object.keys(b).length; i++) {
  816. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  817. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  818. }
  819. }
  820. console.log("[ !BUY ] DEBUG - LOOP 1");
  821. // Loop for sets he has never crafted
  822. for (let i = 0; i < Object.keys(botSets).length; i++) {
  823. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  824. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  825. hisMaxSets += 5;
  826. } else {
  827. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  828. }
  829. }
  830. botNSets += botSets[Object.keys(botSets)[i]].length;
  831. }
  832. totalBotSets = botNSets;
  833. let playThis = CONFIG.PLAYGAMES;
  834. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  835. playThis[0] = parseString(playThis[0], totalBotSets);
  836. }
  837. client.gamesPlayed(playThis);
  838. console.log("[ Debug ] Loop 2");
  839. // HERE
  840. if (amountofsets <= hisMaxSets) {
  841. hisMaxSets = amountofsets;
  842. console.log("[ Debug ] Trade Created");
  843. sortSetsByAmount(botSets, (DATA) => {
  844. console.log("[ Debug ] " + DATA);
  845. console.log("[ Debug ] Sets has been sorted");
  846. firstLoop: for (let i = 0; i < DATA.length; i++) {
  847. if (b[DATA[i]] == 0) {
  848. continue firstLoop;
  849. } else {
  850. console.log("[ Debug ] DEBUG - " + i);
  851. console.log("[ Debug ] For Itemloop");
  852. if (hisMaxSets > 0) {
  853. console.log("[ !BUY ] DEBUG - Max Sets more than 1");
  854. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  855. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  856. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  857. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  858. t.addMyItems(botSets[DATA[i]][j]);
  859. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  860. hisMaxSets--;
  861. continue firstLoop;
  862. } else {
  863. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  864. continue firstLoop;
  865. }
  866. }
  867. }
  868. } else {
  869. console.log("DEBUG#RETURN");
  870. break firstLoop;
  871. }
  872. }
  873. }
  874. if (hisMaxSets > 0) {
  875. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  876. } else {
  877. console.log("DEBUG#SENDING");
  878. t.addTheirItems(theirKeys);
  879. t.data("commandused", "BuyOne");
  880. t.data("amountofkeys", n);
  881. t.data("amountofsets", amountofsets.toString());
  882. t.send((ERR, STATUS) => {
  883. if (ERR) {
  884. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  885. console.log("## An error occurred while sending trade: " + ERR);
  886. } else {
  887. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  888. console.log("## Trade offer sent");
  889. }
  890. });
  891. }
  892. });
  893. } else {
  894. 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.");
  895. }
  896. // TO HERE
  897. } else {
  898. console.log("An error occurred while getting badges: " + ERR);
  899. }
  900. } else {
  901. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  902. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  903. }
  904. });
  905. }
  906. } else {
  907. console.log("## An error occurred while getting inventory: " + ERR);
  908. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  909. }
  910. }
  911. });
  912. } else {
  913. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  914. }
  915. });
  916. } else {
  917. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  918. }
  919. } else {
  920. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  921. }
  922. } else {
  923. client.chatMessage(SENDER, "Please try again later.");
  924. }
  925. } else if (MSG.toUpperCase().indexOf("!BUYANY") >= 0) {
  926. if (botSets) {
  927. let n = MSG.toUpperCase().replace("!BUYANY ", ""),
  928. amountofsets = parseInt(n) * CONFIG.CARDS.BUYCSGO;
  929. if (!isNaN(n) && parseInt(n) > 0) {
  930. if (n <= CONFIG.MESSAGES.MAXBUY) {
  931. let t = manager.createOffer(SENDER.getSteamID64());
  932. n = parseInt(n);
  933. let theirKeys = [];
  934. t.getUserDetails((ERR, ME, THEM) => {
  935. if (ERR) {
  936. console.log("## An error occurred while getting trade holds: " + ERR);
  937. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  938. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  939. client.chatMessage(SENDER, "Processing your request.");
  940. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOID, 2, true, (ERR, INV, CURR) => {
  941. if (ERR) {
  942. console.log("## An error occurred while getting inventory: " + ERR);
  943. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  944. } else {
  945. let amountofB = amountofsets;
  946. for (let i = 0; i < INV.length; i++) {
  947. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  948. theirKeys.push(INV[i]);
  949. }
  950. }
  951. if (theirKeys.length != n) {
  952. client.chatMessage(SENDER, "You do not have enough keys.");
  953. } else {
  954. sortSetsByAmount(botSets, (DATA) => {
  955. let setsSent = {};
  956. firstLoop: for (let i = 0; i < DATA.length; i++) {
  957. console.log(setsSent);
  958. console.log(DATA[i]);
  959. if (botSets[DATA[i]]) {
  960. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  961. if (amountofB > 0) {
  962. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < 5) || !setsSent[DATA[i]]) {
  963. t.addMyItems(botSets[DATA[i]][j]);
  964. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  965. amountofB--;
  966. if (!setsSent[DATA[i]]) {
  967. setsSent[DATA[i]] = 1;
  968. } else {
  969. setsSent[DATA[i]] += 1;
  970. }
  971. } else {
  972. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  973. continue firstLoop;
  974. }
  975. } else {
  976. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  977. continue firstLoop;
  978. }
  979. }
  980. } else {
  981. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  982. continue firstLoop;
  983. }
  984. }
  985. });
  986. }
  987. if (amountofB > 0) {
  988. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  989. } else {
  990. console.log("DEBUG#SENDING");
  991. t.addTheirItems(theirKeys);
  992. t.data("commandused", "BuyAny");
  993. t.data("amountofsets", amountofsets.toString());
  994. t.data("amountofkeys", n);
  995. t.send((ERR, STATUS) => {
  996. if (ERR) {
  997. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  998. console.log("## An error occurred while sending trade: " + ERR);
  999. } else {
  1000. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  1001. console.log("## Trade offer sent!");
  1002. }
  1003. });
  1004. }
  1005. }
  1006. });
  1007. } else {
  1008. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1009. }
  1010. });
  1011. } else {
  1012. client.chatMessage(SENDER, "Please try a lower amount of keys");
  1013. }
  1014. } else {
  1015. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  1016. }
  1017. } else {
  1018. client.chatMessage(SENDER, "Please try again later.");
  1019. }
  1020. } else if (MSG.toUpperCase().indexOf("!BUY") >= 0) {
  1021. if (botSets) {
  1022. let n = MSG.toUpperCase().replace("!BUY ", ""),
  1023. amountofsets = 0;
  1024. if (parseInt(n) == 1) {
  1025. if (Object.keys(blockedBuyUsers).indexOf(SENDER.getSteamID64()) < 0) {
  1026. blockedBuyUsers[SENDER.getSteamID64()] = {};
  1027. blockedBuyUsers[SENDER.getSteamID64()].blocked = 1;
  1028. fs.writeFile("./UserData/blockedBuyUsers.json", JSON.stringify(blockedBuyUsers), (ERR) => {
  1029. if (ERR) {
  1030. console.log("[ DEBUG ] An error occurred while writing blockedBuyUsers file: " + ERR);
  1031. }
  1032. });
  1033. amountofsets = CONFIG.CARDS.BUYCSGO + 8;
  1034. }
  1035. } else {
  1036. amountofsets = parseInt(n) * CONFIG.CARDS.BUYCSGO;
  1037. }
  1038. if (!isNaN(n) && parseInt(n) > 0) {
  1039. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1040. let t = manager.createOffer(SENDER.getSteamID64());
  1041. t.getUserDetails((ERR, ME, THEM) => {
  1042. if (ERR) {
  1043. console.log("## An error occurred while getting trade holds: " + ERR);
  1044. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  1045. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1046. n = parseInt(n);
  1047. let theirKeys = [];
  1048. client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  1049. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOID, 2, true, (ERR, INV, CURR) => {
  1050. if (ERR) {
  1051. console.log("## An error occurred while getting inventory: " + ERR);
  1052. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1053. } else {
  1054. console.log("DEBUG#INV LOADED");
  1055. if (!ERR) {
  1056. console.log("DEBUG#INV LOADED NOERR");
  1057. for (let i = 0; i < INV.length; i++) {
  1058. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1059. theirKeys.push(INV[i]);
  1060. }
  1061. }
  1062. if (theirKeys.length != n) {
  1063. client.chatMessage(SENDER, "Error: You don't have enough keys. Feel free to come back when you collect more keys.");
  1064. } else {
  1065. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1066. if (!ERR) {
  1067. console.log("DEBUG#BADGE LOADED");
  1068. if (!ERR) {
  1069. let b = {}; // List with badges that CAN still be crafted
  1070. if (DATA) {
  1071. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1072. if (DATA[Object.keys(DATA)[i]] < 6) {
  1073. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1074. }
  1075. }
  1076. } else {
  1077. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1078. }
  1079. console.log(DATA);
  1080. console.log(b);
  1081. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1082. // 1: GET BOTS CARDS. DONE
  1083. // 2: GET PLAYER's BADGES. DONE
  1084. // 3: MAGIC
  1085. let hisMaxSets = 0,
  1086. botNSets = 0;
  1087. // Loop for sets he has partially completed
  1088. for (let i = 0; i < Object.keys(b).length; i++) {
  1089. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1090. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1091. }
  1092. }
  1093. console.log("DEBUG#LOOP 1 DONE");
  1094. // Loop for sets he has never crafted
  1095. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1096. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1097. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1098. hisMaxSets += 5;
  1099. } else {
  1100. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1101. }
  1102. }
  1103. botNSets += botSets[Object.keys(botSets)[i]].length;
  1104. }
  1105. console.log("DEBUG#LOOP 2 DONE");
  1106. // HERE
  1107. if (amountofsets <= hisMaxSets) {
  1108. hisMaxSets = amountofsets;
  1109. console.log("DEBUG#TRADE CREATED");
  1110. sortSetsByAmount(botSets, (DATA) => {
  1111. console.log("DEBUG#" + DATA);
  1112. console.log("DEBUG#SETS SORTED");
  1113. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1114. if (b[DATA[i]] == 0) {
  1115. continue firstLoop;
  1116. } else {
  1117. console.log("DEBUG#" + i);
  1118. console.log("DEBUG#FOR LOOP ITEMS");
  1119. if (hisMaxSets > 0) {
  1120. console.log("DEBUG#MAXSETSMORETHAN1");
  1121. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1122. // BOT HAS ENOUGH SETS OF THIS KIND
  1123. console.log("DEBUG#LOOP #1");
  1124. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1125. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1126. console.log("DEBUG#LOOP #1: ITEM ADD");
  1127. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1128. t.addMyItems(botSets[DATA[i]][j]);
  1129. hisMaxSets--;
  1130. console.log(hisMaxSets);
  1131. } else {
  1132. console.log("DEBUG#LOOP #1: RETURN");
  1133. continue firstLoop;
  1134. }
  1135. }
  1136. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1137. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1138. console.log("DEBUG#LOOP #1 CONTINUE");
  1139. continue; // *
  1140. } 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
  1141. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1142. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1143. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1144. t.addMyItems(botSets[DATA[i]][j]);
  1145. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1146. hisMaxSets--;
  1147. } else {
  1148. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1149. continue firstLoop;
  1150. }
  1151. }
  1152. }
  1153. else if (hisMaxSets < 5) {
  1154. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1155. console.log("DEBUG#LOOP #2");
  1156. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  1157. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1158. t.addMyItems(botSets[DATA[i]][j]);
  1159. console.log("DEBUG#LOOP #2: ITEM ADD");
  1160. hisMaxSets--;
  1161. console.log(hisMaxSets);
  1162. } else {
  1163. console.log("DEBUG#LOOP #2: RETURN");
  1164. continue firstLoop;
  1165. }
  1166. }
  1167. } else {
  1168. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1169. console.log("DEBUG#LOOP #2");
  1170. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  1171. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1172. t.addMyItems(botSets[DATA[i]][j]);
  1173. console.log("DEBUG#LOOP #2: ITEM ADD");
  1174. hisMaxSets--;
  1175. console.log(hisMaxSets);
  1176. } else {
  1177. console.log("DEBUG#LOOP #2: RETURN");
  1178. continue firstLoop;
  1179. }
  1180. }
  1181. }
  1182. } else {
  1183. console.log("DEBUG#RETURN");
  1184. break firstLoop;
  1185. }
  1186. }
  1187. }
  1188. if (hisMaxSets > 0) {
  1189. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1190. } else {
  1191. console.log("DEBUG#SENDING");
  1192. t.addTheirItems(theirKeys);
  1193. t.data("commandused", "Buy");
  1194. t.data("amountofkeys", n);
  1195. t.data("amountofsets", amountofsets.toString());
  1196. t.send((ERR, STATUS) => {
  1197. if (ERR) {
  1198. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1199. console.log("## An error occurred while sending trade: " + ERR);
  1200. } else {
  1201. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  1202. console.log("## Trade offer sent");
  1203. }
  1204. });
  1205. }
  1206. });
  1207. } else {
  1208. 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.");
  1209. }
  1210. // TO HERE
  1211. } else {
  1212. console.log("An error occurred while getting badges: " + ERR);
  1213. }
  1214. } else {
  1215. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1216. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1217. }
  1218. });
  1219. }
  1220. } else {
  1221. console.log("## An error occurred while getting inventory: " + ERR);
  1222. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1223. }
  1224. }
  1225. });
  1226. } else {
  1227. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1228. }
  1229. });
  1230. } else {
  1231. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1232. }
  1233. } else {
  1234. client.chatMessage(SENDER, "Error: Please provide a valid amount of keys.");
  1235. }
  1236. } else {
  1237. client.chatMessage(SENDER, "Please try again later.");
  1238. }
  1239. }
  1240. else if (MSG.toUpperCase().indexOf("!TFBUY") >= 0) {
  1241. if (botSets) {
  1242. let n = MSG.toUpperCase().replace("!TFBUY ", ""),
  1243. amountofsets = parseInt(n) * CONFIG.CARDS.BUYTF;
  1244. if (!isNaN(n) && parseInt(n) > 0) {
  1245. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1246. let t = manager.createOffer(SENDER.getSteamID64());
  1247. t.getUserDetails((ERR, ME, THEM) => {
  1248. if (ERR) {
  1249. console.log("## An error occurred while getting trade holds: " + ERR);
  1250. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  1251. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1252. n = parseInt(n);
  1253. let theirKeys = [];
  1254. client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  1255. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFID, 2, true, (ERR, INV, CURR) => {
  1256. if (ERR) {
  1257. console.log("## An error occurred while getting inventory: " + ERR);
  1258. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1259. } else {
  1260. console.log("DEBUG#INV LOADED");
  1261. if (!ERR) {
  1262. console.log("DEBUG#INV LOADED NOERR");
  1263. for (let i = 0; i < INV.length; i++) {
  1264. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYSTF.indexOf(INV[i].market_hash_name) >= 0) {
  1265. theirKeys.push(INV[i]);
  1266. }
  1267. }
  1268. if (theirKeys.length != n) {
  1269. client.chatMessage(SENDER, "Error: You don't have enough keys. Feel free to come back when you collect more keys.");
  1270. } else {
  1271. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1272. if (!ERR) {
  1273. console.log("DEBUG#BADGE LOADED");
  1274. if (!ERR) {
  1275. let b = {}; // List with badges that CAN still be crafted
  1276. if (DATA) {
  1277. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1278. if (DATA[Object.keys(DATA)[i]] < 6) {
  1279. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1280. }
  1281. }
  1282. } else {
  1283. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1284. }
  1285. console.log(DATA);
  1286. console.log(b);
  1287. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1288. // 1: GET BOTS CARDS. DONE
  1289. // 2: GET PLAYER's BADGES. DONE
  1290. // 3: MAGIC
  1291. let hisMaxSets = 0,
  1292. botNSets = 0;
  1293. // Loop for sets he has partially completed
  1294. for (let i = 0; i < Object.keys(b).length; i++) {
  1295. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1296. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1297. }
  1298. }
  1299. console.log("DEBUG#LOOP 1 DONE");
  1300. // Loop for sets he has never crafted
  1301. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1302. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1303. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1304. hisMaxSets += 5;
  1305. } else {
  1306. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1307. }
  1308. }
  1309. botNSets += botSets[Object.keys(botSets)[i]].length;
  1310. }
  1311. console.log("DEBUG#LOOP 2 DONE");
  1312. // HERE
  1313. if (amountofsets <= hisMaxSets) {
  1314. hisMaxSets = amountofsets;
  1315. console.log("DEBUG#TRADE CREATED");
  1316. sortSetsByAmount(botSets, (DATA) => {
  1317. console.log("DEBUG#" + DATA);
  1318. console.log("DEBUG#SETS SORTED");
  1319. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1320. if (b[DATA[i]] == 0) {
  1321. continue firstLoop;
  1322. } else {
  1323. console.log("DEBUG#" + i);
  1324. console.log("DEBUG#FOR LOOP ITEMS");
  1325. if (hisMaxSets > 0) {
  1326. console.log("DEBUG#MAXSETSMORETHAN1");
  1327. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1328. // BOT HAS ENOUGH SETS OF THIS KIND
  1329. console.log("DEBUG#LOOP #1");
  1330. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1331. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1332. console.log("DEBUG#LOOP #1: ITEM ADD");
  1333. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1334. t.addMyItems(botSets[DATA[i]][j]);
  1335. hisMaxSets--;
  1336. console.log(hisMaxSets);
  1337. } else {
  1338. console.log("DEBUG#LOOP #1: RETURN");
  1339. continue firstLoop;
  1340. }
  1341. }
  1342. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1343. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1344. console.log("DEBUG#LOOP #1 CONTINUE");
  1345. continue; // *
  1346. } 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
  1347. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1348. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1349. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1350. t.addMyItems(botSets[DATA[i]][j]);
  1351. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1352. hisMaxSets--;
  1353. } else {
  1354. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1355. continue firstLoop;
  1356. }
  1357. }
  1358. }
  1359. else if (hisMaxSets < 5) {
  1360. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1361. console.log("DEBUG#LOOP #2");
  1362. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  1363. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1364. t.addMyItems(botSets[DATA[i]][j]);
  1365. console.log("DEBUG#LOOP #2: ITEM ADD");
  1366. hisMaxSets--;
  1367. console.log(hisMaxSets);
  1368. } else {
  1369. console.log("DEBUG#LOOP #2: RETURN");
  1370. continue firstLoop;
  1371. }
  1372. }
  1373. } else {
  1374. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1375. console.log("DEBUG#LOOP #2");
  1376. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  1377. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1378. t.addMyItems(botSets[DATA[i]][j]);
  1379. console.log("DEBUG#LOOP #2: ITEM ADD");
  1380. hisMaxSets--;
  1381. console.log(hisMaxSets);
  1382. } else {
  1383. console.log("DEBUG#LOOP #2: RETURN");
  1384. continue firstLoop;
  1385. }
  1386. }
  1387. }
  1388. } else {
  1389. console.log("DEBUG#RETURN");
  1390. break firstLoop;
  1391. }
  1392. }
  1393. }
  1394. if (hisMaxSets > 0) {
  1395. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1396. } else {
  1397. console.log("DEBUG#SENDING");
  1398. t.addTheirItems(theirKeys);
  1399. t.data("commandused", "Buy");
  1400. t.data("amountofkeys", n);
  1401. t.data("amountofsets", amountofsets.toString());
  1402. t.send((ERR, STATUS) => {
  1403. if (ERR) {
  1404. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1405. console.log("## An error occurred while sending trade: " + ERR);
  1406. } else {
  1407. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  1408. console.log("## Trade offer sent");
  1409. }
  1410. });
  1411. }
  1412. });
  1413. } else {
  1414. 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.");
  1415. }
  1416. // TO HERE
  1417. } else {
  1418. console.log("An error occurred while getting badges: " + ERR);
  1419. }
  1420. } else {
  1421. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1422. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1423. }
  1424. });
  1425. }
  1426. } else {
  1427. console.log("## An error occurred while getting inventory: " + ERR);
  1428. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1429. }
  1430. }
  1431. });
  1432. } else {
  1433. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1434. }
  1435. });
  1436. } else {
  1437. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1438. }
  1439. } else {
  1440. client.chatMessage(SENDER, "Error: Please provide a valid amount of keys.");
  1441. }
  1442. } else {
  1443. client.chatMessage(SENDER, "Please try again later.");
  1444. }
  1445. }
  1446. else if (MSG.toUpperCase().indexOf("!PUBGCRATEBUY") >= 0) {
  1447. if (botSets) {
  1448. let n = MSG.toUpperCase().replace("!PUBGCRATEBUY ", ""),
  1449. amountofsets = parseInt(n) * CONFIG.CARDS.BUYPUBGCRATE;
  1450. if (!isNaN(n) && parseInt(n) > 0) {
  1451. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1452. let t = manager.createOffer(SENDER.getSteamID64());
  1453. t.getUserDetails((ERR, ME, THEM) => {
  1454. if (ERR) {
  1455. console.log("## An error occurred while getting trade holds: " + ERR);
  1456. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  1457. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1458. n = parseInt(n);
  1459. let theirKeys = [];
  1460. client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  1461. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGID, 2, true, (ERR, INV, CURR) => {
  1462. if (ERR) {
  1463. console.log("## An error occurred while getting inventory: " + ERR);
  1464. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1465. } else {
  1466. console.log("DEBUG#INV LOADED");
  1467. if (!ERR) {
  1468. console.log("DEBUG#INV LOADED NOERR");
  1469. for (let i = 0; i < INV.length; i++) {
  1470. if (theirKeys.length < n && CONFIG.ACCEPTEDCRATESPUBG.indexOf(INV[i].market_hash_name) >= 0) {
  1471. theirKeys.push(INV[i]);
  1472. }
  1473. }
  1474. if (theirKeys.length != n) {
  1475. client.chatMessage(SENDER, "Error: You don't have enough keys. Feel free to come back when you collect more keys.");
  1476. } else {
  1477. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1478. if (!ERR) {
  1479. console.log("DEBUG#BADGE LOADED");
  1480. if (!ERR) {
  1481. let b = {}; // List with badges that CAN still be crafted
  1482. if (DATA) {
  1483. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1484. if (DATA[Object.keys(DATA)[i]] < 6) {
  1485. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1486. }
  1487. }
  1488. } else {
  1489. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1490. }
  1491. console.log(DATA);
  1492. console.log(b);
  1493. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1494. // 1: GET BOTS CARDS. DONE
  1495. // 2: GET PLAYER's BADGES. DONE
  1496. // 3: MAGIC
  1497. let hisMaxSets = 0,
  1498. botNSets = 0;
  1499. // Loop for sets he has partially completed
  1500. for (let i = 0; i < Object.keys(b).length; i++) {
  1501. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1502. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1503. }
  1504. }
  1505. console.log("DEBUG#LOOP 1 DONE");
  1506. // Loop for sets he has never crafted
  1507. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1508. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1509. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1510. hisMaxSets += 5;
  1511. } else {
  1512. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1513. }
  1514. }
  1515. botNSets += botSets[Object.keys(botSets)[i]].length;
  1516. }
  1517. console.log("DEBUG#LOOP 2 DONE");
  1518. // HERE
  1519. if (amountofsets <= hisMaxSets) {
  1520. hisMaxSets = amountofsets;
  1521. console.log("DEBUG#TRADE CREATED");
  1522. sortSetsByAmount(botSets, (DATA) => {
  1523. console.log("DEBUG#" + DATA);
  1524. console.log("DEBUG#SETS SORTED");
  1525. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1526. if (b[DATA[i]] == 0) {
  1527. continue firstLoop;
  1528. } else {
  1529. console.log("DEBUG#" + i);
  1530. console.log("DEBUG#FOR LOOP ITEMS");
  1531. if (hisMaxSets > 0) {
  1532. console.log("DEBUG#MAXSETSMORETHAN1");
  1533. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1534. // BOT HAS ENOUGH SETS OF THIS KIND
  1535. console.log("DEBUG#LOOP #1");
  1536. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1537. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1538. console.log("DEBUG#LOOP #1: ITEM ADD");
  1539. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1540. t.addMyItems(botSets[DATA[i]][j]);
  1541. hisMaxSets--;
  1542. console.log(hisMaxSets);
  1543. } else {
  1544. console.log("DEBUG#LOOP #1: RETURN");
  1545. continue firstLoop;
  1546. }
  1547. }
  1548. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1549. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1550. console.log("DEBUG#LOOP #1 CONTINUE");
  1551. continue; // *
  1552. } 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
  1553. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1554. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1555. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1556. t.addMyItems(botSets[DATA[i]][j]);
  1557. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1558. hisMaxSets--;
  1559. } else {
  1560. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1561. continue firstLoop;
  1562. }
  1563. }
  1564. }
  1565. else if (hisMaxSets < 5) {
  1566. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1567. console.log("DEBUG#LOOP #2");
  1568. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  1569. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1570. t.addMyItems(botSets[DATA[i]][j]);
  1571. console.log("DEBUG#LOOP #2: ITEM ADD");
  1572. hisMaxSets--;
  1573. console.log(hisMaxSets);
  1574. } else {
  1575. console.log("DEBUG#LOOP #2: RETURN");
  1576. continue firstLoop;
  1577. }
  1578. }
  1579. } else {
  1580. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1581. console.log("DEBUG#LOOP #2");
  1582. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  1583. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1584. t.addMyItems(botSets[DATA[i]][j]);
  1585. console.log("DEBUG#LOOP #2: ITEM ADD");
  1586. hisMaxSets--;
  1587. console.log(hisMaxSets);
  1588. } else {
  1589. console.log("DEBUG#LOOP #2: RETURN");
  1590. continue firstLoop;
  1591. }
  1592. }
  1593. }
  1594. } else {
  1595. console.log("DEBUG#RETURN");
  1596. break firstLoop;
  1597. }
  1598. }
  1599. }
  1600. if (hisMaxSets > 0) {
  1601. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1602. } else {
  1603. console.log("DEBUG#SENDING");
  1604. t.addTheirItems(theirKeys);
  1605. t.data("commandused", "Buy");
  1606. t.data("amountofkeys", n);
  1607. t.data("amountofsets", amountofsets.toString());
  1608. t.send((ERR, STATUS) => {
  1609. if (ERR) {
  1610. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1611. console.log("## An error occurred while sending trade: " + ERR);
  1612. } else {
  1613. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  1614. console.log("## Trade offer sent");
  1615. }
  1616. });
  1617. }
  1618. });
  1619. } else {
  1620. 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.");
  1621. }
  1622. // TO HERE
  1623. } else {
  1624. console.log("An error occurred while getting badges: " + ERR);
  1625. }
  1626. } else {
  1627. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1628. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1629. }
  1630. });
  1631. }
  1632. } else {
  1633. console.log("## An error occurred while getting inventory: " + ERR);
  1634. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1635. }
  1636. }
  1637. });
  1638. } else {
  1639. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1640. }
  1641. });
  1642. } else {
  1643. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1644. }
  1645. } else {
  1646. client.chatMessage(SENDER, "Error: Please provide a valid amount of keys.");
  1647. }
  1648. } else {
  1649. client.chatMessage(SENDER, "Please try again later.");
  1650. }
  1651. }
  1652. else if (MSG.toUpperCase().indexOf("!PUBGBUY") >= 0) {
  1653. if (botSets) {
  1654. let n = MSG.toUpperCase().replace("!PUBGBUY ", ""),
  1655. amountofsets = parseInt(n) * CONFIG.CARDS.BUYPUBG;
  1656. if (!isNaN(n) && parseInt(n) > 0) {
  1657. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1658. let t = manager.createOffer(SENDER.getSteamID64());
  1659. t.getUserDetails((ERR, ME, THEM) => {
  1660. if (ERR) {
  1661. console.log("## An error occurred while getting trade holds: " + ERR);
  1662. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  1663. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  1664. n = parseInt(n);
  1665. let theirKeys = [];
  1666. client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  1667. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGID, 2, true, (ERR, INV, CURR) => {
  1668. if (ERR) {
  1669. console.log("## An error occurred while getting inventory: " + ERR);
  1670. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1671. } else {
  1672. console.log("DEBUG#INV LOADED");
  1673. if (!ERR) {
  1674. console.log("DEBUG#INV LOADED NOERR");
  1675. for (let i = 0; i < INV.length; i++) {
  1676. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYSPUBG.indexOf(INV[i].market_hash_name) >= 0) {
  1677. theirKeys.push(INV[i]);
  1678. }
  1679. }
  1680. if (theirKeys.length != n) {
  1681. client.chatMessage(SENDER, "Error: You don't have enough keys. Feel free to come back when you collect more keys.");
  1682. } else {
  1683. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1684. if (!ERR) {
  1685. console.log("DEBUG#BADGE LOADED");
  1686. if (!ERR) {
  1687. let b = {}; // List with badges that CAN still be crafted
  1688. if (DATA) {
  1689. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1690. if (DATA[Object.keys(DATA)[i]] < 6) {
  1691. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1692. }
  1693. }
  1694. } else {
  1695. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1696. }
  1697. console.log(DATA);
  1698. console.log(b);
  1699. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1700. // 1: GET BOTS CARDS. DONE
  1701. // 2: GET PLAYER's BADGES. DONE
  1702. // 3: MAGIC
  1703. let hisMaxSets = 0,
  1704. botNSets = 0;
  1705. // Loop for sets he has partially completed
  1706. for (let i = 0; i < Object.keys(b).length; i++) {
  1707. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1708. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1709. }
  1710. }
  1711. console.log("DEBUG#LOOP 1 DONE");
  1712. // Loop for sets he has never crafted
  1713. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1714. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1715. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1716. hisMaxSets += 5;
  1717. } else {
  1718. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1719. }
  1720. }
  1721. botNSets += botSets[Object.keys(botSets)[i]].length;
  1722. }
  1723. console.log("DEBUG#LOOP 2 DONE");
  1724. // HERE
  1725. if (amountofsets <= hisMaxSets) {
  1726. hisMaxSets = amountofsets;
  1727. console.log("DEBUG#TRADE CREATED");
  1728. sortSetsByAmount(botSets, (DATA) => {
  1729. console.log("DEBUG#" + DATA);
  1730. console.log("DEBUG#SETS SORTED");
  1731. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1732. if (b[DATA[i]] == 0) {
  1733. continue firstLoop;
  1734. } else {
  1735. console.log("DEBUG#" + i);
  1736. console.log("DEBUG#FOR LOOP ITEMS");
  1737. if (hisMaxSets > 0) {
  1738. console.log("DEBUG#MAXSETSMORETHAN1");
  1739. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1740. // BOT HAS ENOUGH SETS OF THIS KIND
  1741. console.log("DEBUG#LOOP #1");
  1742. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1743. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1744. console.log("DEBUG#LOOP #1: ITEM ADD");
  1745. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1746. t.addMyItems(botSets[DATA[i]][j]);
  1747. hisMaxSets--;
  1748. console.log(hisMaxSets);
  1749. } else {
  1750. console.log("DEBUG#LOOP #1: RETURN");
  1751. continue firstLoop;
  1752. }
  1753. }
  1754. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1755. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1756. console.log("DEBUG#LOOP #1 CONTINUE");
  1757. continue; // *
  1758. } 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
  1759. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1760. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1761. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1762. t.addMyItems(botSets[DATA[i]][j]);
  1763. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1764. hisMaxSets--;
  1765. } else {
  1766. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1767. continue firstLoop;
  1768. }
  1769. }
  1770. }
  1771. else if (hisMaxSets < 5) {
  1772. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1773. console.log("DEBUG#LOOP #2");
  1774. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  1775. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1776. t.addMyItems(botSets[DATA[i]][j]);
  1777. console.log("DEBUG#LOOP #2: ITEM ADD");
  1778. hisMaxSets--;
  1779. console.log(hisMaxSets);
  1780. } else {
  1781. console.log("DEBUG#LOOP #2: RETURN");
  1782. continue firstLoop;
  1783. }
  1784. }
  1785. } else {
  1786. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1787. console.log("DEBUG#LOOP #2");
  1788. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  1789. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1790. t.addMyItems(botSets[DATA[i]][j]);
  1791. console.log("DEBUG#LOOP #2: ITEM ADD");
  1792. hisMaxSets--;
  1793. console.log(hisMaxSets);
  1794. } else {
  1795. console.log("DEBUG#LOOP #2: RETURN");
  1796. continue firstLoop;
  1797. }
  1798. }
  1799. }
  1800. } else {
  1801. console.log("DEBUG#RETURN");
  1802. break firstLoop;
  1803. }
  1804. }
  1805. }
  1806. if (hisMaxSets > 0) {
  1807. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1808. } else {
  1809. console.log("DEBUG#SENDING");
  1810. t.addTheirItems(theirKeys);
  1811. t.data("commandused", "Buy");
  1812. t.data("amountofkeys", n);
  1813. t.data("amountofsets", amountofsets.toString());
  1814. t.send((ERR, STATUS) => {
  1815. if (ERR) {
  1816. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1817. console.log("## An error occurred while sending trade: " + ERR);
  1818. } else {
  1819. client.chatMessage(SENDER, "Trade Sent! Confirming it... Please wait.");
  1820. console.log("## Trade offer sent");
  1821. }
  1822. });
  1823. }
  1824. });
  1825. } else {
  1826. 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.");
  1827. }
  1828. // TO HERE
  1829. } else {
  1830. console.log("An error occurred while getting badges: " + ERR);
  1831. }
  1832. } else {
  1833. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1834. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1835. }
  1836. });
  1837. }
  1838. } else {
  1839. console.log("## An error occurred while getting inventory: " + ERR);
  1840. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1841. }
  1842. }
  1843. });
  1844. } else {
  1845. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1846. }
  1847. });
  1848. } else {
  1849. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1850. }
  1851. } else {
  1852. client.chatMessage(SENDER, "Error: Please provide a valid amount of keys.");
  1853. }
  1854. } else {
  1855. client.chatMessage(SENDER, "Please try again later.");
  1856. }
  1857. }
  1858. //else if (MSG.toUpperCase() == "!PROOF") {
  1859. // client.chatMessage(SENDER, "b0gotac @ github");
  1860. //}
  1861. else if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
  1862. // Admin commands.
  1863. if (MSG.toUpperCase().indexOf("!BLOCK") >= 0) {
  1864. let n = MSG.toUpperCase().replace("!BLOCK ", "").toString();
  1865. if (SID64REGEX.test(n)) {
  1866. client.chatMessage(SENDER, "User blocked.");
  1867. client.blockUser(n);
  1868. } else {
  1869. client.chatMessage(SENDER, "Please provide a valid SteamID64");
  1870. }
  1871. } else if (MSG.toUpperCase().indexOf("!USERCHECK") >= 0) {
  1872. let n = MSG.toUpperCase().replace("!USERCHECK ", "").toString();
  1873. if (SID64REGEX.test(n)) {
  1874. if (Object.keys(botSets).length > 0) {
  1875. client.chatMessage(SENDER, "Loading badges...");
  1876. Utils.getBadges(n, (ERR, DATA) => {
  1877. if (!ERR) {
  1878. let b = {}; // List with badges that CAN still be crafted
  1879. if (DATA) {
  1880. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1881. if (DATA[Object.keys(DATA)[i]] < 6) {
  1882. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1883. }
  1884. }
  1885. } else {
  1886. client.chatMessage(SENDER.getSteamID64(), n + "'s badges are empty, sending an offer without checking badges.");
  1887. }
  1888. // console.log(b);
  1889. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1890. // 1: GET BOTS CARDS. DONE
  1891. // 2: GET PLAYER's BADGES. DONE
  1892. // 3: MAGIC
  1893. let hisMaxSets = 0,
  1894. botNSets = 0;
  1895. // Loop for sets he has partially completed
  1896. for (let i = 0; i < Object.keys(b).length; i++) {
  1897. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1898. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1899. }
  1900. }
  1901. // Loop for sets he has never crafted
  1902. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1903. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1904. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1905. hisMaxSets += 5;
  1906. } else {
  1907. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1908. }
  1909. }
  1910. botNSets += botSets[Object.keys(botSets)[i]].length;
  1911. }
  1912. 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.");
  1913. } else {
  1914. client.chatMessage(SENDER, "An error occurred while getting " + n + "'s badges. Please try again.");
  1915. console.log("An error occurred while getting badges: " + ERR);
  1916. }
  1917. });
  1918. } else {
  1919. client.chatMessage(SENDER, "Please try again later.");
  1920. }
  1921. } else {
  1922. client.chatMessage(SENDER, "Please provide a valid SteamID64.");
  1923. }
  1924. } else {
  1925. client.chatMessage(SENDER, "Command not recognized.");;
  1926. }
  1927. } else {
  1928. client.chatMessage(SENDER, "Command not recognized. Use !help to see how this bot works.")
  1929. }
  1930. });
  1931.  
  1932. client.on("friendRelationship", (SENDER, REL) => {
  1933. if (REL === 2) {
  1934. client.addFriend(SENDER);
  1935. } else if (REL === 3) {
  1936. if (CONFIG.INVITETOGROUPID) {
  1937. client.inviteToGroup(SENDER, CONFIG.INVITETOGROUPID);
  1938. }
  1939. client.chatMessage(SENDER, CONFIG.MESSAGES.WELCOME);
  1940. }
  1941. });
  1942.  
  1943. // manager.on("unknownOfferSent", (o, os) => {
  1944. // if (o.state == 9) {
  1945. // console.log("## OFFER SENT LIST");
  1946. // community.checkConfirmations();
  1947. // }
  1948. // });
  1949.  
  1950. // community.on("newConfirmation", (CONF) => {
  1951. // console.log("## New confirmation.");
  1952. // community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id);
  1953. // });
  1954.  
  1955. manager.on("sentOfferChanged", (OFFER, OLDSTATE) => {
  1956. if(OFFER.state == 2) {
  1957. client.chatMessage(OFFER.partner, "Trade confirmed! Click here to accept it: https://www.steamcommunity.com/tradeoffer/" + OFFER.id);
  1958. } else if (OFFER.state == 3) {
  1959. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  1960. if (!ERR) {
  1961. let s = DATA;
  1962. Utils.getSets(s, allCards, (ERR, DATA) => {
  1963. if (!ERR) {
  1964. botSets = DATA;
  1965. console.log("## Bot's sets loaded.");
  1966. } else {
  1967. console.log("## An error occurred while getting bot sets: " + ERR);
  1968. }
  1969. let botNSets = 0;
  1970. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1971. botNSets += botSets[Object.keys(botSets)[i]].length;
  1972. }
  1973. totalBotSets = botNSets;
  1974. let playThis = CONFIG.PLAYGAMES;
  1975. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  1976. playThis[0] = parseString(playThis[0], totalBotSets);
  1977. }
  1978. client.gamesPlayed(playThis);
  1979. });
  1980. } else {
  1981. console.log("## An error occurred while getting bot inventory: " + ERR);
  1982. }
  1983. });
  1984. if (CONFIG.INVITETOGROUPID) {
  1985. client.inviteToGroup(OFFER.partner, CONFIG.INVITETOGROUPID);
  1986. }
  1987. let d = "" + OFFER.data("commandused") + "";
  1988. d += "\nSets: " + OFFER.data("amountofsets");
  1989. d += "\nKeys: " + OFFER.data("amountofkeys");
  1990. d += "\nSteamID: " + OFFER.partner.getSteamID64();
  1991. fs.writeFile("./TradesAccepted/" + OFFER.id + "-" + OFFER.partner.getSteamID64() + ".txt", d, (ERR) => {
  1992. if (ERR) {
  1993. console.log("## An error occurred while writing trade file: " + ERR);
  1994. }
  1995. });
  1996. community.getSteamUser(OFFER.partner, (ERR, USER) => {
  1997. if (ERR) {
  1998. console.log("## An error occurred while getting user profile: " + ERR);
  1999. client.chatMessage(USER.steamID, "An error occurred while getting your profile (to comment).");
  2000. } else {
  2001. USER.comment(CONFIG.COMMENTAFTERTRADE, (ERR) => {
  2002. if (ERR) {
  2003. console.log("## An error occurred while commenting on user profile: " + ERR);
  2004. client.chatMessage(USER.steamID, "An error occurred while getting commenting on your profile.");
  2005. } else {
  2006. client.chatMessage(USER.steamID, "Trade was successful!");
  2007. }
  2008. });
  2009. }
  2010. });
  2011. } else if (OFFER.state == 6) {
  2012. client.chatMessage(OFFER.partner, "Hey, you did not accept the offer. Please try again if you wish to receive sets!");
  2013. }
  2014. /* else if (OFFER.state == 9) {
  2015. community.checkConfirmations();
  2016. }*/
  2017. });
  2018.  
  2019. manager.on("newOffer", (OFFER) => {
  2020. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(OFFER.partner.getSteamID64())) >= 0) {
  2021. OFFER.getUserDetails((ERR, ME, THEM) => {
  2022. if (ERR) {
  2023. console.log("[ NewOffer ] An error occurred while getting trade holds: " + ERR);
  2024. client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again and make sure you have no trade hold.");
  2025. OFFER.decline((ERR) => {
  2026. if (ERR) {
  2027. console.log("[ NewOffer ] An error occurred while declining trade: " + ERR);
  2028. }
  2029. });
  2030. }
  2031. else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  2032. OFFER.accept((ERR) => {
  2033. if (ERR) {
  2034. console.log("[ NewOffer ] An error occurred while accepting trade: " + ERR);
  2035. OFFER.decline((ERR) => {
  2036. if (ERR) {
  2037. console.log("[ NewOffer ] An error occurred while accepting trade: " + ERR);
  2038. }
  2039. });
  2040. } else {
  2041. client.chatMessage(OFFER.partner, "The offer has been accepted!");
  2042. }
  2043. });
  2044. }
  2045. else {
  2046. client.chatMessage(OFFER.partner, "Please make sure you don't have a trade hold!");
  2047. OFFER.decline((ERR) => {
  2048. if (ERR) {
  2049. console.log("[ NewOffer ] An error occurred while declining trade: " + ERR);
  2050. }
  2051. });
  2052. }
  2053. });
  2054. }
  2055. else if (OFFER.itemsToGive.length == 0) {
  2056. OFFER.accept((ERR) => {
  2057. console.log("[ NewOffer ] New Donation");
  2058. if (ERR) {
  2059. console.log("[ NewOffer ] An error occurred while accepting trade: " + ERR);
  2060. }
  2061. });
  2062. }
  2063. else {
  2064. OFFER.decline((ERR) => {
  2065. if (ERR) {
  2066. console.log("[ NewOffer ] An error occurred while declining trade: " + ERR);
  2067. }
  2068. });
  2069. }
  2070. });
  2071.  
  2072. // If we get a new confirmation then confirm the Trade
  2073. community.on("newConfirmation", (CONF) => {
  2074. console.log("[ NewConf. ] New confirmation.");
  2075. community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id, (ERR) => {
  2076. if (ERR) {
  2077. console.log("[ NewConf. ] An error occurred while accepting confirmation: " + ERR);
  2078. }
  2079. else {
  2080. console.log("[ NewConf. ] Confirmation accepted.");
  2081. }
  2082. });
  2083. });
  2084.  
  2085. function sortSetsByAmount(SETS, callback) {
  2086. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length).reverse());
  2087. }
  2088.  
  2089. function sortSetsByAmountB(SETS, callback) {
  2090. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length));
  2091. }
  2092.  
  2093. function parseString(INPUT, SETS) {
  2094. return INPUT.replace(":sets:", SETS);
  2095.  
  2096. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement