@@ -7,6 +7,6 @@ namespace Discord.Commands | |||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] | ||||
public abstract class ParameterPreconditionAttribute : Attribute | public abstract class ParameterPreconditionAttribute : Attribute | ||||
{ | { | ||||
public abstract Task<PreconditionResult> CheckPermissions(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider services); | |||||
public abstract Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider services); | |||||
} | } | ||||
} | } |
@@ -13,6 +13,6 @@ namespace Discord.Commands | |||||
/// </summary> | /// </summary> | ||||
public string Group { get; set; } = null; | public string Group { get; set; } = null; | ||||
public abstract Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services); | |||||
public abstract Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services); | |||||
} | } | ||||
} | } |
@@ -41,7 +41,7 @@ namespace Discord.Commands | |||||
GuildPermission = null; | GuildPermission = null; | ||||
} | } | ||||
public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
public override async Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
{ | { | ||||
IGuildUser guildUser = null; | IGuildUser guildUser = null; | ||||
if (context.Guild != null) | if (context.Guild != null) | ||||
@@ -38,7 +38,7 @@ namespace Discord.Commands | |||||
Contexts = contexts; | Contexts = contexts; | ||||
} | } | ||||
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
{ | { | ||||
bool isValid = false; | bool isValid = false; | ||||
@@ -9,7 +9,7 @@ namespace Discord.Commands | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class RequireNsfwAttribute : PreconditionAttribute | public class RequireNsfwAttribute : PreconditionAttribute | ||||
{ | { | ||||
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
{ | { | ||||
if (context.Channel is ITextChannel text && text.IsNsfw) | if (context.Channel is ITextChannel text && text.IsNsfw) | ||||
return Task.FromResult(PreconditionResult.FromSuccess()); | return Task.FromResult(PreconditionResult.FromSuccess()); | ||||
@@ -11,7 +11,7 @@ namespace Discord.Commands | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class RequireOwnerAttribute : PreconditionAttribute | public class RequireOwnerAttribute : PreconditionAttribute | ||||
{ | { | ||||
public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
public override async Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
{ | { | ||||
switch (context.Client.TokenType) | switch (context.Client.TokenType) | ||||
{ | { | ||||
@@ -42,7 +42,7 @@ namespace Discord.Commands | |||||
GuildPermission = null; | GuildPermission = null; | ||||
} | } | ||||
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) | |||||
{ | { | ||||
var guildUser = context.User as IGuildUser; | var guildUser = context.User as IGuildUser; | ||||
@@ -78,7 +78,7 @@ namespace Discord.Commands | |||||
{ | { | ||||
foreach (PreconditionAttribute precondition in preconditionGroup) | foreach (PreconditionAttribute precondition in preconditionGroup) | ||||
{ | { | ||||
var result = await precondition.CheckPermissions(context, this, services).ConfigureAwait(false); | |||||
var result = await precondition.CheckPermissionsAsync(context, this, services).ConfigureAwait(false); | |||||
if (!result.IsSuccess) | if (!result.IsSuccess) | ||||
return result; | return result; | ||||
} | } | ||||
@@ -87,7 +87,7 @@ namespace Discord.Commands | |||||
{ | { | ||||
var results = new List<PreconditionResult>(); | var results = new List<PreconditionResult>(); | ||||
foreach (PreconditionAttribute precondition in preconditionGroup) | foreach (PreconditionAttribute precondition in preconditionGroup) | ||||
results.Add(await precondition.CheckPermissions(context, this, services).ConfigureAwait(false)); | |||||
results.Add(await precondition.CheckPermissionsAsync(context, this, services).ConfigureAwait(false)); | |||||
if (!results.Any(p => p.IsSuccess)) | if (!results.Any(p => p.IsSuccess)) | ||||
return PreconditionGroupResult.FromError($"{type} precondition group {preconditionGroup.Key} failed.", results); | return PreconditionGroupResult.FromError($"{type} precondition group {preconditionGroup.Key} failed.", results); | ||||
@@ -59,7 +59,7 @@ namespace Discord.Commands | |||||
public async Task<TypeReaderResult> Parse(ICommandContext context, string input, IServiceProvider services = null) | public async Task<TypeReaderResult> Parse(ICommandContext context, string input, IServiceProvider services = null) | ||||
{ | { | ||||
services = services ?? EmptyServiceProvider.Instance; | services = services ?? EmptyServiceProvider.Instance; | ||||
return await _reader.Read(context, input, services).ConfigureAwait(false); | |||||
return await _reader.ReadAsync(context, input, services).ConfigureAwait(false); | |||||
} | } | ||||
public override string ToString() => Name; | public override string ToString() => Name; | ||||
@@ -9,7 +9,7 @@ namespace Discord.Commands | |||||
internal class ChannelTypeReader<T> : TypeReader | internal class ChannelTypeReader<T> : TypeReader | ||||
where T : class, IChannel | where T : class, IChannel | ||||
{ | { | ||||
public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
if (context.Guild != null) | if (context.Guild != null) | ||||
{ | { | ||||
@@ -44,7 +44,7 @@ namespace Discord.Commands | |||||
_enumsByValue = byValueBuilder.ToImmutable(); | _enumsByValue = byValueBuilder.ToImmutable(); | ||||
} | } | ||||
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
object enumValue; | object enumValue; | ||||
@@ -7,7 +7,7 @@ namespace Discord.Commands | |||||
internal class MessageTypeReader<T> : TypeReader | internal class MessageTypeReader<T> : TypeReader | ||||
where T : class, IMessage | where T : class, IMessage | ||||
{ | { | ||||
public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
ulong id; | ulong id; | ||||
@@ -24,11 +24,11 @@ namespace Discord.Commands | |||||
_baseTypeReader = baseTypeReader; | _baseTypeReader = baseTypeReader; | ||||
} | } | ||||
public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase)) | if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase)) | ||||
return TypeReaderResult.FromSuccess(new T?()); | return TypeReaderResult.FromSuccess(new T?()); | ||||
return await _baseTypeReader.Read(context, input, services); ; | |||||
return await _baseTypeReader.ReadAsync(context, input, services); ; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -30,7 +30,7 @@ namespace Discord.Commands | |||||
_score = score; | _score = score; | ||||
} | } | ||||
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
if (_tryParse(input, out T value)) | if (_tryParse(input, out T value)) | ||||
return Task.FromResult(TypeReaderResult.FromSuccess(new TypeReaderValue(value, _score))); | return Task.FromResult(TypeReaderResult.FromSuccess(new TypeReaderValue(value, _score))); | ||||
@@ -9,7 +9,7 @@ namespace Discord.Commands | |||||
internal class RoleTypeReader<T> : TypeReader | internal class RoleTypeReader<T> : TypeReader | ||||
where T : class, IRole | where T : class, IRole | ||||
{ | { | ||||
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
ulong id; | ulong id; | ||||
@@ -5,6 +5,6 @@ namespace Discord.Commands | |||||
{ | { | ||||
public abstract class TypeReader | public abstract class TypeReader | ||||
{ | { | ||||
public abstract Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services); | |||||
public abstract Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services); | |||||
} | } | ||||
} | } |
@@ -10,7 +10,7 @@ namespace Discord.Commands | |||||
internal class UserTypeReader<T> : TypeReader | internal class UserTypeReader<T> : TypeReader | ||||
where T : class, IUser | where T : class, IUser | ||||
{ | { | ||||
public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services) | |||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | { | ||||
var results = new Dictionary<ulong, TypeReaderValue>(); | var results = new Dictionary<ulong, TypeReaderValue>(); | ||||
IReadOnlyCollection<IUser> channelUsers = (await context.Channel.GetUsersAsync(CacheMode.CacheOnly).Flatten().ConfigureAwait(false)).ToArray(); //TODO: must be a better way? | IReadOnlyCollection<IUser> channelUsers = (await context.Channel.GetUsersAsync(CacheMode.CacheOnly).Flatten().ConfigureAwait(false)).ToArray(); //TODO: must be a better way? | ||||