Esempio n. 1
0
        public async Task LinkSystem(Context ctx)
        {
            ctx.CheckSystem();

            await using var conn = await _db.Obtain();

            var account = await ctx.MatchUser() ?? throw new PKSyntaxError("You must pass an account to link with (either ID or @mention).");

            var accountIds = await _repo.GetSystemAccounts(conn, ctx.System.Id);

            if (accountIds.Contains(account.Id))
            {
                throw Errors.AccountAlreadyLinked;
            }

            var existingAccount = await _repo.GetSystemByAccount(conn, account.Id);

            if (existingAccount != null)
            {
                throw Errors.AccountInOtherSystem(existingAccount);
            }

            var msg      = $"{account.Mention}, please confirm the link by clicking the {Emojis.Success} reaction on this message.";
            var mentions = new IMention[] { new UserMention(account) };

            if (!await ctx.PromptYesNo(msg, user: account, mentions: mentions))
            {
                throw Errors.MemberLinkCancelled;
            }
            await _repo.AddAccount(conn, ctx.System.Id, account.Id);

            await ctx.Reply($"{Emojis.Success} Account linked to system.");
        }
Esempio n. 2
0
        public async Task LinkSystem(Context ctx)
        {
            ctx.CheckSystem();

            await using var conn = await _db.Obtain();
            
            var account = await ctx.MatchUser() ?? throw new PKSyntaxError("You must pass an account to link with (either ID or @mention).");
            var accountIds = await _repo.GetSystemAccounts(conn, ctx.System.Id);
            if (accountIds.Contains(account.Id))
                throw Errors.AccountAlreadyLinked;

            var existingAccount = await _repo.GetSystemByAccount(conn, account.Id);
            if (existingAccount != null)
                throw Errors.AccountInOtherSystem(existingAccount); 

            var msg = $"{account.Mention()}, please confirm the link.";
            if (!await ctx.PromptYesNo(msg, "Confirm", user: account, matchFlag: false)) throw Errors.MemberLinkCancelled;
            await _repo.AddAccount(conn, ctx.System.Id, account.Id);
            await ctx.Reply($"{Emojis.Success} Account linked to system.");
        }