Guest User

Untitled

a guest
Aug 24th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (MSG.toUpperCase().indexOf("!GEMBUY") >= 0) {
  2.         if (botSets) {
  3.             let n = MSG.toUpperCase().replace("!GEMBUY ", ""),
  4.                 amountofsets = parseInt(n) * CONFIG.CARDS.BUY1GEMFORAMOUNTOFSETS;
  5.             if (!isNaN(n) && parseInt(n) > 0) {
  6.                 if (n <= CONFIG.MESSAGES.MAXBUY) {
  7.                     let t = manager.createOffer(SENDER.getSteamID64());
  8.                     t.getUserDetails((ERR, ME, THEM) => {
  9.                         if (ERR) {
  10.                             console.log("## An error occurred while getting trade holds: " + ERR);
  11.                             client.chatMessage(SENDER, "An error occurred while getting your trade holds. Please try again");
  12.                         } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
  13.                             n = parseInt(n);
  14.                             let theirKeys = [];
  15.                             client.chatMessage(SENDER, "The bot is currently processing your request, please give it some time.");
  16.                             manager.getUserInventoryContents(SENDER.getSteamID64(), CONFIG.GEMSFROMGAMESTEAM, 2, true, (ERR, INV, CURR) => {
  17.                                 if (ERR) {
  18.                                     console.log("## An error occurred while getting inventory: " + ERR);
  19.                                     client.chatMessage(SENDER, "An error occurred while loading your inventory. Please try later");
  20.                                 } else {
  21.                                     console.log("DEBUG#INV LOADED");
  22.                                     if (!ERR) {
  23.                                         console.log("DEBUG#INV LOADED NOERR");
  24.                                         for (let i = 0; i < INV.length; i++) {
  25.                                             if (theirKeys.length < n && CONFIG.ACCEPTEDGEMS.indexOf(INV[i].market_hash_name) >= 0) {
  26.                                                 theirKeys.push(INV[i]);
  27.                                             }
  28.                                         }
  29.                                         if (theirKeys.length != n) {
  30.                                             client.chatMessage(SENDER, "Error: You don't have enough Gems. Feel free to come back when you collect more keys.");
  31.                                         } else {
  32.                                             Utils.getBadges(SENDER.getSteamID64(), (ERR, DATA) => {
  33.                                                 if (!ERR) {
  34.                                                     console.log("DEBUG#BADGE LOADED");
  35.                                                     if (!ERR) {
  36.                                                         let b = {}; // List with badges that CAN still be crafted
  37.                                                         if (DATA) {
  38.                                                             for (let i = 0; i < Object.keys(DATA).length; i++) {
  39.                                                                 if (DATA[Object.keys(DATA)[i]] < 6) {
  40.                                                                     b[Object.keys(DATA)[i]] = 5 - DATA[Object.keys(DATA)[i]];
  41.                                                                 }
  42.                                                             }
  43.                                                         } else {
  44.                                                             client.chatMessage(SENDER.getSteamID64(), "Your badges are empty, sending an offer without checking badges.");
  45.                                                         }
  46.                                                         console.log(DATA);
  47.                                                         console.log(b);
  48.                                                         // TODO: COUNT AMOUNT OF SETS BOT CAN GIVE HIM
  49.                                                         // 1: GET BOTS CARDS. DONE
  50.                                                         // 2: GET PLAYER's BADGES. DONE
  51.                                                         // 3: MAGIC
  52.                                                         let hisMaxSets = 0,
  53.                                                             botNSets = 0;
  54.                                                         // Loop for sets he has partially completed
  55.                                                         for (let i = 0; i < Object.keys(b).length; i++) {
  56.                                                             if (botSets[Object.keys(b)[i]] && botSets[Object.keys(b)[i]].length >= 5 - b[Object.keys(b)[i]].length) {
  57.                                                                 hisMaxSets += 5 - b[Object.keys(b)[i]].length;
  58.                                                             }
  59.                                                         }
  60.                                                         console.log("DEBUG#LOOP 1 DONE");
  61.                                                         // Loop for sets he has never crafted
  62.                                                         for (let i = 0; i < Object.keys(botSets).length; i++) {
  63.                                                             if (Object.keys(b).indexOf(Object.keys(botSets)[i]) < 0) {
  64.                                                                 if (botSets[Object.keys(botSets)[i]].length >= 5) {
  65.                                                                     hisMaxSets += 5;
  66.                                                                 } else {
  67.                                                                     hisMaxSets += botSets[Object.keys(botSets)[i]].length;
  68.                                                                 }
  69.                                                             }
  70.                                                             botNSets += botSets[Object.keys(botSets)[i]].length;
  71.                                                         }
  72.                                                         console.log("DEBUG#LOOP 2 DONE");
  73.                                                         // HERE
  74.                                                         if (amountofsets <= hisMaxSets) {
  75.                                                             hisMaxSets = amountofsets;
  76.                                                             console.log("DEBUG#TRADE CREATED");
  77.                                                             sortSetsByAmount(botSets, (DATA) => {
  78.                                                                 console.log("DEBUG#" + DATA);
  79.                                                                 console.log("DEBUG#SETS SORTED");
  80.                                                                 firstLoop: for (let i = 0; i < DATA.length; i++) {
  81.                                                                     if (b[DATA[i]] == 0) {
  82.                                                                         continue firstLoop;
  83.                                                                     } else {
  84.                                                                         console.log("DEBUG#" + i);
  85.                                                                         console.log("DEBUG#FOR LOOP ITEMS");
  86.                                                                         if (hisMaxSets > 0) {
  87.                                                                             console.log("DEBUG#MAXSETSMORETHAN1");
  88.                                                                             if (b[DATA[i]] && botSets[DATA[i]].length >= b[DATA[i]]) {
  89.                                                                                 // BOT HAS ENOUGH SETS OF THIS KIND
  90.                                                                                 console.log("DEBUG#LOOP #1");
  91.                                                                                 sLoop: for (let j = 0; j < 5 - b[DATA[i]]; j++) {
  92.                                                                                     if (j + 1 < b[DATA[i]] && hisMaxSets > 0) {
  93.                                                                                         console.log("DEBUG#LOOP #1: ITEM ADD");
  94.                                                                                         console.log("DEBUG#LOOP #1: " + botSets[DATA[i]][j]);
  95.                                                                                         t.addMyItems(botSets[DATA[i]][j]);
  96.                                                                                         hisMaxSets--;
  97.                                                                                         console.log(hisMaxSets);
  98.                                                                                     } else {
  99.                                                                                         console.log("DEBUG#LOOP #1: RETURN");
  100.                                                                                         continue firstLoop;
  101.                                                                                     }
  102.                                                                                 }
  103.                                                                             } else if (b[DATA[i]] && botSets[DATA[i]].length < b[DATA[i]]) {
  104.                                                                                 // BOT DOESNT HAVE ENOUGH SETS OF THIS KIND
  105.                                                                                 console.log("DEBUG#LOOP #1 CONTINUE");
  106.                                                                                 continue; // *
  107.                                                                             } 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
  108.                                                                                 // BOT HAS ENOUGH SETS AND USER NEVER CRAFTED THIS
  109.                                                                                 bLoop: for (let j = 0; j < botSets[DATA[i]].length - b[DATA[i]]; j++) {
  110.                                                                                     if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  111.                                                                                         t.addMyItems(botSets[DATA[i]][j]);
  112.                                                                                         console.log("DEBUG#LOOP #2 CONTINUE: ITEM ADD");
  113.                                                                                         hisMaxSets--;
  114.                                                                                     } else {
  115.                                                                                         console.log("DEBUG#LOOP #2 CONTINUE: RETURN");
  116.                                                                                         continue firstLoop;
  117.                                                                                     }
  118.                                                                                 }
  119.                                                                             }
  120.                                                                             else if (hisMaxSets < 5) {
  121.                                                                                 // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS 5 SETS:
  122.                                                                                 console.log("DEBUG#LOOP #2");
  123.                                                                                 tLoop: for (let j = 0; j != hisMaxSets; j++) {
  124.                                                                                     if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  125.                                                                                         t.addMyItems(botSets[DATA[i]][j]);
  126.                                                                                         console.log("DEBUG#LOOP #2: ITEM ADD");
  127.                                                                                         hisMaxSets--;
  128.                                                                                         console.log(hisMaxSets);
  129.                                                                                     } else {
  130.                                                                                         console.log("DEBUG#LOOP #2: RETURN");
  131.                                                                                         continue firstLoop;
  132.                                                                                     }
  133.                                                                                 }
  134.                                                                             } else {
  135.                                                                                 // BOT DOESNT HAVE CARDS USER AREADY CRAFTED, IF USER STILL NEEDS LESS THAN 5 SETS:
  136.                                                                                 console.log("DEBUG#LOOP #2");
  137.                                                                                 xLoop: for (let j = 0; j != 5; j++ && hisMaxSets > 0) {
  138.                                                                                     if (botSets[DATA[i]][j] && hisMaxSets > 0) {
  139.                                                                                         t.addMyItems(botSets[DATA[i]][j]);
  140.                                                                                         console.log("DEBUG#LOOP #2: ITEM ADD");
  141.                                                                                         hisMaxSets--;
  142.                                                                                         console.log(hisMaxSets);
  143.                                                                                     } else {
  144.                                                                                         console.log("DEBUG#LOOP #2: RETURN");
  145.                                                                                         continue firstLoop;
  146.                                                                                     }
  147.                                                                                 }
  148.                                                                             }
  149.                                                                         } else {
  150.                                                                             console.log("DEBUG#RETURN");
  151.                                                                             break firstLoop;
  152.                                                                         }
  153.                                                                     }
  154.                                                                 }
  155.                                                                 if (hisMaxSets > 0) {
  156.                                                                     client.chatMessage(SENDER, "There are not enough sets. Please try again later.");
  157.                                                                 } else {
  158.                                                                     console.log("DEBUG#SENDING");
  159.                                                                     t.addTheirItems(theirKeys);
  160.                                                                     t.data("commandused", "Buy");
  161.                                                                     t.data("amountofkeys", n);
  162.                                                                     t.data("amountofsets", amountofsets.toString());
  163.                                                                     t.send((ERR, STATUS) => {
  164.                                                                         if (ERR) {
  165.                                                                             client.chatMessage(SENDER, "An error occurred while sending your trade. Steam Trades could be down. Please try again later.");
  166.                                                                             console.log("## An error occurred while sending trade: " + ERR);
  167.                                                                         } else {
  168.                                                                             client.chatMessage(SENDER, "Trade Sent! Confirming it...");
  169.                                                                             console.log("## Trade offer sent");
  170.                                                                         }
  171.                                                                     });
  172.                                                                 }
  173.                                                             });
  174.                                                         } else {
  175.                                                             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.");
  176.                                                         }
  177.                                                         // TO HERE
  178.                                                     } else {
  179.                                                         console.log("An error occurred while getting badges: " + ERR);
  180.                                                     }
  181.                                                 } else {
  182.                                                     client.chatMessage(SENDER, "An error occurred while getting your badges. Please try again.");
  183.                                                     console.log(SENDER, "## An error occurred while loading badges: " + ERR);
  184.                                                 }
  185.                                             });
  186.                                         }
  187.                                     } else {
  188.                                         console.log("## An error occurred while getting inventory: " + ERR);
  189.                                         client.chatMessage(SENDER, "An error occurred while loading your inventory, please make sure it's set to public.");
  190.                                     }
  191.                                 }
  192.                             });
  193.                         } else {
  194.                             client.chatMessage(SENDER, "Please make sure you don't have a trade hold!");
  195.                         }
  196.                     });
  197.                 } else {
  198.                     client.chatMessage(SENDER, "Please try a lower amount of Gem sacks.");
  199.                 }
  200.             } else {
  201.                 client.chatMessage(SENDER, "Error: Please provide a valid amount of gem sacks.");
  202.             }
  203.         } else {
  204.             client.chatMessage(SENDER, "Please try again later.");
  205.         }
  206.        
  207.     }
Add Comment
Please, Sign In to add comment