Discord-Net-Labs / Discord.Net-Labs

An experimental fork of Discord.Net that implements the newest discord features for testing and development to eventually get merged into Discord.Net
https://labs.discordnet.dev
MIT License
156 stars 42 forks source link

Component TypeConverters and TypeReaders #449

Closed Cenngo closed 2 years ago

Cenngo commented 2 years ago

This PR adds support for [ComponentInteraction] TypeConverters for converting Component values and TypeReaders for converting customId segments into user implemented command parameter types.

TypeReaders are exclusively used for converting string values. This PR also includes default TypeReaders for IConvertibles and Snowflake entities. A new SerializeAsync() method is introduced to the Interaction service for serializing objects into string values using the TypeReader assigned to the corresponding object type. This allows the users to easily inject objects into CustomIds.

Component TypeConverters are used for parsing component values into [ComponentInteraction] parameters and modal fields. This PR ships with a DefaultArrayConverter and a default Iconvertible converter. Default array converter is used for parsing select menu items and relies on TypeReaders for parsing individual collection items. IConvertible converter is used to parsing Text input values into the IConvertible types.

This update ships with every necessary converter type to ensure that every legecy [ComponetInteraction] will keep working after this update.

Cenngo commented 2 years ago

@sabihoshi

Cenngo commented 2 years ago

moved to discord-net/Discord.Net#2169