diff --git a/PluralKit.Bot/CommandSystem/Context.cs b/PluralKit.Bot/CommandSystem/Context.cs index 037173e2..0f08edf1 100644 --- a/PluralKit.Bot/CommandSystem/Context.cs +++ b/PluralKit.Bot/CommandSystem/Context.cs @@ -112,6 +112,19 @@ namespace PluralKit.Bot.CommandSystem return null; } + public bool MatchUserRaw(out ulong id) + { + id = 0; + + var text = PeekArgument(); + if (MentionUtils.TryParseUser(text, out var mentionId)) + id = mentionId; + else if (ulong.TryParse(text, out var rawId)) + id = rawId; + + return id != 0; + } + public Task PeekSystem() => MatchSystemInner(); public async Task MatchSystem() diff --git a/PluralKit.Bot/Commands/LinkCommands.cs b/PluralKit.Bot/Commands/LinkCommands.cs index c77daf6e..83d86e11 100644 --- a/PluralKit.Bot/Commands/LinkCommands.cs +++ b/PluralKit.Bot/Commands/LinkCommands.cs @@ -36,21 +36,21 @@ namespace PluralKit.Bot.Commands { ctx.CheckSystem(); - IUser account; + ulong id; if (!ctx.HasNext()) - account = ctx.Author; - else - account = await ctx.MatchUser() ?? throw new PKSyntaxError("You must pass an account to link with (either ID or @mention)."); + id = ctx.Author.Id; + else if (!ctx.MatchUserRaw(out id)) + throw new PKSyntaxError("You must pass an account to link with (either ID or @mention)."); var accountIds = (await _data.GetSystemAccounts(ctx.System)).ToList(); - if (!accountIds.Contains(account.Id)) throw Errors.AccountNotLinked; + if (!accountIds.Contains(id)) throw Errors.AccountNotLinked; if (accountIds.Count == 1) throw Errors.UnlinkingLastAccount; var msg = await ctx.Reply( - $"Are you sure you want to unlink {account.Mention} from your system?"); + $"Are you sure you want to unlink <@{id}> from your system?"); if (!await ctx.PromptYesNo(msg)) throw Errors.MemberUnlinkCancelled; - await _data.RemoveAccount(ctx.System, account.Id); + await _data.RemoveAccount(ctx.System, id); await ctx.Reply($"{Emojis.Success} Account unlinked."); } }