parseMessageComponent method
Implementation
MessageComponent parseMessageComponent(Map<String, Object?> raw) {
final type = MessageComponentType(raw['type'] as int);
return switch (type) {
MessageComponentType.actionRow => ActionRowComponent(
components: parseMany(raw['components'] as List, parseMessageComponent),
),
MessageComponentType.button => ButtonComponent(
style: ButtonStyle(raw['style'] as int),
label: raw['label'] as String?,
emoji: maybeParse(raw['emoji'], client.guilds[Snowflake.zero].emojis.parse),
customId: raw['custom_id'] as String?,
skuId: maybeParse(raw['sku_id'], Snowflake.parse),
url: maybeParse(raw['url'], Uri.parse),
isDisabled: raw['disabled'] as bool?,
),
MessageComponentType.textInput => TextInputComponent(
customId: raw['custom_id'] as String,
style: maybeParse(raw['style'], TextInputStyle.new),
label: raw['label'] as String?,
minLength: raw['min_length'] as int?,
maxLength: raw['max_length'] as int?,
isRequired: raw['required'] as bool?,
value: raw['value'] as String?,
placeholder: raw['placeholder'] as String?,
),
MessageComponentType.stringSelect ||
MessageComponentType.userSelect ||
MessageComponentType.roleSelect ||
MessageComponentType.mentionableSelect ||
MessageComponentType.channelSelect =>
SelectMenuComponent(
type: type,
customId: raw['custom_id'] as String,
options: maybeParseMany(raw['options'], parseSelectMenuOption),
channelTypes: maybeParseMany(raw['channel_types'], ChannelType.new),
placeholder: raw['placeholder'] as String?,
defaultValues: maybeParseMany(raw['default_values'], parseSelectMenuDefaultValue),
minValues: raw['min_values'] as int?,
maxValues: raw['max_values'] as int?,
isDisabled: raw['disabled'] as bool?,
),
MessageComponentType() => throw StateError('Unknown message component type: $type'),
};
}