Skip to content

Commit

Permalink
🔀 Merge pull request #1150 from TF2Autobot/craftToken-max
Browse files Browse the repository at this point in the history
🔄 update `!craftToken` command, can put `max` as amount
  • Loading branch information
idinium96 authored Jun 7, 2022
2 parents 40aaac3 + 3c604b5 commit 1769786
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/classes/Commands/sub-classes/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ export default class CraftingCommands {
'❌ Wrong syntax. Correct syntax: !craftToken <tokenType> <subTokenType> <amount>' +
'\n - tokenType: "class" or "slot"' +
'\n - subTokenType: one of the 9 TF2 class characters if TokenType is class, or "primary"/"secondary"/"melee"/"pda2" if TokenType is slot' +
'\n - amount: Must be an integer'
'\n - amount: Must be an integer, or "max"'
);
}

const tokenType = parts[0];
const subTokenType = parts[1];
const amount = parseInt(parts[2]);
const amount: number | 'max' = parts[2] === 'max' ? 'max' : parseInt(parts[2]);

if (isNaN(amount)) {
return this.bot.sendMessage(steamID, '❌ Amount must be type integer!');
if (amount !== 'max') {
if (isNaN(amount)) {
return this.bot.sendMessage(steamID, '❌ Amount must be type integer!');
}
}

if (!['class', 'slot'].includes(tokenType)) {
Expand Down Expand Up @@ -117,7 +119,7 @@ export default class CraftingCommands {
const capTokenType = capitalize(tokenType);
const capSubTokenType = subTokenType === 'pda2' ? 'PDA2' : capitalize(subTokenType);

if (amount > amountCanCraft) {
if (amount !== 'max' && amount > amountCanCraft) {
return this.bot.sendMessage(
steamID,
`❌ I can only craft ${amountCanCraft} ${capTokenType} Token - ${capSubTokenType} at the moment, since I only ` +
Expand All @@ -130,7 +132,8 @@ export default class CraftingCommands {

let crafted = 0;
let callbackIndex = 0;
for (let i = 0; i < amount; i++) {
const amountToCraft = amount === 'max' ? amountCanCraft : amount;
for (let i = 0; i < amountToCraft; i++) {
const assetidsToCraft = assetids.splice(0, 3);
this.bot.tf2gc.craftToken(assetidsToCraft, tokenType as TokenType, subTokenType as SubTokenType, err => {
if (err) {
Expand All @@ -143,15 +146,15 @@ export default class CraftingCommands {
callbackIndex++;
crafted++;

if (amount - callbackIndex === 0) {
if (amountToCraft - callbackIndex === 0) {
this.isCrafting = false;

this.bot.client.gamesPlayed([]);
this.bot.client.gamesPlayed(
this.bot.options.miscSettings.game.playOnlyTF2 ? 440 : [this.bot.handler.customGameName, 440]
);

if (crafted < amount) {
if (crafted < amountToCraft) {
return this.bot.sendMessage(
steamID,
`✅ Successfully crafted ${crafted} ${capTokenType} Token - ${capSubTokenType} (there were some error while crafting).`
Expand Down

0 comments on commit 1769786

Please sign in to comment.