remove redundant autocomplete step

This commit is contained in:
Jill 2023-11-22 16:45:55 +03:00
parent e5b049d0b2
commit 8f0fa740d7
11 changed files with 20 additions and 24 deletions

View File

@ -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 <t:${Math.floor((Date.now() + INVINCIBLE_TIMER) / 1000)}:R> (or if they perform an action first).`);
},
autocomplete: autocomplete(weaponAutocomplete),
autocomplete: weaponAutocomplete,
} satisfies Command;

View File

@ -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;

View File

@ -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 <t:${Math.floor(nextUsableAt / 1000)}:R>` : ''}`);
},
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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<CustomCraftingRecipe>('customCraftingRecipes');
@ -251,5 +250,5 @@ export default {
name: formatRecipe(recipe, true),
value: recipe.id.toString()
}));
}),
},
} satisfies Command;

View File

@ -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;

View File

@ -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);
}

View File

@ -1,9 +1,10 @@
import { Collection, SlashCommandBuilder, CommandInteraction, Client } from 'discord.js';
import { Autocomplete } from '../lib/autocomplete';
export interface Command {
data: Pick<SlashCommandBuilder, 'toJSON' | 'name'>,
execute: (interaction: CommandInteraction) => Promise<unknown>,
autocomplete?: (interaction: AutocompleteInteraction) => Promise<unknown>,
autocomplete?: Autocomplete,
onClientReady?: (client: Client) => Promise<unknown>,
serverWhitelist?: string[],
}