Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 261.40 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. reload = require('reload'),
  6. Utils = require("./utils.js"),
  7. CONFIG = require("./SETTINGS/config.js"),
  8. DATA = require("./DATA/data.js"),
  9. allCards = {},
  10. botSets = {},
  11. fs = require("fs"),
  12. users = {},
  13. userMsgs = {},
  14. SID64REGEX = new RegExp(/^[0-9]{17}$/),
  15. chatLogs = "",
  16. userLogs = {},
  17. totalBotSets = 0;
  18. jsonfile = require('jsonfile');
  19.  
  20. let client = new SteamUser(),
  21. manager = new TradeOfferManager({
  22. "steam": client,
  23. "language": "en",
  24. "pollInterval": "10000",
  25. "cancelTime": "7200000" // 2 hours in ms
  26. }),
  27. community = new SteamCommunity();
  28.  
  29. fs.readFile("./UserData/Users.json", (ERR, DATA) => {
  30. if (ERR) {
  31. console.log("## An error occurred while getting Users: " + ERR);
  32. } else {
  33. users = JSON.parse(DATA);
  34. }
  35. });
  36.  
  37. Utils.getCardsInSets((ERR, DATA) => {
  38. if (!ERR) {
  39. allCards = DATA;
  40. console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
  41. } else {
  42. console.log("An error occurred while getting cards: " + ERR);
  43. }
  44. });
  45.  
  46. setInterval(() => {
  47. for (let i = 0; i < Object.keys(users).length; i++) {
  48. if (users[Object.keys(users)[i]].idleforhours >= CONFIG.MAXHOURSADDED) {
  49. 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.");
  50. client.removeFriend(Object.keys(users)[i]);
  51. delete users[Object.keys(users)[i]];
  52. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  53. if (ERR) {
  54. console.log("## An error occurred while writing UserData file: " + ERR);
  55. }
  56. });
  57. } else {
  58. users[Object.keys(users)[i]].idleforhours += 1;
  59. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  60. if (ERR) {
  61. console.log("## An error occurred while writing UserData file: " + ERR);
  62. }
  63. });
  64. }
  65. }
  66. }, 1000 * 60 * 60);
  67.  
  68. setInterval(() => {
  69. for (let i = 0; i < Object.keys(userMsgs).length; i++) {
  70. if (userMsgs[Object.keys(userMsgs)[i]] > CONFIG.MAXMSGPERSEC) {
  71. client.chatMessage(Object.keys(userMsgs)[i], "You have been removed for spamming. Another offense will get you blocked.");
  72. client.removeFriend(Object.keys(userMsgs)[i]);
  73. for (let j = 0; j < CONFIG.ADMINS.length; j++) {
  74. client.chatMessage(CONFIG.ADMINS[j], "User #" + Object.keys(userMsgs)[i] + " has been removed for spamming. To block him use !block [STEAMID64]");
  75. }
  76. }
  77. }
  78. userMsgs = {};
  79. }, 1000);
  80.  
  81. client.logOn({
  82. accountName: CONFIG.USERNAME,
  83. password: CONFIG.PASSWORD,
  84. twoFactorCode: SteamTotp.getAuthCode(CONFIG.SHAREDSECRET),
  85. rememberPassword: true
  86. });
  87.  
  88. client.on("loggedOn", (details, parental) => {
  89. client.getPersonas([client.steamID], (personas) => {
  90. console.log("## Logged in as #" + client.steamID + " (" + personas[client.steamID].player_name + ")");
  91. });
  92. client.setPersona(1);
  93. });
  94.  
  95. client.on("webSession", (sessionID, cookies) => {
  96. manager.setCookies(cookies, (ERR) => {
  97. if (ERR) {
  98. console.log("## An error occurred while setting cookies.");
  99. } else {
  100. console.log("## Websession created and cookies set.");
  101. }
  102. });
  103. community.setCookies(cookies);
  104. community.startConfirmationChecker(10000, CONFIG.IDENTITYSECRET);
  105. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  106. console.log("DEBUG#INVLOADED");
  107. if (!ERR) {
  108. let s = DATA;
  109. Utils.getSets(s, allCards, (ERR, DATA) => {
  110. console.log("DEBUG#SETSLOADED");
  111. if (!ERR) {
  112. botSets = DATA;
  113. console.log("## Bot's sets loaded.");
  114. let botNSets = 0;
  115. for (let i = 0; i < Object.keys(botSets).length; i++) {
  116. botNSets += botSets[Object.keys(botSets)[i]].length;
  117. }
  118. totalBotSets = botNSets;
  119. let playThis = CONFIG.PLAYGAMES;
  120. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  121. playThis[0] = parseString(playThis[0], totalBotSets);
  122. }
  123. client.gamesPlayed(playThis);
  124. } else {
  125. console.log("## An error occurred while getting bot sets: " + ERR);
  126. process.exit();
  127. }
  128. });
  129. } else {
  130. console.log("## An error occurred while getting bot inventory: " + ERR);
  131. }
  132. });
  133. });
  134.  
  135. community.on("sessionExpired", (ERR) => {
  136. console.log("## Session Expired. Relogging.");
  137. client.webLogOn();
  138. });
  139.  
  140. client.on("friendMessage", (SENDER, MSG) => {
  141. if (userLogs[SENDER.getSteamID64()]) {
  142. userLogs[SENDER.getSteamID64()].push(MSG);
  143. } else {
  144. userLogs[SENDER.getSteamID64()] = [];
  145. userLogs[SENDER.getSteamID64()].push(MSG);
  146. }
  147. fs.writeFile("./ChatLogs/UserLogs/" + SENDER.getSteamID64() + "-log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".json", JSON.stringify({logs: userLogs[SENDER.getSteamID64()]}), (ERR) => {
  148. if (ERR) {
  149. console.log("## An error occurred while writing UserLogs file: " + ERR);
  150. }
  151. });
  152. chatLogs += SENDER.getSteamID64() + " : " + MSG + "\n";
  153. fs.writeFile("./ChatLogs/FullLogs/log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".txt", chatLogs, (ERR) => {
  154. if (ERR) {
  155. console.log("## An error occurred while writing FullLogs file: " + ERR);
  156. }
  157. });
  158. if (Object.keys(users).indexOf(SENDER.getSteamID64()) < 0) {
  159. users[SENDER.getSteamID64()] = {};
  160. users[SENDER.getSteamID64()].idleforhours = 0;
  161. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  162. if (ERR) {
  163. console.log("## An error occurred while writing UserData file: " + ERR);
  164. }
  165. });
  166. } else {
  167. users[SENDER.getSteamID64()].idleforhours = 0;
  168. }
  169. if (userMsgs[SENDER.getSteamID64()]) {
  170. userMsgs[SENDER.getSteamID64()]++;
  171. } else {
  172. userMsgs[SENDER.getSteamID64()] = 1;
  173. }
  174. if (MSG.toUpperCase().indexOf("!LEVEL") >= 0) {
  175. let n = parseInt(MSG.toUpperCase().replace("!LEVEL ", ""));
  176. if (!isNaN(n) && parseInt(n) > 0) {
  177. if (n <= CONFIG.MESSAGES.MAXLEVEL) {
  178. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA, CURRENTLEVEL, XPNEEDED) => {
  179. if (!ERR) {
  180. if (DATA) {
  181. if (n > CURRENTLEVEL) {
  182. let s = 0,
  183. l = 0;
  184. for (let i = 0; i < (n - CURRENTLEVEL); i++) {
  185. s += parseInt((CURRENTLEVEL + l) / 10) + 1;
  186. l++;
  187. }
  188. 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.CSGO.buy_sets_by_one * 100) / 100 + " keys.");
  189. } else {
  190. client.chatMessage(SENDER, "Please provide a valid level.");
  191. }
  192. } else {
  193. client.chatMessage(SENDER, "Your level could not be retrieved. Make sure your Steam Profile is public and try again.");
  194. }
  195. } else {
  196. console.log("## An error occurred while getting badge data: " + ERR);
  197. client.chatMessage(SENDER, "An error occurred while loading your badges. Please try again later.");
  198. }
  199. });
  200. } else {
  201. client.chatMessage(SENDER, "Please try a lower level.");
  202. }
  203. } else {
  204. client.chatMessage(SENDER, "Please provide a valid level.");
  205. }
  206. }
  207. else if (MSG.toUpperCase() === "!COMMANDS") {
  208. client.chatMessage(SENDER, "\nAvalible commands:" +
  209. "\n!owner - Provides my owners profile, please add him if you have any problems!" +
  210. "\n!rate - shows the current prices of the bot"+
  211. "\n\n!level [your dream level] - Automatically calculates how many sets and how many items it will require to get to your desired level" +
  212. "\n!check - Show how many sets the bot has available and how much you can craft" +
  213. "\n\n!buy [amount of CS:GO keys] - use to buy that amount of CS:GO keys for sets you dont have" +
  214. "\n!buypubg [amount of pubg keys] - use to buy the amount of pubg key for sets you dont have" +
  215. "\n!buytf2 [amount of Tf keys] - use to buy that amount of tf keys for sets you dont have" +
  216. "\n!buygems !buygems [amount of sets] - use to buy that amount of sets for gems" +
  217. "\n\n!csgobuyone [amount of CS:GO keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate" +
  218. "\n!pubgbuyone [amount of PUBG keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate" +
  219. "\n!tfbuyone [amount of TF2 keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate" +
  220. "\n!gemsbuyone [amount of sets] - use this if you are a badge collector. sames as !csgobuyone , buy you pay with gems!" +
  221. "\n\n!csgobuyany [amount of CS:GO keys] - use to buy that amount of CS:GO keys for any sets, following the current BOT rate" +
  222. "\n!pubgbuyany [amount of PUBG keys] - use to buy that amount of PUBG keys for any sets, following the current BOT rate" +
  223. "\n!tfbuyany [amount of TF2 keys] - use to buy that amount of TF2 keys for any sets, following the current BOT rate" +
  224. "\n!gemsbuyany [amount of sets] - use to buy that amount of any sets for gems, following the current BOT rate" +
  225. "\n\n!sell [amount of CS:GO keys] - use to sell your sets for CS:GO Key(s)" +
  226. "\n!sellpubg [amount of PUBG keys] - use to sell your sets for PUBG Key(s)" +
  227. "\n!sellgems [amount of sets] - use to sell your sets for Gems" +
  228. "\n!selltf [amount of TF2 keys] - use to sell your sets for TF2 Key(s)" +
  229. "\n!sellcheck [amount of CS:GO keys] - use to check information about sets you can sell"
  230. );
  231. }
  232. else if (MSG.toUpperCase().indexOf("!CHECKBUYONE") >= 0) {
  233. client.chatMessage(SENDER, "Loading badges...");
  234. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  235. if (!ERR) {
  236. let b = {}; // List with badges that CAN still be crafted
  237. if (DATA) {
  238. for (let i = 0; i < Object.keys(DATA).length; i++) {
  239. if (DATA[Object.keys(DATA)[i]] < 6) {
  240. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  241. }
  242. }
  243. } else {
  244. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  245. }
  246. // console.log(b);
  247. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  248. // 1: GET BOTS CARDS. DONE
  249. // 2: GET PLAYER's BADGES. DONE
  250. // 3: MAGIC
  251. let hisMaxSets = 0,
  252. botNSets = 0;
  253. // Loop for sets he has partially completed
  254. for (let i = 0; i < Object.keys(b).length; i++) {
  255. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  256. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  257. }
  258. }
  259. // Loop for sets he has never crafted
  260. for (let i = 0; i < Object.keys(botSets).length; i++) {
  261. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  262. if (botSets[Object.keys(botSets)[i]].length >= 1) {
  263. hisMaxSets += 1;
  264. }
  265. }
  266. botNSets += botSets[Object.keys(botSets)[i]].length;
  267. }
  268. totalBotSets = botNSets;
  269. let playThis = CONFIG.PLAYGAMES;
  270. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  271. playThis[0] = parseString(playThis[0], totalBotSets);
  272. }
  273. client.gamesPlayed(playThis);
  274. 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.CSGO.buy_sets_by_one * 100) / 100 + " keys.");
  275. } else {
  276. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  277. console.log("An error occurred while getting badges: " + ERR);
  278. }
  279. });
  280. }
  281. else if (MSG.toUpperCase().indexOf("!SELLCHECK") >= 0) {
  282. let n = parseInt(MSG.toUpperCase().replace("!SELLCHECK ", ""));
  283. client.chatMessage(SENDER, "Loading inventory...");
  284. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  285. console.log("DEBUG#INVLOADED");
  286. if (!ERR) {
  287. let s = DATA;
  288. Utils.getSets(s, allCards, (ERR, DATA) => {
  289. console.log("DEBUG#SETSLOADED");
  290. if (!ERR) {
  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. // Loop for sets he has never crafted
  300. for (let i = 0; i < Object.keys(DATA).length; i++) {
  301. if (DATA[Object.keys(DATA)[i]].length >= 5) {
  302. hisMaxSets += 5;
  303. } else {
  304. hisMaxSets += DATA[Object.keys(DATA)[i]].length;
  305. }
  306. botNSets += DATA[Object.keys(DATA)[i]].length;
  307. }
  308. totalBotSets = botNSets;
  309. let playThis = CONFIG.PLAYGAMES;
  310. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  311. playThis[0] = parseString(playThis[0], totalBotSets);
  312. }
  313. if (botNSets === 0) {
  314. client.chatMessage(SENDER, "You currently don't have any available set which the bot can buy.");
  315. }
  316. else {
  317. client.gamesPlayed(playThis);
  318. client.chatMessage(SENDER, "You currently have " + botNSets + " set(s) available which the bot can buy. " +
  319. "\r\nFor all of them the bot will pay you:" +
  320. "\r\n" + parseInt(botNSets / CONFIG.CARDS.CSGO.give_one_for * 100) / 100 + " CS:GO Key(s) or" +
  321. "\r\n" + parseInt(botNSets / CONFIG.CARDS.PUBG.give_one_for * 100) / 100 + " PUBG Key(s) or" +
  322. "\r\n" + parseInt(botNSets / CONFIG.CARDS.TF2.give_one_for * 100) / 100 + " TF2 Key(s) or" +
  323. "\r\n" + parseInt(botNSets * CONFIG.CARDS.GEMS.give_one_set_for * 100) / 100 + " Gems."
  324. );
  325. }
  326. } else {
  327. console.log("## An error occurred while getting user sets: " + ERR);
  328. }
  329. });
  330. } else {
  331. console.log("## An error occurred while getting user inventory: " + ERR);
  332. }
  333. });
  334. }
  335.  
  336. else if (MSG.toUpperCase().indexOf("!CHECK") >= 0) {
  337. let n = parseInt(MSG.toUpperCase().replace("!CHECK ", ""));
  338. if (!isNaN(n) && parseInt(n) > 0) {
  339. client.chatMessage(SENDER, "\n\nThe currently prices are:" +
  340. "\r\nWith " + n + " CS:GO Key(s) you can get " + n * CONFIG.CARDS.CSGO.buy_sets_by_one + " set(s)." +
  341. "\r\nWith " + n + " PUBG Key(s) you can get " + n * CONFIG.CARDS.PUBG.buy_sets_by_one + " set(s)." +
  342. "\r\nWith " + n + " TF2 Key(s) you can get " + n * CONFIG.CARDS.TF2.buy_sets_by_one + " set(s)." +
  343. "\r\n" + n + " set(s) you can get for " + n * CONFIG.CARDS.GEMS.buy_one_set_for + " Gems." +
  344. "\r\n" +
  345. "\r\nAlso, we're buying sets:" +
  346. "\r\nFor " + n * CONFIG.CARDS.CSGO.give_one_for + " set(s) you can get " + n + " CSGO Key(s)." +
  347. "\r\nFor " + n * CONFIG.CARDS.PUBG.give_one_for + " set(s) you can get " + n + " PUBG Key(s)." +
  348. "\r\nFor " + n * CONFIG.CARDS.TF2.give_one_for + " set(s) you can get " + n + " TF2 Key{s)." +
  349. "\r\nFor " + n * CONFIG.CARDS.GEMS.give_one_set_for + " Gems you can get " + n + " Set{s)."
  350. );
  351. } else {
  352. if (Object.keys(botSets).length > 0) {
  353. client.chatMessage(SENDER, "Loading badges...");
  354. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  355. if (!ERR) {
  356. let b = {}; // List with badges that CAN still be crafted
  357. if (DATA) {
  358. for (let i = 0; i < Object.keys(DATA).length; i++) {
  359. if (DATA[Object.keys(DATA)[i]] < 6) {
  360. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  361. }
  362. }
  363. } else {
  364. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  365. }
  366. // console.log(b);
  367. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  368. // 1: GET BOTS CARDS. DONE
  369. // 2: GET PLAYER's BADGES. DONE
  370. // 3: MAGIC
  371. let hisMaxSets = 0,
  372. botNSets = 0;
  373. // Loop for sets he has partially completed
  374. for (let i = 0; i < Object.keys(b).length; i++) {
  375. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  376. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  377. }
  378. }
  379. // Loop for sets he has never crafted
  380. for (let i = 0; i < Object.keys(botSets).length; i++) {
  381. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  382. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  383. hisMaxSets += 5;
  384. } else {
  385. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  386. }
  387. }
  388. botNSets += botSets[Object.keys(botSets)[i]].length;
  389. }
  390. totalBotSets = botNSets;
  391. let playThis = CONFIG.PLAYGAMES;
  392. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  393. playThis[0] = parseString(playThis[0], totalBotSets);
  394. }
  395. client.gamesPlayed(playThis);
  396. client.chatMessage(SENDER, "There are currently " + hisMaxSets + "/" + botNSets + " sets available which you have not fully crafted yet." +
  397. "Buying all of them will cost you:" +
  398. "\r\n" + parseInt(hisMaxSets / CONFIG.CARDS.CSGO.buy_sets_by_one * 100) / 100 + " CSGO Key(s) or" +
  399. "\r\n" + parseInt(hisMaxSets / CONFIG.CARDS.PUBG.buy_sets_by_one * 100) / 100 + " PUBG Key(s) or" +
  400. "\r\n" + parseInt(hisMaxSets / CONFIG.CARDS.TF2.buy_sets_by_one * 100) / 100 + " TF2 Key(s) or" +
  401. "\r\n" + parseInt(hisMaxSets * CONFIG.CARDS.GEMS.buy_one_set_for * 100) / 100 + " Gems.");
  402. } else {
  403. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  404. console.log("An error occurred while getting badges: " + ERR);
  405. }
  406. });
  407. } else {
  408. client.chatMessage(SENDER, "Please try again later.");
  409. }
  410. }
  411. }
  412.  
  413. else if (MSG.toUpperCase().indexOf("!RATE") >= 0) {
  414. client.chatMessage(SENDER, "The rates are as following:\n"+CONFIG.CARDS.CSGO.buy_sets_by_one+" sets for 1 cs:go key\n"+CONFIG.CARDS.TF2.buy_sets_by_one+" sets for 1 tf key\n"+CONFIG.CARDS.PUBG.buy_sets_by_one+" sets for 1 pubg key\n One set for "+CONFIG.CARDS.GEMS.buy_one_set_for+ " gems\n Use the command !check for more detailed information" );
  415. }
  416.  
  417. else if (MSG.toUpperCase().indexOf("!SELLTF") >= 0) {
  418. if (botSets) {
  419. let n = parseInt(MSG.toUpperCase().replace("!SELLTF ", "")),
  420. amountofsets = n * CONFIG.CARDS.TF2.give_one_for;
  421. if (!isNaN(n) && parseInt(n) > 0) {
  422. if (n <= CONFIG.MESSAGES.MAXSELL) {
  423. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  424. let botKeys = [],
  425. t = manager.createOffer(SENDER.getSteamID64());
  426. t.getUserDetails((ERR, ME, THEM) => {
  427. if (ERR) {
  428. console.log("## An error occurred while getting trade holds: " + ERR);
  429. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  430. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  431. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.TFGAME, 2, true, (ERR, INV, CURR) => {
  432. if (ERR) {
  433. console.log("## An error occurred while getting bot inventory: " + ERR);
  434. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  435. } else {
  436. for (let i = 0; i < INV.length; i++) {
  437. if (botKeys.length < n && CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  438. botKeys.push(INV[i]);
  439. }
  440. }
  441. if (botKeys.length !== n) {
  442. client.chatMessage(SENDER, "The bot does not have enough keys.");
  443. } else {
  444. let amountofB = amountofsets;
  445. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  446. if (!ERR) {
  447. let s = DATA;
  448. Utils.getSets(s, allCards, (ERR, DDATA) => {
  449. if (!ERR) {
  450. sortSetsByAmountB(s, (DATA) => {
  451. let setsSent = {};
  452. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  453. console.log(setsSent);
  454. console.log(DATA[i]);
  455. if (DDATA[DATA[i]]) {
  456. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  457. if (amountofB > 0) {
  458. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.TF2.MAXSETSELL) || !setsSent[DATA[i]]) {
  459. t.addTheirItems(DDATA[DATA[i]][j]);
  460. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  461. amountofB--;
  462. if (!setsSent[DATA[i]]) {
  463. setsSent[DATA[i]] = 1;
  464. } else {
  465. setsSent[DATA[i]] += 1;
  466. }
  467. } else {
  468. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  469. continue firsttLoop;
  470. }
  471. } else {
  472. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  473. continue firsttLoop;
  474. }
  475. }
  476. } else {
  477. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  478. continue firsttLoop;
  479. }
  480. }
  481. });
  482. if (amountofB > 0) {
  483. client.chatMessage(SENDER, "You do not have enough sets, (this bot only accepts " + CONFIG.CARDS.TF2.MAXSETSELL + " sets per set type at a time). Please try again later.");
  484. } else {
  485. console.log("DEBUG#SENDING");
  486. t.addMyItems(botKeys);
  487. t.data("commandused", "Sell");
  488. t.data("amountofsets", amountofsets.toString());
  489. t.data("amountofkeys", n);
  490. t.send((ERR, STATUS) => {
  491. if (ERR) {
  492. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  493. console.log("## An error occurred while sending trade: " + ERR);
  494. } else {
  495. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  496. console.log("## Trade offer sent!");
  497. }
  498. });
  499. }
  500. } else {
  501. console.log("## An error occurred while getting bot sets: " + ERR);
  502. }
  503. });
  504. } else {
  505. console.log("## An error occurred while getting user inventory: " + ERR);
  506. }
  507. });
  508. }
  509. }
  510. });
  511. } else {
  512. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  513. }
  514. });
  515. } else {
  516. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  517. }
  518. } else {
  519. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  520. }
  521. } else {
  522. client.chatMessage(SENDER, "Please try again later.");
  523. }
  524. }
  525. else if (MSG.toUpperCase().indexOf("!SELLPUBG") >= 0) {
  526. if (botSets) {
  527. let n = parseInt(MSG.toUpperCase().replace("!SELLPUBG ", "")),
  528. amountofsets = n * CONFIG.CARDS.PUBG.give_one_for;
  529. if (!isNaN(n) && parseInt(n) > 0) {
  530. if (n <= CONFIG.MESSAGES.MAXSELL) {
  531. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  532. let botKeys = [],
  533. t = manager.createOffer(SENDER.getSteamID64());
  534. t.getUserDetails((ERR, ME, THEM) => {
  535. if (ERR) {
  536. console.log("## An error occurred while getting trade holds: " + ERR);
  537. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  538. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  539. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.PUBGAME, 2, true, (ERR, INV, CURR) => {
  540. if (ERR) {
  541. console.log("## An error occurred while getting bot inventory: " + ERR);
  542. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  543. } else {
  544. for (let i = 0; i < INV.length; i++) {
  545. if (botKeys.length < n && CONFIG.PUBGACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  546. botKeys.push(INV[i]);
  547. }
  548. }
  549. if (botKeys.length !== n) {
  550. client.chatMessage(SENDER, "The bot does not have enough keys.");
  551. } else {
  552. let amountofB = amountofsets;
  553. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  554. if (!ERR) {
  555. let s = DATA;
  556. Utils.getSets(s, allCards, (ERR, DDATA) => {
  557. if (!ERR) {
  558. sortSetsByAmountB(s, (DATA) => {
  559. let setsSent = {};
  560. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  561. console.log(setsSent);
  562. console.log(DATA[i]);
  563. if (DDATA[DATA[i]]) {
  564. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  565. if (amountofB > 0) {
  566. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.PUBG.MAXSETSELL) || !setsSent[DATA[i]]) {
  567. t.addTheirItems(DDATA[DATA[i]][j]);
  568. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  569. amountofB--;
  570. if (!setsSent[DATA[i]]) {
  571. setsSent[DATA[i]] = 1;
  572. } else {
  573. setsSent[DATA[i]] += 1;
  574. }
  575. } else {
  576. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  577. continue firsttLoop;
  578. }
  579. } else {
  580. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  581. continue firsttLoop;
  582. }
  583. }
  584. } else {
  585. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  586. continue firsttLoop;
  587. }
  588. }
  589. });
  590. if (amountofB > 0) {
  591. client.chatMessage(SENDER, "You do not have enough sets, (this bot only accepts " + CONFIG.CARDS.PUBG.MAXSETSELL + " sets per set type at a time). Please try again later.");
  592. } else {
  593. console.log("DEBUG#SENDING");
  594. t.addMyItems(botKeys);
  595. t.data("commandused", "Sell");
  596. t.data("amountofsets", amountofsets.toString());
  597. t.data("amountofkeys", n);
  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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  604. console.log("## Trade offer sent!");
  605. }
  606. });
  607. }
  608. } else {
  609. console.log("## An error occurred while getting bot sets: " + ERR);
  610. }
  611. });
  612. } else {
  613. console.log("## An error occurred while getting user inventory: " + ERR);
  614. }
  615. });
  616. }
  617. }
  618. });
  619. } else {
  620. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  621. }
  622. });
  623. } else {
  624. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  625. }
  626. } else {
  627. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  628. }
  629. } else {
  630. client.chatMessage(SENDER, "Please try again later.");
  631. }
  632. }
  633. else if (MSG.toUpperCase().indexOf("!SELLGEMS") >= 0) {
  634. if (botSets) {
  635. let n = parseInt(MSG.toUpperCase().replace("!SELLGEMS ", "")),
  636. amountofsets = n;
  637. if (!isNaN(n) && parseInt(n) > 0) {
  638. if (n <= CONFIG.MESSAGES.MAXSELL) {
  639. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  640. let gemsAmount = 0;
  641. let botGems = [];
  642. let t = manager.createOffer(SENDER.getSteamID64());
  643. t.getUserDetails((ERR, ME, THEM) => {
  644. if (ERR) {
  645. console.log("## An error occurred while getting trade holds: " + ERR);
  646. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  647. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  648. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  649. if (ERR) {
  650. console.log("## An error occurred while getting bot inventory: " + ERR);
  651. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  652. } else {
  653. for (let i = 0; i < INV.length; i++) {
  654. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  655. gemsAmount = INV[i].amount;
  656. INV[i].amount = (n * CONFIG.CARDS.GEMS.give_one_set_for);
  657. botGems.push(INV[i]);
  658. break;
  659. }
  660. }
  661. if (gemsAmount < n) {
  662. client.chatMessage(SENDER, "The bot does not have enough Gems.");
  663. } else {
  664. let amountofB = amountofsets;
  665. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  666. if (!ERR) {
  667. let s = DATA;
  668. Utils.getSets(s, allCards, (ERR, DDATA) => {
  669. if (!ERR) {
  670. sortSetsByAmountB(s, (DATA) => {
  671. let setsSent = {};
  672. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  673. console.log(setsSent);
  674. console.log(DATA[i]);
  675. if (DDATA[DATA[i]]) {
  676. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  677. if (amountofB > 0) {
  678. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.TF2.MAXSETSELL) || !setsSent[DATA[i]]) {
  679. t.addTheirItems(DDATA[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 firsttLoop;
  690. }
  691. } else {
  692. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  693. continue firsttLoop;
  694. }
  695. }
  696. } else {
  697. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  698. continue firsttLoop;
  699. }
  700. }
  701. });
  702. if (amountofB > 0) {
  703. client.chatMessage(SENDER, "You do not have enough sets, (this bot only accepts " + CONFIG.CARDS.GEMS.MAXSETSELL + " sets per set type at a time). Please try again later.");
  704. } else {
  705. console.log("DEBUG#SENDING");
  706. t.addMyItems(botGems);
  707. t.data("commandused", "Sell");
  708. t.data("amountofsets", amountofsets.toString());
  709. t.data("amountofkeys", n);
  710. t.send((ERR, STATUS) => {
  711. if (ERR) {
  712. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  713. console.log("## An error occurred while sending trade: " + ERR);
  714. } else {
  715. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  716. console.log("## Trade offer sent!");
  717. }
  718. });
  719. }
  720. } else {
  721. console.log("## An error occurred while getting bot sets: " + ERR);
  722. }
  723. });
  724. } else {
  725. console.log("## An error occurred while getting user inventory: " + ERR);
  726. }
  727. });
  728. }
  729. }
  730. });
  731. } else {
  732. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  733. }
  734. });
  735. } else {
  736. client.chatMessage(SENDER, "Please try a lower amount of sets.");
  737. }
  738. } else {
  739. client.chatMessage(SENDER, "Please enter a valid amount of setss!");
  740. }
  741. } else {
  742. client.chatMessage(SENDER, "Please try again later.");
  743. }
  744. }
  745. else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
  746. if (botSets) {
  747. let n = parseInt(MSG.toUpperCase().replace("!SELL ", "")),
  748. amountofsets = n * CONFIG.CARDS.CSGO.give_one_for;
  749. if (!isNaN(n) && parseInt(n) > 0) {
  750. if (n <= CONFIG.MESSAGES.MAXSELL) {
  751. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  752. let botKeys = [],
  753. t = manager.createOffer(SENDER.getSteamID64());
  754. t.getUserDetails((ERR, ME, THEM) => {
  755. if (ERR) {
  756. console.log("## An error occurred while getting trade holds: " + ERR);
  757. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  758. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  759. manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.CSGOGAME, 2, true, (ERR, INV, CURR) => {
  760. if (ERR) {
  761. console.log("## An error occurred while getting bot inventory: " + ERR);
  762. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  763. } else {
  764. for (let i = 0; i < INV.length; i++) {
  765. if (botKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  766. botKeys.push(INV[i]);
  767. }
  768. }
  769. if (botKeys.length !== n) {
  770. client.chatMessage(SENDER, "The bot does not have enough keys.");
  771. } else {
  772. let amountofB = amountofsets;
  773. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  774. if (!ERR) {
  775. let s = DATA;
  776. Utils.getSets(s, allCards, (ERR, DDATA) => {
  777. if (!ERR) {
  778. sortSetsByAmountB(s, (DATA) => {
  779. let setsSent = {};
  780. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  781. console.log(setsSent);
  782. console.log(DATA[i]);
  783. if (DDATA[DATA[i]]) {
  784. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  785. if (amountofB > 0) {
  786. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.CSGO.MAXSETSELL) || !setsSent[DATA[i]]) {
  787. t.addTheirItems(DDATA[DATA[i]][j]);
  788. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  789. amountofB--;
  790. if (!setsSent[DATA[i]]) {
  791. setsSent[DATA[i]] = 1;
  792. } else {
  793. setsSent[DATA[i]] += 1;
  794. }
  795. } else {
  796. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  797. continue firsttLoop;
  798. }
  799. } else {
  800. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  801. continue firsttLoop;
  802. }
  803. }
  804. } else {
  805. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  806. continue firsttLoop;
  807. }
  808. }
  809. });
  810. if (amountofB > 0) {
  811. client.chatMessage(SENDER, "You do not have enough sets, (this bot only accepts " + CONFIG.CARDS.CSGO.MAXSETSELL + " sets per set type at a time). Please try again later.");
  812. } else {
  813. console.log("DEBUG#SENDING");
  814. t.addMyItems(botKeys);
  815. t.data("commandused", "Sell");
  816. t.data("amountofsets", amountofsets.toString());
  817. t.data("amountofkeys", n);
  818. t.send((ERR, STATUS) => {
  819. if (ERR) {
  820. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  821. console.log("## An error occurred while sending trade: " + ERR);
  822. } else {
  823. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  824. console.log("## Trade offer sent!");
  825. }
  826. });
  827. }
  828. } else {
  829. console.log("## An error occurred while getting bot sets: " + ERR);
  830. }
  831. });
  832. } else {
  833. console.log("## An error occurred while getting user inventory: " + ERR);
  834. }
  835. });
  836. }
  837. }
  838. });
  839. } else {
  840. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  841. }
  842. });
  843. } else {
  844. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  845. }
  846. } else {
  847. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  848. }
  849. } else {
  850. client.chatMessage(SENDER, "Please try again later.");
  851. }
  852. }
  853.  
  854. else if (MSG.toUpperCase().indexOf("!BUYTF2") >= 0) {
  855. if (botSets) {
  856. let n = MSG.toUpperCase().replace("!BUYTF2 ", "");
  857. let amountofsets = parseInt(n) * CONFIG.CARDS.TF2.buy_sets_by_one;
  858. if (!isNaN(n) && parseInt(n) > 0) {
  859. if (n <= CONFIG.MESSAGES.MAXBUY) {
  860. let t = manager.createOffer(SENDER.getSteamID64());
  861. t.getUserDetails((ERR, ME, THEM) => {
  862. if (ERR) {
  863. console.log("## An error occurred while getting trade holds: " + ERR);
  864. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  865. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  866. n = parseInt(n);
  867. let theirKeys = [];
  868. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  869. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 2, true, (ERR, INV, CURR) => {
  870. if (ERR) {
  871. console.log("## An error occurred while getting inventory: " + ERR);
  872. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  873. } else {
  874. console.log("DEBUG#INV LOADED");
  875. if (!ERR) {
  876. console.log("DEBUG#INV LOADED NOERR");
  877. for (let i = 0; i < INV.length; i++) {
  878. if (theirKeys.length < n && CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  879. theirKeys.push(INV[i]);
  880. }
  881. }
  882. if (theirKeys.length !== n) {
  883. client.chatMessage(SENDER, "You do not have enough keys.");
  884. } else {
  885. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  886. if (!ERR) {
  887. console.log("DEBUG#BADGE LOADED");
  888. if (!ERR) {
  889. let b = {}; // List with badges that CAN still be crafted
  890. if (DATA) {
  891. for (let i = 0; i < Object.keys(DATA).length; i++) {
  892. if (DATA[Object.keys(DATA)[i]] < 6) {
  893. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  894. }
  895. }
  896. } else {
  897. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  898. }
  899. console.log(DATA);
  900. console.log(b);
  901. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  902. // 1: GET BOTS CARDS. DONE
  903. // 2: GET PLAYER's BADGES. DONE
  904. // 3: MAGIC
  905. let hisMaxSets = 0,
  906. botNSets = 0;
  907. // Loop for sets he has partially completed
  908. for (let i = 0; i < Object.keys(b).length; i++) {
  909. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  910. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  911. }
  912. }
  913. console.log("DEBUG#LOOP 1 DONE");
  914. // Loop for sets he has never crafted
  915. for (let i = 0; i < Object.keys(botSets).length; i++) {
  916. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  917. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  918. hisMaxSets += 5;
  919. } else {
  920. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  921. }
  922. }
  923. botNSets += botSets[Object.keys(botSets)[i]].length;
  924. }
  925. console.log("DEBUG#LOOP 2 DONE");
  926. // HERE
  927. if (amountofsets <= hisMaxSets) {
  928. hisMaxSets = amountofsets;
  929. console.log("DEBUG#TRADE CREATED");
  930. sortSetsByAmount(botSets, (DATA) => {
  931. console.log("DEBUG#" + DATA);
  932. console.log("DEBUG#SETS SORTED");
  933. firstLoop: for (let i = 0; i < DATA.length; i++) {
  934. if (b[DATA[i]] === 0) {
  935. continue firstLoop;
  936. } else {
  937. console.log("DEBUG#" + i);
  938. console.log("DEBUG#FOR LOOP ITEMS");
  939. if (hisMaxSets > 0) {
  940. console.log("DEBUG#MAXSETSMORETHAN1");
  941. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  942. // BOT HAS ENOUGH SETS OF THIS KIND
  943. console.log("DEBUG#LOOP #1");
  944. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  945. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  946. console.log("DEBUG#LOOP #1: ITEM ADD");
  947. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  948. t.addMyItems(botSets[DATA[i]][j]);
  949. hisMaxSets--;
  950. console.log(hisMaxSets);
  951. } else {
  952. console.log("DEBUG#LOOP #1: RETURN");
  953. continue firstLoop;
  954. }
  955. }
  956. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  957. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  958. console.log("DEBUG#LOOP #1 CONTINUE");
  959. continue; // *
  960. } 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
  961. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  962. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  963. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  964. t.addMyItems(botSets[DATA[i]][j]);
  965. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  966. hisMaxSets--;
  967. } else {
  968. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  969. continue firstLoop;
  970. }
  971. }
  972. }
  973. else if (hisMaxSets < 5) {
  974. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  975. console.log("DEBUG#LOOP #2");
  976. tLoop: for (let j = 0; j !== hisMaxSets; j++) {
  977. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  978. t.addMyItems(botSets[DATA[i]][j]);
  979. console.log("DEBUG#LOOP #2: ITEM ADD");
  980. hisMaxSets--;
  981. console.log(hisMaxSets);
  982. } else {
  983. console.log("DEBUG#LOOP #2: RETURN");
  984. continue firstLoop;
  985. }
  986. }
  987. } else {
  988. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  989. console.log("DEBUG#LOOP #2");
  990. xLoop: for (let j = 0; j !== 5; j++ && hisMaxSets > 0) {
  991. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  992. t.addMyItems(botSets[DATA[i]][j]);
  993. console.log("DEBUG#LOOP #2: ITEM ADD");
  994. hisMaxSets--;
  995. console.log(hisMaxSets);
  996. } else {
  997. console.log("DEBUG#LOOP #2: RETURN");
  998. continue firstLoop;
  999. }
  1000. }
  1001. }
  1002. } else {
  1003. console.log("DEBUG#RETURN");
  1004. break firstLoop;
  1005. }
  1006. }
  1007. }
  1008. if (hisMaxSets > 0) {
  1009. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1010. } else {
  1011. console.log("DEBUG#SENDING");
  1012. t.addTheirItems(theirKeys);
  1013. t.data("commandused", "Buy");
  1014. t.data("amountofkeys", n);
  1015. t.data("amountofsets", amountofsets.toString());
  1016. t.send((ERR, STATUS) => {
  1017. if (ERR) {
  1018. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1019. console.log("## An error occurred while sending trade: " + ERR);
  1020. } else {
  1021. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  1022. console.log("## Trade offer sent");
  1023. }
  1024. });
  1025. }
  1026. });
  1027. } else {
  1028. 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.");
  1029. }
  1030. // TO HERE
  1031. } else {
  1032. console.log("An error occurred while getting badges: " + ERR);
  1033. }
  1034. } else {
  1035. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1036. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1037. }
  1038. });
  1039. }
  1040. } else {
  1041. console.log("## An error occurred while getting inventory: " + ERR);
  1042. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1043. }
  1044. }
  1045. });
  1046. } else {
  1047. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1048. }
  1049. });
  1050. } else {
  1051. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1052. }
  1053. } else {
  1054. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  1055. }
  1056. } else {
  1057. client.chatMessage(SENDER, "Please try again later.");
  1058. }
  1059. }
  1060. else if (MSG.toUpperCase().indexOf("!BUYPUBG") >= 0) {
  1061. if (botSets) {
  1062. let n = MSG.toUpperCase().replace("!BUYPUBG ", "");
  1063. let amountofsets = parseInt(n) * CONFIG.CARDS.PUBG.buy_sets_by_one;
  1064. if (!isNaN(n) && parseInt(n) > 0) {
  1065. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1066. let t = manager.createOffer(SENDER.getSteamID64());
  1067. t.getUserDetails((ERR, ME, THEM) => {
  1068. if (ERR) {
  1069. console.log("## An error occurred while getting trade holds: " + ERR);
  1070. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  1071. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  1072. n = parseInt(n);
  1073. let theirKeys = [];
  1074. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  1075. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGAME, 2, true, (ERR, INV, CURR) => {
  1076. if (ERR) {
  1077. console.log("## An error occurred while getting inventory: " + ERR);
  1078. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1079. } else {
  1080. console.log("DEBUG#INV LOADED");
  1081. if (!ERR) {
  1082. console.log("DEBUG#INV LOADED NOERR");
  1083. for (let i = 0; i < INV.length; i++) {
  1084. if (theirKeys.length < n && CONFIG.PUBGACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1085. theirKeys.push(INV[i]);
  1086. }
  1087. }
  1088. if (theirKeys.length !== n) {
  1089. client.chatMessage(SENDER, "You do not have enough keys.");
  1090. } else {
  1091. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1092. if (!ERR) {
  1093. console.log("DEBUG#BADGE LOADED");
  1094. if (!ERR) {
  1095. let b = {}; // List with badges that CAN still be crafted
  1096. if (DATA) {
  1097. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1098. if (DATA[Object.keys(DATA)[i]] < 6) {
  1099. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1100. }
  1101. }
  1102. } else {
  1103. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1104. }
  1105. console.log(DATA);
  1106. console.log(b);
  1107. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1108. // 1: GET BOTS CARDS. DONE
  1109. // 2: GET PLAYER's BADGES. DONE
  1110. // 3: MAGIC
  1111. let hisMaxSets = 0,
  1112. botNSets = 0;
  1113. // Loop for sets he has partially completed
  1114. for (let i = 0; i < Object.keys(b).length; i++) {
  1115. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1116. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1117. }
  1118. }
  1119. console.log("DEBUG#LOOP 1 DONE");
  1120. // Loop for sets he has never crafted
  1121. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1122. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1123. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1124. hisMaxSets += 5;
  1125. } else {
  1126. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1127. }
  1128. }
  1129. botNSets += botSets[Object.keys(botSets)[i]].length;
  1130. }
  1131. console.log("DEBUG#LOOP 2 DONE");
  1132. // HERE
  1133. if (amountofsets <= hisMaxSets) {
  1134. hisMaxSets = amountofsets;
  1135. console.log("DEBUG#TRADE CREATED");
  1136. sortSetsByAmount(botSets, (DATA) => {
  1137. console.log("DEBUG#" + DATA);
  1138. console.log("DEBUG#SETS SORTED");
  1139. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1140. if (b[DATA[i]] === 0) {
  1141. continue firstLoop;
  1142. } else {
  1143. console.log("DEBUG#" + i);
  1144. console.log("DEBUG#FOR LOOP ITEMS");
  1145. if (hisMaxSets > 0) {
  1146. console.log("DEBUG#MAXSETSMORETHAN1");
  1147. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1148. // BOT HAS ENOUGH SETS OF THIS KIND
  1149. console.log("DEBUG#LOOP #1");
  1150. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1151. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1152. console.log("DEBUG#LOOP #1: ITEM ADD");
  1153. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1154. t.addMyItems(botSets[DATA[i]][j]);
  1155. hisMaxSets--;
  1156. console.log(hisMaxSets);
  1157. } else {
  1158. console.log("DEBUG#LOOP #1: RETURN");
  1159. continue firstLoop;
  1160. }
  1161. }
  1162. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1163. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1164. console.log("DEBUG#LOOP #1 CONTINUE");
  1165. continue; // *
  1166. } 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
  1167. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1168. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1169. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1170. t.addMyItems(botSets[DATA[i]][j]);
  1171. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1172. hisMaxSets--;
  1173. } else {
  1174. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1175. continue firstLoop;
  1176. }
  1177. }
  1178. }
  1179. else if (hisMaxSets < 5) {
  1180. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1181. console.log("DEBUG#LOOP #2");
  1182. tLoop: for (let j = 0; j !== hisMaxSets; j++) {
  1183. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1184. t.addMyItems(botSets[DATA[i]][j]);
  1185. console.log("DEBUG#LOOP #2: ITEM ADD");
  1186. hisMaxSets--;
  1187. console.log(hisMaxSets);
  1188. } else {
  1189. console.log("DEBUG#LOOP #2: RETURN");
  1190. continue firstLoop;
  1191. }
  1192. }
  1193. } else {
  1194. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1195. console.log("DEBUG#LOOP #2");
  1196. xLoop: for (let j = 0; j !== 5; j++ && hisMaxSets > 0) {
  1197. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1198. t.addMyItems(botSets[DATA[i]][j]);
  1199. console.log("DEBUG#LOOP #2: ITEM ADD");
  1200. hisMaxSets--;
  1201. console.log(hisMaxSets);
  1202. } else {
  1203. console.log("DEBUG#LOOP #2: RETURN");
  1204. continue firstLoop;
  1205. }
  1206. }
  1207. }
  1208. } else {
  1209. console.log("DEBUG#RETURN");
  1210. break firstLoop;
  1211. }
  1212. }
  1213. }
  1214. if (hisMaxSets > 0) {
  1215. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1216. } else {
  1217. console.log("DEBUG#SENDING");
  1218. t.addTheirItems(theirKeys);
  1219. t.data("commandused", "Buy");
  1220. t.data("amountofkeys", n);
  1221. t.data("amountofsets", amountofsets.toString());
  1222. t.send((ERR, STATUS) => {
  1223. if (ERR) {
  1224. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1225. console.log("## An error occurred while sending trade: " + ERR);
  1226. } else {
  1227. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  1228. console.log("## Trade offer sent");
  1229. }
  1230. });
  1231. }
  1232. });
  1233. } else {
  1234. 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.");
  1235. }
  1236. // TO HERE
  1237. } else {
  1238. console.log("An error occurred while getting badges: " + ERR);
  1239. }
  1240. } else {
  1241. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1242. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1243. }
  1244. });
  1245. }
  1246. } else {
  1247. console.log("## An error occurred while getting inventory: " + ERR);
  1248. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1249. }
  1250. }
  1251. });
  1252. } else {
  1253. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1254. }
  1255. });
  1256. } else {
  1257. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1258. }
  1259. } else {
  1260. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  1261. }
  1262. } else {
  1263. client.chatMessage(SENDER, "Please try again later.");
  1264. }
  1265. }
  1266. else if (MSG.toUpperCase().indexOf("!BUYGEMS") >= 0) {
  1267. if (botSets) {
  1268. let n = MSG.toUpperCase().replace("!BUYGEMS ", ""),
  1269. amountofsets = parseInt(n);
  1270. if (!isNaN(n) && parseInt(n) > 0) {
  1271. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1272. let t = manager.createOffer(SENDER.getSteamID64());
  1273. t.getUserDetails((ERR, ME, THEM) => {
  1274. if (ERR) {
  1275. console.log("## An error occurred while getting trade holds: " + ERR);
  1276. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  1277. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  1278. n = parseInt(n);
  1279. let theirGems = [];
  1280. let amountTheirGems = 0;
  1281. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  1282. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  1283. if (ERR) {
  1284. console.log("## An error occurred while getting inventory: " + ERR);
  1285. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1286. } else {
  1287. console.log("DEBUG#INV LOADED");
  1288. if (!ERR) {
  1289. console.log("DEBUG#INV LOADED NOERR");
  1290. for (let i = 0; i < INV.length; i++) {
  1291. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  1292. amountTheirGems = INV[i].amount;
  1293. INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
  1294. theirGems.push(INV[i]);
  1295. break;
  1296. }
  1297. }
  1298. if (amountTheirGems < ( n * CONFIG.CARDS.GEMS.buy_one_set_for )) {
  1299. client.chatMessage(SENDER, "You do not have enough Gems.");
  1300. } else {
  1301. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1302. if (!ERR) {
  1303. console.log("DEBUG#BADGE LOADED");
  1304. if (!ERR) {
  1305. let b = {}; // List with badges that CAN still be crafted
  1306. if (DATA) {
  1307. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1308. if (DATA[Object.keys(DATA)[i]] < 6) {
  1309. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1310. }
  1311. }
  1312. } else {
  1313. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1314. }
  1315. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1316. // 1: GET BOTS CARDS. DONE
  1317. // 2: GET PLAYER's BADGES. DONE
  1318. // 3: MAGIC
  1319. let hisMaxSets = 0,
  1320. botNSets = 0;
  1321. // Loop for sets he has partially completed
  1322. for (let i = 0; i < Object.keys(b).length; i++) {
  1323. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1324. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1325. }
  1326. }
  1327. console.log("DEBUG#LOOP 1 DONE");
  1328. // Loop for sets he has never crafted
  1329. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1330. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1331. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1332. hisMaxSets += 5;
  1333. } else {
  1334. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1335. }
  1336. }
  1337. botNSets += botSets[Object.keys(botSets)[i]].length;
  1338. }
  1339. console.log("DEBUG#LOOP 2 DONE");
  1340. // HERE
  1341. if (amountofsets <= hisMaxSets) {
  1342. hisMaxSets = amountofsets;
  1343. console.log("DEBUG#TRADE CREATED");
  1344. sortSetsByAmount(botSets, (DATA) => {
  1345. console.log("DEBUG#" + DATA);
  1346. console.log("DEBUG#SETS SORTED");
  1347. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1348. if (b[DATA[i]] === 0) {
  1349. continue firstLoop;
  1350. } else {
  1351. console.log("DEBUG#" + i);
  1352. console.log("DEBUG#FOR LOOP ITEMS");
  1353. if (hisMaxSets > 0) {
  1354. console.log("DEBUG#MAXSETSMORETHAN1");
  1355. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1356. // BOT HAS ENOUGH SETS OF THIS KIND
  1357. console.log("DEBUG#LOOP #1");
  1358. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1359. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1360. console.log("DEBUG#LOOP #1: ITEM ADD");
  1361. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1362. t.addMyItems(botSets[DATA[i]][j]);
  1363. hisMaxSets--;
  1364. console.log(hisMaxSets);
  1365. } else {
  1366. console.log("DEBUG#LOOP #1: RETURN");
  1367. continue firstLoop;
  1368. }
  1369. }
  1370. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1371. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1372. console.log("DEBUG#LOOP #1 CONTINUE");
  1373. continue; // *
  1374. } 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
  1375. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1376. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1377. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1378. t.addMyItems(botSets[DATA[i]][j]);
  1379. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1380. hisMaxSets--;
  1381. } else {
  1382. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1383. continue firstLoop;
  1384. }
  1385. }
  1386. }
  1387. else if (hisMaxSets < 5) {
  1388. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1389. console.log("DEBUG#LOOP #2");
  1390. tLoop: for (let j = 0; j !== hisMaxSets; j++) {
  1391. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1392. t.addMyItems(botSets[DATA[i]][j]);
  1393. console.log("DEBUG#LOOP #2: ITEM ADD");
  1394. hisMaxSets--;
  1395. console.log(hisMaxSets);
  1396. } else {
  1397. console.log("DEBUG#LOOP #2: RETURN");
  1398. continue firstLoop;
  1399. }
  1400. }
  1401. } else {
  1402. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1403. console.log("DEBUG#LOOP #2");
  1404. xLoop: for (let j = 0; j !== 5; j++ && hisMaxSets > 0) {
  1405. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1406. t.addMyItems(botSets[DATA[i]][j]);
  1407. console.log("DEBUG#LOOP #2: ITEM ADD");
  1408. hisMaxSets--;
  1409. console.log(hisMaxSets);
  1410. } else {
  1411. console.log("DEBUG#LOOP #2: RETURN");
  1412. continue firstLoop;
  1413. }
  1414. }
  1415. }
  1416. } else {
  1417. console.log("DEBUG#RETURN");
  1418. break firstLoop;
  1419. }
  1420. }
  1421. }
  1422. if (hisMaxSets > 0) {
  1423. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1424. } else {
  1425. console.log("DEBUG#SENDING");
  1426. t.addTheirItems(theirGems);
  1427. t.data("commandused", "Buy");
  1428. //t.data("amountofkeys", n);
  1429. //t.data("amountofsets", amountofsets.toString());
  1430. t.send((ERR, STATUS) => {
  1431. if (ERR) {
  1432. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1433. console.log("## An error occurred while sending trade: " + ERR);
  1434. } else {
  1435. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  1436. console.log("## Trade offer sent");
  1437. }
  1438. });
  1439. }
  1440. });
  1441. } else {
  1442. 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.");
  1443. }
  1444. // TO HERE
  1445. } else {
  1446. console.log("An error occurred while getting badges: " + ERR);
  1447. }
  1448. } else {
  1449. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1450. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1451. }
  1452. });
  1453. }
  1454. } else {
  1455. console.log("## An error occurred while getting inventory: " + ERR);
  1456. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1457. }
  1458. }
  1459. });
  1460. } else {
  1461. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1462. }
  1463. });
  1464. } else {
  1465. client.chatMessage(SENDER, "Please try a lower amount of sets.");
  1466. }
  1467. } else {
  1468. client.chatMessage(SENDER, "Please provide a valid amount of sets.");
  1469. }
  1470. } else {
  1471. client.chatMessage(SENDER, "Please try again later.");
  1472. }
  1473. }
  1474. else if (MSG.toUpperCase().indexOf("!BUY") >= 0) {
  1475. if (botSets) {
  1476. let n = MSG.toUpperCase().replace("!BUY ", ""),
  1477. amountofsets = parseInt(n) * CONFIG.CARDS.CSGO.buy_sets_by_one;
  1478. if (!isNaN(n) && parseInt(n) > 0) {
  1479. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1480. let t = manager.createOffer(SENDER.getSteamID64());
  1481. t.getUserDetails((ERR, ME, THEM) => {
  1482. if (ERR) {
  1483. console.log("## An error occurred while getting trade holds: " + ERR);
  1484. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  1485. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  1486. n = parseInt(n);
  1487. let theirKeys = [];
  1488. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  1489. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 2, true, (ERR, INV, CURR) => {
  1490. if (ERR) {
  1491. console.log("## An error occurred while getting inventory: " + ERR);
  1492. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1493. } else {
  1494. console.log("DEBUG#INV LOADED");
  1495. if (!ERR) {
  1496. console.log("DEBUG#INV LOADED NOERR");
  1497. for (let i = 0; i < INV.length; i++) {
  1498. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1499. theirKeys.push(INV[i]);
  1500. }
  1501. }
  1502. if (theirKeys.length !== n) {
  1503. client.chatMessage(SENDER, "You do not have enough keys.");
  1504. } else {
  1505. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1506. if (!ERR) {
  1507. console.log("DEBUG#BADGE LOADED");
  1508. if (!ERR) {
  1509. let b = {}; // List with badges that CAN still be crafted
  1510. if (DATA) {
  1511. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1512. if (DATA[Object.keys(DATA)[i]] < 6) {
  1513. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1514. }
  1515. }
  1516. } else {
  1517. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1518. }
  1519. console.log(DATA);
  1520. console.log(b);
  1521. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1522. // 1: GET BOTS CARDS. DONE
  1523. // 2: GET PLAYER's BADGES. DONE
  1524. // 3: MAGIC
  1525. let hisMaxSets = 0,
  1526. botNSets = 0;
  1527. // Loop for sets he has partially completed
  1528. for (let i = 0; i < Object.keys(b).length; i++) {
  1529. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1530. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1531. }
  1532. }
  1533. console.log("DEBUG#LOOP 1 DONE");
  1534. // Loop for sets he has never crafted
  1535. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1536. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1537. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1538. hisMaxSets += 5;
  1539. } else {
  1540. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1541. }
  1542. }
  1543. botNSets += botSets[Object.keys(botSets)[i]].length;
  1544. }
  1545. console.log("DEBUG#LOOP 2 DONE");
  1546. // HERE
  1547. if (amountofsets <= hisMaxSets) {
  1548. hisMaxSets = amountofsets;
  1549. console.log("DEBUG#TRADE CREATED");
  1550. sortSetsByAmount(botSets, (DATA) => {
  1551. console.log("DEBUG#" + DATA);
  1552. console.log("DEBUG#SETS SORTED");
  1553. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1554. if (b[DATA[i]] === 0) {
  1555. continue firstLoop;
  1556. } else {
  1557. console.log("DEBUG#" + i);
  1558. console.log("DEBUG#FOR LOOP ITEMS");
  1559. if (hisMaxSets > 0) {
  1560. console.log("DEBUG#MAXSETSMORETHAN1");
  1561. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  1562. // BOT HAS ENOUGH SETS OF THIS KIND
  1563. console.log("DEBUG#LOOP #1");
  1564. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  1565. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  1566. console.log("DEBUG#LOOP #1: ITEM ADD");
  1567. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  1568. t.addMyItems(botSets[DATA[i]][j]);
  1569. hisMaxSets--;
  1570. console.log(hisMaxSets);
  1571. } else {
  1572. console.log("DEBUG#LOOP #1: RETURN");
  1573. continue firstLoop;
  1574. }
  1575. }
  1576. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  1577. // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  1578. console.log("DEBUG#LOOP #1 CONTINUE");
  1579. continue; // *
  1580. } 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
  1581. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1582. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  1583. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1584. t.addMyItems(botSets[DATA[i]][j]);
  1585. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1586. hisMaxSets--;
  1587. } else {
  1588. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1589. continue firstLoop;
  1590. }
  1591. }
  1592. }
  1593. else if (hisMaxSets < 5) {
  1594. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  1595. console.log("DEBUG#LOOP #2");
  1596. tLoop: for (let j = 0; j !== hisMaxSets; j++) {
  1597. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1598. t.addMyItems(botSets[DATA[i]][j]);
  1599. console.log("DEBUG#LOOP #2: ITEM ADD");
  1600. hisMaxSets--;
  1601. console.log(hisMaxSets);
  1602. } else {
  1603. console.log("DEBUG#LOOP #2: RETURN");
  1604. continue firstLoop;
  1605. }
  1606. }
  1607. } else {
  1608. // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  1609. console.log("DEBUG#LOOP #2");
  1610. xLoop: for (let j = 0; j !== 5; j++ && hisMaxSets > 0) {
  1611. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1612. t.addMyItems(botSets[DATA[i]][j]);
  1613. console.log("DEBUG#LOOP #2: ITEM ADD");
  1614. hisMaxSets--;
  1615. console.log(hisMaxSets);
  1616. } else {
  1617. console.log("DEBUG#LOOP #2: RETURN");
  1618. continue firstLoop;
  1619. }
  1620. }
  1621. }
  1622. } else {
  1623. console.log("DEBUG#RETURN");
  1624. break firstLoop;
  1625. }
  1626. }
  1627. }
  1628. if (hisMaxSets > 0) {
  1629. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1630. } else {
  1631. console.log("DEBUG#SENDING");
  1632. t.addTheirItems(theirKeys);
  1633. t.data("commandused", "Buy");
  1634. t.data("amountofkeys", n);
  1635. t.data("amountofsets", amountofsets.toString());
  1636. t.send((ERR, STATUS) => {
  1637. if (ERR) {
  1638. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1639. console.log("## An error occurred while sending trade: " + ERR);
  1640. } else {
  1641. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  1642. console.log("## Trade offer sent");
  1643. }
  1644. });
  1645. }
  1646. });
  1647. } else {
  1648. 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.");
  1649. }
  1650. // TO HERE
  1651. } else {
  1652. console.log("An error occurred while getting badges: " + ERR);
  1653. }
  1654. } else {
  1655. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1656. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1657. }
  1658. });
  1659. }
  1660. } else {
  1661. console.log("## An error occurred while getting inventory: " + ERR);
  1662. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1663. }
  1664. }
  1665. });
  1666. } else {
  1667. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1668. }
  1669. });
  1670. } else {
  1671. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1672. }
  1673. } else {
  1674. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  1675. }
  1676. } else {
  1677. client.chatMessage(SENDER, "Please try again later.");
  1678. }
  1679. }
  1680.  
  1681. else if (MSG.toUpperCase().indexOf("!TFBUYONE") >= 0) {
  1682. if (botSets) {
  1683. let n = MSG.toUpperCase().replace("!TFBUYONE ", ""),
  1684. amountofsets = parseInt(n) * CONFIG.CARDS.TF2.buy_sets_by_one;
  1685. if (!isNaN(n) && parseInt(n) > 0) {
  1686. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1687. let t = manager.createOffer(SENDER.getSteamID64());
  1688. t.getUserDetails((ERR, ME, THEM) => {
  1689. if (ERR) {
  1690. console.log("## An error occurred while getting trade holds: " + ERR);
  1691. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  1692. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  1693. n = parseInt(n);
  1694. let theirKeys = [];
  1695. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  1696. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 2, true, (ERR, INV, CURR) => {
  1697. if (ERR) {
  1698. console.log("## An error occurred while getting inventory: " + ERR);
  1699. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1700. } else {
  1701. console.log("DEBUG#INV LOADED");
  1702. if (!ERR) {
  1703. console.log("DEBUG#INV LOADED NOERR");
  1704. for (let i = 0; i < INV.length; i++) {
  1705. if (theirKeys.length < n && CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1706. theirKeys.push(INV[i]);
  1707. }
  1708. }
  1709. if (theirKeys.length !== n) {
  1710. client.chatMessage(SENDER, "You do not have enough keys.");
  1711. } else {
  1712. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1713. if (!ERR) {
  1714. console.log("DEBUG#BADGE LOADED");
  1715. if (!ERR) {
  1716. let b = {}; // List with badges that CAN still be crafted
  1717. if (DATA) {
  1718. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1719. if (DATA[Object.keys(DATA)[i]] < 6) {
  1720. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1721. }
  1722. }
  1723. } else {
  1724. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1725. }
  1726. console.log(DATA);
  1727. console.log(b);
  1728. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1729. // 1: GET BOTS CARDS. DONE
  1730. // 2: GET PLAYER's BADGES. DONE
  1731. // 3: MAGIC
  1732. let hisMaxSets = 0,
  1733. botNSets = 0;
  1734. // Loop for sets he has partially completed
  1735. for (let i = 0; i < Object.keys(b).length; i++) {
  1736. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1737. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1738. }
  1739. }
  1740. console.log("DEBUG#LOOP 1 DONE");
  1741. // Loop for sets he has never crafted
  1742. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1743. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1744. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1745. hisMaxSets += 5;
  1746. } else {
  1747. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1748. }
  1749. }
  1750. botNSets += botSets[Object.keys(botSets)[i]].length;
  1751. }
  1752. totalBotSets = botNSets;
  1753. let playThis = CONFIG.PLAYGAMES;
  1754. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  1755. playThis[0] = parseString(playThis[0], totalBotSets);
  1756. }
  1757. client.gamesPlayed(playThis);
  1758. console.log("DEBUG#LOOP 2 DONE");
  1759. // HERE
  1760. if (amountofsets <= hisMaxSets) {
  1761. hisMaxSets = amountofsets;
  1762. console.log("DEBUG#TRADE CREATED");
  1763. sortSetsByAmount(botSets, (DATA) => {
  1764. console.log("DEBUG#" + DATA);
  1765. console.log("DEBUG#SETS SORTED");
  1766. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1767. if (b[DATA[i]] === 0) {
  1768. continue firstLoop;
  1769. } else {
  1770. console.log("DEBUG#" + i);
  1771. console.log("DEBUG#FOR LOOP ITEMS");
  1772. if (hisMaxSets > 0) {
  1773. console.log("DEBUG#MAXSETSMORETHAN1");
  1774. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  1775. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1776. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  1777. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1778. t.addMyItems(botSets[DATA[i]][j]);
  1779. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1780. hisMaxSets--;
  1781. continue firstLoop;
  1782. } else {
  1783. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1784. continue firstLoop;
  1785. }
  1786. }
  1787. }
  1788. } else {
  1789. console.log("DEBUG#RETURN");
  1790. break firstLoop;
  1791. }
  1792. }
  1793. }
  1794. if (hisMaxSets > 0) {
  1795. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1796. } else {
  1797. console.log("DEBUG#SENDING");
  1798. t.addTheirItems(theirKeys);
  1799. t.data("commandused", "BuyOne");
  1800. t.data("amountofkeys", n);
  1801. t.data("amountofsets", amountofsets.toString());
  1802. t.send((ERR, STATUS) => {
  1803. if (ERR) {
  1804. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1805. console.log("## An error occurred while sending trade: " + ERR);
  1806. } else {
  1807. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  1808. console.log("## Trade offer sent");
  1809. }
  1810. });
  1811. }
  1812. });
  1813. } else {
  1814. 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.");
  1815. }
  1816. // TO HERE
  1817. } else {
  1818. console.log("An error occurred while getting badges: " + ERR);
  1819. }
  1820. } else {
  1821. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1822. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1823. }
  1824. });
  1825. }
  1826. } else {
  1827. console.log("## An error occurred while getting inventory: " + ERR);
  1828. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1829. }
  1830. }
  1831. });
  1832. } else {
  1833. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1834. }
  1835. });
  1836. } else {
  1837. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  1838. }
  1839. } else {
  1840. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  1841. }
  1842. } else {
  1843. client.chatMessage(SENDER, "Please try again later.");
  1844. }
  1845. }
  1846. else if (MSG.toUpperCase().indexOf("!PUBGBUYONE") >= 0) {
  1847. if (botSets) {
  1848. let n = MSG.toUpperCase().replace("!PUBGBUYONE ", ""),
  1849. amountofsets = parseInt(n) * CONFIG.CARDS.PUBG.buy_sets_by_one;
  1850. if (!isNaN(n) && parseInt(n) > 0) {
  1851. if (n <= CONFIG.MESSAGES.MAXBUY) {
  1852. let t = manager.createOffer(SENDER.getSteamID64());
  1853. t.getUserDetails((ERR, ME, THEM) => {
  1854. if (ERR) {
  1855. console.log("## An error occurred while getting trade holds: " + ERR);
  1856. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  1857. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  1858. n = parseInt(n);
  1859. let theirKeys = [];
  1860. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  1861. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGAME, 2, true, (ERR, INV, CURR) => {
  1862. if (ERR) {
  1863. console.log("## An error occurred while getting inventory: " + ERR);
  1864. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  1865. } else {
  1866. console.log("DEBUG#INV LOADED");
  1867. if (!ERR) {
  1868. console.log("DEBUG#INV LOADED NOERR");
  1869. for (let i = 0; i < INV.length; i++) {
  1870. if (theirKeys.length < n && CONFIG.PUBGACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  1871. theirKeys.push(INV[i]);
  1872. }
  1873. }
  1874. if (theirKeys.length !== n) {
  1875. client.chatMessage(SENDER, "You do not have enough keys.");
  1876. } else {
  1877. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  1878. if (!ERR) {
  1879. console.log("DEBUG#BADGE LOADED");
  1880. if (!ERR) {
  1881. let b = {}; // List with badges that CAN still be crafted
  1882. if (DATA) {
  1883. for (let i = 0; i < Object.keys(DATA).length; i++) {
  1884. if (DATA[Object.keys(DATA)[i]] < 6) {
  1885. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  1886. }
  1887. }
  1888. } else {
  1889. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  1890. }
  1891. console.log(DATA);
  1892. console.log(b);
  1893. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  1894. // 1: GET BOTS CARDS. DONE
  1895. // 2: GET PLAYER's BADGES. DONE
  1896. // 3: MAGIC
  1897. let hisMaxSets = 0,
  1898. botNSets = 0;
  1899. // Loop for sets he has partially completed
  1900. for (let i = 0; i < Object.keys(b).length; i++) {
  1901. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  1902. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  1903. }
  1904. }
  1905. console.log("DEBUG#LOOP 1 DONE");
  1906. // Loop for sets he has never crafted
  1907. for (let i = 0; i < Object.keys(botSets).length; i++) {
  1908. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  1909. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  1910. hisMaxSets += 5;
  1911. } else {
  1912. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  1913. }
  1914. }
  1915. botNSets += botSets[Object.keys(botSets)[i]].length;
  1916. }
  1917. totalBotSets = botNSets;
  1918. let playThis = CONFIG.PLAYGAMES;
  1919. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  1920. playThis[0] = parseString(playThis[0], totalBotSets);
  1921. }
  1922. client.gamesPlayed(playThis);
  1923. console.log("DEBUG#LOOP 2 DONE");
  1924. // HERE
  1925. if (amountofsets <= hisMaxSets) {
  1926. hisMaxSets = amountofsets;
  1927. console.log("DEBUG#TRADE CREATED");
  1928. sortSetsByAmount(botSets, (DATA) => {
  1929. console.log("DEBUG#" + DATA);
  1930. console.log("DEBUG#SETS SORTED");
  1931. firstLoop: for (let i = 0; i < DATA.length; i++) {
  1932. if (b[DATA[i]] === 0) {
  1933. continue firstLoop;
  1934. } else {
  1935. console.log("DEBUG#" + i);
  1936. console.log("DEBUG#FOR LOOP ITEMS");
  1937. if (hisMaxSets > 0) {
  1938. console.log("DEBUG#MAXSETSMORETHAN1");
  1939. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  1940. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  1941. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  1942. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  1943. t.addMyItems(botSets[DATA[i]][j]);
  1944. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  1945. hisMaxSets--;
  1946. continue firstLoop;
  1947. } else {
  1948. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  1949. continue firstLoop;
  1950. }
  1951. }
  1952. }
  1953. } else {
  1954. console.log("DEBUG#RETURN");
  1955. break firstLoop;
  1956. }
  1957. }
  1958. }
  1959. if (hisMaxSets > 0) {
  1960. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  1961. } else {
  1962. console.log("DEBUG#SENDING");
  1963. t.addTheirItems(theirKeys);
  1964. t.data("commandused", "BuyOne");
  1965. t.data("amountofkeys", n);
  1966. t.data("amountofsets", amountofsets.toString());
  1967. t.send((ERR, STATUS) => {
  1968. if (ERR) {
  1969. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  1970. console.log("## An error occurred while sending trade: " + ERR);
  1971. } else {
  1972. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  1973. console.log("## Trade offer sent");
  1974. }
  1975. });
  1976. }
  1977. });
  1978. } else {
  1979. 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.");
  1980. }
  1981. // TO HERE
  1982. } else {
  1983. console.log("An error occurred while getting badges: " + ERR);
  1984. }
  1985. } else {
  1986. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  1987. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  1988. }
  1989. });
  1990. }
  1991. } else {
  1992. console.log("## An error occurred while getting inventory: " + ERR);
  1993. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  1994. }
  1995. }
  1996. });
  1997. } else {
  1998. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  1999. }
  2000. });
  2001. } else {
  2002. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  2003. }
  2004. } else {
  2005. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2006. }
  2007. } else {
  2008. client.chatMessage(SENDER, "Please try again later.");
  2009. }
  2010. }
  2011. else if (MSG.toUpperCase().indexOf("!BUYONEGEMS") >= 0) {
  2012. if (botSets) {
  2013. let n = MSG.toUpperCase().replace("!BUYONEGEMS ", ""),
  2014. amountofsets = parseInt(n);
  2015. if (!isNaN(n) && parseInt(n) > 0) {
  2016. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2017. let t = manager.createOffer(SENDER.getSteamID64());
  2018. t.getUserDetails((ERR, ME, THEM) => {
  2019. if (ERR) {
  2020. console.log("## An error occurred while getting trade holds: " + ERR);
  2021. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2022. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  2023. n = parseInt(n);
  2024. let theirGems = [];
  2025. let amountTheirGems = 0;
  2026. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  2027. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  2028. if (ERR) {
  2029. console.log("## An error occurred while getting inventory: " + ERR);
  2030. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2031. } else {
  2032. console.log("DEBUG#INV LOADED");
  2033. if (!ERR) {
  2034. console.log("DEBUG#INV LOADED NOERR");
  2035. for (let i = 0; i < INV.length; i++) {
  2036. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  2037. amountTheirGems = INV[i].amount;
  2038. INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
  2039. theirGems.push(INV[i]);
  2040. break;
  2041. }
  2042. }
  2043. if (amountTheirGems < (n * CONFIG.CARDS.GEMS.buy_one_set_for)) {
  2044. client.chatMessage(SENDER, "You do not have enough Gems.");
  2045. } else {
  2046. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  2047. if (!ERR) {
  2048. console.log("DEBUG#BADGE LOADED");
  2049. if (!ERR) {
  2050. let b = {}; // List with badges that CAN still be crafted
  2051. if (DATA) {
  2052. for (let i = 0; i < Object.keys(DATA).length; i++) {
  2053. if (DATA[Object.keys(DATA)[i]] < 6) {
  2054. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  2055. }
  2056. }
  2057. } else {
  2058. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  2059. }
  2060. console.log(DATA);
  2061. console.log(b);
  2062. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  2063. // 1: GET BOTS CARDS. DONE
  2064. // 2: GET PLAYER's BADGES. DONE
  2065. // 3: MAGIC
  2066. let hisMaxSets = 0,
  2067. botNSets = 0;
  2068. // Loop for sets he has partially completed
  2069. for (let i = 0; i < Object.keys(b).length; i++) {
  2070. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  2071. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  2072. }
  2073. }
  2074. console.log("DEBUG#LOOP 1 DONE");
  2075. // Loop for sets he has never crafted
  2076. for (let i = 0; i < Object.keys(botSets).length; i++) {
  2077. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  2078. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  2079. hisMaxSets += 5;
  2080. } else {
  2081. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  2082. }
  2083. }
  2084. botNSets += botSets[Object.keys(botSets)[i]].length;
  2085. }
  2086. totalBotSets = botNSets;
  2087. let playThis = CONFIG.PLAYGAMES;
  2088. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  2089. playThis[0] = parseString(playThis[0], totalBotSets);
  2090. }
  2091. client.gamesPlayed(playThis);
  2092. console.log("DEBUG#LOOP 2 DONE");
  2093. // HERE
  2094. if (amountofsets <= hisMaxSets) {
  2095. hisMaxSets = amountofsets;
  2096. console.log("DEBUG#TRADE CREATED");
  2097. sortSetsByAmount(botSets, (DATA) => {
  2098. console.log("DEBUG#" + DATA);
  2099. console.log("DEBUG#SETS SORTED");
  2100. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2101. if (b[DATA[i]] === 0) {
  2102. continue firstLoop;
  2103. } else {
  2104. console.log("DEBUG#" + i);
  2105. console.log("DEBUG#FOR LOOP ITEMS");
  2106. if (hisMaxSets > 0) {
  2107. console.log("DEBUG#MAXSETSMORETHAN1");
  2108. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  2109. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  2110. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2111. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  2112. t.addMyItems(botSets[DATA[i]][j]);
  2113. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2114. hisMaxSets--;
  2115. continue firstLoop;
  2116. } else {
  2117. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2118. continue firstLoop;
  2119. }
  2120. }
  2121. }
  2122. } else {
  2123. console.log("DEBUG#RETURN");
  2124. break firstLoop;
  2125. }
  2126. }
  2127. }
  2128. if (hisMaxSets > 0) {
  2129. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2130. } else {
  2131. console.log("DEBUG#SENDING");
  2132. t.addTheirItems(theirGems);
  2133. t.data("commandused", "BuyOne");
  2134. t.data("amountofkeys", n);
  2135. t.data("amountofsets", amountofsets.toString());
  2136. t.send((ERR, STATUS) => {
  2137. if (ERR) {
  2138. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2139. console.log("## An error occurred while sending trade: " + ERR);
  2140. } else {
  2141. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  2142. console.log("## Trade offer sent");
  2143. }
  2144. });
  2145. }
  2146. });
  2147. } else {
  2148. 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.");
  2149. }
  2150. // TO HERE
  2151. } else {
  2152. console.log("An error occurred while getting badges: " + ERR);
  2153. }
  2154. } else {
  2155. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  2156. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  2157. }
  2158. });
  2159. }
  2160. } else {
  2161. console.log("## An error occurred while getting inventory: " + ERR);
  2162. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  2163. }
  2164. }
  2165. });
  2166. } else {
  2167. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2168. }
  2169. });
  2170. } else {
  2171. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  2172. }
  2173. } else {
  2174. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2175. }
  2176. } else {
  2177. client.chatMessage(SENDER, "Please try again later.");
  2178. }
  2179. }
  2180. else if (MSG.toUpperCase().indexOf("!GEMSBUYONE") >= 0) {
  2181. if (botSets) {
  2182. let n = MSG.toUpperCase().replace("!GEMSBUYONE ", ""),
  2183. amountofsets = parseInt(n);
  2184. if (!isNaN(n) && parseInt(n) > 0) {
  2185. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2186. let t = manager.createOffer(SENDER.getSteamID64());
  2187. t.getUserDetails((ERR, ME, THEM) => {
  2188. if (ERR) {
  2189. console.log("## An error occurred while getting trade holds: " + ERR);
  2190. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2191. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  2192. n = parseInt(n);
  2193. let theirGems = [];
  2194. let amountTheirGems = 0;
  2195. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  2196. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  2197. if (ERR) {
  2198. console.log("## An error occurred while getting inventory: " + ERR);
  2199. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2200. } else {
  2201. console.log("DEBUG#INV LOADED");
  2202. if (!ERR) {
  2203. console.log("DEBUG#INV LOADED NOERR");
  2204. for (let i = 0; i < INV.length; i++) {
  2205. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  2206. amountTheirGems = INV[i].amount;
  2207. INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
  2208. theirGems.push(INV[i]);
  2209. break;
  2210. }
  2211. }
  2212. if (amountTheirGems < (n * CONFIG.CARDS.GEMS.buy_one_set_for)) {
  2213. client.chatMessage(SENDER, "You do not have enough Gems.");
  2214. } else {
  2215. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  2216. if (!ERR) {
  2217. console.log("DEBUG#BADGE LOADED");
  2218. if (!ERR) {
  2219. let b = {}; // List with badges that CAN still be crafted
  2220. if (DATA) {
  2221. for (let i = 0; i < Object.keys(DATA).length; i++) {
  2222. if (DATA[Object.keys(DATA)[i]] < 6) {
  2223. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  2224. }
  2225. }
  2226. } else {
  2227. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  2228. }
  2229. console.log(DATA);
  2230. console.log(b);
  2231. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  2232. // 1: GET BOTS CARDS. DONE
  2233. // 2: GET PLAYER's BADGES. DONE
  2234. // 3: MAGIC
  2235. let hisMaxSets = 0,
  2236. botNSets = 0;
  2237. // Loop for sets he has partially completed
  2238. for (let i = 0; i < Object.keys(b).length; i++) {
  2239. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  2240. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  2241. }
  2242. }
  2243. console.log("DEBUG#LOOP 1 DONE");
  2244. // Loop for sets he has never crafted
  2245. for (let i = 0; i < Object.keys(botSets).length; i++) {
  2246. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  2247. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  2248. hisMaxSets += 5;
  2249. } else {
  2250. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  2251. }
  2252. }
  2253. botNSets += botSets[Object.keys(botSets)[i]].length;
  2254. }
  2255. totalBotSets = botNSets;
  2256. let playThis = CONFIG.PLAYGAMES;
  2257. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  2258. playThis[0] = parseString(playThis[0], totalBotSets);
  2259. }
  2260. client.gamesPlayed(playThis);
  2261. console.log("DEBUG#LOOP 2 DONE");
  2262. // HERE
  2263. if (amountofsets <= hisMaxSets) {
  2264. hisMaxSets = amountofsets;
  2265. console.log("DEBUG#TRADE CREATED");
  2266. sortSetsByAmount(botSets, (DATA) => {
  2267. console.log("DEBUG#" + DATA);
  2268. console.log("DEBUG#SETS SORTED");
  2269. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2270. if (b[DATA[i]] === 0) {
  2271. continue firstLoop;
  2272. } else {
  2273. console.log("DEBUG#" + i);
  2274. console.log("DEBUG#FOR LOOP ITEMS");
  2275. if (hisMaxSets > 0) {
  2276. console.log("DEBUG#MAXSETSMORETHAN1");
  2277. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  2278. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  2279. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2280. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  2281. t.addMyItems(botSets[DATA[i]][j]);
  2282. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2283. hisMaxSets--;
  2284. continue firstLoop;
  2285. } else {
  2286. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2287. continue firstLoop;
  2288. }
  2289. }
  2290. }
  2291. } else {
  2292. console.log("DEBUG#RETURN");
  2293. break firstLoop;
  2294. }
  2295. }
  2296. }
  2297. if (hisMaxSets > 0) {
  2298. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2299. } else {
  2300. console.log("DEBUG#SENDING");
  2301. t.addTheirItems(theirGems);
  2302. t.data("commandused", "BuyOne");
  2303. t.data("amountofkeys", n);
  2304. t.data("amountofsets", amountofsets.toString());
  2305. t.send((ERR, STATUS) => {
  2306. if (ERR) {
  2307. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2308. console.log("## An error occurred while sending trade: " + ERR);
  2309. } else {
  2310. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  2311. console.log("## Trade offer sent");
  2312. }
  2313. });
  2314. }
  2315. });
  2316. } else {
  2317. 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.");
  2318. }
  2319. // TO HERE
  2320. } else {
  2321. console.log("An error occurred while getting badges: " + ERR);
  2322. }
  2323. } else {
  2324. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  2325. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  2326. }
  2327. });
  2328. }
  2329. } else {
  2330. console.log("## An error occurred while getting inventory: " + ERR);
  2331. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  2332. }
  2333. }
  2334. });
  2335. } else {
  2336. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2337. }
  2338. });
  2339. } else {
  2340. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  2341. }
  2342. } else {
  2343. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2344. }
  2345. } else {
  2346. client.chatMessage(SENDER, "Please try again later.");
  2347. }
  2348. }
  2349.  
  2350. else if (MSG.toUpperCase().indexOf("!CSGOBUYONE") >= 0) {
  2351. if (botSets) {
  2352. let n = MSG.toUpperCase().replace("!CSGOBUYONE", ""),
  2353. amountofsets = parseInt(n) * CONFIG.CARDS.CSGO.buy_sets_by_one;
  2354. if (!isNaN(n) && parseInt(n) > 0) {
  2355. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2356. let t = manager.createOffer(SENDER.getSteamID64());
  2357. t.getUserDetails((ERR, ME, THEM) => {
  2358. if (ERR) {
  2359. console.log("## An error occurred while getting trade holds: " + ERR);
  2360. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2361. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  2362. n = parseInt(n);
  2363. let theirKeys = [];
  2364. client.chatMessage(SENDER, ":checkpoint: Processing your request.");
  2365. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 2, true, (ERR, INV, CURR) => {
  2366. if (ERR) {
  2367. console.log("## An error occurred while getting inventory: " + ERR);
  2368. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2369. } else {
  2370. console.log("DEBUG#INV LOADED");
  2371. if (!ERR) {
  2372. console.log("DEBUG#INV LOADED NOERR");
  2373. for (let i = 0; i < INV.length; i++) {
  2374. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  2375. theirKeys.push(INV[i]);
  2376. }
  2377. }
  2378. if (theirKeys.length != n) {
  2379. client.chatMessage(SENDER, "You do not have enough keys.");
  2380. } else {
  2381. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  2382. if (!ERR) {
  2383. console.log("DEBUG#BADGE LOADED");
  2384. if (!ERR) {
  2385. let b = {}; // List with badges that CAN still be crafted
  2386. if (DATA) {
  2387. for (let i = 0; i < Object.keys(DATA).length; i++) {
  2388. if (DATA[Object.keys(DATA)[i]] < 6) {
  2389. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  2390. }
  2391. }
  2392. } else {
  2393. client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  2394. }
  2395. console.log(DATA);
  2396. console.log(b);
  2397. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  2398. // 1: GET BOTS CARDS. DONE
  2399. // 2: GET PLAYER's BADGES. DONE
  2400. // 3: MAGIC
  2401. let hisMaxSets = 0,
  2402. botNSets = 0;
  2403. // Loop for sets he has partially completed
  2404. for (let i = 0; i < Object.keys(b).length; i++) {
  2405. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  2406. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  2407. }
  2408. }
  2409. console.log("DEBUG#LOOP 1 DONE");
  2410. // Loop for sets he has never crafted
  2411. for (let i = 0; i < Object.keys(botSets).length; i++) {
  2412. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  2413. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  2414. hisMaxSets += 5;
  2415. } else {
  2416. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  2417. }
  2418. }
  2419. botNSets += botSets[Object.keys(botSets)[i]].length;
  2420. }
  2421. totalBotSets = botNSets;
  2422. let playThis = CONFIG.PLAYGAMES;
  2423. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
  2424. playThis[0] = parseString(playThis[0], totalBotSets);
  2425. }
  2426. client.gamesPlayed(playThis);
  2427. console.log("DEBUG#LOOP 2 DONE");
  2428. // HERE
  2429. if (amountofsets <= hisMaxSets) {
  2430. hisMaxSets = amountofsets;
  2431. console.log("DEBUG#TRADE CREATED");
  2432. sortSetsByAmount(botSets, (DATA) => {
  2433. console.log("DEBUG#" + DATA);
  2434. console.log("DEBUG#SETS SORTED");
  2435. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2436. if (b[DATA[i]] == 0) {
  2437. continue firstLoop;
  2438. } else {
  2439. console.log("DEBUG#" + i);
  2440. console.log("DEBUG#FOR LOOP ITEMS");
  2441. if (hisMaxSets > 0) {
  2442. console.log("DEBUG#MAXSETSMORETHAN1");
  2443. if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
  2444. // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  2445. bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2446. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  2447. t.addMyItems(botSets[DATA[i]][j]);
  2448. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2449. hisMaxSets--;
  2450. continue firstLoop;
  2451. } else {
  2452. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2453. continue firstLoop;
  2454. }
  2455. }
  2456. }
  2457. } else {
  2458. console.log("DEBUG#RETURN");
  2459. break firstLoop;
  2460. }
  2461. }
  2462. }
  2463. if (hisMaxSets > 0) {
  2464. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2465. } else {
  2466. console.log("DEBUG#SENDING");
  2467. t.addTheirItems(theirKeys);
  2468. t.data("commandused", "BuyOne");
  2469. t.data("amountofkeys", n);
  2470. t.data("amountofsets", amountofsets.toString());
  2471. t.data("index", setsThatShouldntBeSent.length);
  2472. setsThatShouldntBeSent.push(t.itemsToGive);
  2473. t.send((ERR, STATUS) => {
  2474. if (ERR) {
  2475. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2476. console.log("## An error occurred while sending trade: " + ERR);
  2477. } else {
  2478. client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  2479. console.log("## Trade offer sent");
  2480. }
  2481. });
  2482. }
  2483. });
  2484. } else {
  2485. 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.");
  2486. }
  2487. // TO HERE
  2488. } else {
  2489. console.log("An error occurred while getting badges: " + ERR);
  2490. }
  2491. } else {
  2492. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  2493. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  2494. }
  2495. });
  2496. }
  2497. } else {
  2498. console.log("## An error occurred while getting inventory: " + ERR);
  2499. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  2500. }
  2501. }
  2502. });
  2503. } else {
  2504. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2505. }
  2506. });
  2507. } else {
  2508. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  2509. }
  2510. } else {
  2511. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2512. }
  2513. } else {
  2514. client.chatMessage(SENDER, "Please try again later.");
  2515. }
  2516. }
  2517.  
  2518. else if (MSG.toUpperCase().indexOf("!TFBUYANY") >= 0) {
  2519. if (botSets) {
  2520. let n = MSG.toUpperCase().replace("!TFBUYANY ", ""),
  2521. amountofsets = parseInt(n) * CONFIG.CARDS.TF2.buy_sets_by_one;
  2522. if (!isNaN(n) && parseInt(n) > 0) {
  2523. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2524. let t = manager.createOffer(SENDER.getSteamID64());
  2525. n = parseInt(n);
  2526. let theirKeys = [];
  2527. t.getUserDetails((ERR, ME, THEM) => {
  2528. if (ERR) {
  2529. console.log("## An error occurred while getting trade holds: " + ERR);
  2530. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2531. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  2532. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  2533. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 2, true, (ERR, INV, CURR) => {
  2534. if (ERR) {
  2535. console.log("## An error occurred while getting inventory: " + ERR);
  2536. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2537. } else {
  2538. let amountofB = amountofsets;
  2539. for (let i = 0; i < INV.length; i++) {
  2540. if (theirKeys.length < n && CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  2541. theirKeys.push(INV[i]);
  2542. }
  2543. }
  2544. if (theirKeys.length !== n) {
  2545. client.chatMessage(SENDER, "You do not have enough keys.");
  2546. } else {
  2547. sortSetsByAmount(botSets, (DATA) => {
  2548. let setsSent = {};
  2549. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2550. console.log(setsSent);
  2551. console.log(DATA[i]);
  2552. if (botSets[DATA[i]]) {
  2553. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2554. if (amountofB > 0) {
  2555. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < 5) || !setsSent[DATA[i]]) {
  2556. t.addMyItems(botSets[DATA[i]][j]);
  2557. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2558. amountofB--;
  2559. if (!setsSent[DATA[i]]) {
  2560. setsSent[DATA[i]] = 1;
  2561. } else {
  2562. setsSent[DATA[i]] += 1;
  2563. }
  2564. } else {
  2565. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2566. continue firstLoop;
  2567. }
  2568. } else {
  2569. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2570. continue firstLoop;
  2571. }
  2572. }
  2573. } else {
  2574. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  2575. continue firstLoop;
  2576. }
  2577. }
  2578. });
  2579. }
  2580. if (amountofB > 0) {
  2581. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2582. } else {
  2583. console.log("DEBUG#SENDING");
  2584. t.addTheirItems(theirKeys);
  2585. t.data("commandused", "BuyAny");
  2586. t.data("amountofsets", amountofsets.toString());
  2587. t.data("amountofkeys", n);
  2588. t.send((ERR, STATUS) => {
  2589. if (ERR) {
  2590. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2591. console.log("## An error occurred while sending trade: " + ERR);
  2592. } else {
  2593. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  2594. console.log("## Trade offer sent!");
  2595. }
  2596. });
  2597. }
  2598. }
  2599. });
  2600. } else {
  2601. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2602. }
  2603. });
  2604. } else {
  2605. client.chatMessage(SENDER, "Please try a lower amount of keys");
  2606. }
  2607. } else {
  2608. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2609. }
  2610. } else {
  2611. client.chatMessage(SENDER, "Please try again later.");
  2612. }
  2613. }
  2614. else if (MSG.toUpperCase().indexOf("!PUBGBUYANY") >= 0) {
  2615. if (botSets) {
  2616. let n = MSG.toUpperCase().replace("!BUYANYPUBG ", ""),
  2617. amountofsets = parseInt(n) * CONFIG.CARDS.PUBG.buy_sets_by_one;
  2618. if (!isNaN(n) && parseInt(n) > 0) {
  2619. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2620. let t = manager.createOffer(SENDER.getSteamID64());
  2621. n = parseInt(n);
  2622. let theirKeys = [];
  2623. t.getUserDetails((ERR, ME, THEM) => {
  2624. if (ERR) {
  2625. console.log("## An error occurred while getting trade holds: " + ERR);
  2626. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2627. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  2628. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  2629. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGAME, 2, true, (ERR, INV, CURR) => {
  2630. if (ERR) {
  2631. console.log("## An error occurred while getting inventory: " + ERR);
  2632. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2633. } else {
  2634. let amountofB = amountofsets;
  2635. for (let i = 0; i < INV.length; i++) {
  2636. if (theirKeys.length < n && CONFIG.PUBGACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  2637. theirKeys.push(INV[i]);
  2638. }
  2639. }
  2640. if (theirKeys.length !== n) {
  2641. client.chatMessage(SENDER, "You do not have enough keys.");
  2642. } else {
  2643. sortSetsByAmount(botSets, (DATA) => {
  2644. let setsSent = {};
  2645. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2646. console.log(setsSent);
  2647. console.log(DATA[i]);
  2648. if (botSets[DATA[i]]) {
  2649. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2650. if (amountofB > 0) {
  2651. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < 5) || !setsSent[DATA[i]]) {
  2652. t.addMyItems(botSets[DATA[i]][j]);
  2653. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2654. amountofB--;
  2655. if (!setsSent[DATA[i]]) {
  2656. setsSent[DATA[i]] = 1;
  2657. } else {
  2658. setsSent[DATA[i]] += 1;
  2659. }
  2660. } else {
  2661. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2662. continue firstLoop;
  2663. }
  2664. } else {
  2665. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2666. continue firstLoop;
  2667. }
  2668. }
  2669. } else {
  2670. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  2671. continue firstLoop;
  2672. }
  2673. }
  2674. });
  2675. }
  2676. if (amountofB > 0) {
  2677. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2678. } else {
  2679. console.log("DEBUG#SENDING");
  2680. t.addTheirItems(theirKeys);
  2681. t.data("commandused", "BuyAny");
  2682. t.data("amountofsets", amountofsets.toString());
  2683. t.data("amountofkeys", n);
  2684. t.send((ERR, STATUS) => {
  2685. if (ERR) {
  2686. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2687. console.log("## An error occurred while sending trade: " + ERR);
  2688. } else {
  2689. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  2690. console.log("## Trade offer sent!");
  2691. }
  2692. });
  2693. }
  2694. }
  2695. });
  2696. } else {
  2697. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2698. }
  2699. });
  2700. } else {
  2701. client.chatMessage(SENDER, "Please try a lower amount of keys");
  2702. }
  2703. } else {
  2704. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2705. }
  2706. } else {
  2707. client.chatMessage(SENDER, "Please try again later.");
  2708. }
  2709. }
  2710. else if (MSG.toUpperCase().indexOf("!GEMSBUYANY") >= 0) {
  2711. if (botSets) {
  2712. let n = MSG.toUpperCase().replace("!GEMSBUYANY ", ""),
  2713. amountofsets = parseInt(n);
  2714. if (!isNaN(n) && parseInt(n) > 0) {
  2715. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2716. let t = manager.createOffer(SENDER.getSteamID64());
  2717. n = parseInt(n);
  2718. let theirGems = [];
  2719. let amountTheirGems = 0;
  2720. t.getUserDetails((ERR, ME, THEM) => {
  2721. if (ERR) {
  2722. console.log("## An error occurred while getting trade holds: " + ERR);
  2723. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2724. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  2725. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  2726. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  2727. if (ERR) {
  2728. console.log("## An error occurred while getting inventory: " + ERR);
  2729. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2730. } else {
  2731. let amountofB = amountofsets;
  2732. for (let i = 0; i < INV.length; i++) {
  2733. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  2734. amountTheirGems = INV[i].amount;
  2735. INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
  2736. theirGems.push(INV[i]);
  2737. break;
  2738. }
  2739. }
  2740. if (amountTheirGems < ( n * CONFIG.CARDS.GEMS.buy_one_set_for )) {
  2741. client.chatMessage(SENDER, "You do not have enough Gems.");
  2742. } else {
  2743. sortSetsByAmount(botSets, (DATA) => {
  2744. let setsSent = {};
  2745. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2746. console.log(setsSent);
  2747. console.log(DATA[i]);
  2748. if (botSets[DATA[i]]) {
  2749. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2750. if (amountofB > 0) {
  2751. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < 5) || !setsSent[DATA[i]]) {
  2752. t.addMyItems(botSets[DATA[i]][j]);
  2753. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2754. amountofB--;
  2755. if (!setsSent[DATA[i]]) {
  2756. setsSent[DATA[i]] = 1;
  2757. } else {
  2758. setsSent[DATA[i]] += 1;
  2759. }
  2760. } else {
  2761. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2762. continue firstLoop;
  2763. }
  2764. } else {
  2765. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2766. continue firstLoop;
  2767. }
  2768. }
  2769. } else {
  2770. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  2771. continue firstLoop;
  2772. }
  2773. }
  2774. });
  2775. }
  2776. if (amountofB > 0) {
  2777. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2778. } else {
  2779. console.log("DEBUG#SENDING");
  2780. t.addTheirItems(theirGems);
  2781. t.data("commandused", "BuyAny");
  2782. t.data("amountofsets", amountofsets.toString());
  2783. t.data("amountofkeys", n);
  2784. t.send((ERR, STATUS) => {
  2785. if (ERR) {
  2786. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2787. console.log("## An error occurred while sending trade: " + ERR);
  2788. } else {
  2789. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  2790. console.log("## Trade offer sent!");
  2791. }
  2792. });
  2793. }
  2794. }
  2795. });
  2796. } else {
  2797. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2798. }
  2799. });
  2800. } else {
  2801. client.chatMessage(SENDER, "Please try a lower amount of keys");
  2802. }
  2803. } else {
  2804. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2805. }
  2806. } else {
  2807. client.chatMessage(SENDER, "Please try again later.");
  2808. }
  2809. }
  2810. else if (MSG.toUpperCase().indexOf("!CSGOBUYANY") >= 0) {
  2811. if (botSets) {
  2812. let n = MSG.toUpperCase().replace("!CSGOBUYANY ", ""),
  2813. amountofsets = parseInt(n) * CONFIG.CARDS.CSGO.buy_sets_by_one;
  2814. if (!isNaN(n) && parseInt(n) > 0) {
  2815. if (n <= CONFIG.MESSAGES.MAXBUY) {
  2816. let t = manager.createOffer(SENDER.getSteamID64());
  2817. n = parseInt(n);
  2818. let theirKeys = [];
  2819. t.getUserDetails((ERR, ME, THEM) => {
  2820. if (ERR) {
  2821. console.log("## An error occurred while getting trade holds: " + ERR);
  2822. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  2823. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  2824. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  2825. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 2, true, (ERR, INV, CURR) => {
  2826. if (ERR) {
  2827. console.log("## An error occurred while getting inventory: " + ERR);
  2828. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  2829. } else {
  2830. let amountofB = amountofsets;
  2831. for (let i = 0; i < INV.length; i++) {
  2832. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  2833. theirKeys.push(INV[i]);
  2834. }
  2835. }
  2836. if (theirKeys.length !== n) {
  2837. client.chatMessage(SENDER, "You do not have enough keys.");
  2838. } else {
  2839. sortSetsByAmount(botSets, (DATA) => {
  2840. let setsSent = {};
  2841. firstLoop: for (let i = 0; i < DATA.length; i++) {
  2842. console.log(setsSent);
  2843. console.log(DATA[i]);
  2844. if (botSets[DATA[i]]) {
  2845. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  2846. if (amountofB > 0) {
  2847. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < 5) || !setsSent[DATA[i]]) {
  2848. t.addMyItems(botSets[DATA[i]][j]);
  2849. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  2850. amountofB--;
  2851. if (!setsSent[DATA[i]]) {
  2852. setsSent[DATA[i]] = 1;
  2853. } else {
  2854. setsSent[DATA[i]] += 1;
  2855. }
  2856. } else {
  2857. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2858. continue firstLoop;
  2859. }
  2860. } else {
  2861. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  2862. continue firstLoop;
  2863. }
  2864. }
  2865. } else {
  2866. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  2867. continue firstLoop;
  2868. }
  2869. }
  2870. });
  2871. }
  2872. if (amountofB > 0) {
  2873. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  2874. } else {
  2875. console.log("DEBUG#SENDING");
  2876. t.addTheirItems(theirKeys);
  2877. t.data("commandused", "BuyAny");
  2878. t.data("amountofsets", amountofsets.toString());
  2879. t.data("amountofkeys", n);
  2880. t.send((ERR, STATUS) => {
  2881. if (ERR) {
  2882. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  2883. console.log("## An error occurred while sending trade: " + ERR);
  2884. } else {
  2885. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  2886. console.log("## Trade offer sent!");
  2887. }
  2888. });
  2889. }
  2890. }
  2891. });
  2892. } else {
  2893. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  2894. }
  2895. });
  2896. } else {
  2897. client.chatMessage(SENDER, "Please try a lower amount of keys");
  2898. }
  2899. } else {
  2900. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  2901. }
  2902. } else {
  2903. client.chatMessage(SENDER, "Please try again later.");
  2904. }
  2905. }
  2906.  
  2907. else if (MSG.toUpperCase() === "!OWNER") {
  2908. client.chatMessage(SENDER, "My steam account: \r\n" + CONFIG.OWNERLINK);
  2909. }
  2910. else if (MSG.toUpperCase() === "!DEVELOPER") {
  2911. client.chatMessage(SENDER, CONFIG.CREDITS);
  2912. }
  2913. else if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
  2914. // Admin commands.
  2915. if (MSG.toUpperCase() === "!ADMIN") {
  2916. client.chatMessage(SENDER, "List of admin commands:\n" +
  2917. "!withdraw - withdraw x amount of CS:GO keys\n" +
  2918. "!tfwithdraw - withdraw x amount of TFkeys\n" +
  2919. "!gemswithdraw - withdraw x amount of Gems\n" +
  2920. "!deposit - deposit x amount of CS:GO keys\n" +
  2921. "!tfdeposit - deposit x amount of TF keys\n" +
  2922. "!gemsdeposit - deposit x amount of Gems\n" +
  2923. "!shutdown - logoff bot account and close application\n" +
  2924. "!restart - logoff and login account\n" +
  2925. "!block - block desired steam user\n" +
  2926. "!unblock - unblock desired steam user\n" +
  2927. "!stock - send a trade offer to owner requesting all available sets to trade");
  2928. }
  2929. else if (MSG.toUpperCase().indexOf("!WITHDRAW") >= 0) {
  2930. let amountkeys = parseInt(MSG.toUpperCase().replace("!WITHDRAW ", ""))
  2931. if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
  2932. manager.getInventoryContents(CONFIG.CSGOGAME, 2, true, (ERR, INV, CURR) => {
  2933. if (ERR) {
  2934. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory.");
  2935. console.log("## An error occurred while getting inventory: " + ERR);
  2936. } else {
  2937. let botkeys = 0;
  2938. let t = manager.createOffer(SENDER.getSteamID64());
  2939. let added = 0;
  2940. for (let i = 0; i < INV.length; i++) {
  2941. if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  2942. botkeys++;
  2943. if (added < amountkeys) {
  2944. t.addMyItem(INV[i]);
  2945. added++;
  2946. }
  2947. }
  2948. }
  2949. if (botkeys < amountkeys)
  2950. client.chatMessage(SENDER, "Bot don't have enough keys to send. (He has " + botkeys + " keys)");
  2951. else {
  2952. t.send();
  2953. client.chatMessage(SENDER, amountkeys + " keys sent to your account.");
  2954. }
  2955. }
  2956. });
  2957. } else {
  2958. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  2959. }
  2960. }
  2961.  
  2962. else if (MSG.toUpperCase().indexOf("!TFWITHDRAW") >= 0) {
  2963. let amountkeys = parseInt(MSG.toUpperCase().replace("!TFWITHDRAW ", ""))
  2964. if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
  2965. manager.getInventoryContents(CONFIG.TFGAME, 2, true, (ERR, INV, CURR) => {
  2966. if (ERR) {
  2967. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory.");
  2968. console.log("## An error occurred while getting inventory: " + ERR);
  2969. } else {
  2970. let botkeys = 0;
  2971. let t = manager.createOffer(SENDER.getSteamID64());
  2972. let added = 0;
  2973. for (let i = 0; i < INV.length; i++) {
  2974. if (CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  2975. botkeys++;
  2976. if (added < amountkeys) {
  2977. t.addMyItem(INV[i]);
  2978. added++;
  2979. }
  2980. }
  2981. }
  2982. if (botkeys < amountkeys)
  2983. client.chatMessage(SENDER, "Bot don't have enough keys to send. (He has " + botkeys + " keys)");
  2984. else {
  2985. t.send();
  2986. client.chatMessage(SENDER, amountkeys + " keys sent to your account.");
  2987. }
  2988. }
  2989. });
  2990. } else {
  2991. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  2992. }
  2993. }
  2994. else if (MSG.toUpperCase().indexOf("!GEMSWITHDRAW") >= 0) {
  2995. let amountgems = parseInt(MSG.toUpperCase().replace("!GEMSWITHDRAW ", ""))
  2996. if (!isNaN(amountgems) && parseInt(amountgems) > 0) {
  2997. manager.getInventoryContents(CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  2998. if (ERR) {
  2999. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory.");
  3000. console.log("## An error occurred while getting inventory: " + ERR);
  3001. } else {
  3002. let botgems = 0;
  3003. let t = manager.createOffer(SENDER.getSteamID64());
  3004. for (let i = 0; i < INV.length; i++) {
  3005. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  3006. botgems = INV[i].amount;
  3007. if (INV[i].amount >= amountgems) {
  3008. INV[i].amount = amountgems;
  3009. t.addMyItem(INV[i]);
  3010. break;
  3011. }
  3012. }
  3013. }
  3014. if (botgems < amountgems)
  3015. client.chatMessage(SENDER, "Bot don't have enough gems to send. (He has " + botgems + " gems)");
  3016. else {
  3017. t.send();
  3018. client.chatMessage(SENDER, amountgems + " gems sent to your account.");
  3019. }
  3020. }
  3021. });
  3022. } else {
  3023. client.chatMessage(SENDER, "Please enter a valid amount of gems!");
  3024. }
  3025. }
  3026. else if (MSG.toUpperCase().indexOf("!DEPOSIT") >= 0) {
  3027. let amountkeys = parseInt(MSG.toUpperCase().replace("!DEPOSIT ", ""));
  3028. if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
  3029. let t = manager.createOffer(SENDER.getSteamID64());
  3030. t.getUserDetails((ERR, ME, THEM) => {
  3031. if (ERR) {
  3032. console.log("## An error occurred while getting trade holds: " + ERR);
  3033. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  3034. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  3035. let theirKeys = [];
  3036. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  3037. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 2, true, (ERR, INV, CURR) => {
  3038. if (ERR) {
  3039. console.log("## An error occurred while getting inventory: " + ERR);
  3040. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  3041. } else {
  3042. let theirKeys = [];
  3043. for (let i = 0; i < INV.length; i++) {
  3044. if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  3045. theirKeys.push(INV[i]);
  3046. }
  3047. }
  3048. if (theirKeys.length < amountkeys) {
  3049. client.chatMessage(SENDER, "You don't have enough keys to send. (You have " + theirKeys.length + " keys)");
  3050. } else {
  3051. t.addTheirItems(theirKeys);
  3052. t.send();
  3053. client.chatMessage(SENDER, "You sent me " + amountkeys + " keys.");
  3054. }
  3055. }
  3056. });
  3057. } else {
  3058. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  3059. }
  3060. });
  3061. } else {
  3062. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  3063. }
  3064. }
  3065. else if (MSG.toUpperCase().indexOf("!TFDEPOSIT") >= 0) {
  3066. let amountkeys = parseInt(MSG.toUpperCase().replace("!TFDEPOSIT ", ""));
  3067. if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
  3068. let t = manager.createOffer(SENDER.getSteamID64());
  3069. t.getUserDetails((ERR, ME, THEM) => {
  3070. if (ERR) {
  3071. console.log("## An error occurred while getting trade holds: " + ERR);
  3072. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  3073. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  3074. let theirKeys = [];
  3075. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  3076. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 2, true, (ERR, INV, CURR) => {
  3077. if (ERR) {
  3078. console.log("## An error occurred while getting inventory: " + ERR);
  3079. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  3080. } else {
  3081. let theirKeys = [];
  3082. for (let i = 0; i < INV.length; i++) {
  3083. if (CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  3084. theirKeys.push(INV[i]);
  3085. }
  3086. }
  3087. if (theirKeys.length < amountkeys) {
  3088. client.chatMessage(SENDER, "You don't have enough keys to send. (You have " + theirKeys.length + " keys)");
  3089. } else {
  3090. t.addTheirItems(theirKeys);
  3091. t.send();
  3092. client.chatMessage(SENDER, "You sent me " + amountkeys + " keys.");
  3093. }
  3094. }
  3095. });
  3096. } else {
  3097. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  3098. }
  3099. });
  3100. } else {
  3101. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  3102. }
  3103. }
  3104. else if (MSG.toUpperCase().indexOf("!GEMSDEPOSIT") >= 0) {
  3105. let amountgems = parseInt(MSG.toUpperCase().replace("!GEMSDEPOSIT ", ""));
  3106. if (!isNaN(amountgems) && parseInt(amountgems) > 0) {
  3107. let t = manager.createOffer(SENDER.getSteamID64());
  3108. t.getUserDetails((ERR, ME, THEM) => {
  3109. if (ERR) {
  3110. console.log("## An error occurred while getting trade holds: " + ERR);
  3111. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  3112. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  3113. let theirKeys = [];
  3114. client.chatMessage(SENDER, ":checkpoint: Processing your request...");
  3115. manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, true, (ERR, INV, CURR) => {
  3116. if (ERR) {
  3117. console.log("## An error occurred while getting inventory: " + ERR);
  3118. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  3119. } else {
  3120. let theirKeys = [];
  3121. let botgems = 0;
  3122. for (let i = 0; i < INV.length; i++) {
  3123. if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  3124. botgems = INV[i].amount;
  3125. if (INV[i].amount >= amountgems) {
  3126. INV[i].amount = amountgems;
  3127. t.addTheirItem(INV[i]);
  3128. break;
  3129. }
  3130. }
  3131. }
  3132. if (botgems < amountgems) {
  3133. client.chatMessage(SENDER, "You don't have enough gems to send. (You have " + botgems + " gems)");
  3134. } else {
  3135. t.send();
  3136. client.chatMessage(SENDER, "You sent me " + amountgems + " gems.");
  3137. }
  3138. }
  3139. });
  3140. } else {
  3141. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  3142. }
  3143. });
  3144. } else {
  3145. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  3146. }
  3147. }
  3148. else if (MSG.toUpperCase() === "!SHUTDOWN") {
  3149. client.chatMessage(SENDER, "GoodBye!");
  3150. client.logOff();
  3151. process.exit(69)
  3152. }
  3153. else if (MSG.toUpperCase() === "!RESTART") {
  3154. client.chatMessage(SENDER, "Relogging!");
  3155. client.relog();
  3156. }
  3157. else if (MSG.toUpperCase().indexOf("!BLOCK") >= 0) {
  3158. let n = MSG.toUpperCase().replace("!BLOCK ", "").toString();
  3159. if (SID64REGEX.test(n)) {
  3160. client.chatMessage(SENDER, "User blocked.");
  3161. client.blockUser(n);
  3162. } else {
  3163. client.chatMessage(SENDER, "Please provide a valid SteamID64");
  3164. }
  3165. }
  3166. else if (MSG.toUpperCase().indexOf("!UNBLOCK") >= 0) {
  3167. let n = MSG.toUpperCase().replace("!UNBLOCK ", "").toString();
  3168. if (SID64REGEX.test(n)) {
  3169. client.chatMessage(SENDER, "User unblocked.");
  3170. client.unblockUser(n);
  3171. } else {
  3172. client.chatMessage(SENDER, "Please provide a valid SteamID64");
  3173. }
  3174. }
  3175. else if (MSG.toUpperCase().indexOf("!USERCHECK") >= 0) {
  3176. let n = MSG.toUpperCase().replace("!USERCHECK ", "").toString();
  3177. if (SID64REGEX.test(n)) {
  3178. if (Object.keys(botSets).length > 0) {
  3179. client.chatMessage(SENDER, "Loading badges...");
  3180. Utils.getBadges(n, (ERR, DATA) => {
  3181. if (!ERR) {
  3182. let b = {}; // List with badges that CAN still be crafted
  3183. if (DATA) {
  3184. for (let i = 0; i < Object.keys(DATA).length; i++) {
  3185. if (DATA[Object.keys(DATA)[i]] < 6) {
  3186. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  3187. }
  3188. }
  3189. } else {
  3190. client.chatMessage(SENDER.getSteamID64(), n + "'s badges are empty, sending an offer without checking badges.");
  3191. }
  3192. console.log(b);
  3193. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  3194. // 1: GET BOTS CARDS. DONE
  3195. // 2: GET PLAYER's BADGES. DONE
  3196. // 3: MAGIC
  3197. let hisMaxSets = 0,
  3198. botNSets = 0;
  3199. // Loop for sets he has partially completed
  3200. for (let i = 0; i < Object.keys(b).length; i++) {
  3201. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  3202. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  3203. }
  3204. }
  3205. // Loop for sets he has never crafted
  3206. for (let i = 0; i < Object.keys(botSets).length; i++) {
  3207. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  3208. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  3209. hisMaxSets += 5;
  3210. } else {
  3211. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  3212. }
  3213. }
  3214. botNSets += botSets[Object.keys(botSets)[i]].length;
  3215. }
  3216. 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.CSGO.BUY1FORAMOUNTOFSETS * 100) / 100 + " keys.");
  3217. } else {
  3218. client.chatMessage(SENDER, "An error occurred while getting " + n + "'s badges. Please try again.");
  3219. console.log("An error occurred while getting badges: " + ERR);
  3220. }
  3221. });
  3222. } else {
  3223. client.chatMessage(SENDER, "Please try again later.");
  3224. }
  3225. } else {
  3226. client.chatMessage(SENDER, "Please provide a valid SteamID64.");
  3227. }
  3228. }
  3229. else if (MSG.toUpperCase() === "!STOCK") {
  3230. client.chatMessage(SENDER, "Loading inventory...");
  3231. Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
  3232. console.log("DEBUG#INVLOADED");
  3233. if (!ERR) {
  3234. let s = DATA;
  3235. Utils.getSets(s, allCards, (ERR, DATA) => {
  3236. console.log("DEBUG#SETSLOADED");
  3237. if (!ERR) {
  3238. // console.log(b);
  3239. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  3240. // 1: GET BOTS CARDS. DONE
  3241. // 2: GET PLAYER's BADGES. DONE
  3242. // 2: GET PLAYER's BADGES. DONE
  3243. // 3: MAGIC
  3244. let hisMaxSets = 0,
  3245. botNSets = 0;
  3246. // Loop for sets he has partially completed
  3247. // Loop for sets he has never crafted
  3248. for (let i = 0; i < Object.keys(DATA).length; i++) {
  3249. if (DATA[Object.keys(DATA)[i]].length >= 5) {
  3250. hisMaxSets += 5;
  3251. } else {
  3252. hisMaxSets += DATA[Object.keys(DATA)[i]].length;
  3253. }
  3254. botNSets += DATA[Object.keys(DATA)[i]].length;
  3255. }
  3256. totalBotSets = botNSets;
  3257. let playThis = CONFIG.PLAYGAMES;
  3258. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  3259. playThis[0] = parseString(playThis[0], totalBotSets);
  3260. }
  3261. if (botNSets === 0) {
  3262. client.chatMessage(SENDER, "You currently don't have any available set which the bot can stock.");
  3263. }
  3264. else {
  3265. client.gamesPlayed(playThis);
  3266. client.chatMessage(SENDER, "You currently have " + botNSets + " set(s) available which the bot can stock.\r\nSending offer...");
  3267. let t = manager.createOffer(SENDER.getSteamID64());
  3268. Utils.getSets(s, allCards, (ERR, DDATA) => {
  3269. if (!ERR) {
  3270. sortSetsByAmountB(s, (DATA) => {
  3271. let setsSent = {};
  3272. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  3273. console.log(setsSent);
  3274. console.log(DATA[i]);
  3275. if (DDATA[DATA[i]]) {
  3276. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  3277. t.addTheirItems(DDATA[DATA[i]][j]);
  3278. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  3279. }
  3280. } else {
  3281. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  3282. continue firsttLoop;
  3283. }
  3284. }
  3285. });
  3286. console.log("DEBUG#SENDING");
  3287. t.data("commandused", "Stock");
  3288. t.send((ERR, STATUS) => {
  3289. if (ERR) {
  3290. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  3291. console.log("## An error occurred while sending trade: " + ERR);
  3292. } else {
  3293. client.chatMessage(SENDER, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
  3294. console.log("## Trade offer sent!");
  3295. }
  3296. });
  3297. } else {
  3298. console.log("## An error occurred while getting bot sets: " + ERR);
  3299. }
  3300. });
  3301. }
  3302. } else {
  3303. console.log("## An error occurred while getting user sets: " + ERR);
  3304. }
  3305. });
  3306. } else {
  3307. console.log("## An error occurred while getting user inventory: " + ERR);
  3308. }
  3309. });
  3310. }
  3311. else {
  3312. client.chatMessage(SENDER, "Command not recognized.");
  3313. }
  3314. }
  3315. else {
  3316. client.chatMessage(SENDER, "Command not recognized. Use !COMMANDS to see how this bot works.");
  3317. }
  3318. });
  3319.  
  3320. client.on("friendRelationship", (SENDER, REL) => {
  3321. if (REL === 2) {
  3322. client.addFriend(SENDER);
  3323. } else if (REL === 3) {
  3324. if (CONFIG.INVITETOGROUPID) {
  3325. client.inviteToGroup(SENDER, CONFIG.INVITETOGROUPID);
  3326. }
  3327. client.chatMessage(SENDER, CONFIG.MESSAGES.WELCOME);
  3328. }
  3329. });
  3330.  
  3331. // manager.on("unknownOfferSent", (o, os) => {
  3332. // if (o.state === 9) {
  3333. // console.log("## OFFER SENT LIST");
  3334. // community.checkConfirmations();
  3335. // }
  3336. // });
  3337.  
  3338. // community.on("newConfirmation", (CONF) => {
  3339. // console.log("## New confirmation.");
  3340. // community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id);
  3341. // });
  3342. manager.on("sentOfferChanged", (OFFER, OLDSTATE) => {
  3343. if (OFFER.state === 2) {
  3344. client.chatMessage(OFFER.partner, "Trade confirmed! Click here to accept itI sent you a trade, please check: http://steamcommunity.com/tradeoffer/" + OFFER.id);
  3345. } else if (OFFER.state === 3) {
  3346. Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
  3347. if (!ERR) {
  3348. let s = DATA;
  3349. Utils.getSets(s, allCards, (ERR, DATA) => {
  3350. if (!ERR) {
  3351. botSets = DATA;
  3352. console.log("## Bot's sets loaded.");
  3353. } else {
  3354. console.log("## An error occurred while getting bot sets: " + ERR);
  3355. }
  3356. let botNSets = 0;
  3357. for (let i = 0; i < Object.keys(botSets).length; i++) {
  3358. botNSets += botSets[Object.keys(botSets)[i]].length;
  3359. }
  3360. totalBotSets = botNSets;
  3361. let playThis = CONFIG.PLAYGAMES;
  3362. if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) === "string") {
  3363. playThis[0] = parseString(playThis[0], totalBotSets);
  3364. }
  3365. client.gamesPlayed(playThis);
  3366. });
  3367. } else {
  3368. console.log("## An error occurred while getting bot inventory: " + ERR);
  3369. }
  3370. });
  3371. if (CONFIG.INVITETOGROUPID) {
  3372. client.inviteToGroup(OFFER.partner, CONFIG.INVITETOGROUPID);
  3373. }
  3374. let d = "" + OFFER.data("commandused") + "";
  3375. d += "\nSets: " + OFFER.data("amountofsets");
  3376. d += "\nKeys: " + OFFER.data("amountofkeys");
  3377. d += "\nSteamID: " + OFFER.partner.getSteamID64();
  3378. fs.writeFile("./TradesAccepted/" + OFFER.id + "-" + OFFER.partner.getSteamID64() + ".txt", d, (ERR) => {
  3379. if (ERR) {
  3380. console.log("## An error occurred while writing trade file: " + ERR);
  3381. }
  3382. });
  3383. //IF TRADE WAS GAME GIVE PLAYER THE CODE
  3384. if (OFFER.data("commandused") === "BuyGame") {
  3385. let gamesStock = jsonfile.readFileSync(gamesstockfilename);
  3386. let cdkey = gamesStock.stock[OFFER.data("index")].keys[0];
  3387. let name = gamesStock.stock[OFFER.data("index")].name;
  3388. gamesStock.stock[OFFER.data("index")].keys.splice(0, 1);
  3389.  
  3390. fs.writeFile(gamesstockfilename, JSON.stringify(gamesStock, null, "\t"), function (err) {
  3391. if (err) return console.log(err);
  3392. console.log('Steam CD Key successfully removed.');
  3393. });
  3394. client.chatMessage(OFFER.partner.getSteamID64(), "\nYour Steam CD Key for game \"" + name + "\" is:\r\n" + cdkey);
  3395. client.chatMessage(OFFER.partner.getSteamID64(), "\nYour Steam CD Key for game \"" + name + "\" is:\r\n" + cdkey);
  3396. client.chatMessage(OFFER.partner.getSteamID64(), "\nYour Steam CD Key for game \"" + name + "\" is:\r\n" + cdkey);
  3397. }
  3398. ///////////////////////////////////////// If you are reading this, yes I had in this bot game cd keys commands, I was too lazy to delete some functions etc. x) -FOX
  3399. community.getSteamUser(OFFER.partner, (ERR, USER) => {
  3400. if (ERR) {
  3401. console.log("## An error occurred while getting user profile: " + ERR);
  3402. client.chatMessage(USER.steamID, "An error occurred while getting your profile (to comment).");
  3403. } else {
  3404. USER.comment(CONFIG.COMMENTAFTERTRADE, (ERR) => {
  3405. if (ERR) {
  3406. console.log("## An error occurred while commenting on user profile: " + ERR);
  3407. client.chatMessage(USER.steamID, "An error occurred while getting commenting on your profile.");
  3408. } else {
  3409. client.chatMessage(USER.steamID, "Thanks for trading! :D");
  3410. }
  3411. });
  3412. }
  3413. });
  3414. }
  3415. else if (OFFER.state == 4) {
  3416. client.chatMessage(OFFER.partner, "You tried to send an counter offer, trade will be canceled. TradeID:" + OFFER.id);
  3417. console.log("[ SendOffer ] Aborted because of counter offer:" + OFFER.id);
  3418. }
  3419. else if (OFFER.state == 5) {
  3420. client.chatMessage(OFFER.partner, "You havent accepted the Trade. Trade expired. TradeID:" + OFFER.id);
  3421. console.log("[ SendOffer ] Tradeoffer expired. TradeID:" + OFFER.id);
  3422. }
  3423. else if (OFFER.state == 6) {
  3424. client.chatMessage(OFFER.partner, "We canceled the offer it may be expired. Please try again if you wish to receive sets!");
  3425. console.log("[ SendOffer ] Tradeoffer canceled by Bot (expired). TradeID:" + OFFER.id);
  3426. }
  3427. else if (OFFER.state == 7) {
  3428. client.chatMessage(OFFER.partner, "You declined the Trade. TradeID:" + OFFER.id);
  3429. console.log("[ SendOffer ] Tradeoffer declined by User. TradeID:" + OFFER.id);
  3430. }
  3431. else if (OFFER.state == 11) {
  3432. client.chatMessage(OFFER.partner, "You are in escrow and need to check your account for limitations. TradeID:" + OFFER.id);
  3433. console.log("[ SendOffer ] Tradeoffer aborted because user is in escrow and cant trade. TradeID:" + OFFER.id);
  3434. }
  3435. });
  3436.  
  3437. manager.on("newOffer", (OFFER) => {
  3438. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(OFFER.partner.getSteamID64())) >= 0) {
  3439. OFFER.getUserDetails((ERR, ME, THEM) => {
  3440. if (ERR) {
  3441. console.log("## An error occurred while getting trade holds: " + ERR);
  3442. client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again");
  3443. OFFER.decline((ERR) => {
  3444. if (ERR) {
  3445. console.log("## An error occurred while declining trade: " + ERR);
  3446. }
  3447. });
  3448. } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
  3449. OFFER.accept((ERR) => {
  3450. if (ERR) {
  3451. console.log("## An error occurred while declining trade: " + ERR);
  3452. OFFER.decline((ERR) => {
  3453. if (ERR) {
  3454. console.log("## An error occurred while declining trade: " + ERR);
  3455. }
  3456. });
  3457. } else {
  3458. client.chatMessage(OFFER.partner, "Offer accepted!");
  3459. }
  3460. });
  3461. } else {
  3462. client.chatMessage(OFFER.partner, "Please make sure you don't have a trade hold!");
  3463. OFFER.decline((ERR) => {
  3464. if (ERR) {
  3465. console.log("## An error occurred while declining trade: " + ERR);
  3466. }
  3467. });
  3468. }
  3469. });
  3470. } else if (OFFER.itemsToGive.length === 0) {
  3471. let onlySteam = true;
  3472. for (let i = 0; i < OFFER.itemsToReceive.length; i++) {
  3473. if (OFFER.itemsToReceive[i].appid !== 753) {
  3474. onlySteam = false;
  3475. }
  3476. }
  3477. if (onlySteam) {
  3478. OFFER.accept((ERR) => {
  3479. if (ERR) {
  3480. console.log("## An error occurred while declining trade: " + ERR);
  3481. }
  3482. });
  3483. }
  3484. } else {
  3485. OFFER.decline((ERR) => {
  3486. if (ERR) {
  3487. console.log("## An error occurred while declining trade: " + ERR);
  3488. }
  3489. });
  3490. }
  3491. });
  3492.  
  3493. community.on("newConfirmation", (CONF) => {
  3494. console.log("## New confirmation.");
  3495. community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id, (ERR) => {
  3496. if (ERR) {
  3497. console.log("## An error occurred while accepting confirmation: " + ERR);
  3498. } else {
  3499. console.log("## Confirmation accepted.");
  3500. }
  3501. });
  3502. });
  3503.  
  3504. function sortSetsByAmount(SETS, callback) {
  3505. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length).reverse());
  3506. }
  3507.  
  3508. function sortSetsByAmountB(SETS, callback) {
  3509. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length));
  3510. }
  3511.  
  3512. function parseString(INPUT, SETS) {
  3513. return INPUT.replace(":sets:", SETS);
  3514. }
  3515.  
  3516. setInterval(function () {
  3517. let botNSets = 0;
  3518. for (let i = 0; i < Object.keys(botSets).length; i++) {
  3519. botNSets += botSets[Object.keys(botSets)[i]].length;
  3520. }
  3521. totalBotSets = botNSets;
  3522. let playThis = CONFIG.PLAYGAMES;
  3523. playThis[0] =
  3524. totalBotSets + " Sets - 14:1 CS:GO / 1:290 Gems / 11:1 TF / 14:1 PUBG";
  3525. client.gamesPlayed(playThis);
  3526.  
  3527. }, 1000 * 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement