Format the project with 'dotnet format' (#2551)
* Sync and Re-Format * Fix Title string. * Fix indentation.
This commit is contained in:
@@ -43,8 +43,8 @@ namespace Discord.Commands
|
||||
{
|
||||
if (!TypeReaderTypeInfo.IsAssignableFrom(overridenTypeReader.GetTypeInfo()))
|
||||
throw new ArgumentException($"{nameof(overridenTypeReader)} must inherit from {nameof(TypeReader)}.");
|
||||
|
||||
|
||||
TypeReader = overridenTypeReader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Discord.Commands
|
||||
if (GuildPermission.HasValue)
|
||||
{
|
||||
if (guildUser == null)
|
||||
return Task.FromResult(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel."));
|
||||
return Task.FromResult(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel."));
|
||||
if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
|
||||
return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires guild permission {GuildPermission.Value}."));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Commands.Builders
|
||||
{
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Discord.Commands.Builders
|
||||
public string Name { get; set; }
|
||||
public string Summary { get; set; }
|
||||
public string Remarks { get; set; }
|
||||
public string Group { get => _group;
|
||||
public string Group
|
||||
{
|
||||
get => _group;
|
||||
set
|
||||
{
|
||||
_aliases.Remove(_group);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Discord.Commands.Builders;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord.Commands.Builders;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
internal static class ModuleClassBuilder
|
||||
@@ -80,11 +79,11 @@ namespace Discord.Commands
|
||||
{
|
||||
if (!IsValidModuleDefinition(typeInfo))
|
||||
continue;
|
||||
|
||||
|
||||
if (builtTypes.Contains(typeInfo))
|
||||
continue;
|
||||
|
||||
builder.AddModule((module) =>
|
||||
|
||||
builder.AddModule((module) =>
|
||||
{
|
||||
BuildModule(module, typeInfo, service, services);
|
||||
BuildSubTypes(module, typeInfo.DeclaredNestedTypes, builtTypes, service, services);
|
||||
@@ -139,7 +138,7 @@ namespace Discord.Commands
|
||||
|
||||
foreach (var method in validCommands)
|
||||
{
|
||||
builder.AddCommand((command) =>
|
||||
builder.AddCommand((command) =>
|
||||
{
|
||||
BuildCommand(command, typeInfo, method, service, services);
|
||||
});
|
||||
@@ -149,7 +148,7 @@ namespace Discord.Commands
|
||||
private static void BuildCommand(CommandBuilder builder, TypeInfo typeInfo, MethodInfo method, CommandService service, IServiceProvider serviceprovider)
|
||||
{
|
||||
var attributes = method.GetCustomAttributes();
|
||||
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
switch (attribute)
|
||||
@@ -191,7 +190,7 @@ namespace Discord.Commands
|
||||
int pos = 0, count = parameters.Length;
|
||||
foreach (var paramInfo in parameters)
|
||||
{
|
||||
builder.AddParameter((parameter) =>
|
||||
builder.AddParameter((parameter) =>
|
||||
{
|
||||
BuildParameter(parameter, paramInfo, pos++, count, service, serviceprovider);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Commands.Builders
|
||||
{
|
||||
public class ParameterBuilder
|
||||
@@ -25,7 +24,7 @@ namespace Discord.Commands.Builders
|
||||
|
||||
public IReadOnlyList<ParameterPreconditionAttribute> Preconditions => _preconditions;
|
||||
public IReadOnlyList<Attribute> Attributes => _attributes;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Automatic
|
||||
internal ParameterBuilder(CommandBuilder command)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Discord.Commands.Builders;
|
||||
using Discord.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -6,8 +8,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands.Builders;
|
||||
using Discord.Logging;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
@@ -653,7 +653,7 @@ namespace Discord.Commands
|
||||
var bestCandidate = preconditionResults
|
||||
.OrderByDescending(x => x.Key.Command.Priority)
|
||||
.FirstOrDefault(x => !x.Value.IsSuccess);
|
||||
return MatchResult.FromSuccess(bestCandidate.Key,bestCandidate.Value);
|
||||
return MatchResult.FromSuccess(bestCandidate.Key, bestCandidate.Value);
|
||||
}
|
||||
|
||||
var parseResults = new Dictionary<CommandMatch, ParseResult>();
|
||||
@@ -685,7 +685,7 @@ namespace Discord.Commands
|
||||
.Where(x => x.Value.IsSuccess)
|
||||
.ToArray();
|
||||
|
||||
if(successfulParses.Length == 0)
|
||||
if (successfulParses.Length == 0)
|
||||
{
|
||||
var bestMatch = parseResults
|
||||
.FirstOrDefault(x => !x.Value.IsSuccess);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Discord.Commands
|
||||
/// Gets or sets the <see cref="char"/> that separates an argument with another.
|
||||
/// </summary>
|
||||
public char SeparatorChar { get; set; } = ' ';
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether commands should be case-sensitive.
|
||||
/// </summary>
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Discord.Commands
|
||||
internal class EmptyServiceProvider : IServiceProvider
|
||||
{
|
||||
public static readonly EmptyServiceProvider Instance = new EmptyServiceProvider();
|
||||
|
||||
|
||||
public object GetService(Type serviceType) => null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,4 @@ namespace Discord.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,13 +45,17 @@ namespace Discord.Commands
|
||||
public static bool HasMentionPrefix(this IUserMessage msg, IUser user, ref int argPos)
|
||||
{
|
||||
var text = msg.Content;
|
||||
if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@') return false;
|
||||
if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@')
|
||||
return false;
|
||||
|
||||
int endPos = text.IndexOf('>');
|
||||
if (endPos == -1) return false;
|
||||
if (text.Length < endPos + 2 || text[endPos + 1] != ' ') return false; //Must end in "> "
|
||||
if (endPos == -1)
|
||||
return false;
|
||||
if (text.Length < endPos + 2 || text[endPos + 1] != ' ')
|
||||
return false; //Must end in "> "
|
||||
|
||||
if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId)) return false;
|
||||
if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId))
|
||||
return false;
|
||||
if (userId == user.Id)
|
||||
{
|
||||
argPos = endPos + 2;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Discord.Commands.Builders;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -175,7 +175,7 @@ namespace Discord.Commands
|
||||
|
||||
return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services)
|
||||
{
|
||||
if (!parseResult.IsSuccess)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Discord.Commands.Builders;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using Discord.Commands.Builders;
|
||||
using System.Linq;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Discord.Commands.Builders;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands.Builders;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Discord.Commands
|
||||
private readonly IReadOnlyDictionary<T, object> _enumsByValue;
|
||||
private readonly Type _enumType;
|
||||
private readonly TryParseDelegate<T> _tryParse;
|
||||
|
||||
|
||||
public EnumTypeReader(Type type, TryParseDelegate<T> parser)
|
||||
{
|
||||
_enumType = type;
|
||||
@@ -33,7 +33,7 @@ namespace Discord.Commands
|
||||
var byValueBuilder = ImmutableDictionary.CreateBuilder<T, object>();
|
||||
|
||||
foreach (var v in Enum.GetNames(_enumType))
|
||||
{
|
||||
{
|
||||
var parsedValue = Enum.Parse(_enumType, v);
|
||||
byNameBuilder.Add(v.ToLower(), parsedValue);
|
||||
if (!byValueBuilder.ContainsKey((T)parsedValue))
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Discord.Commands
|
||||
argv = input.Substring(beginRead + 1, currentRead - beginRead - 1).Trim();
|
||||
currentRead++;
|
||||
}
|
||||
else
|
||||
else
|
||||
argv = input.Substring(beginRead, currentRead - beginRead);
|
||||
|
||||
return _tProps[currentParam];
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Discord.Commands
|
||||
|
||||
//By Id (0.9)
|
||||
if (ulong.TryParse(input, NumberStyles.None, CultureInfo.InvariantCulture, out id))
|
||||
AddResult(results, context.Guild.GetRole(id) as T, 0.90f);
|
||||
AddResult(results, context.Guild.GetRole(id) as T, 0.90f);
|
||||
|
||||
//By Name (0.7-0.8)
|
||||
foreach (var role in roles.Where(x => string.Equals(input, x.Name, StringComparison.OrdinalIgnoreCase)))
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Discord.Commands
|
||||
.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase))
|
||||
.ForEachAsync(channelUser => AddResult(results, channelUser as T, channelUser.Username == input ? 0.65f : 0.55f))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
|
||||
foreach (var guildUser in guildUsers.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase)))
|
||||
AddResult(results, guildUser as T, guildUser.Username == input ? 0.60f : 0.50f);
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace Discord.Commands
|
||||
}
|
||||
|
||||
public static MatchResult FromSuccess(CommandMatch match, IResult pipeline)
|
||||
=> new MatchResult(match,pipeline,null, null);
|
||||
=> new MatchResult(match, pipeline, null, null);
|
||||
public static MatchResult FromError(CommandError error, string reason)
|
||||
=> new MatchResult(null,null,error, reason);
|
||||
=> new MatchResult(null, null, error, reason);
|
||||
public static MatchResult FromError(Exception ex)
|
||||
=> FromError(CommandError.Exception, ex.Message);
|
||||
public static MatchResult FromError(IResult result)
|
||||
=> new MatchResult(null, null,result.Error, result.ErrorReason);
|
||||
=> new MatchResult(null, null, result.Error, result.ErrorReason);
|
||||
public static MatchResult FromError(IResult pipeline, CommandError error, string reason)
|
||||
=> new MatchResult(null, pipeline, error, reason);
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Discord.Commands
|
||||
args[i] = GetMember(commands, services, parameters[i].ParameterType, typeInfo);
|
||||
var obj = InvokeConstructor<T>(constructor, args, typeInfo);
|
||||
|
||||
foreach(var property in properties)
|
||||
foreach (var property in properties)
|
||||
property.SetValue(obj, GetMember(commands, services, property.PropertyType, typeInfo));
|
||||
return obj;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user