| @@ -51,8 +51,6 @@ namespace Discord.Interactions | |||||
| var paramCount = paramList.Count(); | var paramCount = paramList.Count(); | ||||
| var captureCount = wildcardCaptures?.Count() ?? 0; | var captureCount = wildcardCaptures?.Count() ?? 0; | ||||
| if (paramCount < captureCount + 1) | |||||
| return await InvokeEventAndReturn(context, ExecuteResult.FromError(InteractionCommandError.BadArgs, "Command was invoked with too many parameters")).ConfigureAwait(false); | |||||
| if (context.Interaction is not IComponentInteraction messageComponent) | if (context.Interaction is not IComponentInteraction messageComponent) | ||||
| return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Component Command Interaction"); | return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Component Command Interaction"); | ||||
| @@ -914,8 +914,23 @@ namespace Discord.Interactions | |||||
| /// <returns> | /// <returns> | ||||
| /// A task representing the conversion process. The task result contains the result of the conversion. | /// A task representing the conversion process. The task result contains the result of the conversion. | ||||
| /// </returns> | /// </returns> | ||||
| public Task<string> SerializeValue<T>(T obj, IServiceProvider services = null) => | |||||
| _typeReaderMap.Get(typeof(T), services).SerializeAsync(obj); | |||||
| public Task<string> SerializeValueAsync<T>(T obj, IServiceProvider services) => | |||||
| _typeReaderMap.Get(typeof(T), services).SerializeAsync(obj, services); | |||||
| public async Task<string> GenerateCustomIdStringAsync(string format, IServiceProvider services, params object[] args) | |||||
| { | |||||
| var serializedValues = new string[args.Length]; | |||||
| for(var i = 0; i < args.Length; i++) | |||||
| { | |||||
| var arg = args[i]; | |||||
| var typeReader = _typeReaderMap.Get(arg.GetType(), null); | |||||
| var result = await typeReader.SerializeAsync(arg, services); | |||||
| serializedValues[i] = result; | |||||
| } | |||||
| return string.Format(format, serializedValues); | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Loads and caches an <see cref="ModalInfo"/> for the provided <see cref="IModal"/>. | /// Loads and caches an <see cref="ModalInfo"/> for the provided <see cref="IModal"/>. | ||||
| @@ -19,7 +19,7 @@ namespace Discord.Interactions | |||||
| TypeConverterResult.FromSuccess(result) : TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"{option} must be a valid {typeof(T).Name} snowflake to be parsed."); | TypeConverterResult.FromSuccess(result) : TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"{option} must be a valid {typeof(T).Name} snowflake to be parsed."); | ||||
| } | } | ||||
| public override Task<string> SerializeAsync(object obj) => Task.FromResult((obj as ISnowflakeEntity)?.Id.ToString()); | |||||
| public override Task<string> SerializeAsync(object obj, IServiceProvider services) => Task.FromResult((obj as ISnowflakeEntity)?.Id.ToString()); | |||||
| } | } | ||||
| internal sealed class DefaultUserReader<T> : DefaultSnowflakeReader<T> | internal sealed class DefaultUserReader<T> : DefaultSnowflakeReader<T> | ||||
| @@ -12,7 +12,7 @@ namespace Discord.Interactions | |||||
| TypeConverterResult.FromSuccess(result) : TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Value {option} cannot be converted to {nameof(T)}")); | TypeConverterResult.FromSuccess(result) : TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Value {option} cannot be converted to {nameof(T)}")); | ||||
| } | } | ||||
| public override Task<string> SerializeAsync(object obj) | |||||
| public override Task<string> SerializeAsync(object obj, IServiceProvider services) | |||||
| { | { | ||||
| var name = Enum.GetName(typeof(T), obj); | var name = Enum.GetName(typeof(T), obj); | ||||
| @@ -33,7 +33,7 @@ namespace Discord.Interactions | |||||
| /// <returns> | /// <returns> | ||||
| /// A task representing the conversion process. The result of the task contains the conversion result. | /// A task representing the conversion process. The result of the task contains the conversion result. | ||||
| /// </returns> | /// </returns> | ||||
| public virtual Task<string> SerializeAsync(object obj) => Task.FromResult(obj.ToString()); | |||||
| public virtual Task<string> SerializeAsync(object obj, IServiceProvider services) => Task.FromResult(obj.ToString()); | |||||
| } | } | ||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||