From 2f557d40642688126a27cd74282d6013a278493c Mon Sep 17 00:00:00 2001 From: Cenngo Date: Tue, 17 May 2022 13:14:16 +0300 Subject: [PATCH] add converter and reader to interactionservice --- src/Discord.Net.Interactions/InteractionService.cs | 6 ++++-- .../ComponentInteractions/NullableComponentConverter.cs | 2 +- src/Discord.Net.Interactions/TypeReaders/NullableReader.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index 8eb5799d6..48dbd52aa 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -223,7 +223,8 @@ namespace Discord.Interactions new ConcurrentDictionary { [typeof(Array)] = typeof(DefaultArrayComponentConverter<>), - [typeof(IConvertible)] = typeof(DefaultValueComponentConverter<>) + [typeof(IConvertible)] = typeof(DefaultValueComponentConverter<>), + [typeof(Nullable<>)] = typeof(NullableComponentConverter<>) }); _typeReaderMap = new TypeMap(this, new ConcurrentDictionary(), @@ -234,7 +235,8 @@ namespace Discord.Interactions [typeof(IUser)] = typeof(DefaultUserReader<>), [typeof(IMessage)] = typeof(DefaultMessageReader<>), [typeof(IConvertible)] = typeof(DefaultValueReader<>), - [typeof(Enum)] = typeof(EnumReader<>) + [typeof(Enum)] = typeof(EnumReader<>), + [typeof(Nullable<>)] = typeof(NullableReader<>) }); } diff --git a/src/Discord.Net.Interactions/TypeConverters/ComponentInteractions/NullableComponentConverter.cs b/src/Discord.Net.Interactions/TypeConverters/ComponentInteractions/NullableComponentConverter.cs index 513e46933..ba6568ad1 100644 --- a/src/Discord.Net.Interactions/TypeConverters/ComponentInteractions/NullableComponentConverter.cs +++ b/src/Discord.Net.Interactions/TypeConverters/ComponentInteractions/NullableComponentConverter.cs @@ -18,6 +18,6 @@ namespace Discord.Interactions } public override Task ReadAsync(IInteractionContext context, IComponentInteractionData option, IServiceProvider services) - => _typeConverter.ReadAsync(context, option, services); + => string.IsNullOrEmpty(option.Value) ? Task.FromResult(TypeConverterResult.FromSuccess(null)) : _typeConverter.ReadAsync(context, option, services); } } diff --git a/src/Discord.Net.Interactions/TypeReaders/NullableReader.cs b/src/Discord.Net.Interactions/TypeReaders/NullableReader.cs index 5d5647b53..ed88dc64a 100644 --- a/src/Discord.Net.Interactions/TypeReaders/NullableReader.cs +++ b/src/Discord.Net.Interactions/TypeReaders/NullableReader.cs @@ -18,6 +18,6 @@ namespace Discord.Interactions } public override Task ReadAsync(IInteractionContext context, string option, IServiceProvider services) - => _typeReader.ReadAsync(context, option, services); + => string.IsNullOrEmpty(option) ? Task.FromResult(TypeConverterResult.FromSuccess(null)) : _typeReader.ReadAsync(context, option, services); } }