Advertisement
Guest User

Untitled

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