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"),
- reload = require('reload'),
- Utils = require("./utils.js"),
- CONFIG = require("./SETTINGS/config.js"),
- DATA = require("./DATA/data.js"),
- allCards = {},
- botSets = {},
- fs = require("fs"),
- users = {},
- userMsgs = {},
- SID64REGEX = new RegExp(/^[0-9]{17}$/),
- chatLogs = "",
- userLogs = {},
- totalBotSets = 0;
- jsonfile = require('jsonfile');
- 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 this bot again re-add it.");
- 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 have been removed for spamming. Another offense will get you blocked.");
- 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),
- rememberPassword: true
- });
- 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.");
- }
- });
- community.setCookies(cookies);
- community.startConfirmationChecker(10000, CONFIG.IDENTITYSECRET);
- 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().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 " + parseInt((s - Math.floor(XPNEEDED / 100)) / CONFIG.CARDS.CSGO.buy_sets_by_one * 100) / 100 + " keys.");
- } else {
- client.chatMessage(SENDER, "Please provide a valid level.");
- }
- } else {
- client.chatMessage(SENDER, "Your level could not be retrieved. Make sure your Steam Profile is public and try again.");
- }
- } 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 try a lower level.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid level.");
- }
- }
- else if (MSG.toUpperCase() === "!COMMANDS") {
- client.chatMessage(SENDER, "\nAvalible commands:" +
- "\n!owner - Provides my owners profile, please add him if you have any problems!" +
- "\n!rate - shows the current prices of the bot"+
- "\n\n!level [your dream level] - Automatically calculates how many sets and how many items it will require to get to your desired level" +
- "\n!check - Show how many sets the bot has available and how much you can craft" +
- "\n\n!buy [amount of CS:GO keys] - use to buy that amount of CS:GO keys for sets you dont have" +
- "\n!buypubg [amount of pubg keys] - use to buy the amount of pubg key for sets you dont have" +
- "\n!buytf2 [amount of Tf keys] - use to buy that amount of tf keys for sets you dont have" +
- "\n!buygems !buygems [amount of sets] - use to buy that amount of sets for gems" +
- "\n\n!csgobuyone [amount of CS:GO keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate" +
- "\n!pubgbuyone [amount of PUBG keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate" +
- "\n!tfbuyone [amount of TF2 keys] - use this if you are a badge collector. BOT will send only one set of each game, following the current BOT rate" +
- "\n!gemsbuyone [amount of sets] - use this if you are a badge collector. sames as !csgobuyone , buy you pay with gems!" +
- "\n\n!csgobuyany [amount of CS:GO keys] - use to buy that amount of CS:GO keys for any sets, following the current BOT rate" +
- "\n!pubgbuyany [amount of PUBG keys] - use to buy that amount of PUBG keys for any sets, following the current BOT rate" +
- "\n!tfbuyany [amount of TF2 keys] - use to buy that amount of TF2 keys for any sets, following the current BOT rate" +
- "\n!gemsbuyany [amount of sets] - use to buy that amount of any sets for gems, following the current BOT rate" +
- "\n\n!sell [amount of CS:GO keys] - use to sell your sets for CS:GO Key(s)" +
- "\n!sellpubg [amount of PUBG keys] - use to sell your sets for PUBG Key(s)" +
- "\n!sellgems [amount of sets] - use to sell your sets for Gems" +
- "\n!selltf [amount of TF2 keys] - use to sell your sets for TF2 Key(s)" +
- "\n!sellcheck [amount of CS:GO keys] - use to check information about sets you can sell"
- );
- }
- else if (MSG.toUpperCase().indexOf("!CHECKBUYONE") >= 0) {
- client.chatMessage(SENDER, "Loading 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.CSGO.buy_sets_by_one * 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, "Loading 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);
- }
- if (botNSets === 0) {
- client.chatMessage(SENDER, "You currently don't have any available set which the bot can buy.");
- }
- else {
- client.gamesPlayed(playThis);
- client.chatMessage(SENDER, "You currently have " + botNSets + " set(s) available which the bot can buy. " +
- "\r\nFor all of them the bot will pay you:" +
- "\r\n" + parseInt(botNSets / CONFIG.CARDS.CSGO.give_one_for * 100) / 100 + " CS:GO Key(s) or" +
- "\r\n" + parseInt(botNSets / CONFIG.CARDS.PUBG.give_one_for * 100) / 100 + " PUBG Key(s) or" +
- "\r\n" + parseInt(botNSets / CONFIG.CARDS.TF2.give_one_for * 100) / 100 + " TF2 Key(s) or" +
- "\r\n" + parseInt(botNSets * CONFIG.CARDS.GEMS.give_one_set_for * 100) / 100 + " Gems."
- );
- }
- } 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, "\n\nThe currently prices are:" +
- "\r\nWith " + n + " CS:GO Key(s) you can get " + n * CONFIG.CARDS.CSGO.buy_sets_by_one + " set(s)." +
- "\r\nWith " + n + " PUBG Key(s) you can get " + n * CONFIG.CARDS.PUBG.buy_sets_by_one + " set(s)." +
- "\r\nWith " + n + " TF2 Key(s) you can get " + n * CONFIG.CARDS.TF2.buy_sets_by_one + " set(s)." +
- "\r\n" + n + " set(s) you can get for " + n * CONFIG.CARDS.GEMS.buy_one_set_for + " Gems." +
- "\r\n" +
- "\r\nAlso, we're buying sets:" +
- "\r\nFor " + n * CONFIG.CARDS.CSGO.give_one_for + " set(s) you can get " + n + " CSGO Key(s)." +
- "\r\nFor " + n * CONFIG.CARDS.PUBG.give_one_for + " set(s) you can get " + n + " PUBG Key(s)." +
- "\r\nFor " + n * CONFIG.CARDS.TF2.give_one_for + " set(s) you can get " + n + " TF2 Key{s)." +
- "\r\nFor " + n * CONFIG.CARDS.GEMS.give_one_set_for + " Gems you can get " + n + " Set{s)."
- );
- } else {
- if (Object.keys(botSets).length > 0) {
- client.chatMessage(SENDER, "Loading 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:" +
- "\r\n" + parseInt(hisMaxSets / CONFIG.CARDS.CSGO.buy_sets_by_one * 100) / 100 + " CSGO Key(s) or" +
- "\r\n" + parseInt(hisMaxSets / CONFIG.CARDS.PUBG.buy_sets_by_one * 100) / 100 + " PUBG Key(s) or" +
- "\r\n" + parseInt(hisMaxSets / CONFIG.CARDS.TF2.buy_sets_by_one * 100) / 100 + " TF2 Key(s) or" +
- "\r\n" + parseInt(hisMaxSets * CONFIG.CARDS.GEMS.buy_one_set_for * 100) / 100 + " Gems.");
- } 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("!RATE") >= 0) {
- client.chatMessage(SENDER, "The rates are as following:\n"+CONFIG.CARDS.CSGO.buy_sets_by_one+" sets for 1 cs:go key\n"+CONFIG.CARDS.TF2.buy_sets_by_one+" sets for 1 tf key\n"+CONFIG.CARDS.PUBG.buy_sets_by_one+" sets for 1 pubg key\n One set for "+CONFIG.CARDS.GEMS.buy_one_set_for+ " gems\n Use the command !check for more detailed information" );
- }
- else if (MSG.toUpperCase().indexOf("!SELLTF") >= 0) {
- if (botSets) {
- let n = parseInt(MSG.toUpperCase().replace("!SELLTF ", "")),
- amountofsets = n * CONFIG.CARDS.TF2.give_one_for;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXSELL) {
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- 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 try again");
- } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
- manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.TFGAME, 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.TFACCEPTEDKEYS.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.");
- } 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.TF2.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.TF2.MAXSETSELL + " sets per set type 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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, "Please try again later.");
- }
- }
- else if (MSG.toUpperCase().indexOf("!SELLPUBG") >= 0) {
- if (botSets) {
- let n = parseInt(MSG.toUpperCase().replace("!SELLPUBG ", "")),
- amountofsets = n * CONFIG.CARDS.PUBG.give_one_for;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXSELL) {
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- 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 try again");
- } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
- manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.PUBGAME, 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.PUBGACCEPTEDKEYS.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.");
- } 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.PUBG.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.PUBG.MAXSETSELL + " sets per set type 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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, "Please try again later.");
- }
- }
- else if (MSG.toUpperCase().indexOf("!SELLGEMS") >= 0) {
- if (botSets) {
- let n = parseInt(MSG.toUpperCase().replace("!SELLGEMS ", "")),
- amountofsets = n;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXSELL) {
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- let gemsAmount = 0;
- let botGems = [];
- 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) {
- manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.STEAMGAME, 6, 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 (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- gemsAmount = INV[i].amount;
- INV[i].amount = (n * CONFIG.CARDS.GEMS.give_one_set_for);
- botGems.push(INV[i]);
- break;
- }
- }
- if (gemsAmount < n) {
- client.chatMessage(SENDER, "The bot does not have enough Gems.");
- } 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.TF2.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.GEMS.MAXSETSELL + " sets per set type at a time). Please try again later.");
- } else {
- console.log("DEBUG#SENDING");
- t.addMyItems(botGems);
- 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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 sets.");
- }
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of setss!");
- }
- } else {
- client.chatMessage(SENDER, "Please try again later.");
- }
- }
- else if (MSG.toUpperCase().indexOf("!SELL") >= 0) {
- if (botSets) {
- let n = parseInt(MSG.toUpperCase().replace("!SELL ", "")),
- amountofsets = n * CONFIG.CARDS.CSGO.give_one_for;
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXSELL) {
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- 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 try again");
- } else if (ME.escrowDays === 0 && THEM.escrowDays === 0) {
- manager.getUserInventoryContents(client.steamID.getSteamID64(), CONFIG.CSGOGAME, 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.");
- } 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.CSGO.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.CSGO.MAXSETSELL + " sets per set type 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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, "Please try again later.");
- }
- }
- else if (MSG.toUpperCase().indexOf("!BUYTF2") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYTF2 ", "");
- let amountofsets = parseInt(n) * CONFIG.CARDS.TF2.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 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.TFACCEPTEDKEYS.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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!BUYPUBG") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYPUBG ", "");
- let amountofsets = parseInt(n) * CONFIG.CARDS.PUBG.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGAME, 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.PUBGACCEPTEDKEYS.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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!BUYGEMS") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYGEMS ", ""),
- amountofsets = parseInt(n);
- 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 theirGems = [];
- let amountTheirGems = 0;
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, 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.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- amountTheirGems = INV[i].amount;
- INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
- theirGems.push(INV[i]);
- break;
- }
- }
- if (amountTheirGems < ( n * CONFIG.CARDS.GEMS.buy_one_set_for )) {
- client.chatMessage(SENDER, "You do not have enough Gems.");
- } 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.");
- }
- // 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(theirGems);
- t.data("commandused", "Buy");
- //t.data("amountofkeys", n);
- //t.data("amountofsets", amountofsets.toString());
- 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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 sets.");
- }
- } else {
- client.chatMessage(SENDER, "Please provide a valid amount of sets.");
- }
- } 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.CSGO.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!TFBUYONE") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!TFBUYONE ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.TF2.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 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.TFACCEPTEDKEYS.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;
- }
- 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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!PUBGBUYONE") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!PUBGBUYONE ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.PUBG.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGAME, 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.PUBGACCEPTEDKEYS.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;
- }
- 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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!BUYONEGEMS") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYONEGEMS ", ""),
- amountofsets = parseInt(n);
- 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 theirGems = [];
- let amountTheirGems = 0;
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, 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.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- amountTheirGems = INV[i].amount;
- INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
- theirGems.push(INV[i]);
- break;
- }
- }
- if (amountTheirGems < (n * CONFIG.CARDS.GEMS.buy_one_set_for)) {
- client.chatMessage(SENDER, "You do not have enough Gems.");
- } 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(theirGems);
- t.data("commandused", "BuyOne");
- t.data("amountofkeys", n);
- t.data("amountofsets", amountofsets.toString());
- 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!GEMSBUYONE") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!GEMSBUYONE ", ""),
- amountofsets = parseInt(n);
- 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 theirGems = [];
- let amountTheirGems = 0;
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, 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.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- amountTheirGems = INV[i].amount;
- INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
- theirGems.push(INV[i]);
- break;
- }
- }
- if (amountTheirGems < (n * CONFIG.CARDS.GEMS.buy_one_set_for)) {
- client.chatMessage(SENDER, "You do not have enough Gems.");
- } 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(theirGems);
- t.data("commandused", "BuyOne");
- t.data("amountofkeys", n);
- t.data("amountofsets", amountofsets.toString());
- 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!CSGOBUYONE") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!CSGOBUYONE", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.CSGO.buy_sets_by_one;
- 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, ":checkpoint: Processing your request.");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 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;
- }
- 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, "Trade Sent! Confirming it...");
- 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("!TFBUYANY") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!TFBUYANY ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.TF2.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 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.TFACCEPTEDKEYS.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]] < 5) || !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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!PUBGBUYANY") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYANYPUBG ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.PUBG.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.PUBGAME, 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.PUBGACCEPTEDKEYS.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]] < 5) || !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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!GEMSBUYANY") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!GEMSBUYANY ", ""),
- amountofsets = parseInt(n);
- if (!isNaN(n) && parseInt(n) > 0) {
- if (n <= CONFIG.MESSAGES.MAXBUY) {
- let t = manager.createOffer(SENDER.getSteamID64());
- n = parseInt(n);
- let theirGems = [];
- let amountTheirGems = 0;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, 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 (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- amountTheirGems = INV[i].amount;
- INV[i].amount = (n * CONFIG.CARDS.GEMS.buy_one_set_for);
- theirGems.push(INV[i]);
- break;
- }
- }
- if (amountTheirGems < ( n * CONFIG.CARDS.GEMS.buy_one_set_for )) {
- client.chatMessage(SENDER, "You do not have enough Gems.");
- } 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]] < 5) || !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(theirGems);
- t.data("commandused", "BuyAny");
- 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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("!CSGOBUYANY") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!CSGOBUYANY ", ""),
- amountofsets = parseInt(n) * CONFIG.CARDS.CSGO.buy_sets_by_one;
- 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, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 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]] < 5) || !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.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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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() === "!OWNER") {
- client.chatMessage(SENDER, "My steam account: \r\n" + CONFIG.OWNERLINK);
- }
- else if (MSG.toUpperCase() === "!DEVELOPER") {
- client.chatMessage(SENDER, CONFIG.CREDITS);
- }
- else if (CONFIG.ADMINS.indexOf(SENDER.getSteamID64()) >= 0 || CONFIG.ADMINS.indexOf(parseInt(SENDER.getSteamID64())) >= 0) {
- // Admin commands.
- if (MSG.toUpperCase() === "!ADMIN") {
- client.chatMessage(SENDER, "List of admin commands:\n" +
- "!withdraw - withdraw x amount of CS:GO keys\n" +
- "!tfwithdraw - withdraw x amount of TFkeys\n" +
- "!gemswithdraw - withdraw x amount of Gems\n" +
- "!deposit - deposit x amount of CS:GO keys\n" +
- "!tfdeposit - deposit x amount of TF keys\n" +
- "!gemsdeposit - deposit x amount of Gems\n" +
- "!shutdown - logoff bot account and close application\n" +
- "!restart - logoff and login account\n" +
- "!block - block desired steam user\n" +
- "!unblock - unblock desired steam user\n" +
- "!stock - send a trade offer to owner requesting all available sets to trade");
- }
- else if (MSG.toUpperCase().indexOf("!WITHDRAW") >= 0) {
- let amountkeys = parseInt(MSG.toUpperCase().replace("!WITHDRAW ", ""))
- if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
- manager.getInventoryContents(CONFIG.CSGOGAME, 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 botkeys = 0;
- let t = manager.createOffer(SENDER.getSteamID64());
- let added = 0;
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- botkeys++;
- if (added < amountkeys) {
- t.addMyItem(INV[i]);
- added++;
- }
- }
- }
- if (botkeys < amountkeys)
- client.chatMessage(SENDER, "Bot don't have enough keys to send. (He has " + botkeys + " keys)");
- else {
- t.send();
- client.chatMessage(SENDER, amountkeys + " keys sent to your account.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of keys!");
- }
- }
- else if (MSG.toUpperCase().indexOf("!TFWITHDRAW") >= 0) {
- let amountkeys = parseInt(MSG.toUpperCase().replace("!TFWITHDRAW ", ""))
- if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
- manager.getInventoryContents(CONFIG.TFGAME, 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 botkeys = 0;
- let t = manager.createOffer(SENDER.getSteamID64());
- let added = 0;
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- botkeys++;
- if (added < amountkeys) {
- t.addMyItem(INV[i]);
- added++;
- }
- }
- }
- if (botkeys < amountkeys)
- client.chatMessage(SENDER, "Bot don't have enough keys to send. (He has " + botkeys + " keys)");
- else {
- t.send();
- client.chatMessage(SENDER, amountkeys + " keys sent to your account.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of keys!");
- }
- }
- else if (MSG.toUpperCase().indexOf("!GEMSWITHDRAW") >= 0) {
- let amountgems = parseInt(MSG.toUpperCase().replace("!GEMSWITHDRAW ", ""))
- if (!isNaN(amountgems) && parseInt(amountgems) > 0) {
- manager.getInventoryContents(CONFIG.STEAMGAME, 6, 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 botgems = 0;
- let t = manager.createOffer(SENDER.getSteamID64());
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- botgems = INV[i].amount;
- if (INV[i].amount >= amountgems) {
- INV[i].amount = amountgems;
- t.addMyItem(INV[i]);
- break;
- }
- }
- }
- if (botgems < amountgems)
- client.chatMessage(SENDER, "Bot don't have enough gems to send. (He has " + botgems + " gems)");
- else {
- t.send();
- client.chatMessage(SENDER, amountgems + " gems sent to your account.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of gems!");
- }
- }
- else if (MSG.toUpperCase().indexOf("!DEPOSIT") >= 0) {
- let amountkeys = parseInt(MSG.toUpperCase().replace("!DEPOSIT ", ""));
- if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
- 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) {
- let theirKeys = [];
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.CSGOGAME, 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 theirKeys = [];
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.ACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- theirKeys.push(INV[i]);
- }
- }
- if (theirKeys.length < amountkeys) {
- client.chatMessage(SENDER, "You don't have enough keys to send. (You have " + theirKeys.length + " keys)");
- } else {
- t.addTheirItems(theirKeys);
- t.send();
- client.chatMessage(SENDER, "You sent me " + amountkeys + " keys.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of keys!");
- }
- }
- else if (MSG.toUpperCase().indexOf("!TFDEPOSIT") >= 0) {
- let amountkeys = parseInt(MSG.toUpperCase().replace("!TFDEPOSIT ", ""));
- if (!isNaN(amountkeys) && parseInt(amountkeys) > 0) {
- 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) {
- let theirKeys = [];
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.TFGAME, 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 theirKeys = [];
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.TFACCEPTEDKEYS.indexOf(INV[i].market_hash_name) >= 0) {
- theirKeys.push(INV[i]);
- }
- }
- if (theirKeys.length < amountkeys) {
- client.chatMessage(SENDER, "You don't have enough keys to send. (You have " + theirKeys.length + " keys)");
- } else {
- t.addTheirItems(theirKeys);
- t.send();
- client.chatMessage(SENDER, "You sent me " + amountkeys + " keys.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of keys!");
- }
- }
- else if (MSG.toUpperCase().indexOf("!GEMSDEPOSIT") >= 0) {
- let amountgems = parseInt(MSG.toUpperCase().replace("!GEMSDEPOSIT ", ""));
- if (!isNaN(amountgems) && parseInt(amountgems) > 0) {
- 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) {
- let theirKeys = [];
- client.chatMessage(SENDER, ":checkpoint: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.STEAMGAME, 6, 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 theirKeys = [];
- let botgems = 0;
- for (let i = 0; i < INV.length; i++) {
- if (CONFIG.STEAMGEMS.indexOf(INV[i].market_hash_name) >= 0) {
- botgems = INV[i].amount;
- if (INV[i].amount >= amountgems) {
- INV[i].amount = amountgems;
- t.addTheirItem(INV[i]);
- break;
- }
- }
- }
- if (botgems < amountgems) {
- client.chatMessage(SENDER, "You don't have enough gems to send. (You have " + botgems + " gems)");
- } else {
- t.send();
- client.chatMessage(SENDER, "You sent me " + amountgems + " gems.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
- }
- });
- } else {
- client.chatMessage(SENDER, "Please enter a valid amount of keys!");
- }
- }
- else if (MSG.toUpperCase() === "!SHUTDOWN") {
- client.chatMessage(SENDER, "GoodBye!");
- client.logOff();
- process.exit(69)
- }
- else if (MSG.toUpperCase() === "!RESTART") {
- client.chatMessage(SENDER, "Relogging!");
- client.relog();
- }
- else 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("!UNBLOCK") >= 0) {
- let n = MSG.toUpperCase().replace("!UNBLOCK ", "").toString();
- if (SID64REGEX.test(n)) {
- client.chatMessage(SENDER, "User unblocked.");
- client.unblockUser(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, "Loading 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.CSGO.BUY1FORAMOUNTOFSETS * 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() === "!STOCK") {
- client.chatMessage(SENDER, "Loading 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
- // 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);
- }
- if (botNSets === 0) {
- client.chatMessage(SENDER, "You currently don't have any available set which the bot can stock.");
- }
- else {
- client.gamesPlayed(playThis);
- client.chatMessage(SENDER, "You currently have " + botNSets + " set(s) available which the bot can stock.\r\nSending offer...");
- let t = manager.createOffer(SENDER.getSteamID64());
- 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++) {
- t.addTheirItems(DDATA[DATA[i]][j]);
- console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
- }
- } else {
- console.log("DEBUG#LOOP #2 CONTINUE: RETURN 2");
- continue firsttLoop;
- }
- }
- });
- console.log("DEBUG#SENDING");
- t.data("commandused", "Stock");
- 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, "Ok, let me prepare a trade offer for you... It can take a few minutes...");
- 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 sets: " + ERR);
- }
- });
- } else {
- console.log("## An error occurred while getting user inventory: " + ERR);
- }
- });
- }
- else {
- client.chatMessage(SENDER, "Command not recognized.");
- }
- }
- else {
- client.chatMessage(SENDER, "Command not recognized. Use !COMMANDS to see how this bot works.");
- }
- });
- 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, "Trade confirmed! Click here to accept itI sent you a trade, please check: http://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);
- }
- });
- //IF TRADE WAS GAME GIVE PLAYER THE CODE
- if (OFFER.data("commandused") === "BuyGame") {
- let gamesStock = jsonfile.readFileSync(gamesstockfilename);
- let cdkey = gamesStock.stock[OFFER.data("index")].keys[0];
- let name = gamesStock.stock[OFFER.data("index")].name;
- gamesStock.stock[OFFER.data("index")].keys.splice(0, 1);
- fs.writeFile(gamesstockfilename, JSON.stringify(gamesStock, null, "\t"), function (err) {
- if (err) return console.log(err);
- console.log('Steam CD Key successfully removed.');
- });
- client.chatMessage(OFFER.partner.getSteamID64(), "\nYour Steam CD Key for game \"" + name + "\" is:\r\n" + cdkey);
- client.chatMessage(OFFER.partner.getSteamID64(), "\nYour Steam CD Key for game \"" + name + "\" is:\r\n" + cdkey);
- client.chatMessage(OFFER.partner.getSteamID64(), "\nYour Steam CD Key for game \"" + name + "\" is:\r\n" + cdkey);
- }
- ///////////////////////////////////////// If you are reading this, yes I had in this bot game cd keys commands, I was too lazy to delete some functions etc. x) -FOX
- community.getSteamUser(OFFER.partner, (ERR, USER) => {
- if (ERR) {
- console.log("## An error occurred while getting user profile: " + ERR);
- client.chatMessage(USER.steamID, "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(USER.steamID, "An error occurred while getting commenting on your profile.");
- } else {
- client.chatMessage(USER.steamID, "Thanks for trading! :D");
- }
- });
- }
- });
- }
- else if (OFFER.state == 4) {
- client.chatMessage(OFFER.partner, "You tried to send an counter offer, trade will be canceled. TradeID:" + OFFER.id);
- console.log("[ SendOffer ] Aborted because of counter offer:" + OFFER.id);
- }
- else if (OFFER.state == 5) {
- client.chatMessage(OFFER.partner, "You havent accepted the Trade. Trade expired. TradeID:" + OFFER.id);
- console.log("[ SendOffer ] Tradeoffer expired. TradeID:" + OFFER.id);
- }
- else if (OFFER.state == 6) {
- client.chatMessage(OFFER.partner, "We canceled the offer it may be expired. Please try again if you wish to receive sets!");
- console.log("[ SendOffer ] Tradeoffer canceled by Bot (expired). TradeID:" + OFFER.id);
- }
- else if (OFFER.state == 7) {
- client.chatMessage(OFFER.partner, "You declined the Trade. TradeID:" + OFFER.id);
- console.log("[ SendOffer ] Tradeoffer declined by User. TradeID:" + OFFER.id);
- }
- else if (OFFER.state == 11) {
- client.chatMessage(OFFER.partner, "You are in escrow and need to check your account for limitations. TradeID:" + OFFER.id);
- console.log("[ SendOffer ] Tradeoffer aborted because user is in escrow and cant trade. TradeID:" + OFFER.id);
- }
- });
- 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) {
- let onlySteam = true;
- for (let i = 0; i < OFFER.itemsToReceive.length; i++) {
- if (OFFER.itemsToReceive[i].appid !== 753) {
- onlySteam = false;
- }
- }
- if (onlySteam) {
- OFFER.accept((ERR) => {
- 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);
- }
- setInterval(function () {
- 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;
- playThis[0] =
- totalBotSets + " Sets - 14:1 CS:GO / 1:290 Gems / 11:1 TF / 14:1 PUBG";
- client.gamesPlayed(playThis);
- }, 1000 * 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement