Example #1
0
        public static async Task <string> Format(this IBalance balance, IUserService users)
        {
            var a = await users.Name(balance.UserA);

            var b = await users.Name(balance.UserB);

            var(borrower, lender) = balance.Amount < 0 ? (a, b) : (b, a);

            var currency = TransactionFormatting.FormatCurrency(Math.Abs(balance.Amount), balance.Unit);

            return($"{borrower} owes {currency} to {lender}");
        }
Example #2
0
        public async Task CreateDebt(IUser user, decimal amount, string unit, [Remainder] string?note = null)
        {
            if (amount < 0)
            {
                await RespondAsync("You cannot owe a negative amount!");

                return;
            }

            var message = $"{Context.User.Mention} owes {TransactionFormatting.FormatCurrency(amount, unit)} to {user.Mention}";

            var confirmed = await InteractionUtility.ConfirmAsync(_client, Context.Channel, TimeSpan.FromMinutes(1), message);

            if (!confirmed)
            {
                await RespondAsync("Confirmation timed out. Cancelled transaction!");

                return;
            }

            await _transactions.CreateTransaction(user.Id, Context.User.Id, amount, unit, note, DateTime.UtcNow);

            await RespondAsync(message);
        }