예제 #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.");
        }
예제 #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.");
        }
예제 #3
0
        public async Task New(Context ctx)
        {
            ctx.CheckNoSystem();

            var systemName = ctx.RemainderOrNull();

            if (systemName != null && systemName.Length > Limits.MaxSystemNameLength)
            {
                throw Errors.SystemNameTooLongError(systemName.Length);
            }

            var system = _db.Execute(async c =>
            {
                var system = await _repo.CreateSystem(c, systemName);
                await _repo.AddAccount(c, system.Id, ctx.Author.Id);
                return(system);
            });

            // TODO: better message, perhaps embed like in groups?
            await ctx.Reply($"{Emojis.Success} Your system has been created. Type `pk;system` to view it, and type `pk;system help` for more information about commands you can use now. Now that you have that set up, check out the getting started guide on setting up members and proxies: <https://pluralkit.me/start>");
        }