Пример #1
0
        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
 [NotNull] private string FormatTransaction([NotNull] ITransaction tsx)
 {
     return(TransactionFormatting.FormatTransaction(this, tsx));
 }