Skip to content

Commit

Permalink
refactor: update to StringSelectMenu due to deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
zapteryx committed Nov 30, 2022
1 parent 8711e2e commit fe80280
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 75 deletions.
6 changes: 3 additions & 3 deletions src/commands/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
EmbedBuilder,
escapeMarkdown,
Message,
SelectMenuBuilder,
SlashCommandBuilder,
StringSelectMenuBuilder,
} from 'discord.js';

// credit: https://github.com/lavaclient/djs-v13-example/blob/main/src/commands/Play.ts
Expand Down Expand Up @@ -135,8 +135,8 @@ export default {
}),
{
components: [
new ActionRowBuilder<SelectMenuBuilder>().addComponents(
new SelectMenuBuilder()
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId('search')
.setPlaceholder(
await getGuildLocaleString(
Expand Down
6 changes: 3 additions & 3 deletions src/commands/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
EmbedBuilder,
Message,
PermissionsBitField,
SelectMenuBuilder,
SlashCommandBuilder,
StringSelectMenuBuilder,
} from 'discord.js';

export default {
Expand Down Expand Up @@ -77,8 +77,8 @@ export default {
[description, ...embeds],
{
components: [
new ActionRowBuilder<SelectMenuBuilder>().addComponents(
new SelectMenuBuilder()
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId('settings')
.addOptions(
settingsOptions.map(
Expand Down
14 changes: 9 additions & 5 deletions src/components/buttons/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import {
import type {
ButtonInteraction,
MessageActionRowComponentBuilder,
SelectMenuComponent,
StringSelectMenuComponent,
} from 'discord.js';
import {
ActionRowBuilder,
EmbedBuilder,
StringSelectMenuBuilder,
} from 'discord.js';
import { ActionRowBuilder, EmbedBuilder, SelectMenuBuilder } from 'discord.js';

export default {
name: 'format',
Expand Down Expand Up @@ -86,10 +90,10 @@ export default {
)}: \`${current}\``;
await interaction.replyHandler.reply([description, ...embeds], {
components: [
new ActionRowBuilder<SelectMenuBuilder>().addComponents(
SelectMenuBuilder.from(
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
StringSelectMenuBuilder.from(
interaction.message.components[0]
.components[0] as SelectMenuComponent,
.components[0] as StringSelectMenuComponent,
),
),
actionRow as ActionRowBuilder<MessageActionRowComponentBuilder>,
Expand Down
10 changes: 5 additions & 5 deletions src/components/buttons/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
ButtonInteraction,
GuildMember,
MessageActionRowComponentBuilder,
SelectMenuComponent,
StringSelectMenuComponent,
} from 'discord.js';
import {
ActionRowBuilder,
Expand All @@ -35,7 +35,7 @@ import {
EmbedBuilder,
escapeMarkdown,
PermissionsBitField,
SelectMenuBuilder,
StringSelectMenuBuilder,
} from 'discord.js';

export default {
Expand Down Expand Up @@ -296,14 +296,14 @@ export default {
pages.length.toString(),
),
});
updated.components[0] = <ActionRowBuilder<SelectMenuBuilder>>(
updated.components[0] = <ActionRowBuilder<StringSelectMenuBuilder>>(
ActionRowBuilder.from(original.components[0])
);
updated.components[1] = <ActionRowBuilder<ButtonBuilder>>(
ActionRowBuilder.from(original.components[1])
);
const selectComponent = SelectMenuBuilder.from(
<SelectMenuComponent>original.components[0].components[0],
const selectComponent = StringSelectMenuBuilder.from(
<StringSelectMenuComponent>original.components[0].components[0],
).setOptions(
pages[page - 1]
.map(
Expand Down
18 changes: 11 additions & 7 deletions src/components/selectmenus/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ import {
} from '#src/lib/util/util.js';
import type {
MessageActionRowComponentBuilder,
SelectMenuComponent,
SelectMenuComponentOptionData,
SelectMenuInteraction,
StringSelectMenuComponent,
StringSelectMenuInteraction,
} from 'discord.js';
import {
ActionRowBuilder,
EmbedBuilder,
StringSelectMenuBuilder,
} from 'discord.js';
import { ActionRowBuilder, EmbedBuilder, SelectMenuBuilder } from 'discord.js';

export default {
name: 'language',
checks: [Check.InteractionStarter],
async execute(
interaction: QuaverInteraction<SelectMenuInteraction>,
interaction: QuaverInteraction<StringSelectMenuInteraction>,
): Promise<void> {
if (!confirmationTimeout[interaction.message.id]) {
await interaction.replyHandler.locale(
Expand Down Expand Up @@ -128,9 +132,9 @@ export default {
[description, ...embeds],
{
components: [
new ActionRowBuilder<SelectMenuBuilder>().addComponents(
SelectMenuBuilder.from(
<SelectMenuComponent>(
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
StringSelectMenuBuilder.from(
<StringSelectMenuComponent>(
interaction.message.components[0].components[0]
),
).setOptions(
Expand Down
19 changes: 10 additions & 9 deletions src/components/selectmenus/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import type {
APISelectMenuOption,
ButtonComponent,
MessageActionRowComponentBuilder,
SelectMenuComponent,
SelectMenuComponentOptionData,
SelectMenuInteraction,
StringSelectMenuComponent,
StringSelectMenuInteraction,
} from 'discord.js';
import {
ActionRowBuilder,
ButtonBuilder,
EmbedBuilder,
SelectMenuBuilder,
StringSelectMenuBuilder,
} from 'discord.js';

export default {
name: 'search',
checks: [Check.InteractionStarter],
async execute(
interaction: QuaverInteraction<SelectMenuInteraction>,
interaction: QuaverInteraction<StringSelectMenuInteraction>,
): Promise<void> {
const state = searchState[interaction.message.id];
if (!state) {
Expand Down Expand Up @@ -79,15 +79,16 @@ export default {
} = { components: [] };
updated.components[0] = ActionRowBuilder.from(
original.components[0],
) as ActionRowBuilder<SelectMenuBuilder>;
) as ActionRowBuilder<StringSelectMenuBuilder>;
updated.components[1] = ActionRowBuilder.from(
original.components[1],
) as ActionRowBuilder<ButtonBuilder>;
updated.components[0].components[0] = SelectMenuBuilder.from(
original.components[0].components[0] as SelectMenuComponent,
updated.components[0].components[0] = StringSelectMenuBuilder.from(
original.components[0].components[0] as StringSelectMenuComponent,
).setOptions(
(
original.components[0].components[0] as SelectMenuComponent
original.components[0]
.components[0] as StringSelectMenuComponent
).options
.map(
(
Expand Down Expand Up @@ -145,7 +146,7 @@ export default {
(options): boolean =>
!(
original.components[0]
.components[0] as SelectMenuComponent
.components[0] as StringSelectMenuComponent
).options.find(
(opt): boolean =>
opt.value === options.value,
Expand Down
44 changes: 25 additions & 19 deletions src/components/selectmenus/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import {
import type {
MessageActionRowComponentBuilder,
SelectMenuComponentOptionData,
SelectMenuInteraction,
StringSelectMenuInteraction,
} from 'discord.js';
import {
ActionRowBuilder,
EmbedBuilder,
StringSelectMenuBuilder,
} from 'discord.js';
import { ActionRowBuilder, EmbedBuilder, SelectMenuBuilder } from 'discord.js';

export default {
name: 'settings',
checks: [Check.InteractionStarter],
async execute(
interaction: QuaverInteraction<SelectMenuInteraction>,
interaction: QuaverInteraction<StringSelectMenuInteraction>,
): Promise<void> {
if (!confirmationTimeout[interaction.message.id]) {
await interaction.replyHandler.locale(
Expand Down Expand Up @@ -92,23 +96,25 @@ export default {
}`;
await interaction.replyHandler.reply([description, ...embeds], {
components: [
new ActionRowBuilder<SelectMenuBuilder>().addComponents(
new SelectMenuBuilder().setCustomId('settings').addOptions(
settingsOptions.map(
(opt): SelectMenuComponentOptionData => ({
label: getLocaleString(
guildLocaleCode,
`CMD.SETTINGS.MISC.${opt.toUpperCase()}.NAME`,
),
description: getLocaleString(
guildLocaleCode,
`CMD.SETTINGS.MISC.${opt.toUpperCase()}.DESCRIPTION`,
),
value: opt,
default: opt === option,
}),
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId('settings')
.addOptions(
settingsOptions.map(
(opt): SelectMenuComponentOptionData => ({
label: getLocaleString(
guildLocaleCode,
`CMD.SETTINGS.MISC.${opt.toUpperCase()}.NAME`,
),
description: getLocaleString(
guildLocaleCode,
`CMD.SETTINGS.MISC.${opt.toUpperCase()}.DESCRIPTION`,
),
value: opt,
default: opt === option,
}),
),
),
),
),
actionRow as ActionRowBuilder<MessageActionRowComponentBuilder>,
],
Expand Down
4 changes: 2 additions & 2 deletions src/events/interactionCreate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
ChatInputCommandInteraction,
ModalSubmitInteraction,
PermissionsBitField,
SelectMenuInteraction,
SlashCommandBuilder,
StringSelectMenuInteraction,
} from 'discord.js';

export type ChatInputCommand = {
Expand All @@ -31,7 +31,7 @@ export type Button = {
export type SelectMenu = {
name: string;
checks?: Check[];
execute(interaction: SelectMenuInteraction): Promise<void>;
execute(interaction: StringSelectMenuInteraction): Promise<void>;
};

export type ModalSubmit = {
Expand Down
8 changes: 4 additions & 4 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
GuildMember,
Interaction,
ModalSubmitInteraction,
SelectMenuInteraction,
StringSelectMenuInteraction,
} from 'discord.js';
import { PermissionsBitField } from 'discord.js';
import type {
Expand All @@ -25,7 +25,7 @@ async function handleFailedChecks(
interaction: QuaverInteraction<
| ChatInputCommandInteraction
| ButtonInteraction
| SelectMenuInteraction
| StringSelectMenuInteraction
| ModalSubmitInteraction
>,
): Promise<void> {
Expand All @@ -37,7 +37,7 @@ async function handleFailedChecks(
? 'Command'
: interaction.isButton()
? 'Button'
: interaction.isSelectMenu()
: interaction.isStringSelectMenu()
? 'Select menu'
: 'Modal'
} ${
Expand Down Expand Up @@ -284,7 +284,7 @@ export default {
return;
}
}
if (interaction.isSelectMenu()) {
if (interaction.isStringSelectMenu()) {
const selectmenu = interaction.client.selectmenus.get(
interaction.customId.split(':')[0],
) as SelectMenu;
Expand Down
42 changes: 24 additions & 18 deletions src/lib/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import type {
MessageActionRowComponentBuilder,
MessageCreateOptions,
ModalSubmitInteraction,
SelectMenuInteraction,
Snowflake,
StringSelectMenuInteraction,
} from 'discord.js';
import {
ActionRowBuilder,
Expand All @@ -30,7 +30,7 @@ import {
EmbedBuilder,
escapeMarkdown,
GuildMember,
SelectMenuBuilder,
StringSelectMenuBuilder,
} from 'discord.js';
import { readdirSync } from 'fs';
import { get } from 'lodash-es';
Expand Down Expand Up @@ -317,7 +317,7 @@ export function getFailedChecks(
member: GuildMember & { client: QuaverClient },
interaction?:
| ButtonInteraction
| SelectMenuInteraction
| StringSelectMenuInteraction
| ModalSubmitInteraction,
): Check[] {
const failedChecks: Check[] = [];
Expand Down Expand Up @@ -423,22 +423,28 @@ export async function buildSettingsPage(
Language[guildLocaleCode] ?? 'Unknown'
} (${guildLocaleCode})`;
actionRow.addComponents(
new SelectMenuBuilder().setCustomId('language').addOptions(
readdirSync(
getAbsoluteFileURL(import.meta.url, [
'..',
'..',
'..',
'locales',
]),
).map(
(file: keyof typeof Language): APISelectMenuOption => ({
label: `${Language[file] ?? 'Unknown'} (${file})`,
value: file,
default: file === guildLocaleCode,
}),
new StringSelectMenuBuilder()
.setCustomId('language')
.addOptions(
readdirSync(
getAbsoluteFileURL(import.meta.url, [
'..',
'..',
'..',
'locales',
]),
).map(
(
file: keyof typeof Language,
): APISelectMenuOption => ({
label: `${
Language[file] ?? 'Unknown'
} (${file})`,
value: file,
default: file === guildLocaleCode,
}),
),
),
),
);
break;
case 'format': {
Expand Down

0 comments on commit fe80280

Please sign in to comment.