From 8f0fa740d7f682f3c09eeb93e50ec264d159af66 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Wed, 22 Nov 2023 16:45:55 +0300 Subject: [PATCH] remove redundant autocomplete step --- src/commands/attack.ts | 3 +-- src/commands/counter.ts | 6 +++--- src/commands/craft.ts | 6 +++--- src/commands/decrease.ts | 3 +-- src/commands/increase.ts | 3 +-- src/commands/item.ts | 6 +++--- src/commands/put.ts | 3 +-- src/commands/recipe.ts | 5 ++--- src/commands/take.ts | 3 +-- src/index.ts | 3 ++- src/types/index.d.ts | 3 ++- 11 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/commands/attack.ts b/src/commands/attack.ts index 60011c6..462d877 100644 --- a/src/commands/attack.ts +++ b/src/commands/attack.ts @@ -2,7 +2,6 @@ import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js import { weaponAutocomplete, getItem, getItemQuantity, formatItems, formatItem } from '../lib/rpg/items'; import { Command } from '../types/index'; import { initHealth, dealDamage, BLOOD_ITEM, BLOOD_ID, resetInvincible, INVINCIBLE_TIMER, getInvincibleMs } from '../lib/rpg/pvp'; -import { autocomplete } from '../lib/autocomplete'; export default { data: new SlashCommandBuilder() @@ -49,5 +48,5 @@ export default { await interaction.followUp(`You hit ${user} with ${formatItem(weapon)} for ${BLOOD_ITEM.emoji} **${dmg}** damage! They are now at ${formatItems(BLOOD_ITEM, newHealth.quantity)}.\nYou can attack them again (or if they perform an action first).`); }, - autocomplete: autocomplete(weaponAutocomplete), + autocomplete: weaponAutocomplete, } satisfies Command; \ No newline at end of file diff --git a/src/commands/counter.ts b/src/commands/counter.ts index 7167fc1..cb98c6f 100644 --- a/src/commands/counter.ts +++ b/src/commands/counter.ts @@ -4,7 +4,7 @@ import { counterAutocomplete, counterConfigs, findCounter, getCounterConfigRaw, import { outdent } from 'outdent'; import { formatItem, formatItems, getItem, itemAutocomplete } from '../lib/rpg/items'; import { Command } from '../types/index'; -import { autocomplete, set } from '../lib/autocomplete'; +import { set } from '../lib/autocomplete'; function extendOption(t: string) { return {name: t, value: t}; @@ -443,7 +443,7 @@ export default { } }, - autocomplete: autocomplete(set({ + autocomplete: set({ type: counterAutocomplete, item: itemAutocomplete, value: async (interaction: AutocompleteInteraction) => { @@ -486,5 +486,5 @@ export default { return options; } - })), + }), } satisfies Command; \ No newline at end of file diff --git a/src/commands/craft.ts b/src/commands/craft.ts index fbfb061..53f2646 100644 --- a/src/commands/craft.ts +++ b/src/commands/craft.ts @@ -5,7 +5,7 @@ import { formatItem, getItemQuantity, formatItems, getMaxStack, giveItem, format import { getRecipe, defaultRecipes, formatRecipe, resolveCustomRecipe } from '../lib/rpg/recipes'; import { Command } from '../types/index'; import { initHealth, resetInvincible } from '../lib/rpg/pvp'; -import { autocomplete, set } from '../lib/autocomplete'; +import { set } from '../lib/autocomplete'; export default { data: new SlashCommandBuilder() @@ -103,7 +103,7 @@ export default { return interaction.followUp(`${station.emoji} ${verb(station)} ${formatItemsArray(outputs)}!${outputs.length === 1 ? `\n_${outputs[0].item.description}_` : ''}${nextUsableAt ? `\n${station.name} usable again ` : ''}`); }, - autocomplete: autocomplete(set({ + autocomplete: set({ station: async (interaction: AutocompleteInteraction) => (await Promise.all( craftingStations @@ -142,5 +142,5 @@ export default { value: recipe.id.toString() })); } - })), + }), } satisfies Command; \ No newline at end of file diff --git a/src/commands/decrease.ts b/src/commands/decrease.ts index 2be9adc..829f2aa 100644 --- a/src/commands/decrease.ts +++ b/src/commands/decrease.ts @@ -1,7 +1,6 @@ import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { changeCounterInteraction, counterAutocomplete } from '../lib/rpg/counter'; import { Command } from '../types/index'; -import { autocomplete } from '../lib/autocomplete' export default { data: new SlashCommandBuilder() @@ -36,5 +35,5 @@ export default { changeCounterInteraction(interaction, member, -amount, type); }, - autocomplete: autocomplete(counterAutocomplete), + autocomplete: counterAutocomplete, } satisfies Command; \ No newline at end of file diff --git a/src/commands/increase.ts b/src/commands/increase.ts index d060c7e..c921e35 100644 --- a/src/commands/increase.ts +++ b/src/commands/increase.ts @@ -1,7 +1,6 @@ import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { changeCounterInteraction, counterAutocomplete } from '../lib/rpg/counter'; import { Command } from '../types/index'; -import { autocomplete } from '../lib/autocomplete'; export default { data: new SlashCommandBuilder() @@ -36,5 +35,5 @@ export default { changeCounterInteraction(interaction, member, amount, type); }, - autocomplete: autocomplete(counterAutocomplete) + autocomplete: counterAutocomplete, } satisfies Command; \ No newline at end of file diff --git a/src/commands/item.ts b/src/commands/item.ts index e449453..439d64a 100644 --- a/src/commands/item.ts +++ b/src/commands/item.ts @@ -4,7 +4,7 @@ import { customItemAutocomplete, formatItem, formatItems, getCustomItem, getItem import { Command } from '../types/index'; import { formatRecipe, getCustomRecipe } from '../lib/rpg/recipes'; import { behaviors, formatBehavior, getBehavior } from '../lib/rpg/behaviors'; -import { autocomplete, set } from '../lib/autocomplete'; +import { set } from '../lib/autocomplete'; //function extendOption(t: string) { // return {name: t, value: t}; @@ -322,7 +322,7 @@ export default { } }, - autocomplete: autocomplete(set({ + autocomplete: set({ item: itemAutocomplete, customitem: customItemAutocomplete, behavior: async (interaction: AutocompleteInteraction) => { @@ -355,5 +355,5 @@ export default { value: b.behavior.name })); }, - })), + }), } satisfies Command; \ No newline at end of file diff --git a/src/commands/put.ts b/src/commands/put.ts index 1b6888b..a81140a 100644 --- a/src/commands/put.ts +++ b/src/commands/put.ts @@ -2,7 +2,6 @@ import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js import { changeLinkedCounterInteraction, linkedCounterAutocomplete } from '../lib/rpg/counter'; import { Command } from '../types/index'; import { initHealth } from '../lib/rpg/pvp'; -import { autocomplete } from '../lib/autocomplete'; export default { data: new SlashCommandBuilder() @@ -39,5 +38,5 @@ export default { changeLinkedCounterInteraction(interaction, member, amount, type); }, - autocomplete: autocomplete(linkedCounterAutocomplete), + autocomplete: linkedCounterAutocomplete, } satisfies Command; \ No newline at end of file diff --git a/src/commands/recipe.ts b/src/commands/recipe.ts index 893e70e..98e6428 100644 --- a/src/commands/recipe.ts +++ b/src/commands/recipe.ts @@ -4,7 +4,6 @@ import { Items, getItem } from '../lib/rpg/items'; import { formatRecipe, getCustomRecipe, resolveCustomRecipe } from '../lib/rpg/recipes'; import { craftingStations, getStation } from '../lib/rpg/craftingStations'; import { CustomCraftingRecipe, CustomCraftingRecipeItem, db } from '../lib/db'; -import { autocomplete } from '../lib/autocomplete'; export default { data: new SlashCommandBuilder() @@ -236,7 +235,7 @@ export default { }); }, - autocomplete: autocomplete(async (interaction: AutocompleteInteraction) => { + autocomplete: async (interaction: AutocompleteInteraction) => { const focused = interaction.options.getFocused(); const customRecipes = await db('customCraftingRecipes'); @@ -251,5 +250,5 @@ export default { name: formatRecipe(recipe, true), value: recipe.id.toString() })); - }), + }, } satisfies Command; \ No newline at end of file diff --git a/src/commands/take.ts b/src/commands/take.ts index bdba406..5ad607f 100644 --- a/src/commands/take.ts +++ b/src/commands/take.ts @@ -2,7 +2,6 @@ import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js import { changeLinkedCounterInteraction, linkedCounterAutocomplete } from '../lib/rpg/counter'; import { initHealth } from '../lib/rpg/pvp'; import { Command } from '../types/index'; -import { autocomplete } from '../lib/autocomplete'; export default { data: new SlashCommandBuilder() @@ -39,5 +38,5 @@ export default { changeLinkedCounterInteraction(interaction, member, -amount, type); }, - autocomplete: autocomplete(linkedCounterAutocomplete) + autocomplete: linkedCounterAutocomplete, } satisfies Command; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 30dc29f..b88fbda 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import prettyBytes from 'pretty-bytes'; import { Command } from './types/index'; import { startServer } from './web/web'; import { init as initPVP } from './lib/rpg/pvp'; +import { autocomplete } from './lib/autocomplete'; const bot = new Client({ intents: [ @@ -114,7 +115,7 @@ bot.on(Events.InteractionCreate, async (interaction) => { try { if (!command.autocomplete) throw `Trying to invoke autocomplete for command ${interaction.commandName} which does not have it defined`; - await command.autocomplete(interaction); + await autocomplete(command.autocomplete)(interaction); } catch (error) { log.error(error); } diff --git a/src/types/index.d.ts b/src/types/index.d.ts index cfbdeb0..293edc7 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1,9 +1,10 @@ import { Collection, SlashCommandBuilder, CommandInteraction, Client } from 'discord.js'; +import { Autocomplete } from '../lib/autocomplete'; export interface Command { data: Pick, execute: (interaction: CommandInteraction) => Promise, - autocomplete?: (interaction: AutocompleteInteraction) => Promise, + autocomplete?: Autocomplete, onClientReady?: (client: Client) => Promise, serverWhitelist?: string[], }