run dotnet format

This commit is contained in:
spiral
2021-08-27 11:03:47 -04:00
parent 05989242f9
commit ac2671452d
278 changed files with 1913 additions and 1808 deletions

View File

@@ -5,7 +5,7 @@ namespace PluralKit.Bot
public string Key { get; }
public string Usage { get; }
public string Description { get; }
public Command(string key, string usage, string description)
{
Key = key;

View File

@@ -6,7 +6,7 @@ namespace PluralKit.Bot
{
public string Key { get; }
public string Description { get; }
public ICollection<Command> Children { get; }
public CommandGroup(string key, string description, ICollection<Command> children)

View File

@@ -77,7 +77,7 @@ namespace PluralKit.Bot
public DiscordApiClient Rest => _rest;
public PKSystem System => _senderSystem;
public Parameters Parameters => _parameters;
internal IDatabase Database => _db;
@@ -109,7 +109,7 @@ namespace PluralKit.Bot
return msg;
}
public async Task Execute<T>(Command commandDef, Func<T, Task> handler)
{
_currentCommand = commandDef;
@@ -134,15 +134,15 @@ namespace PluralKit.Bot
}
}
public LookupContext LookupContextFor(PKSystem target) =>
public LookupContext LookupContextFor(PKSystem target) =>
System?.Id == target.Id ? LookupContext.ByOwner : LookupContext.ByNonOwner;
public LookupContext LookupContextFor(SystemId systemId) =>
public LookupContext LookupContextFor(SystemId systemId) =>
System?.Id == systemId ? LookupContext.ByOwner : LookupContext.ByNonOwner;
public LookupContext LookupContextFor(PKMember target) =>
System?.Id == target.System ? LookupContext.ByOwner : LookupContext.ByNonOwner;
public IComponentContext Services => _provider;
}
}

View File

@@ -14,8 +14,8 @@ namespace PluralKit.Bot
{
public static string PopArgument(this Context ctx) =>
ctx.Parameters.Pop();
public static string PeekArgument(this Context ctx) =>
public static string PeekArgument(this Context ctx) =>
ctx.Parameters.Peek();
public static string RemainderOrNull(this Context ctx, bool skipFlags = true) =>
@@ -23,10 +23,10 @@ namespace PluralKit.Bot
public static bool HasNext(this Context ctx, bool skipFlags = true) =>
ctx.RemainderOrNull(skipFlags) != null;
public static string FullCommand(this Context ctx) =>
public static string FullCommand(this Context ctx) =>
ctx.Parameters.FullCommand;
/// <summary>
/// Checks if the next parameter is equal to one of the given keywords. Case-insensitive.
/// </summary>
@@ -58,7 +58,7 @@ namespace PluralKit.Bot
{
// Flags are *ALWAYS PARSED LOWERCASE*. This means we skip out on a "ToLower" call here.
// Can assume the caller array only contains lowercase *and* the set below only contains lowercase
var flags = ctx.Parameters.Flags();
return potentialMatches.Any(potentialMatch => flags.Contains(potentialMatch));
}
@@ -66,7 +66,7 @@ namespace PluralKit.Bot
public static async Task<bool> MatchClear(this Context ctx, string toClear = null)
{
var matched = ctx.Match("clear", "reset") || ctx.MatchFlag("c", "clear");
if (matched && toClear != null)
if (matched && toClear != null)
return await ctx.ConfirmClear(toClear);
return matched;
}
@@ -82,11 +82,11 @@ namespace PluralKit.Bot
if (parseRawMessageId && ulong.TryParse(word, out var mid))
return (mid, null);
var match = Regex.Match(word, "https://(?:\\w+.)?discord(?:app)?.com/channels/\\d+/(\\d+)/(\\d+)");
if (!match.Success)
return (null, null);
var channelId = ulong.Parse(match.Groups[1].Value);
var messageId = ulong.Parse(match.Groups[2].Value);
ctx.PopArgument();
@@ -108,11 +108,11 @@ namespace PluralKit.Bot
if (restrictToSystem != null && member.System != restrictToSystem)
throw Errors.NotOwnMemberError; // TODO: name *which* member?
members.Add(member); // Then add to the final output list
}
if (members.Count == 0) throw new PKSyntaxError($"You must input at least one member.");
return members;
}
@@ -131,13 +131,13 @@ namespace PluralKit.Bot
if (restrictToSystem != null && group.System != restrictToSystem)
throw Errors.NotOwnGroupError; // TODO: name *which* group?
groups.Add(group); // Then add to the final output list
}
if (groups.Count == 0) throw new PKSyntaxError($"You must input at least one group.");
return groups;
}
}
}
}

View File

@@ -1,4 +1,4 @@
using Myriad.Types;
using Myriad.Types;
using PluralKit.Core;
@@ -11,27 +11,27 @@ namespace PluralKit.Bot
if (ctx.Channel.GuildId != null) return ctx;
throw new PKError("This command can not be run in a DM.");
}
public static Context CheckSystemPrivacy(this Context ctx, PKSystem target, PrivacyLevel level)
{
if (level.CanAccess(ctx.LookupContextFor(target))) return ctx;
throw new PKError("You do not have permission to access this information.");
}
public static Context CheckOwnMember(this Context ctx, PKMember member)
{
if (member.System != ctx.System?.Id)
throw Errors.NotOwnMemberError;
return ctx;
}
public static Context CheckOwnGroup(this Context ctx, PKGroup group)
{
if (group.System != ctx.System?.Id)
throw Errors.NotOwnGroupError;
return ctx;
}
public static Context CheckSystem(this Context ctx)
{
if (ctx.System == null)
@@ -45,7 +45,7 @@ namespace PluralKit.Bot
throw Errors.ExistingSystemError;
return ctx;
}
public static Context CheckAuthorPermission(this Context ctx, PermissionSet neededPerms, string permissionName)
{
if ((ctx.UserPermissions & neededPerms) != neededPerms)

View File

@@ -23,14 +23,14 @@ namespace PluralKit.Bot
public static bool MatchUserRaw(this Context ctx, out ulong id)
{
id = 0;
var text = ctx.PeekArgument();
if (text.TryParseMention(out var mentionId))
id = mentionId;
return id != 0;
}
public static Task<PKSystem> PeekSystem(this Context ctx) => ctx.MatchSystemInner();
public static async Task<PKSystem> MatchSystem(this Context ctx)
@@ -50,7 +50,7 @@ namespace PluralKit.Bot
// - A system hid
await using var conn = await ctx.Database.Obtain();
// Direct IDs and mentions are both handled by the below method:
if (input.TryParseMention(out var id))
return await ctx.Repository.GetSystemByAccount(conn, id);
@@ -82,7 +82,7 @@ namespace PluralKit.Bot
// And if that again fails, we try finding a member with a display name matching the argument from the system
if (ctx.System != null && await ctx.Repository.GetMemberByDisplayName(conn, ctx.System.Id, input) is PKMember memberByDisplayName)
return memberByDisplayName;
// We didn't find anything, so we return null.
return null;
}
@@ -102,17 +102,17 @@ namespace PluralKit.Bot
// Finally, we return the member value.
return member;
}
public static async Task<PKGroup> PeekGroup(this Context ctx)
{
var input = ctx.PeekArgument();
await using var conn = await ctx.Database.Obtain();
if (ctx.System != null && await ctx.Repository.GetGroupByName(conn, ctx.System.Id, input) is {} byName)
if (ctx.System != null && await ctx.Repository.GetGroupByName(conn, ctx.System.Id, input) is { } byName)
return byName;
if (await ctx.Repository.GetGroupByHid(conn, input) is {} byHid)
if (await ctx.Repository.GetGroupByHid(conn, input) is { } byHid)
return byHid;
if (await ctx.Repository.GetGroupByDisplayName(conn, ctx.System.Id, input) is {} byDisplayName)
if (await ctx.Repository.GetGroupByDisplayName(conn, ctx.System.Id, input) is { } byDisplayName)
return byDisplayName;
return null;
@@ -139,7 +139,7 @@ namespace PluralKit.Bot
return $"Member with name \"{input}\" not found. Note that a member ID is 5 characters long.";
return $"Member not found. Note that a member ID is 5 characters long.";
}
public static string CreateGroupNotFoundError(this Context ctx, string input)
{
// TODO: does this belong here?
@@ -154,18 +154,18 @@ namespace PluralKit.Bot
return $"Group with name \"{input}\" not found. Note that a group ID is 5 characters long.";
return $"Group not found. Note that a group ID is 5 characters long.";
}
public static Task<Channel> MatchChannel(this Context ctx)
{
if (!MentionUtils.TryParseChannel(ctx.PeekArgument(), out var id))
if (!MentionUtils.TryParseChannel(ctx.PeekArgument(), out var id))
return Task.FromResult<Channel>(null);
if (!ctx.Cache.TryGetChannel(id, out var channel))
return Task.FromResult<Channel>(null);
if (!DiscordUtils.IsValidGuildChannel(channel))
return Task.FromResult<Channel>(null);
ctx.PopArgument();
return Task.FromResult(channel);
}

View File

@@ -37,10 +37,10 @@ namespace PluralKit.Bot
{
// Start of the word
internal readonly int startPos;
// End of the word
internal readonly int endPos;
// How much to advance word pointer afterwards to point at the start of the *next* word
internal readonly int advanceAfterWord;
@@ -66,15 +66,15 @@ namespace PluralKit.Bot
private void ParseFlags()
{
_flags = new HashSet<string>();
var ptr = 0;
while (NextWordPosition(ptr) is { } wp)
{
ptr = wp.endPos + wp.advanceAfterWord;
// Is this word a *flag* (as in, starts with a - AND is not quoted)
if (_cmd[wp.startPos] != '-' || wp.wasQuoted) continue; // (if not, carry on w/ next word)
// Find the *end* of the flag start (technically allowing arbitrary amounts of dashes)
var flagNameStart = wp.startPos;
while (flagNameStart < _cmd.Length && _cmd[flagNameStart] == '-')
@@ -125,7 +125,7 @@ namespace PluralKit.Bot
if (skipFlags)
{
// Skip all *leading* flags when taking the remainder
while (NextWordPosition(_ptr) is {} wp)
while (NextWordPosition(_ptr) is { } wp)
{
if (_cmd[wp.startPos] != '-' || wp.wasQuoted) break;
_ptr = wp.endPos + wp.advanceAfterWord;
@@ -135,7 +135,7 @@ namespace PluralKit.Bot
// *Then* get the remainder
return _cmd.Substring(Math.Min(_ptr, _cmd.Length)).Trim();
}
public string FullCommand => _cmd;
private WordPosition? NextWordPosition(int position)
@@ -163,7 +163,7 @@ namespace PluralKit.Bot
// Not a quoted word, just find the next space and return if it's the end of the command
var wordEnd = _cmd.IndexOf(' ', position + 1);
return wordEnd == -1
? new WordPosition(position, _cmd.Length, 0, false)
: new WordPosition(position, wordEnd, 1, false);
@@ -179,7 +179,7 @@ namespace PluralKit.Bot
return true;
}
}
correspondingRightQuotes = null;
return false;
}