public void GetTypeConverter_FromString_ToNullableInt32() { TypeConverterResult converterResult = _provider.GetTypeConverter(_string, _nullableInt32); Assert.That(converterResult, Is.Not.EqualTo(TypeConverterResult.Empty), "TypeConverterResult is not empty."); Assert.That(converterResult.TypeConverter.GetType(), Is.EqualTo(typeof(BidirectionalStringConverter))); }
public void GetTypeConverter_FromString_ToExtensibleEnum() { TypeConverterResult converterResult = _provider.GetTypeConverter(_string, typeof(Color)); Assert.That(converterResult.TypeConverterType, Is.EqualTo(TypeConverterType.DestinationTypeConverter)); Assert.That(converterResult.TypeConverter, Is.InstanceOf(typeof(ExtensibleEnumConverter))); Assert.That(((ExtensibleEnumConverter)converterResult.TypeConverter).ExtensibleEnumType, Is.SameAs(typeof(Color))); }
public void GetTypeConverter_FromExtensibleEnum_ToString() { TypeConverterResult converterResult = _provider.GetTypeConverter(typeof(Color), _string); Assert.That(converterResult.TypeConverterType, Is.EqualTo(TypeConverterType.SourceTypeConverter)); Assert.That(converterResult.TypeConverter, Is.InstanceOf(typeof(ExtensibleEnumConverter))); Assert.That(((ExtensibleEnumConverter)converterResult.TypeConverter).ExtensibleEnumType, Is.SameAs(typeof(Color))); }
public void GetTypeConverter_FromString_ToArray() { TypeConverterResult converterResult = _provider.GetTypeConverter(_string, _stringArray); Assert.That(converterResult, Is.Not.EqualTo(TypeConverterResult.Empty), "TypeConverterResult is empty."); Assert.That(converterResult.TypeConverterType, Is.EqualTo(TypeConverterType.SourceTypeConverter)); Assert.That(converterResult.TypeConverter.GetType(), Is.EqualTo(typeof(BidirectionalStringConverter))); }
public override Task <TypeConverterResult> ReadAsync(IInteractionCommandContext context, SocketSlashCommandDataOption option, IServiceProvider services) { if (Enum.TryParse <T>((string)option.Value, out var result)) { return(Task.FromResult(TypeConverterResult.FromSuccess(result))); } else { return(Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Value {option.Value} cannot be converted to {nameof(T)}"))); } }
public override async Task <TypeConverterResult> ReadAsync( IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) { await Task.Yield(); // Get color from hex, TryParse will take care of the pound (#) symbol. return(await Task.FromResult(SKColor.TryParse((string)option.Value, out var color) ?TypeConverterResult.FromSuccess(color) : TypeConverterResult.FromError( InteractionCommandError.ParseFailed, "Not a valid hex!! (*/ω\*)"))); }
/// <inheritdoc /> public override async Task <TypeConverterResult> ReadAsync( IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) { // By Id (1.0) if (ulong.TryParse((string)option.Value, NumberStyles.None, CultureInfo.InvariantCulture, out ulong id) && await context.Channel.GetMessageAsync(id).ConfigureAwait(false) is T msg) { return(await Task.FromResult(TypeConverterResult.FromSuccess(msg))); } return(await Task.FromResult(TypeConverterResult.FromError( InteractionCommandError.BadArgs, "Message not found."))); }
public override Task <TypeConverterResult> ReadAsync(IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) { var input = option.Value as string; if (Emote.TryParse(input, out var emote)) { return(Task.FromResult(TypeConverterResult.FromSuccess(emote))); } if (NeoSmart.Unicode.Emoji.IsEmoji(input)) { return(Task.FromResult(TypeConverterResult.FromSuccess(new Emoji(input)))); } // Doesn't seem to throw anything/tell me not success... // return Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.Unsuccessful, "That is not an emote.")); return(Task.FromResult(TypeConverterResult.FromSuccess(null))); }
public override async Task <TypeConverterResult> ReadAsync( IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) { // Custom emote. if (Emote.TryParse((string)option.Value, out var emote)) { return(await Task.FromResult(TypeConverterResult.FromSuccess(emote as T))); } // Unicode emoji. var emoji = new Emoji((string)option.Value); return(await Task.FromResult(string.IsNullOrEmpty(emoji.ToString()) is false ?TypeConverterResult.FromSuccess(emoji as T) : TypeConverterResult.FromError( InteractionCommandError.ParseFailed, $"Could not parse emote from input `{option.Value}`."))); }
public void GetTypeConverter_FromString_ToObject() { TypeConverterResult converterResult = _provider.GetTypeConverter(_string, _object); Assert.That(converterResult, Is.EqualTo(TypeConverterResult.Empty), "TypeConverterResult is not empty."); }
public void GetTypeConverter_FromNullableInt32_ToInt32() { TypeConverterResult converterResult = _provider.GetTypeConverter(_nullableInt32, _int32); Assert.That(converterResult, Is.EqualTo(TypeConverterResult.Empty), "TypeConverterResult is not empty."); }