[Refactor] Remove some unnecessary async/await (#2739)
* Remove some unnecessary async/await * More not-so-async stuff * More not-so-async stuff * Fix merge issue
This commit is contained in:
@@ -162,18 +162,18 @@ namespace Discord.Commands
|
||||
return PreconditionResult.FromSuccess();
|
||||
}
|
||||
|
||||
public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
|
||||
public Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
|
||||
{
|
||||
services ??= EmptyServiceProvider.Instance;
|
||||
|
||||
if (!searchResult.IsSuccess)
|
||||
return ParseResult.FromError(searchResult);
|
||||
return Task.FromResult(ParseResult.FromError(searchResult));
|
||||
if (preconditionResult != null && !preconditionResult.IsSuccess)
|
||||
return ParseResult.FromError(preconditionResult);
|
||||
return Task.FromResult(ParseResult.FromError(preconditionResult));
|
||||
|
||||
string input = searchResult.Text.Substring(startIndex);
|
||||
|
||||
return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap).ConfigureAwait(false);
|
||||
return CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap);
|
||||
}
|
||||
|
||||
public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services)
|
||||
|
||||
@@ -87,10 +87,10 @@ namespace Discord.Commands
|
||||
return PreconditionResult.FromSuccess();
|
||||
}
|
||||
|
||||
public async Task<TypeReaderResult> ParseAsync(ICommandContext context, string input, IServiceProvider services = null)
|
||||
public Task<TypeReaderResult> ParseAsync(ICommandContext context, string input, IServiceProvider services = null)
|
||||
{
|
||||
services ??= EmptyServiceProvider.Instance;
|
||||
return await _reader.ReadAsync(context, input, services).ConfigureAwait(false);
|
||||
return _reader.ReadAsync(context, input, services);
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
@@ -42,12 +42,11 @@ namespace Discord.Commands
|
||||
/// <param name="stickers">A collection of stickers to send with the file.</param>
|
||||
/// <param name="embeds">A array of <see cref="Embed"/>s to send with this response. Max 10.</param>
|
||||
/// <param name="flags">Message flags combined as a bitfield.</param>
|
||||
protected virtual async Task<IUserMessage> ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null,
|
||||
protected virtual Task<IUserMessage> ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null,
|
||||
AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null,
|
||||
Embed[] embeds = null, MessageFlags flags = MessageFlags.None)
|
||||
{
|
||||
return await Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags).ConfigureAwait(false);
|
||||
}
|
||||
=> Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags);
|
||||
|
||||
/// <summary>
|
||||
/// The method to execute asynchronously before executing the command.
|
||||
/// </summary>
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace Discord.Commands
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
|
||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
|
||||
{
|
||||
if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase))
|
||||
return TypeReaderResult.FromSuccess(new T?());
|
||||
return await _baseTypeReader.ReadAsync(context, input, services).ConfigureAwait(false);
|
||||
return Task.FromResult(TypeReaderResult.FromSuccess(new T?()));
|
||||
return _baseTypeReader.ReadAsync(context, input, services);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user