Advertisement
Guest User

Untitled

a guest
May 21st, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.74 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.  
  12. // /Hey, you did not accept the offer. Please try again if you wish to receive sets!
  13.  
  14. let client = new SteamUser(),
  15. manager = new TradeOfferManager({
  16. "steam": client,
  17. "language": "en",
  18. "pollInterval": "10000",
  19. "cancelTime": "7200000" // 2 hours in ms
  20. }),
  21. community = new SteamCommunity();
  22.  
  23. fs.readFile("./UserData/Users.json", (ERR, DATA) => {
  24. if (ERR) {
  25. console.log("## An error occurred while getting Users: " + ERR);
  26. } else {
  27. users = JSON.parse(DATA);
  28. }
  29. });
  30.  
  31. Utils.getCardsInSets((ERR, DATA) => {
  32. if (!ERR) {
  33. allCards = DATA;
  34. console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
  35. } else {
  36. console.log("An error occurred while getting cards: " + ERR);
  37. }
  38. });
  39.  
  40. setInterval(() => {
  41. for (let i = 0; i < Object.keys(users).length; i++) {
  42. if (users[Object.keys(users)[i]].idleforhours >= CONFIG.MAXHOURSADDED) {
  43. client.chatMessage(Object.keys(users)[i], "Hello, you have been inactive for a long time. If you wish to use K4Cs service again, readd me.");
  44. client.removeFriend(Object.keys(users)[i]);
  45. delete users[Object.keys(users)[i]];
  46. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  47. if (ERR) {
  48. console.log("## An error occurred while writing UserData file: " + ERR);
  49. }
  50. });
  51. } else {
  52. users[Object.keys(users)[i]].idleforhours += 1;
  53. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  54. if (ERR) {
  55. console.log("## An error occurred while writing UserData file: " + ERR);
  56. }
  57. });
  58. }
  59. }
  60. }, 1000 * 60 * 60);
  61.  
  62. client.logOn({
  63. accountName: CONFIG.USERNAME,
  64. password: CONFIG.PASSWORD,
  65. twoFactorCode: SteamTotp.getAuthCode(CONFIG.SHAREDSECRET)
  66. });
  67.  
  68. client.on("loggedOn", (details, parental) => {
  69. client.getPersonas([client.steamID], (personas) => {
  70. console.log("## Logged in as #" + client.steamID + " (" + personas[client.steamID].player_name + ")");
  71. });
  72. client.setPersona(1);
  73. client.gamesPlayed(CONFIG.PLAYGAMES);
  74. });
  75.  
  76. client.on("webSession", (sessionID, cookies) => {
  77. manager.setCookies(cookies, (ERR) => {
  78. if (ERR) {
  79. console.log("## An error occurred while setting cookies.");
  80. } else {
  81. console.log("## Websession created and cookies set.");
  82. }
  83. });
  84. community.setCookies(cookies);
  85. community.startConfirmationChecker(10000, CONFIG.IDENTITYSECRET);
  86. Utils.getInventory(client.steamID.getSteamID64(), (ERR, DATA) => {
  87. if (!ERR) {
  88. let s = Utils.sortInventory(DATA);
  89. Utils.getSets(s, (ERR, DATA) => {
  90. if (!ERR) {
  91. botSets = DATA;
  92. console.log("## Bot's sets loaded.");
  93. } else {
  94. console.log("## An error occurred while getting bot sets: " + ERR);
  95. }
  96. });
  97. } else {
  98. console.log("## An error occurred while getting bot inventory: " + ERR);
  99. process.exit();
  100. }
  101. });
  102. });
  103.  
  104. client.on("friendMessage", (SENDER, MSG) => {
  105. if (Object.keys(users).indexOf(SENDER.getSteamID64()) < 0) {
  106. users[SENDER.getSteamID64()] = {};
  107. users[SENDER.getSteamID64()].idleforhours = 0;
  108. fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
  109. if (ERR) {
  110. console.log("## An error occurred while writing UserData file: " + ERR);
  111. }
  112. });
  113. } else {
  114. users[SENDER.getSteamID64()].idleforhours = 0;
  115. }
  116. if (MSG.toUpperCase().indexOf("!LEVEL") >= 0) {
  117. let n = parseInt(MSG.toUpperCase().replace("!LEVEL ", ""));
  118. if (!isNaN(n)) {
  119. if (n <= CONFIG.MESSAGES.MAXLEVEL) {
  120. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA, CURRENTLEVEL, XPNEEDED) => {
  121. if (!ERR) {
  122. if (n > CURRENTLEVEL) {
  123. let s = 0,
  124. l = 0;
  125. for (let i = 0; i < (n - CURRENTLEVEL); i++) {
  126. s += parseInt((CURRENTLEVEL + l) / 10) + 1;
  127. l++;
  128. }
  129. client.chatMessage(SENDER, "To get to level " + n + " you will need " + (s - Math.floor(XPNEEDED / 100)) + " sets. That would cost " + parseInt((s - Math.floor(XPNEEDED / 100)) / CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS * 100) / 100 + " keys.");
  130. } else {
  131. client.chatMessage(SENDER, "Please provide a valid level.");
  132. }
  133. } else {
  134. console.log("## An error occurred while getting badge data: " + ERR);
  135. client.chatMessage(SENDER, "An error occurred while loading your badges. Please try again later.");
  136. }
  137. });
  138. } else {
  139. client.chatMessage(SENDER, "Please try a lower level.");
  140. }
  141. } else {
  142. client.chatMessage(SENDER, "Please provide a valid level.");
  143. }
  144. } else
  145. if (MSG.toUpperCase() === "!HELP") {
  146. client.chatMessage(SENDER, CONFIG.MESSAGES.HELP);
  147. if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64()) >= 0) {
  148. client.chatMessage(SENDER, CONFIG.MESSAGES.SELLHELP);
  149. }
  150. } else if (MSG.toUpperCase().indexOf("!CHECK") >= 0) {
  151. let n = parseInt(MSG.toUpperCase().replace("!CHECK ", ""));
  152. if (!isNaN(n)) {
  153. client.chatMessage(SENDER, "With " + n + " keys you can get " + n * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS + " sets.");
  154. } else {
  155. if (Object.keys(botSets).length > 0) {
  156. client.chatMessage(SENDER, "Loading badges...");
  157. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  158. if (!ERR) {
  159. let b = {}; // List with badges that CAN still be crafted
  160. for (let i = 0; i < Object.keys(DATA).length; i++) {
  161. if (DATA[Object.keys(DATA)[i]] < 6) {
  162. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  163. }
  164. }
  165. // console.log(b);
  166. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  167. // 1: GET BOTS CARDS. DONE
  168. // 2: GET PLAYER's BADGES. DONE
  169. // 3: MAGIC
  170. let hisMaxSets = 0,
  171. botNSets = 0;
  172. // Loop for sets he has partially completed
  173. for (let i = 0; i < Object.keys(b).length; i++) {
  174. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  175. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  176. }
  177. }
  178. // Loop for sets he has never crafted
  179. for (let i = 0; i < Object.keys(botSets).length; i++) {
  180. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  181. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  182. hisMaxSets += 5;
  183. } else {
  184. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  185. }
  186. }
  187. botNSets += botSets[Object.keys(botSets)[i]].length;
  188. }
  189. 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.");
  190. } else {
  191. console.log("An error occurred while getting badges: " + ERR);
  192. }
  193. });
  194. } else {
  195. client.chatMessage(SENDER, "Please try again later.");
  196. }
  197. }
  198. } else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
  199. if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64()) >= 0) {
  200. let n = parseInt(MSG.toUpperCase().replace("!SELL ", "")),
  201. amountofsets = n * CONFIG.CARDS.GIVE1KEYPERAMOUNTOFSETS;
  202. if (!isNaN(n)) {
  203. if (n <= CONFIG.MESSAGES.MAXSELL) {
  204. client.chatMessage(SENDER, "Processing your request.");
  205. let botKeys = [],
  206. t = manager.createOffer(SENDER.getSteamID64());
  207. t.getUserDetails((ERR, ME, THEM) => {
  208. if (ERR) {
  209. console.log("## An error occurred while getting trade holds: " + ERR);
  210. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  211. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  212. manager.getUserInventoryContents(client.steamID.getSteamID64(), 730, 2, true, (ERR, INV, CURR) => {
  213. if (ERR) {
  214. console.log("## An error occurred while getting bot inventory: " + ERR);
  215. client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
  216. } else {
  217. for (let i = 0; i < INV.length; i++) {
  218. if (botKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  219. botKeys.push(INV[i]);
  220. }
  221. }
  222. if (botKeys.length != n) {
  223. client.chatMessage(SENDER, "The bot does not have enough keys.");
  224. } else {
  225. let amountofB = amountofsets;
  226. Utils.getInventory(SENDER.getSteamID64(), (ERR, DATA) => {
  227. if (!ERR) {
  228. let s = Utils.sortInventory(DATA);
  229. Utils.getSets(s, (ERR, DDATA) => {
  230. if (!ERR) {
  231. sortSetsByAmountB(s, (DATA) => {
  232. let setsSent = {};
  233. firsttLoop: for (let i = 0; i < DATA.length; i++) {
  234. console.log(setsSent);
  235. console.log(DATA[i]);
  236. if (DDATA[DATA[i]]) {
  237. for (let j = 0; j < DDATA[DATA[i]].length; j++) {
  238. if (amountofB > 0) {
  239. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.MAXSETSELL) || !setsSent[DATA[i]]) {
  240. t.addTheirItems(DDATA[DATA[i]][j]);
  241. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  242. amountofB--;
  243. if (!setsSent[DATA[i]]) {
  244. setsSent[DATA[i]] = 1;
  245. } else {
  246. setsSent[DATA[i]] += 1;
  247. }
  248. } else {
  249. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  250. continue firsttLoop;
  251. }
  252. } else {
  253. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  254. continue firsttLoop;
  255. }
  256. }
  257. } else {
  258. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  259. continue firsttLoop;
  260. }
  261. }
  262. });
  263. if (amountofB > 0) {
  264. 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.");
  265. } else {
  266. console.log("DEBUG#SENDING");
  267. t.addMyItems(botKeys);
  268. t.data("commandused", "Sell");
  269. t.data("amountofsets", amountofsets.toString());
  270. t.data("amountofkeys", n);
  271. t.send((ERR, STATUS) => {
  272. if (ERR) {
  273. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again.");
  274. console.log("## An error occurred while sending trade: " + ERR);
  275. } else {
  276. client.chatMessage(SENDER, "Trade Sent! Click here to accept: https://steamcommunity.com/tradeoffer/" + t.id);
  277. console.log("## Trade offer sent!");
  278. }
  279. });
  280. }
  281. } else {
  282. console.log("## An error occurred while getting bot sets: " + ERR);
  283. }
  284. });
  285. } else {
  286. console.log("## An error occurred while getting user inventory: " + ERR);
  287. }
  288. });
  289. }
  290. }
  291. });
  292. } else {
  293. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  294. }
  295. });
  296. } else {
  297. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  298. }
  299. } else {
  300. client.chatMessage(SENDER, "Please enter a valid amount of keys!");
  301. }
  302. } else {
  303. client.chatMessage(SENDER, "You are not able to sell sets.");
  304. }
  305. } else if (MSG.toUpperCase().indexOf("!BUYANY") >= 0) {
  306. let n = MSG.toUpperCase().replace("!BUYANY ", ""),
  307. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  308. if (!isNaN(n)) {
  309. if (n <= CONFIG.MESSAGES.MAXBUY) {
  310. let t = manager.createOffer(SENDER.getSteamID64());
  311. n = parseInt(n);
  312. let theirKeys = [];
  313. t.getUserDetails((ERR, ME, THEM) => {
  314. if (ERR) {
  315. console.log("## An error occurred while getting trade holds: " + ERR);
  316. client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  317. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  318. client.chatMessage(SENDER, "Processing your request.");
  319. manager.getUserInventoryContents(SENDER.getSteamID64(), 730, 2, true, (ERR, INV, CURR) => {
  320. if (ERR) {
  321. console.log("## An error occurred while getting inventory: " + ERR);
  322. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  323. } else {
  324. amountofB = amountofsets;
  325. for (let i = 0; i < INV.length; i++) {
  326. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  327. theirKeys.push(INV[i]);
  328. }
  329. }
  330. if (theirKeys.length != n) {
  331. client.chatMessage(SENDER, "You do not have enough keys.");
  332. } else {
  333. sortSetsByAmount(botSets, (DATA) => {
  334. let setsSent = {};
  335. firstLoop: for (let i = 0; i < DATA.length; i++) {
  336. console.log(setsSent);
  337. console.log(DATA[i]);
  338. if (botSets[DATA[i]]) {
  339. for (let j = 0; j < botSets[DATA[i]].length; j++) {
  340. if (amountofB > 0) {
  341. if ((setsSent[DATA[i]] && setsSent[DATA[i]] < 5) || !setsSent[DATA[i]]) {
  342. t.addMyItems(botSets[DATA[i]][j]);
  343. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  344. amountofB--;
  345. if (!setsSent[DATA[i]]) {
  346. setsSent[DATA[i]] = 1;
  347. } else {
  348. setsSent[DATA[i]] += 1;
  349. }
  350. } else {
  351. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  352. continue firstLoop;
  353. }
  354. } else {
  355. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  356. continue firstLoop;
  357. }
  358. }
  359. } else {
  360. console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
  361. continue firstLoop;
  362. }
  363. }
  364. });
  365. }
  366. }
  367. if (amountofB > 0) {
  368. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  369. } else {
  370. console.log("DEBUG#SENDING");
  371. t.addTheirItems(theirKeys);
  372. t.data("commandused", "BuyAny");
  373. t.data("amountofsets", amountofsets.toString());
  374. t.data("amountofkeys", n);
  375. t.send((ERR, STATUS) => {
  376. if (ERR) {
  377. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  378. console.log("## An error occurred while sending trade: " + ERR);
  379. } else {
  380. client.chatMessage(SENDER, "Trade Sent! Click here to accept: https://steamcommunity.com/tradeoffer/" + t.id);
  381. console.log("## Trade offer sent!");
  382. }
  383. });
  384. }
  385. });
  386. } else {
  387. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  388. }
  389. });
  390. } else {
  391. client.chatMessage(SENDER, "Please try a lower amount of keys");
  392. }
  393. } else {
  394. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  395. }
  396. } else if (MSG.toUpperCase().indexOf("!BUY") >= 0) {
  397. let n = MSG.toUpperCase().replace("!BUY ", ""),
  398. amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
  399. if (!isNaN(n)) {
  400. if (n <= CONFIG.MESSAGES.MAXBUY) {
  401. let t = manager.createOffer(SENDER.getSteamID64());
  402. t.getUserDetails((ERR, ME, THEM) => {
  403. if (ERR) {
  404. console.log("## An error occurred while getting trade holds: " + ERR);
  405. client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again");
  406. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  407. n = parseInt(n);
  408. let theirKeys = [];
  409. client.chatMessage(SENDER, "Processing your request.");
  410. manager.getUserInventoryContents(SENDER.getSteamID64(), 730, 2, true, (ERR, INV, CURR) => {
  411. if (ERR) {
  412. console.log("## An error occurred while getting inventory: " + ERR);
  413. client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  414. } else {
  415. console.log("DEBUG#INV LOADED");
  416. if (!ERR) {
  417. console.log("DEBUG#INV LOADED NOERR");
  418. for (let i = 0; i < INV.length; i++) {
  419. if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
  420. theirKeys.push(INV[i]);
  421. }
  422. }
  423. if (theirKeys.length != n) {
  424. client.chatMessage(SENDER, "You do not have enough keys.");
  425. } else {
  426. Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  427. if (!ERR) {
  428. console.log("DEBUG#BADGE LOADED");
  429. if (!ERR) {
  430. let b = {}; // List with badges that CAN still be crafted
  431. for (let i = 0; i < Object.keys(DATA).length; i++) {
  432. if (DATA[Object.keys(DATA)[i]] < 6) {
  433. b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  434. }
  435. }
  436. console.log(DATA);
  437. console.log(b);
  438. // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  439. // 1: GET BOTS CARDS. DONE
  440. // 2: GET PLAYER's BADGES. DONE
  441. // 3: MAGIC
  442. let hisMaxSets = 0,
  443. botNSets = 0;
  444. // Loop for sets he has partially completed
  445. for (let i = 0; i < Object.keys(b).length; i++) {
  446. if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  447. hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  448. }
  449. }
  450. console.log("DEBUG#LOOP 1 DONE");
  451. // Loop for sets he has never crafted
  452. for (let i = 0; i < Object.keys(botSets).length; i++) {
  453. if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  454. if (botSets[Object.keys(botSets)[i]].length >= 5) {
  455. hisMaxSets += 5;
  456. } else {
  457. hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  458. }
  459. }
  460. botNSets += botSets[Object.keys(botSets)[i]].length;
  461. }
  462. console.log("DEBUG#LOOP 2 DONE");
  463. // HERE
  464. if (amountofsets <= hisMaxSets) {
  465. hisMaxSets = amountofsets;
  466. console.log("DEBUG#TRADE CREATED");
  467. sortSetsByAmount(botSets, (DATA) => {
  468. console.log("DEBUG#" + DATA);
  469. console.log("DEBUG#SETS SORTED");
  470. firstLoop: for (let i = 0; i < DATA.length; i++) {
  471. if (b[DATA[i]] == 0) {
  472. continue firstLoop;
  473. } else {
  474. console.log("DEBUG#" + i);
  475. console.log("DEBUG#FOR LOOP ITEMS");
  476. if (hisMaxSets > 0) {
  477. console.log("DEBUG#MAXSETSMORETHAN1");
  478. if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  479. console.log("DEBUG#LOOP #1");
  480. sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  481. if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  482. console.log("DEBUG#LOOP #1: ITEM ADD");
  483. console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  484. t.addMyItems(botSets[DATA[i]][j]);
  485. hisMaxSets--;
  486. console.log(hisMaxSets);
  487. } else {
  488. console.log("DEBUG#LOOP #1: RETURN");
  489. continue firstLoop;
  490. }
  491. }
  492. } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  493. console.log("DEBUG#LOOP #1 CONTINUE");
  494. continue; // *
  495. } 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
  496. bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  497. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  498. t.addMyItems(botSets[DATA[i]][j]);
  499. console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  500. hisMaxSets--;
  501. } else {
  502. console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  503. continue firstLoop;
  504. }
  505. }
  506. // console.log("DEBUG#LOOP #2 CONTINUE");
  507. // continue;
  508. }
  509. else if (hisMaxSets < 5) {
  510. console.log("DEBUG#LOOP #2");
  511. tLoop: for (let j = 0; j != hisMaxSets; j++) {
  512. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  513. t.addMyItems(botSets[DATA[i]][j]);
  514. console.log("DEBUG#LOOP #2: ITEM ADD");
  515. hisMaxSets--;
  516. console.log(hisMaxSets);
  517. } else {
  518. console.log("DEBUG#LOOP #2: RETURN");
  519. continue firstLoop;
  520. }
  521. }
  522. } else {
  523. console.log("DEBUG#LOOP #2");
  524. xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  525. if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  526. t.addMyItems(botSets[DATA[i]][j]);
  527. console.log("DEBUG#LOOP #2: ITEM ADD");
  528. hisMaxSets--;
  529. console.log(hisMaxSets);
  530. } else {
  531. console.log("DEBUG#LOOP #2: RETURN");
  532. continue firstLoop;
  533. }
  534. }
  535. }
  536. } else {
  537. console.log("DEBUG#RETURN");
  538. break firstLoop;
  539. }
  540. }
  541. }
  542. if (hisMaxSets > 0) {
  543. client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  544. } else {
  545. console.log("DEBUG#SENDING");
  546. t.addTheirItems(theirKeys);
  547. t.data("commandused", "Buy");
  548. t.data("amountofkeys", n);
  549. t.data("amountofsets", amountofsets.toString());
  550. t.send((ERR, STATUS) => {
  551. if (ERR) {
  552. client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  553. console.log("## An error occurred while sending trade: " + ERR);
  554. } else {
  555. client.chatMessage(SENDER, "Trade Sent! Click here to accept: https://steamcommunity.com/tradeoffer/ " + t.id);
  556. console.log("## Trade offer sent! Click here to accept: https://steamcommunity.com/tradeoffer/" + t.id);
  557. }
  558. });
  559. }
  560. });
  561. } else {
  562. 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.");
  563. }
  564. // TO HERE
  565. } else {
  566. console.log("An error occurred while getting badges: " + ERR);
  567. }
  568. } else {
  569. client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  570. console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  571. }
  572. });
  573. }
  574. } else {
  575. console.log("## An error occurred while getting inventory: " + ERR);
  576. client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  577. }
  578. }
  579. });
  580. } else {
  581. client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  582. }
  583. });
  584. } else {
  585. client.chatMessage(SENDER, "Please try a lower amount of keys.");
  586. }
  587. } else {
  588. client.chatMessage(SENDER, "Please provide a valid amount of keys.");
  589. }
  590. } else {
  591. client.chatMessage(SENDER, "Command not recognized. Use !help to see how this bot works.");
  592. }
  593. });
  594.  
  595. client.on("friendRelationship", (SENDER, REL) => {
  596. if (REL === 2) {
  597. client.addFriend(SENDER);
  598. } else if (REL === 3) {
  599. client.chatMessage(SENDER, CONFIG.MESSAGES.WELCOME);
  600. }
  601. });
  602.  
  603. manager.on("sentOfferChanged", (OFFER, OLDSTATE) => {
  604. Utils.getInventory(client.steamID.getSteamID64(), (ERR, DATA) => {
  605. if (!ERR) {
  606. let s = Utils.sortInventory(DATA);
  607. Utils.getSets(s, (ERR, DATA) => {
  608. if (!ERR) {
  609. botSets = DATA;
  610. console.log("## Bot's sets loaded.");
  611. } else {
  612. console.log("## An error occurred while getting bot sets: " + ERR);
  613. }
  614. });
  615. } else {
  616. console.log("## An error occurred while getting bot inventory: " + ERR);
  617. }
  618. });
  619. if (OFFER.state == 3) {
  620. let d = "" + OFFER.data("commandused") + "";
  621. d += "\nSets: " + OFFER.data("amountofsets");
  622. d += "\nKeys: " + OFFER.data("amountofkeys");
  623. d += "\nSteamID: " + OFFER.partner.getSteamID64();
  624. fs.writeFile("./TradesAccepted/" + OFFER.id + "-" + OFFER.partner.getSteamID64() + ".txt", d, (ERR) => {
  625. if (ERR) {
  626. console.log("## An error occurred while writing trade file: " + ERR);
  627. }
  628. });
  629. community.getSteamUser(OFFER.partner, (ERR, USER) => {
  630. if (ERR) {
  631. console.log("## An error occurred while getting user profile: " + ERR);
  632. client.chatMessage(USER.steamID, "An error occurred while getting your profile (to comment).");
  633. } else {
  634. USER.comment(CONFIG.COMMENTAFTERTRADE, (ERR) => {
  635. if (ERR) {
  636. console.log("## An error occurred while commenting on user profile: " + ERR);
  637. client.chatMessage(USER.steamID, "An error occurred while getting commenting on your profile.");
  638. } else {
  639. client.chatMessage(USER.steamID, "Trade complete");
  640. }
  641. });
  642. }
  643. });
  644. } else if (OFFER.state == 6) {
  645. client.chatMessage(OFFER.partner, "Hey, you did not accept the offer. Please try again if you wish to receive sets!");
  646. }
  647. });
  648.  
  649. manager.on("newOffer", (OFFER) => {
  650. if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0) {
  651. OFFER.getUserDetails((ERR, ME, THEM) => {
  652. if (ERR) {
  653. console.log("## An error occurred while getting trade holds: " + ERR);
  654. client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again");
  655. OFFER.decline((ERR) => {
  656. if (ERR) {
  657. console.log("## An error occurred while declining trade: " + ERR);
  658. }
  659. });
  660. } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  661. OFFER.accept((ERR) => {
  662. if (ERR) {
  663. console.log("## An error occurred while declining trade: " + ERR);
  664. OFFER.decline((ERR) => {
  665. if (ERR) {
  666. console.log("## An error occurred while declining trade: " + ERR);
  667. }
  668. });
  669. } else {
  670. client.chatMessage(OFFER.partner, "Offer accepted!");
  671. }
  672. });
  673. } else {
  674. client.chatMessage(OFFER.partner, "Please make sure you don't have a trade hold!");
  675. OFFER.decline((ERR) => {
  676. if (ERR) {
  677. console.log("## An error occurred while declining trade: " + ERR);
  678. }
  679. });
  680. }
  681. });
  682. } else {
  683. OFFER.decline((ERR) => {
  684. if (ERR) {
  685. console.log("## An error occurred while declining trade: " + ERR);
  686. }
  687. });
  688. }
  689. });
  690.  
  691. function sortSetsByAmount(SETS, callback) {
  692. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length).reverse());
  693. }
  694.  
  695. function sortSetsByAmountB(SETS, callback) {
  696. callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length));
  697. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement