{"size": 2197, "ext": "js", "max_stars_repo_path": "src/Commands/Admin/BOOSTER/WITHDRAW/index.js", "max_stars_repo_name": "Luc4sguilherme/Steam-levelup-BOT", "max_stars_repo_stars_event_min_datetime": "2020-10-03T08:45:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T11:27:15.000Z", "max_issues_repo_path": "src/Commands/Admin/BOOSTER/WITHDRAW/index.js", "max_issues_repo_name": "Luc4sguilherme/Steam-foil-levelup-BOT", "max_issues_repo_issues_event_min_datetime": "2020-10-02T17:28:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T15:34:24.000Z", "max_forks_repo_path": "src/Commands/Admin/BOOSTER/WITHDRAW/index.js", "max_forks_repo_name": "Luc4sguilherme/Steam-levelup-BOT", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 10, "max_issues_count": 22, "max_forks_count": null, "avg_line_length": 29.2933333333, "max_line_length": 79, "alphanum_fraction": 0.5170687301}
const chatMessage = require('../../../../Components/message');
const makeOffer = require('../../../../Components/offer');
const messages = require('../../../../Config/messages');
const log = require('../../../../Components/log');
const utils = require('../../../../Utils');

module.exports = (sender, msg, client, users, manager) => {
  const language = utils.getLanguage(sender.getSteamID64(), users);
  const amountbooster = parseInt(
    msg.toUpperCase().replace('!WITHDRAWBOOSTER ', ''),
    10
  );
  if (!Number.isNaN(amountbooster) && parseInt(amountbooster, 10) > 0) {
    log.adminChat(
      sender.getSteamID64(),
      language,
      `[ !WITHDRAWBOOSTER ${amountbooster} ]`
    );
    chatMessage(client, sender, messages.REQUEST[language]);
    manager.getInventoryContents(753, 6, true, (ERR, INV) => {
      if (ERR) {
        chatMessage(client, sender, messages.ERROR.LOADINVENTORY.US[language]);
        log.error(`An error occurred while getting inventory: ${ERR}`);
      } else {
        const botBooster = [];
        for (let i = 0; i < INV.length; i += 1) {
          if (
            botBooster.length < amountbooster &&
            INV[i].type === 'Booster Pack'
          ) {
            botBooster.push(INV[i]);
          }
        }
        if (botBooster.length < amountbooster) {
          chatMessage(
            client,
            sender,
            messages.ERROR.OUTOFSTOCK.DEFAULT.BOOSTER.US[language].replace(
              '{BOOSTER}',
              botBooster.length
            )
          );
        } else {
          const message = messages.TRADE.SETMESSAGE[0].BOOSTER[
            language
          ].replace('{BOOSTER}', amountbooster.toString());
          makeOffer(
            client,
            users,
            manager,
            sender.getSteamID64(),
            botBooster,
            [],
            '!WITHDRAWBOOSTER',
            message,
            0,
            0,
            0,
            0
          );
        }
      }
    });
  } else {
    chatMessage(
      client,
      sender,
      messages.ERROR.INPUT.INVALID.BOOSTER[language].replace(
        '{command}',
        '!WITHDRAWBOOSTER 1'
      )
    );
  }
};
