feat(string-prompt): Adds string prompt to menu item
This commit is contained in:
parent
1d73ee8a78
commit
5c7c9c9f87
6 changed files with 164 additions and 26 deletions
|
|
@ -13,7 +13,8 @@ import {
|
|||
inlineCode,
|
||||
italic,
|
||||
Snowflake,
|
||||
StringSelectMenuBuilder, StringSelectMenuOptionBuilder
|
||||
StringSelectMenuBuilder, StringSelectMenuOptionBuilder, TextInputBuilder,
|
||||
TextInputStyle
|
||||
} from "discord.js";
|
||||
import {ChannelId} from "../types/DiscordTypes";
|
||||
import {MessageActionRowComponentBuilder} from "@discordjs/builders";
|
||||
|
|
@ -80,7 +81,24 @@ export class ConfigurationMenuHandler {
|
|||
setValue: this.setValue.bind(this)
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
traversalKey: "calendar",
|
||||
label: "Calendar",
|
||||
description: "Provides settings for the metadata contained in the playdate exports.",
|
||||
type: MenuItemType.Collection,
|
||||
children: [
|
||||
{
|
||||
traversalKey: "title",
|
||||
label: "Title",
|
||||
description: "Defines how the calendar entry should be called.",
|
||||
type: MenuItemType.Prompt,
|
||||
getCurrentValue: this.getStringValue.bind(this),
|
||||
getActionRowBuilder: this.getStringBuilder.bind(this),
|
||||
setValue: this.setValue.bind(this)
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +176,29 @@ export class ConfigurationMenuHandler {
|
|||
)
|
||||
}
|
||||
|
||||
private setValue(value: FieldMenuItemSaveValue[], context: FieldMenuItemContext): void {
|
||||
this.configuration.saveConfiguration(context.path.join('.'), value.join('; '));
|
||||
private getStringValue(context: FieldMenuItemContext): string {
|
||||
const value = this.configuration.getConfigurationByPath(context.path.join('.'));
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (typeof value !== 'string') {
|
||||
throw new TypeError(`Value of type ${typeof value} can't be used for a string value!`)
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private getStringBuilder(context: FieldMenuItemContext): TextInputBuilder {
|
||||
return new TextInputBuilder()
|
||||
.setStyle(TextInputStyle.Short)
|
||||
}
|
||||
|
||||
private setValue(value: FieldMenuItemSaveValue[]|string, context: FieldMenuItemContext): void {
|
||||
const savedValue = typeof value !== 'string' ?
|
||||
value.join('; ') :
|
||||
value;
|
||||
|
||||
this.configuration.saveConfiguration(context.path.join('.'), savedValue);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue