Add prefill to custom event modal if you already started pressing buttons
This commit is contained in:
parent
0d5dab8f04
commit
6f0b69e8f2
1
deps.ts
1
deps.ts
|
@ -41,6 +41,7 @@ export type {
|
||||||
MakeRequired,
|
MakeRequired,
|
||||||
Message,
|
Message,
|
||||||
PermissionStrings,
|
PermissionStrings,
|
||||||
|
SelectMenuComponent,
|
||||||
SelectOption,
|
SelectOption,
|
||||||
} from 'https://deno.land/x/discordeno@17.0.1/mod.ts';
|
} from 'https://deno.land/x/discordeno@17.0.1/mod.ts';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ActionRow, ApplicationCommandFlags, ApplicationCommandTypes, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
|
import { ActionRow, ApplicationCommandFlags, ApplicationCommandTypes, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes, SelectMenuComponent } from '../../../deps.ts';
|
||||||
import { infoColor1, somethingWentWrong } from '../../commandUtils.ts';
|
import { infoColor1, somethingWentWrong } from '../../commandUtils.ts';
|
||||||
import { CommandDetails } from '../../types/commandTypes.ts';
|
import { CommandDetails } from '../../types/commandTypes.ts';
|
||||||
import { Activities } from './activities.ts';
|
import { Activities } from './activities.ts';
|
||||||
|
@ -19,15 +19,15 @@ const details: CommandDetails = {
|
||||||
type: ApplicationCommandTypes.ChatInput,
|
type: ApplicationCommandTypes.ChatInput,
|
||||||
};
|
};
|
||||||
|
|
||||||
const customEventRow: ActionRow = {
|
const generateCustomEventRow = (title: string, subtitle: string): ActionRow => ({
|
||||||
type: MessageComponentTypes.ActionRow,
|
type: MessageComponentTypes.ActionRow,
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.Button,
|
type: MessageComponentTypes.Button,
|
||||||
style: ButtonStyles.Primary,
|
style: ButtonStyles.Primary,
|
||||||
label: 'Create Custom Event',
|
label: 'Create Custom Event',
|
||||||
customId: createCustomActivityBtnId,
|
customId: `${createCustomActivityBtnId}${idSeparator}${title}${pathIdxSeparator}${subtitle}${pathIdxSeparator}`,
|
||||||
}],
|
}],
|
||||||
};
|
});
|
||||||
|
|
||||||
const execute = async (bot: Bot, interaction: Interaction) => {
|
const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
if (interaction.data && (interaction.data.name === slashCommandName || interaction.data.customId) && interaction.member && interaction.guildId && interaction.channelId) {
|
if (interaction.data && (interaction.data.name === slashCommandName || interaction.data.customId) && interaction.member && interaction.guildId && interaction.channelId) {
|
||||||
|
@ -90,7 +90,19 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
currentBaseValue = `${currentBaseValue}${idx}${pathIdxSeparator}`;
|
currentBaseValue = `${currentBaseValue}${idx}${pathIdxSeparator}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectMenus.push(customEventRow);
|
// Prefill the custom event modal
|
||||||
|
const prefillArray: Array<string> = [];
|
||||||
|
selectMenus.forEach((menu) => {
|
||||||
|
try {
|
||||||
|
const menuOption = (menu.components[0] as SelectMenuComponent).options.find((option) => option.default);
|
||||||
|
if (menuOption) {
|
||||||
|
prefillArray.push(menuOption.label);
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// do nothing, don't care
|
||||||
|
}
|
||||||
|
});
|
||||||
|
selectMenus.push(generateCustomEventRow(prefillArray.length ? prefillArray[0] : '', prefillArray.length > 1 ? prefillArray[prefillArray.length - 1] : ''));
|
||||||
|
|
||||||
if (interaction.data.customId && interaction.data.customId.includes(fillerChar)) {
|
if (interaction.data.customId && interaction.data.customId.includes(fillerChar)) {
|
||||||
// Let discord know we didn't ignore the user
|
// Let discord know we didn't ignore the user
|
||||||
|
|
Loading…
Reference in New Issue