コード例 #1
0
ファイル: Uoi.cs プロジェクト: Chronojam/Mute
        public async Task Confirm([NotNull] string input)
        {
            var fid = FriendlyId32.Parse(input);

            if (!fid.HasValue)
            {
                await TypingReplyAsync("Invalid ID `{id}`");

                return;
            }

            var transactions = await(await _pending.Get(debtId: fid.Value.Value)).ToArray();

            if (transactions.Length == 0)
            {
                await TypingReplyAsync($"Cannot find a transaction with ID `{fid}`");

                return;
            }

            if (transactions.Length > 1)
            {
                await TypingReplyAsync($"Found multiple transactions with ID `{fid}`! This is probably an error, please report it.");

                return;
            }

            var transaction = transactions[0];

            if (transaction.ToId != Context.User.Id)
            {
                await TypingReplyAsync("You cannot confirm this transaction");

                return;
            }

            var result = await _pending.ConfirmPending(fid.Value.Value);

            switch (result)
            {
            case ConfirmResult.Confirmed:
                await TypingReplyAsync($"Confirmed {TransactionFormatting.FormatTransaction(this, transaction)}");

                break;

            case ConfirmResult.AlreadyDenied:
                await TypingReplyAsync("This transaction has already been denied and cannot be confirmed");

                break;

            case ConfirmResult.AlreadyConfirmed:
                await TypingReplyAsync("This transaction has already been confirmed");

                break;

            case ConfirmResult.IdNotFound:
                await TypingReplyAsync($"Cannot find a transaction with ID `{fid}`! This is probably an error, please report it.");

                break;

            default:
                await TypingReplyAsync($"Unknown transaction state `{result}`! This is probably an error, please report it.");

                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #2
0
ファイル: UOI.cs プロジェクト: martindevans/Mute
        public async Task Confirm(string input)
        {
            var fid = BalderHash32.Parse(input);

            if (!fid.HasValue)
            {
                await RespondAsync("Invalid ID `{id}`");

                return;
            }

            var transactions = await _pending.Get(debtId : fid.Value.Value).ToListAsync();

            if (transactions.Count == 0)
            {
                await RespondAsync($"Cannot find a transaction with ID `{fid}`");

                return;
            }

            if (transactions.Count > 1)
            {
                await RespondAsync($"Found multiple transactions with ID `{fid}`! This is probably an error, please report it.");

                return;
            }

            var transaction = transactions[0];

            if (transaction.ToId != Context.User.Id)
            {
                await RespondAsync("You cannot confirm a transaction which does not belong to you");

                return;
            }

            var result = await _pending.ConfirmPending(fid.Value.Value);

            switch (result)
            {
            case ConfirmResult.Confirmed:
                await RespondAsync($"Confirmed {await transaction.Format(_users)}");

                break;

            case ConfirmResult.AlreadyDenied:
                await RespondAsync("This transaction has already been denied and cannot be confirmed");

                break;

            case ConfirmResult.AlreadyConfirmed:
                await RespondAsync("This transaction has already been confirmed");

                break;

            case ConfirmResult.IdNotFound:
                await RespondAsync($"Cannot find a transaction with ID `{fid}`! This is probably an error, please report it.");

                break;

            default:
                await RespondAsync($"Unknown transaction state `{result}`! This is probably an error, please report it.");

                throw new ArgumentOutOfRangeException();
            }
        }