Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let SteamUser = require("steam-user"),
- SteamTotp = require("steam-totp"),
- TradeOfferManager = require("steam-tradeoffer-manager"),
- SteamCommunity = require("steamcommunity"),
- Utils = require("./utils.js"),
- CONFIG = require("./SETTINGS/config.js"),
- allCards = {},
- botSets = {},
- fs = require("fs"),
- users = {},
- userMsgs = {},
- SID64REGEX = new RegExp(/^[0-9]{17}$/),
- chatLogs = "",
- userLogs = {},
- totalBotSets = 0,
- setsThatShouldntBeSent = [];
- let client = new SteamUser(),
- manager = new TradeOfferManager({
- "steam": client,
- "language": "en",
- "pollInterval": "10000",
- "cancelTime": "7200000" // 2 hours in ms
- }),
- community = new SteamCommunity();
- fs.readFile("./UserData/Users.json", (ERR, DATA) => {
- if (ERR) {
- console.log("## An error occurred while getting Users: " + ERR);
- } else {
- users = JSON.parse(DATA);
- }
- });
- Utils.getCardsInSets((ERR, DATA) => {
- if (!ERR) {
- allCards = DATA;
- console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
- } else {
- console.log("An error occurred while getting cards: " + ERR);
- }
- });
- setInterval(() => {
- for (let i = 0; i < Object.keys(users).length; i++) {
- if (users[Object.keys(users)[i]].idleforhours >= CONFIG.MAXHOURSADDED) {
- client.chatMessage(Object.keys(users)[i], "Hi, you have been inactive on my friends list for too long. If you wish to use The bot again please re-add me.");
- client.removeFriend(Object.keys(users)[i]);
- delete users[Object.keys(users)[i]];
- fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
- if (ERR) {
- console.log("## An error occurred while writing UserData file: " + ERR);
- }
- });
- } else {
- users[Object.keys(users)[i]].idleforhours += 1;
- fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
- if (ERR) {
- console.log("## An error occurred while writing UserData file: " + ERR);
- }
- });
- }
- }
- }, 1000 * 60 * 60);
- setInterval(() => {
- for (let i = 0; i < Object.keys(userMsgs).length; i++) {
- if (userMsgs[Object.keys(userMsgs)[i]] > CONFIG.MAXMSGPERSEC) {
- client.chatMessage(Object.keys(userMsgs)[i], "You will be delted by The bot for spam messaging. If this happens again you will be banned from using the bot.");
- client.removeFriend(Object.keys(userMsgs)[i]);
- for (let j = 0; j < CONFIG.ADMINS.length; j++) {
- client.chatMessage(CONFIG.ADMINS[j], "User #" + Object.keys(userMsgs)[i] + " has been removed for spamming. To block him use !block [STEAMID64]");
- }
- }
- }
- userMsgs = {};
- }, 1000);
- client.logOn({
- accountName: CONFIG.USERNAME,
- password: CONFIG.PASSWORD,
- twoFactorCode: SteamTotp.getAuthCode(CONFIG.SHAREDSECRET)
- });
- console.log(SteamTotp.getAuthCode(CONFIG.SHAREDSECRET));
- client.on("loggedOn", (details, parental) => {
- client.getPersonas([client.steamID], (personas) => {
- console.log("## Logged in as #" + client.steamID + " (" + personas[client.steamID].player_name + ")");
- });
- client.setPersona(1);
- });
- client.on("webSession", (sessionID, cookies) => {
- manager.setCookies(cookies, (ERR) => {
- if (ERR) {
- console.log("## An error occurred while setting cookies.");
- } else {
- console.log("## Websession created and cookies set.");
- }
- });
- // Add people that added the bot while it was online.
- for (let i = 0; i < Object.keys(client.myFriends).length; i++) {
- if (client.myFriends[Object.keys(client.myFriends)[i]] == 2) {
- client.addFriend(Object.keys(client.myFriends)[i]);
- }
- }
- community.setCookies(cookies);
- community.startConfirmationChecker(10000, CONFIG.IDENTITYSECRET);
- 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. :)
- Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
- console.log("DEBUG#INVLOADED");
- if (!ERR) {
- let s = DATA;
- Utils.getSets(s, allCards, (ERR, DATA) => {
- console.log("DEBUG#SETSLOADED");
- if (!ERR) {
- botSets = DATA;
- console.log("## Bot's sets loaded.");
- let botNSets = 0;
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- totalBotSets = botNSets;
- let playThis = CONFIG.PLAYGAMES;
- if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
- playThis[0] = parseString(playThis[0], totalBotSets);
- }
- client.gamesPlayed(playThis);
- } else {
- console.log("## An error occurred while getting bot sets: " + ERR);
- process.exit();
- }
- });
- } else {
- console.log("## An error occurred while getting bot inventory: " + ERR);
- }
- });
- });
- community.on("sessionExpired", (ERR) => {
- console.log("## Session Expired. Relogging.");
- client.webLogOn();
- });
- client.on("friendMessage", (SENDER, MSG) => {
- if (userLogs[SENDER.getSteamID64()]) {
- userLogs[SENDER.getSteamID64()].push(MSG);
- } else {
- userLogs[SENDER.getSteamID64()] = [];
- userLogs[SENDER.getSteamID64()].push(MSG);
- }
- fs.writeFile("./ChatLogs/UserLogs/" + SENDER.getSteamID64() + "-log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".json", JSON.stringify({ logs: userLogs[SENDER.getSteamID64()] }), (ERR) => {
- if (ERR) {
- console.log("## An error occurred while writing UserLogs file: " + ERR);
- }
- });
- chatLogs += SENDER.getSteamID64() + " : " + MSG + "\n";
- fs.writeFile("./ChatLogs/FullLogs/log-" + new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear() + ".txt", chatLogs, (ERR) => {
- if (ERR) {
- console.log("## An error occurred while writing FullLogs file: " + ERR);
- }
- });
- if (Object.keys(users).indexOf(SENDER.getSteamID64()) < 0) {
- users[SENDER.getSteamID64()] = {};
- users[SENDER.getSteamID64()].idleforhours = 0;
- fs.writeFile("./UserData/Users.json", JSON.stringify(users), (ERR) => {
- if (ERR) {
- console.log("## An error occurred while writing UserData file: " + ERR);
- }
- });
- } else {
- users[SENDER.getSteamID64()].idleforhours = 0;
- }
- if (userMsgs[SENDER.getSteamID64()]) {
- userMsgs[SENDER.getSteamID64()]++;
- } else {
- userMsgs[SENDER.getSteamID64()] = 1;
- }
- /*if (MSG.toUpperCase() == "!STOCK") {
- for (let i = 0; i < botSets.length; i++) {
- //
- }
- } else */
- if (MSG.toUpperCase().indexOf("!LEVEL") >= 0) {
- let n = parseInt(MSG.toUpperCase().replace("!LEVEL ", ""));
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXLEVEL) {
- Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA, CURRENTLEVEL, XPNEEDED) => {
- if (!ERR) {
- if (DATA) {
- if (n > CURRENTLEVEL) {
- let s = 0,
- l = 0;
- for (let i = 0; i < (n - CURRENTLEVEL); i++) {
- s += parseInt((CURRENTLEVEL + l) / 10) + 1;
- l++;
- }
- 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.");
- } else {
- client.chatMessage(SENDER, "the bot is unable to process this level, please enter a more realistic level request.");
- }
- } else {
- client.chatMessage(SENDER, "the bot couldn't find your level. Please make sure your Steam Profile is public and retry.");
- }
- } else {
- console.log("## An error occurred while getting badge data: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your badges. Please try again later.");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a lower level.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid level.");
- }
- } else if (MSG.toUpperCase() === "!HELP") {
- client.chatMessage(SENDER, CONFIG.MESSAGES.HELP);
- if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64()) >= 0) {
- client.chatMessage(SENDER, CONFIG.MESSAGES.SELLHELP);
- }
- } else if (MSG.toUpperCase().indexOf("!BUYONECHECK") >= 0) {
- client.chatMessage(SENDER, "the bot is currently loading your badges...");
- Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
- if (!ERR) {
- let b = {}; // List with badges that CAN still be crafted
- if (DATA) {
- for (let i = 0; i < Object.keys(DATA).length; i++) {
- if (DATA[Object.keys(DATA)[i]] < 6) {
- b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
- }
- }
- } else {
- client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
- }
- // console.log(b);
- // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
- // 1: GET BOTS CARDS. DONE
- // 2: GET PLAYER's BADGES. DONE
- // 3: MAGIC
- let hisMaxSets = 0,
- botNSets = 0;
- // Loop for sets he has partially completed
- for (let i = 0; i < Object.keys(b).length; i++) {
- if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
- hisMaxSets += 5 - b[Object.keys(b)[i]].length;
- }
- }
- // Loop for sets he has never crafted
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
- if (botSets[Object.keys(botSets)[i]].length >= 1) {
- hisMaxSets += 1;
- }
- }
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- totalBotSets = botNSets;
- let playThis = CONFIG.PLAYGAMES;
- if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
- playThis[0] = parseString(playThis[0], totalBotSets);
- }
- client.gamesPlayed(playThis);
- 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.");
- } else {
- client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
- console.log("An error occurred while getting badges: " + ERR);
- }
- });
- } else if (MSG.toUpperCase().indexOf("!SELLCHECK") >= 0) {
- let n = parseInt(MSG.toUpperCase().replace("!SELLCHECK ", ""));
- client.chatMessage(SENDER, "the bot is currently loading your inventory...");
- Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
- console.log("DEBUG#INVLOADED");
- if (!ERR) {
- let s = DATA;
- Utils.getSets(s, allCards, (ERR, DATA) => {
- console.log("DEBUG#SETSLOADED");
- if (!ERR) {
- // console.log(b);
- // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
- // 1: GET BOTS CARDS. DONE
- // 2: GET PLAYER's BADGES. DONE
- // 3: MAGIC
- let hisMaxSets = 0,
- botNSets = 0;
- // Loop for sets he has partially completed
- // Loop for sets he has never crafted
- for (let i = 0; i < Object.keys(DATA).length; i++) {
- if (DATA[Object.keys(DATA)[i]].length >= 5) {
- hisMaxSets += 5;
- } else {
- hisMaxSets += DATA[Object.keys(DATA)[i]].length;
- }
- botNSets += DATA[Object.keys(DATA)[i]].length;
- }
- totalBotSets = botNSets;
- let playThis = CONFIG.PLAYGAMES;
- if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
- playThis[0] = parseString(playThis[0], totalBotSets);
- }
- client.gamesPlayed(playThis);
- 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.");
- } else {
- console.log("## An error occurred while getting user sets: " + ERR);
- }
- });
- } else {
- console.log("## An error occurred while getting user inventory: " + ERR);
- }
- });
- } else if (MSG.toUpperCase().indexOf("!CHECK") >= 0) {
- let n = parseInt(MSG.toUpperCase().replace("!CHECK ", ""));
- if (!isNaN(n) && parseInt(n) > 0) {
- client.chatMessage(SENDER, "With " + n + " keys you can get " + n * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS + " sets.");
- } else {
- if (Object.keys(botSets).length > 0) {
- client.chatMessage(SENDER, "the bot is loading your badges...");
- Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
- if (!ERR) {
- let b = {}; // List with badges that CAN still be crafted
- if (DATA) {
- for (let i = 0; i < Object.keys(DATA).length; i++) {
- if (DATA[Object.keys(DATA)[i]] < 6) {
- b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
- }
- }
- } else {
- client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
- }
- // console.log(b);
- // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
- // 1: GET BOTS CARDS. DONE
- // 2: GET PLAYER's BADGES. DONE
- // 3: MAGIC
- let hisMaxSets = 0,
- botNSets = 0;
- // Loop for sets he has partially completed
- for (let i = 0; i < Object.keys(b).length; i++) {
- if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
- hisMaxSets += 5 - b[Object.keys(b)[i]].length;
- }
- }
- // Loop for sets he has never crafted
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
- if (botSets[Object.keys(botSets)[i]].length >= 5) {
- hisMaxSets += 5;
- } else {
- hisMaxSets += botSets[Object.keys(botSets)[i]].length;
- }
- }
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- totalBotSets = botNSets;
- let playThis = CONFIG.PLAYGAMES;
- if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
- playThis[0] = parseString(playThis[0], totalBotSets);
- }
- client.gamesPlayed(playThis);
- 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.");
- } else {
- client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
- console.log("An error occurred while getting badges: " + ERR);
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- }
- } else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
- if (botSets) {
- //if (CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(SENDER.getSteamID64().toString()) >= 0 || CONFIG.CARDS.PEOPLETHATCANSELL.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
- let n = parseInt(MSG.toUpperCase().replace("!SELL ", "")),
- amountofsets = n * CONFIG.CARDS.GIVE1KEYPERAMOUNTOFSETS;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXSELL) {
- client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
- let botKeys = [],
- t = manager.createOffer(SENDER.getSteamID64());
- t.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log("## An error occurred while getting trade holds: " + ERR);
- client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please check is your inventory public.");
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- console.log("## An error occurred while getting bot inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading the bot's inventory. Please try again.");
- } else {
- for (let i = 0; i < INV.length; i++) {
- if (botKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- botKeys.push(INV[i]);
- }
- }
- if (botKeys.length != n) {
- client.chatMessage(SENDER, "The bot does not have enough keys for this task.");
- } else {
- let amountofB = amountofsets;
- Utils.getInventory(SENDER.getSteamID64(), community, (ERR, DATA) => {
- if (!ERR) {
- let s = DATA;
- Utils.getSets(s, allCards, (ERR, DDATA) => {
- if (!ERR) {
- sortSetsByAmountB(s, (DATA) => {
- let setsSent = {};
- firsttLoop: for (let i = 0; i < DATA.length; i++) {
- console.log(setsSent);
- console.log(DATA[i]);
- if (DDATA[DATA[i]]) {
- for (let j = 0; j < DDATA[DATA[i]].length; j++) {
- if (amountofB > 0) {
- if ((setsSent[DATA[i]] && setsSent[DATA[i]] < CONFIG.CARDS.MAXSETSELL) || !setsSent[DATA[i]]) {
- t.addTheirItems(DDATA[DATA[i]][j]);
- console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
- amountofB--;
- if (!setsSent[DATA[i]]) {
- setsSent[DATA[i]] = 1;
- } else {
- setsSent[DATA[i]] += 1;
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
- continue firsttLoop;
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
- continue firsttLoop;
- }
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
- continue firsttLoop;
- }
- }
- });
- if (amountofB > 0) {
- 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.");
- } else {
- console.log("DEBUG#SENDING");
- t.addMyItems(botKeys);
- t.data("commandused", "Sell");
- t.data("amountofsets", amountofsets.toString());
- t.data("amountofkeys", n);
- t.send((ERR, STATUS) => {
- if (ERR) {
- client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
- console.log("## An error occurred while sending trade: " + ERR);
- } else {
- client.chatMessage(SENDER, "The bot has sent your trade! It's being confirmed...");
- console.log("## Trade offer sent!");
- }
- });
- }
- } else {
- console.log("## An error occurred while getting bot sets: " + ERR);
- }
- });
- } else {
- console.log("## An error occurred while getting user inventory: " + ERR);
- }
- });
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try a lower amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of keys!");
- }
- //else {
- //client.chatMessage(SENDER, "You are not able to sell sets.");
- //}
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- } else if (MSG.toUpperCase().indexOf("!BUYONE") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYONE ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXBUY) {
- let t = manager.createOffer(SENDER.getSteamID64());
- t.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log("## An error occurred while getting trade holds: " + ERR);
- client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- n = parseInt(n);
- let theirKeys = [];
- client.chatMessage(SENDER, "Processing your request.");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
- } else {
- console.log("DEBUG#INV LOADED");
- if (!ERR) {
- console.log("DEBUG#INV LOADED NOERR");
- for (let i = 0; i < INV.length; i++) {
- if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- theirKeys.push(INV[i]);
- }
- }
- if (theirKeys.length != n) {
- client.chatMessage(SENDER, "You do not have enough keys. Please try a lower request.");
- } else {
- Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
- if (!ERR) {
- console.log("DEBUG#BADGE LOADED");
- if (!ERR) {
- let b = {}; // List with badges that CAN still be crafted
- if (DATA) {
- for (let i = 0; i < Object.keys(DATA).length; i++) {
- if (DATA[Object.keys(DATA)[i]] < 6) {
- b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
- }
- }
- } else {
- client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
- }
- console.log(DATA);
- console.log(b);
- // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
- // 1: GET BOTS CARDS. DONE
- // 2: GET PLAYER's BADGES. DONE
- // 3: MAGIC
- let hisMaxSets = 0,
- botNSets = 0;
- // Loop for sets he has partially completed
- for (let i = 0; i < Object.keys(b).length; i++) {
- if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
- hisMaxSets += 5 - b[Object.keys(b)[i]].length;
- }
- }
- console.log("DEBUG#LOOP 1 DONE");
- // Loop for sets he has never crafted
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
- if (botSets[Object.keys(botSets)[i]].length >= 5) {
- hisMaxSets += 5;
- } else {
- hisMaxSets += botSets[Object.keys(botSets)[i]].length;
- }
- }
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- totalBotSets = botNSets;
- let playThis = CONFIG.PLAYGAMES;
- if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
- playThis[0] = parseString(playThis[0], totalBotSets);
- }
- client.gamesPlayed(playThis);
- console.log("DEBUG#LOOP 2 DONE");
- // HERE
- if (amountofsets <= hisMaxSets) {
- hisMaxSets = amountofsets;
- console.log("DEBUG#TRADE CREATED");
- sortSetsByAmount(botSets, (DATA) => {
- console.log("DEBUG#" + DATA);
- console.log("DEBUG#SETS SORTED");
- firstLoop: for (let i = 0; i < DATA.length; i++) {
- if (b[DATA[i]] == 0) {
- continue firstLoop;
- } else {
- console.log("DEBUG#" + i);
- console.log("DEBUG#FOR LOOP ITEMS");
- if (hisMaxSets > 0) {
- console.log("DEBUG#MAXSETSMORETHAN1");
- if (!b[DATA[i]] && botSets[DATA[i]].length > 0) { // TODO NOT FOR LOOP WITH BOTSETS. IT SENDS ALL
- // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
- bLoop: for (let j = 0; j < botSets[DATA[i]].length; j++) {
- if (botSets[DATA[i]][j] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
- hisMaxSets--;
- continue firstLoop;
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
- continue firstLoop;
- }
- }
- }
- } else {
- console.log("DEBUG#RETURN");
- break firstLoop;
- }
- }
- }
- if (hisMaxSets > 0) {
- client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
- } else {
- console.log("DEBUG#SENDING");
- t.addTheirItems(theirKeys);
- t.data("commandused", "BuyOne");
- t.data("amountofkeys", n);
- t.data("amountofsets", amountofsets.toString());
- t.data("index", setsThatShouldntBeSent.length);
- setsThatShouldntBeSent.push(t.itemsToGive);
- t.send((ERR, STATUS) => {
- if (ERR) {
- client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
- console.log("## An error occurred while sending trade: " + ERR);
- } else {
- client.chatMessage(SENDER, "The bot has sent your trade! It's being confirmed...");
- console.log("## Trade offer sent");
- }
- });
- }
- });
- } else {
- 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.");
- }
- // TO HERE
- } else {
- console.log("An error occurred while getting badges: " + ERR);
- }
- } else {
- client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
- console.log(SENDER, "## An error occurred while loading badges: " + ERR);
- }
- });
- }
- } else {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try a lower amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- } else if (MSG.toUpperCase().indexOf("!BUYANY") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYANY ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXBUY) {
- let t = manager.createOffer(SENDER.getSteamID64());
- n = parseInt(n);
- let theirKeys = [];
- t.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log("## An error occurred while getting trade holds: " + ERR);
- client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- client.chatMessage(SENDER, "Processing your request.");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
- } else {
- let amountofB = amountofsets;
- for (let i = 0; i < INV.length; i++) {
- if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- theirKeys.push(INV[i]);
- }
- }
- if (theirKeys.length != n) {
- client.chatMessage(SENDER, "You do not have enough keys.");
- } else {
- sortSetsByAmount(botSets, (DATA) => {
- let setsSent = {};
- firstLoop: for (let i = 0; i < DATA.length; i++) {
- console.log(setsSent);
- console.log(DATA[i]);
- if (botSets[DATA[i]]) {
- for (let j = 0; j < botSets[DATA[i]].length; j++) {
- if (amountofB > 0) {
- if ((setsSent[DATA[i]] && setsSent[DATA[i]] > -1) || !setsSent[DATA[i]]) {
- t.addMyItems(botSets[DATA[i]][j]);
- console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
- amountofB--;
- if (!setsSent[DATA[i]]) {
- setsSent[DATA[i]] = 1;
- } else {
- setsSent[DATA[i]] += 1;
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
- continue firstLoop;
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
- continue firstLoop;
- }
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
- continue firstLoop;
- }
- }
- });
- }
- if (amountofB > 0) {
- client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
- } else {
- console.log("DEBUG#SENDING");
- t.addTheirItems(theirKeys);
- t.data("commandused", "BuyAny");
- t.data("amountofsets", amountofsets.toString());
- t.data("amountofkeys", n);
- t.data("index", setsThatShouldntBeSent.length);
- setsThatShouldntBeSent.push(t.itemsToGive);
- t.send((ERR, STATUS) => {
- if (ERR) {
- client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
- console.log("## An error occurred while sending trade: " + ERR);
- } else {
- client.chatMessage(SENDER, "The bot has sent your trade! It's being confirmed...");
- console.log("## Trade offer sent!");
- }
- });
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try a lower amount of keys");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- } else if (MSG.toUpperCase().indexOf("!BUYPUBG") >= 0 && SENDER == "76561198031258757") {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYPUBG ", "");
- let amountofsets = parseInt(n) * 5;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXBUY) {
- let t = manager.createOffer(SENDER.getSteamID64());
- t.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log("## An error occurred while getting trade holds: " + ERR);
- client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- n = parseInt(n);
- /// EDITED PORTION
- userPUBGKeys = [];
- userPUBGKeysCount = [];
- userPUBGKeyTrueCount = 0;
- userSets = [];
- setsAvalible = 0;
- isToGive = [];
- client.chatMessage(SENDER, "Processing your request.");
- manager.getUserInventoryContents(SENDER.getSteamID64(), 578080, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
- } else {
- console.log("DEBUG#INV LOADED");
- if (!ERR) {
- console.log("DEBUG#INV LOADED NOERR");
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.ACCEPTEDKEYSPUBG.indexOf(INV[i].market_hash_name) >= 0 && userPUBGKeyTrueCount != n) {
- if (INV[i].amount >= numberToTake) {
- userPUBGKeys.push(INV[i].assetid);
- userPUBGKeysCount.push(numberToTake);
- userPUBGKeyTrueCount = userPUBGKeyTrueCount + numberToTake;
- numberToTake = numberToTake - numberToTake;
- }
- else {
- userPUBGKeys.push(INV[i].assetid);
- userPUBGKeysCount.push(INV[i].amount);
- userPUBGKeyTrueCount = userPUBGKeyTrueCount + INV[i].amount;
- numberToTake = numberToTake - INV[i].amount;
- }
- }
- }
- if (theirKeys.length != n) {
- client.chatMessage(SENDER, "You do not have enough keys.");
- } else {
- client.chatMessage(SENDER, "Client has enough keys.")
- client.chatMessage(SNEDER, "count of pubg keys!\n"+userPUBGKeyTrueCount)
- }
- } else {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try a lower amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- } else if (MSG.toUpperCase().indexOf("!BUY") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUY ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXBUY) {
- let t = manager.createOffer(SENDER.getSteamID64());
- t.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log("## An error occurred while getting trade holds: " + ERR);
- client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- n = parseInt(n);
- let theirKeys = [];
- client.chatMessage(SENDER, "Processing your request.");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
- } else {
- console.log("DEBUG#INV LOADED");
- if (!ERR) {
- console.log("DEBUG#INV LOADED NOERR");
- for (let i = 0; i < INV.length; i++) {
- if (theirKeys.length < n && CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- theirKeys.push(INV[i]);
- }
- }
- if (theirKeys.length != n) {
- client.chatMessage(SENDER, "You do not have enough keys.");
- } else {
- Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
- if (!ERR) {
- console.log("DEBUG#BADGE LOADED");
- if (!ERR) {
- let b = {}; // List with badges that CAN still be crafted
- if (DATA) {
- for (let i = 0; i < Object.keys(DATA).length; i++) {
- if (DATA[Object.keys(DATA)[i]] < 6) {
- b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
- }
- }
- } else {
- client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
- }
- console.log(DATA);
- console.log(b);
- // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
- // 1: GET BOTS CARDS. DONE
- // 2: GET PLAYER's BADGES. DONE
- // 3: MAGIC
- let hisMaxSets = 0,
- botNSets = 0;
- // Loop for sets he has partially completed
- for (let i = 0; i < Object.keys(b).length; i++) {
- if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
- hisMaxSets += 5 - b[Object.keys(b)[i]].length;
- }
- }
- console.log("DEBUG#LOOP 1 DONE");
- // Loop for sets he has never crafted
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
- if (botSets[Object.keys(botSets)[i]].length >= 5) {
- hisMaxSets += 5;
- } else {
- hisMaxSets += botSets[Object.keys(botSets)[i]].length;
- }
- }
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- console.log("DEBUG#LOOP 2 DONE");
- // HERE
- if (amountofsets <= hisMaxSets) {
- hisMaxSets = amountofsets;
- console.log("DEBUG#TRADE CREATED");
- sortSetsByAmount(botSets, (DATA) => {
- console.log("DEBUG#" + DATA);
- console.log("DEBUG#SETS SORTED");
- firstLoop: for (let i = 0; i < DATA.length; i++) {
- if (b[DATA[i]] == 0) {
- continue firstLoop;
- } else {
- console.log("DEBUG#" + i);
- console.log("DEBUG#FOR LOOP ITEMS");
- if (hisMaxSets > 0) {
- console.log("DEBUG#MAXSETSMORETHAN1");
- if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
- // BOT HAS ENOUGH SETS OF THIS KIND
- console.log("DEBUG#LOOP #1");
- sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
- if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
- console.log("DEBUG#LOOP #1: ITEM ADD");
- console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
- t.addMyItems(botSets[DATA[i]][j]);
- hisMaxSets--;
- console.log(hisMaxSets);
- } else {
- console.log("DEBUG#LOOP #1: RETURN");
- continue firstLoop;
- }
- }
- } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
- // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
- console.log("DEBUG#LOOP #1 CONTINUE");
- continue; // *
- } 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
- // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
- bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
- if (botSets[DATA[i]][j] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
- hisMaxSets--;
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
- continue firstLoop;
- }
- }
- }
- else if (hisMaxSets < 5) {
- // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
- console.log("DEBUG#LOOP #2");
- tLoop: for (let j = 0; j != hisMaxSets; j++) {
- if (botSets[DATA[i]][j] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- console.log("DEBUG#LOOP #2: ITEM ADD");
- hisMaxSets--;
- console.log(hisMaxSets);
- } else {
- console.log("DEBUG#LOOP #2: RETURN");
- continue firstLoop;
- }
- }
- } else {
- // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
- console.log("DEBUG#LOOP #2");
- xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
- if (botSets[DATA[i]][j] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- console.log("DEBUG#LOOP #2: ITEM ADD");
- hisMaxSets--;
- console.log(hisMaxSets);
- } else {
- console.log("DEBUG#LOOP #2: RETURN");
- continue firstLoop;
- }
- }
- }
- } else {
- console.log("DEBUG#RETURN");
- break firstLoop;
- }
- }
- }
- if (hisMaxSets > 0) {
- client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
- } else {
- console.log("DEBUG#SENDING");
- t.addTheirItems(theirKeys);
- t.data("commandused", "Buy");
- t.data("amountofkeys", n);
- t.data("amountofsets", amountofsets.toString());
- t.data("index", setsThatShouldntBeSent.length);
- setsThatShouldntBeSent.push(t.itemsToGive);
- t.send((ERR, STATUS) => {
- if (ERR) {
- client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
- console.log("## An error occurred while sending trade: " + ERR);
- } else {
- client.chatMessage(SENDER, "The bot has sent your trade! It's being confirmed...");
- console.log("## Trade offer sent");
- }
- });
- }
- });
- } else {
- 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.");
- }
- // TO HERE
- } else {
- console.log("An error occurred while getting badges: " + ERR);
- }
- } else {
- client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
- console.log(SENDER, "## An error occurred while loading badges: " + ERR);
- }
- });
- }
- } else {
- console.log("## An error occurred while getting inventory: " + ERR);
- client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try a lower amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid amount of keys.");
- }
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- } else if (MSG.toUpperCase() == "!SR") {
- client.chatMessage(SENDER, "" + CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS + "");
- } else if (MSG.toUpperCase() == "!CP") {
- client.chatMessage(SENDER, "Current price " + CONFIG.CARDS.BUY1KEYFORAMOUNTOFSETS + "");
- } else if (MSG.toUpperCase() == "!OWNER") {
- client.chatMessage(SENDER, "Owner: http://steamcommunity.com/profiles/76561198031258757/");
- } else if (MSG.toUpperCase() == "!GROUP") {
- client.chatMessage(SENDER, "Group: http://steamcommunity.com/groups/TradingCardBot");
- } else if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
- if (MSG.toUpperCase().indexOf("!BLOCK") >= 0) {
- let n = MSG.toUpperCase().replace("!BLOCK ", "").toString();
- if (SID64REGEX.test(n)) {
- client.chatMessage(SENDER, "User blocked.");
- client.blockUser(n);
- } else {
- client.chatMessage(SENDER, "Please provide a valid SteamID64");
- }
- } else if (MSG.toUpperCase().indexOf("!USERCHECK") >= 0) {
- let n = MSG.toUpperCase().replace("!USERCHECK ", "").toString();
- if (SID64REGEX.test(n)) {
- if (Object.keys(botSets).length > 0) {
- client.chatMessage(SENDER, "The bot is loading your badges...");
- Utils.getBadges(n, (ERR, DATA) => {
- if (!ERR) {
- let b = {}; // List with badges that CAN still be crafted
- if (DATA) {
- for (let i = 0; i < Object.keys(DATA).length; i++) {
- if (DATA[Object.keys(DATA)[i]] < 6) {
- b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
- }
- }
- } else {
- client.chatMessage(SENDER.getSteamID64(), n + "'s badges are empty, sending an offer without checking badges.");
- }
- // console.log(b);
- // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
- // 1: GET BOTS CARDS. DONE
- // 2: GET PLAYER's BADGES. DONE
- // 3: MAGIC
- let hisMaxSets = 0,
- botNSets = 0;
- // Loop for sets he has partially completed
- for (let i = 0; i < Object.keys(b).length; i++) {
- if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
- hisMaxSets += 5 - b[Object.keys(b)[i]].length;
- }
- }
- // Loop for sets he has never crafted
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
- if (botSets[Object.keys(botSets)[i]].length >= 5) {
- hisMaxSets += 5;
- } else {
- hisMaxSets += botSets[Object.keys(botSets)[i]].length;
- }
- }
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- 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.");
- } else {
- client.chatMessage(SENDER, "An error occurred while getting " + n + "'s badges. Please try again.");
- console.log("An error occurred while getting badges: " + ERR);
- }
- });
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid SteamID64.");
- }
- } else if (MSG.toUpperCase() == "!KEYS") {
- manager.getInventoryContents(CONFIG.KEYSFROMGAME, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- client.chatMessage(SENDER, "An error occurred while loading the bot's inventory.");
- console.log("## An error occurred while getting inventory: " + ERR);
- } else {
- let t = manager.createOffer(SENDER);
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- t.addMyItem(INV[i]);
- }
- t.send();
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "The bot doesn't recognize this command.");;
- }
- } else {
- client.chatMessage(SENDER, "The bot doesn't recognize this command. Type !help to see how i work.");
- }
- });
- client.on('groupRelationship', function(groupID, relationship) {
- if (relationship == 2) {
- client.respondToGroupInvite(groupID, false);
- console.log('declined group invite');
- }
- });
- client.on("friendRelationship", (SENDER, REL) => {
- if (REL === 2) {
- client.addFriend(SENDER);
- } else if (REL === 3) {
- if (CONFIG.INVITETOGROUPID) {
- client.inviteToGroup(SENDER, CONFIG.INVITETOGROUPID);
- }
- client.chatMessage(SENDER, CONFIG.MESSAGES.WELCOME);
- }
- });
- // manager.on("unknownOfferSent", (o, os) => {
- // if (o.state == 9) {
- // console.log("## OFFER SENT LIST");
- // community.checkConfirmations();
- // }
- // });
- // community.on("newConfirmation", (CONF) => {
- // console.log("## New confirmation.");
- // community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id);
- // });
- manager.on("sentOfferChanged", (OFFER, OLDSTATE) => {
- if (OFFER.state == 2) {
- client.chatMessage(OFFER.partner, "The bot has confirmed your trade! Go here accept it: https://www.steamcommunity.com/tradeoffer/" + OFFER.id);
- } else if (OFFER.state == 3) {
- Utils.getInventory(client.steamID.getSteamID64(), community, (ERR, DATA) => {
- if (!ERR) {
- let s = DATA;
- Utils.getSets(s, allCards, (ERR, DATA) => {
- if (!ERR) {
- botSets = DATA;
- console.log("## Bot's sets loaded.");
- } else {
- console.log("## An error occurred while getting bot sets: " + ERR);
- }
- let botNSets = 0;
- for (let i = 0; i < Object.keys(botSets).length; i++) {
- botNSets += botSets[Object.keys(botSets)[i]].length;
- }
- totalBotSets = botNSets;
- let playThis = CONFIG.PLAYGAMES;
- if (CONFIG.PLAYGAMES && typeof(CONFIG.PLAYGAMES[0]) == "string") {
- playThis[0] = parseString(playThis[0], totalBotSets);
- }
- client.gamesPlayed(playThis);
- });
- } else {
- console.log("## An error occurred while getting bot inventory: " + ERR);
- }
- });
- if (CONFIG.INVITETOGROUPID) {
- client.inviteToGroup(OFFER.partner, CONFIG.INVITETOGROUPID);
- }
- let d = "" + OFFER.data("commandused") + "";
- d += "\nSets: " + OFFER.data("amountofsets");
- d += "\nKeys: " + OFFER.data("amountofkeys");
- d += "\nSteamID: " + OFFER.partner.getSteamID64();
- fs.writeFile("./TradesAccepted/" + OFFER.id + "-" + OFFER.partner.getSteamID64() + ".txt", d, (ERR) => {
- if (ERR) {
- console.log("## An error occurred while writing trade file: " + ERR);
- }
- });
- community.getSteamUser(OFFER.partner, (ERR, USER) => {
- if (ERR) {
- console.log("## An error occurred while getting user profile: " + ERR);
- client.chatMessage(OFFER.partner, "An error occurred while getting your profile (to comment).");
- } else {
- USER.comment(CONFIG.COMMENTAFTERTRADE, (ERR) => {
- if (ERR) {
- console.log("## An error occurred while commenting on user profile: " + ERR);
- client.chatMessage(OFFER.partner, "An error occurred while getting commenting on your profile.");
- } else {
- client.chatMessage(OFFER.partner, "Thank you for trading with the bot, don't forget to leave a comment on my profile about how my service was today.");
- }
- });
- }
- });
- } else if (OFFER.state == 6) {
- client.chatMessage(OFFER.partner, "Hey, you did not accept the offer. Please try again if you wish to receive sets!");
- }
- /* else if (OFFER.state == 9) {
- community.checkConfirmations();
- }*/
- });
- manager.on("newOffer", (OFFER) => {
- if (CONFIG.ADMINS.indexOf(OFFER.partner.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(OFFER.partner.getSteamID64())) >= 0) {
- OFFER.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log("## An error occurred while getting trade holds: " + ERR);
- client.chatMessage(OFFER.partner, "An error occurred while getting your trade holds. Please try again");
- OFFER.decline((ERR) => {
- if (ERR) {
- console.log("## An error occurred while declining trade: " + ERR);
- }
- });
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- OFFER.accept((ERR) => {
- if (ERR) {
- console.log("## An error occurred while declining trade: " + ERR);
- OFFER.decline((ERR) => {
- if (ERR) {
- console.log("## An error occurred while declining trade: " + ERR);
- }
- });
- } else {
- client.chatMessage(OFFER.partner, "Offer accepted!");
- }
- });
- } else {
- client.chatMessage(OFFER.partner, "Please make sure you don't have a trade hold!");
- OFFER.decline((ERR) => {
- if (ERR) {
- console.log("## An error occurred while declining trade: " + ERR);
- }
- });
- }
- });
- } else if (OFFER.itemsToGive.length == 0) {
- OFFER.accept((ERR) => {
- console.log("DONATION ACCEPT");
- if (ERR) {
- console.log("## An error occurred while declining trade: " + ERR);
- }
- });
- } else {
- OFFER.decline((ERR) => {
- if (ERR) {
- console.log("## An error occurred while declining trade: " + ERR);
- }
- });
- }
- });
- community.on("newConfirmation", (CONF) => {
- console.log("## New confirmation.");
- community.acceptConfirmationForObject(CONFIG.IDENTITYSECRET, CONF.id, (ERR) => {
- if (ERR) {
- console.log("## An error occurred while accepting confirmation: " + ERR);
- } else {
- console.log("## Confirmation accepted.");
- }
- });
- });
- function sortSetsByAmount(SETS, callback) {
- callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length).reverse());
- }
- function sortSetsByAmountB(SETS, callback) {
- callback(Object.keys(SETS).sort((k1, k2) => SETS[k1].length - SETS[k2].length));
- }
- function parseString(INPUT, SETS) {
- return INPUT.replace(":sets:", SETS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement