parseMessageComponent method

MessageComponent parseMessageComponent(
  1. Map<String, Object?> raw
)

Implementation

MessageComponent parseMessageComponent(Map<String, Object?> raw) {
  final type = MessageComponentType.parse(raw['type'] as int);

  return switch (type) {
    MessageComponentType.actionRow => ActionRowComponent(
        components: parseMany(raw['components'] as List, parseMessageComponent),
      ),
    MessageComponentType.button => ButtonComponent(
        style: ButtonStyle.parse(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?,
        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.parse),
        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.parse),
        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?,
      ),
  };
}