public override async Task <TypeReaderResult> ReadAsync( ICommandContext context, string input, IServiceProvider services) { var result = await _reader.ReadAsync(context, input, services); return(result.IsSuccess || input.IsSkipped() ? TypeReaderResult.FromSuccess(result) : TypeReaderResult.FromError(result)); }
public async Task <ResultDictionary <T> > GetAnswersAsync(bool deleteResponse = true) { var ret = new Dictionary <T, PromptResult>(); IUserMessage?message = null; foreach (var prompt in Prompts) { var criteria = this.GetCriteria() .Concat(prompt.GetCriteria()) .OfType <ICriterion <SocketMessage> >() .AsCriterion(); var result = await Module.Prompt(prompt.Question, deleteResponse?message : null, prompt.Fields, prompt.Timeout ?? Timeout, criteria, prompt.IsRequired); message = result.message; if (result.response is null) { if (!prompt.IsRequired) { continue; } if (ErrorMessage != null) { await Module.ModifyOrSendMessage(ErrorMessage ?? "You did not respond in time.", message, color : Color.Red); } throw new ArgumentNullException(nameof(result.response), "User did not respond in time"); } object response = result.response.Content; if (prompt.TypeReader != null) { response = await prompt.TypeReader.ReadAsync(Context, response.ToString(), Services); } else if (TypeReader != null) { response = await TypeReader.ReadAsync(Context, response.ToString(), Services); } var promptResult = new PromptResult(prompt.Question, response); ret[prompt.Key] = promptResult; } return(new ResultDictionary <T>(ret)); }
public async Task <TypeReaderResult> ParseAsync(string commandString, string input, IServiceProvider services = null) { services = services ?? EmptyServiceProvider.Instance; return(await _reader.ReadAsync(commandString, input, services).ConfigureAwait(false)); }
public async Task <bool> JudgeAsync(SocketCommandContext sourceContext, SocketMessage parameter) { var result = await _reader.ReadAsync(sourceContext, parameter.Content, _services); return(result.IsSuccess); }