From 8c1be9b526d5e4370e2f4537842eea715aaa4c2e Mon Sep 17 00:00:00 2001 From: idinium96 <47635037+idinium96@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:37:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8E=AF=20simplify=20craftToken=20comm?= =?UTF-8?q?and?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Commands/sub-classes/Crafting.ts | 62 +++++++++----------- src/classes/Commands/sub-classes/Help.ts | 2 +- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/classes/Commands/sub-classes/Crafting.ts b/src/classes/Commands/sub-classes/Crafting.ts index d40ae735f..f9d6cf360 100644 --- a/src/classes/Commands/sub-classes/Crafting.ts +++ b/src/classes/Commands/sub-classes/Crafting.ts @@ -12,6 +12,10 @@ import { const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1); +const classes = ['scout', 'soldier', 'pyro', 'demoman', 'heavy', 'engineer', 'medic', 'sniper', 'spy']; +const slotType = ['primary', 'secondary', 'melee', 'pda2']; +const combineToken = classes.concat(slotType); + export default class CraftingCommands { private craftWeaponsBySlot: CraftWeaponsBySlot; @@ -47,19 +51,17 @@ export default class CraftingCommands { return this.getCraftTokenInfo(steamID); } - if (parts.length < 3) { + if (parts.length < 2) { return this.bot.sendMessage( steamID, - '❌ Wrong syntax. Correct syntax: !craftToken ' + - '\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' + + '❌ Wrong syntax. Correct syntax: !craftToken ' + + '\n - TokenName: one of the 9 TF2 class characters, or "primary"/"secondary"/"melee"/"pda2" slot' + '\n - amount: Must be an integer, or "max"' ); } - const tokenType = parts[0]; - const subTokenType = parts[1]; - const amount: number | 'max' = parts[2] === 'max' ? 'max' : parseInt(parts[2]); + const tokenName = parts[0]; + const amount: number | 'max' = parts[1] === 'max' ? 'max' : parseInt(parts[1]); if (amount !== 'max') { if (isNaN(amount)) { @@ -67,36 +69,29 @@ export default class CraftingCommands { } } - if (!['class', 'slot'].includes(tokenType)) { - return this.bot.sendMessage(steamID, '❌ tokenType must only be either "class" or "slot"!'); - } - - const classes = ['scout', 'soldier', 'pyro', 'demoman', 'heavy', 'engineer', 'medic', 'sniper', 'spy']; - const slotType = ['primary', 'secondary', 'melee', 'pda2']; - - if (tokenType === 'class' && !classes.includes(subTokenType)) { + if (!combineToken.includes(tokenName)) { return this.bot.sendMessage( steamID, - '❌ subTokenType must be one of 9 TF2 class character since your tokenType is "class"!' - ); - } else if (tokenType === 'slot' && !slotType.includes(subTokenType)) { - return this.bot.sendMessage( - steamID, - '❌ subTokenType must only be either "primary", "secondary", "melee", or "pda2" since your tokenType is "slot"!' + '❌ Invalid token name!' + + '\n• Slot: primary/secondary/melee/pda2' + + '\n• Classes: scout/soldier/pyro/demoman/heavy/engineer/medic/sniper/spy' ); } - if (tokenType === 'slot') { + let isSlotToken = false; + + if (slotType.includes(tokenName)) { // only load on demand + isSlotToken = true; this.defineCraftWeaponsBySlots(); } const assetids: string[] = []; const craftableItems = this.bot.inventoryManager.getInventory.getCurrencies( - tokenType === 'class' - ? this.bot.craftWeaponsByClass[subTokenType as ClassesForCraftableWeapons] - : this.craftWeaponsBySlot[subTokenType as SlotsForCraftableWeapons], + !isSlotToken + ? this.bot.craftWeaponsByClass[tokenName as ClassesForCraftableWeapons] + : this.craftWeaponsBySlot[tokenName as SlotsForCraftableWeapons], false ); @@ -115,21 +110,22 @@ export default class CraftingCommands { const availableAmount = assetids.length; const amountCanCraft = Math.floor(availableAmount / 3); + const capTokenName = tokenName === 'pda2' ? 'PDA2' : capitalize(tokenName); + const tokenType = isSlotToken ? 'slot' : 'class'; const capTokenType = capitalize(tokenType); - const capSubTokenType = subTokenType === 'pda2' ? 'PDA2' : capitalize(subTokenType); if (amount === 'max' && amountCanCraft === 0) { return this.bot.sendMessage( steamID, - `❌ Unable to craft ${capTokenType} Token - ${capSubTokenType} since I only have of ${capSubTokenType} ${tokenType} items.` + `❌ Unable to craft ${capTokenType} Token - ${capTokenName} since I only have ${availableAmount} of ${capTokenName} ${capTokenType} items.` ); } if (amount !== 'max' && amount > amountCanCraft) { return this.bot.sendMessage( steamID, - `❌ I can only craft ${amountCanCraft} ${capTokenType} Token - ${capSubTokenType} at the moment, since I only ` + - `have ${availableAmount} of ${capSubTokenType} ${tokenType} items.` + `❌ I can only craft ${amountCanCraft} ${capTokenType} Token - ${capTokenName} at the moment, since I only ` + + `have ${availableAmount} of ${capTokenName} ${capTokenType} items.` ); } @@ -141,10 +137,10 @@ export default class CraftingCommands { 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 => { + this.bot.tf2gc.craftToken(assetidsToCraft, tokenType as TokenType, tokenName as SubTokenType, err => { if (err) { log.debug( - `Error crafting ${assetidsToCraft.join(', ')} for ${capTokenType} Token - ${capSubTokenType}` + `Error crafting ${assetidsToCraft.join(', ')} for ${capTokenType} Token - ${capTokenName}` ); crafted--; } @@ -163,13 +159,13 @@ export default class CraftingCommands { if (crafted < amountToCraft) { return this.bot.sendMessage( steamID, - `✅ Successfully crafted ${crafted} ${capTokenType} Token - ${capSubTokenType} (there were some error while crafting).` + `✅ Successfully crafted ${crafted} ${capTokenType} Token - ${capTokenName} (there were some error while crafting).` ); } return this.bot.sendMessage( steamID, - `✅ Successfully crafted ${crafted} ${capTokenType} Token - ${capSubTokenType}!` + `✅ Successfully crafted ${crafted} ${capTokenType} Token - ${capTokenName}!` ); } }); diff --git a/src/classes/Commands/sub-classes/Help.ts b/src/classes/Commands/sub-classes/Help.ts index 275262f6d..54c149a10 100644 --- a/src/classes/Commands/sub-classes/Help.ts +++ b/src/classes/Commands/sub-classes/Help.ts @@ -131,7 +131,7 @@ export default class HelpCommands { '.\n✨=== Crafting ===✨\n- ' + [ `${prefix}craftToken - Check the availability to craft tokens ℹ️🔨`, - `${prefix}craftToken - Craft Class or Slot Tokens 🔨` + `${prefix}craftToken - Craft Class or Slot Tokens 🔨` ].join('\n- ') ); From 146c5dc81235ca1d793fd4e9ed16cfa9a974edce Mon Sep 17 00:00:00 2001 From: idinium96 <47635037+idinium96@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:41:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A8=20short=20command=20for=20craf?= =?UTF-8?q?tToken=20(ct)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Commands/Commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/Commands/Commands.ts b/src/classes/Commands/Commands.ts index d2bf3fc91..d4a689996 100644 --- a/src/classes/Commands/Commands.ts +++ b/src/classes/Commands/Commands.ts @@ -289,7 +289,7 @@ export default class Commands { this.buyBPTFPremiumCommand(steamID, message); } else if (command === 'refreshschema' && isAdmin) { this.manager.refreshSchema(steamID); - } else if (command === 'crafttoken' && isAdmin) { + } else if (['crafttoken', 'ct'].includes(command) && isAdmin) { this.crafting.craftTokenCommand(steamID, message); } else { const custom = this.bot.options.customMessage.commandNotFound;