Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- } else if (MSG.toUpperCase().indexOf("!BUYGEMS") >= 0) {
- if (botSets) {
- let n = MSG.toUpperCase().replace("!BUYGEMS ", ""),
- amountofsets = parseInt(n) * 1;
- if (!isNaN(n)) {
- if (n <= 10) {
- let t = manager.createOffer(SENDER.getSteamID64());
- t.getUserDetails((ERR, ME, THEM) => {
- if (ERR) {
- console.log(getHourNow() + " !!! An error occurred while checking trade holds (!buygems): " + ERR);
- client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while checking your Steam trade holds. Please try again in 2 minutes.");
- } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
- n = parseInt(n);
- var item = [];
- client.chatMessage(SENDER, ":revclock: Processing your request...");
- manager.getUserInventoryContents(SENDER.getSteamID64(), 753, 2, true, (ERR, INV, CURR) => {
- if (ERR) {
- console.log(getHourNow() + " !!! An error occurred while loading Steam inventory inventory (!buygems): " + ERR);
- client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while loading your Steam inventory. Please try again in 2 minutes.");
- } else {
- if (!ERR) {
- for (let i = 0; i < INV.length; i++) {
- var gems = INV[i];
- var amountNeeded = 10 * n;
- if (gems.market_hash_name === "753-Gems"){
- if(gems.amount >= amountNeeded){
- item.push({assetid: gems.id, appid: '753', contextid: '6', amount: amountNeeded});
- console.log(item);
- }
- }
- }
- }
- if (item.length != 1) {
- client.chatMessage(SENDER, ":exclamationPointRed: You don't have enough gems.");
- client.chatMessage(SENDER, "This BOT accepts any CS:GO case keys. If you purchased your keys at Steam market or CS:GO in-game store, your keys will have a 7 day trade restriction. You may check your keys by clicking on them at your inventory." + "\n" + "\n" + ":ns_key: Tradeable keys I can see in your inventory: " + theirGems.length);
- } else {
- Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
- if (!ERR) {
- 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 {
- console.log(getHourNow() + " # Badges are empty, sending offer without checking badges. (!buy)")
- client.chatMessage(SENDER.getSteamID64(), ":exclamationPointRed: 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;
- }
- }
- // 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;
- }
- // HERE
- if (amountofsets <= hisMaxSets) {
- hisMaxSets = amountofsets;
- sortSetsByAmount(botSets, (DATA) => {
- firstLoop: for (let i = 0; i < DATA.length; i++) {
- if (b[DATA[i]] == 0) {
- continue firstLoop;
- } else {
- if (hisMaxSets > 0) {
- if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
- // BOT HAS ENOUGH SETS OF THIS KIND
- sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
- if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- hisMaxSets--;
- } else {
- continue firstLoop;
- }
- }
- } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
- // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
- 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]);
- hisMaxSets--;
- } else {
- continue firstLoop;
- }
- }
- }
- else if (hisMaxSets < 5) {
- // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
- tLoop: for (let j = 0; j != hisMaxSets; j++) {
- if (botSets[DATA[i]][j] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- hisMaxSets--;
- } else {
- continue firstLoop;
- }
- }
- } else {
- // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
- xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
- if (botSets[DATA[i]][j] && hisMaxSets > 0) {
- t.addMyItems(botSets[DATA[i]][j]);
- hisMaxSets--;
- } else {
- continue firstLoop;
- }
- }
- }
- } else {
- break firstLoop;
- }
- }
- }
- if (hisMaxSets > 0) {
- client.chatMessage(SENDER, ":exclamationPointRed: There are not enough sets. Please try again later.");
- } else {
- console.log(getHourNow() + " # Sending trade offer... (!buy)");
- t.addTheirItems(item);
- t.data("commandused", "Buy");
- t.data("amountofkeys", n);
- t.data("amountofsets", amountofsets.toString());
- t.setMessage("Here are " + t.data("amountofsets") + " cards sets in exchange for " + t.data("amountofkeys") + " CS:GO keys.")
- t.send((ERR, STATUS) => {
- if (ERR) {
- console.log(getHourNow() + " !!! An error occurred while sending trade (!buy): " + ERR);
- client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while sending your trade. Steam Trades could be down. Please try again in 2 minutes.");
- loadSets();
- } else {
- console.log(getHourNow() + " # Trade offer sent! (!buy)");
- client.chatMessage(SENDER, ":clickpointer: Trade offer sent! Check your Steam notifications or click here to accept: https://steamcommunity.com/tradeoffer/" + t.id);
- }
- });
- }
- });
- } else {
- client.chatMessage(SENDER, ":exclamationPointRed: 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(getHourNow() + " !!! An error occurred while getting buyer badges (!buy): " + ERR);
- }
- } else {
- console.log(getHourNow() + " !!! An error occurred while loading buyer badges (!buy): " + ERR);
- client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while checking your badges. Please try again in 2 minutes.");
- }
- });
- }
- } else {
- console.log(getHourNow() + " !!! An error occurred while loading buyer's CS:GO inventory (!buy): " + ERR);
- client.chatMessage(SENDER, ":exclamationPointRed: An error occurred while loading your CS:GO inventory. Please make sure it's set to public.");
- }
- }
- });
- } else {
- client.chatMessage(SENDER, ":exclamationPointRed: Please make sure you don't have a trade hold. If you don't own a smartphone, use SteamDesktopAuthenticator." + "\n" + "\n" + "https://help.steampowered.com/pt-br/wizard/HelpWhyCantITrade");
- }
- });
- } else {
- client.chatMessage(SENDER, ":exclamationPointRed: You can buy up to " + 10 + " keys at once.");
- }
- } else {
- client.chatMessage(SENDER, ":exclamationPointRed: Please provide a valid amount of keys - example: !buy 2");
- }
- } else {
- client.chatMessage(SENDER, ":exclamationPointRed: Please try again later.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement