Browse Source

add converter and reader to interactionservice

pull/2307/head
Cenngo 3 years ago
parent
commit
2f557d4064
3 changed files with 6 additions and 4 deletions
  1. +4
    -2
      src/Discord.Net.Interactions/InteractionService.cs
  2. +1
    -1
      src/Discord.Net.Interactions/TypeConverters/ComponentInteractions/NullableComponentConverter.cs
  3. +1
    -1
      src/Discord.Net.Interactions/TypeReaders/NullableReader.cs

+ 4
- 2
src/Discord.Net.Interactions/InteractionService.cs View File

@@ -223,7 +223,8 @@ namespace Discord.Interactions
new ConcurrentDictionary<Type, Type>
{
[typeof(Array)] = typeof(DefaultArrayComponentConverter<>),
[typeof(IConvertible)] = typeof(DefaultValueComponentConverter<>)
[typeof(IConvertible)] = typeof(DefaultValueComponentConverter<>),
[typeof(Nullable<>)] = typeof(NullableComponentConverter<>)
});

_typeReaderMap = new TypeMap<TypeReader, string>(this, new ConcurrentDictionary<Type, TypeReader>(),
@@ -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<>)
});
}



+ 1
- 1
src/Discord.Net.Interactions/TypeConverters/ComponentInteractions/NullableComponentConverter.cs View File

@@ -18,6 +18,6 @@ namespace Discord.Interactions
}

public override Task<TypeConverterResult> 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);
}
}

+ 1
- 1
src/Discord.Net.Interactions/TypeReaders/NullableReader.cs View File

@@ -18,6 +18,6 @@ namespace Discord.Interactions
}

public override Task<TypeConverterResult> 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);
}
}

Loading…
Cancel
Save