public DiscordEmbed GetBankBalanceEmbed(DiscordGuild guild)
        {
            DiscordEmbedBuilder builder = new DiscordEmbedBuilder();

            builder.Title     = $"{guild.Name} Bank";
            builder.Timestamp = DateTime.Now;


            builder.AddField("Current Balance:", $"{FormatHelpers.FormattedNumber(GetBankBalance(guild).ToString())} aUEC", true);
            builder.AddField("Current Merits:", $"{FormatHelpers.FormattedNumber(GetBankMeritBalance(guild).ToString())}", true);

            builder.AddField("\nTop Contributors", "Keep up the good work!", false).WithColor(DiscordColor.Red);

            foreach (var trans in new TransactionController().GetTopTransactions(guild))
            {
                builder.AddField(trans.MemberName, $"Credits: {FormatHelpers.FormattedNumber(trans.Amount.ToString())} aUEC");
            }

            builder.AddField("Top Merits Contributors", "Keep up the good work!", true).WithColor(DiscordColor.Red);

            foreach (var trans in new TransactionController().GetTopMeritTransactions(guild))
            {
                builder.AddField(trans.MemberName, $"{FormatHelpers.FormattedNumber(trans.Merits.ToString())} Merits");
            }

            return(builder.Build());
        }
        public Tuple <string, string> Reconcile(CommandContext ctx, string merits, string credits)
        {
            var bank              = MultiBotDb.Bank.Single(x => x.OrgId == new OrgController().GetOrgId(ctx.Guild));
            var differenceMerits  = Math.Abs(bank.Merits - int.Parse(merits)).ToString();
            var differenceCredits = Math.Abs((int)bank.Balance - int.Parse(credits)).ToString();

            if (int.Parse(credits) < (int)bank.Balance)
            {
                differenceCredits = $"-{differenceCredits}";
            }
            if (int.Parse(merits) < (int)bank.Merits)
            {
                differenceMerits = $"-{differenceMerits}";
            }

            bank.Merits  = int.Parse(merits);
            bank.Balance = int.Parse(credits);
            MultiBotDb.Bank.Update(bank);
            MultiBotDb.SaveChanges();



            return(new Tuple <string, string>(FormatHelpers.FormattedNumber(differenceCredits.ToString()),
                                              FormatHelpers.FormattedNumber(differenceMerits.ToString())));
        }
Example #3
0
        public string GetContributions(DiscordGuild guild, DiscordMember dMember)
        {
            var data = MultiBotDb.Transactions.AsQueryable()
                       .Join(
                MultiBotDb.Mcmember,
                trans => trans.UserId,
                mem => mem.UserId,
                (trans, mem) => new
            {
                memberName = mem.Username,
                discordID  = mem.DiscordId,
                orgId      = mem.OrgId.GetValueOrDefault(),
                amount     = trans.Amount,
                merits     = trans.Merits,
                xp         = mem.Xp,
            }
                ).FirstOrDefault(x => x.orgId == new OrgController().GetOrgId(guild) && (x.amount != 0 || x.merits != 0) && x.discordID == dMember.Id.ToString());

            if (data == null)
            {
                return($"Could not find Transactions for **{ dMember.Nickname ?? dMember.DisplayName}**");
            }
            else
            {
                return($"**Contribution by User:** {dMember.Nickname ?? dMember.DisplayName} \n " +
                       $"**CREDITS:** {FormatHelpers.FormattedNumber(data.amount.ToString())}" +
                       $"\n**MERITS:** {FormatHelpers.FormattedNumber(data.merits.ToString())}" +
                       $"\n**ORG XP:** {FormatHelpers.FormattedNumber(data.xp.ToString())}");
            }
        }
        public Tuple <string, string> Withdraw(BankTransaction trans)
        {
            var bankContext = MultiBotDb.Bank;
            var bankItem    = GetBankByOrg(trans.Guild);

            bankItem.Balance = bankItem.Balance - trans.Amount;
            bankItem.Merits  = bankItem.Merits - trans.Merits;

            bankContext.Update(bankItem);
            MultiBotDb.SaveChanges();

            return(new Tuple <string, string>(FormatHelpers.FormattedNumber(GetBankBalance(trans.Guild).ToString()),
                                              FormatHelpers.FormattedNumber(GetBankMeritBalance(trans.Guild).ToString())));
        }
Example #5
0
        public DiscordEmbed GetLoanEmbed(DiscordGuild guild)
        {
            try
            {
                var loanCtx          = MultiBotDb.Loans;
                int orgId            = new OrgController().GetOrgId(guild);
                var loanList         = loanCtx.AsQueryable().AsQueryable().Where(x => x.OrgId == orgId && x.IsCompleted == 0).ToList();
                var memberController = new MemberController();

                DiscordEmbedBuilder builder = new DiscordEmbedBuilder();
                builder.Title     = $"{guild.Name} Loans";
                builder.Timestamp = DateTime.Now;

                builder.Description = $"Here is a list of all of your Loans that are outstanding or waiting for funding! \n\u200b";


                builder.AddField("Status: Not Funded", "Waiting To Be Funded").WithColor(DiscordColor.Green);

                foreach (var item in loanList.AsQueryable().Where(x => x.Status == "Waiting To Be Funded"))
                {
                    builder.AddField($"Loan ID: {item.LoanId} \nApplicant: {memberController.GetMemberById(item.ApplicantId).Username}",
                                     $"Asking for ${FormatHelpers.FormattedNumber(item.RequestedAmount.ToString())} for interest payment of " +
                                     $"${FormatHelpers.FormattedNumber(item.InterestAmount.ToString())}")
                    .WithColor(DiscordColor.Green);
                }

                builder.AddField("\u200b\n Status: Funded", "Awaiting Repayment").WithColor(DiscordColor.Green);

                foreach (var item in loanList.AsQueryable().Where(x => x.Status == "Funded"))
                {
                    builder.AddField($"Loan ID: {item.LoanId} \nApplicant: {memberController.GetMemberById(item.ApplicantId).Username}" +
                                     $"\nFunded by {memberController.GetMemberById(item.FunderId.GetValueOrDefault()).Username}",
                                     $"Total Loan: ${FormatHelpers.FormattedNumber((item.RequestedAmount + item.InterestAmount).ToString())} \n" +
                                     $"Remaining Amount:  ${FormatHelpers.FormattedNumber(item.RemainingAmount.ToString())}")
                    .WithColor(DiscordColor.Red);
                }

                return(builder.Build());
            }
            catch (Exception e)
            {
                tHelper.LogException($"Method: GetLoanEmbed; Org: {guild.Name};", e);
                Console.WriteLine(e);
                return(null);
            }
        }
Example #6
0
        public DiscordEmbed GetFundedLoansEmbed(DiscordGuild guild)
        {
            var loans   = GetFundedLoans(guild);
            var builder = new DiscordEmbedBuilder();

            builder.Title       = "Funded Loans";
            builder.Description = "To Complete a loan ensure you have paid the final amount, then respond with the Loan Id";
            foreach (var loan in loans)
            {
                builder.AddField($"ID: {loan.LoanId} - Applicant: {new MemberController().GetMemberById(loan.ApplicantId).Username}"
                                 , $"Requesting ${FormatHelpers.FormattedNumber(loan.RequestedAmount.ToString())} \n" +
                                 $"They are willing to pay ${FormatHelpers.FormattedNumber(loan.InterestAmount.ToString())} in interest\n" +
                                 $"The Total Repayment will be ${FormatHelpers.FormattedNumber(loan.RemainingAmount.ToString())}");
            }

            return(builder.Build());
        }
Example #7
0
        public DiscordEmbed GetWaitingLoansEmbed(DiscordGuild guild)
        {
            var loans   = GetWaitingLoans(guild);
            var builder = new DiscordEmbedBuilder();

            builder.Title       = "Loans Waiting for Funding";
            builder.Description = "Please provide the loan ID you want to fund";
            foreach (var loan in loans)
            {
                builder.AddField($"ID: {loan.LoanId} - Applicant: {new MemberController().GetMemberById(loan.ApplicantId).Username}"
                                 , $"Requesting ${FormatHelpers.FormattedNumber(loan.RequestedAmount.ToString())} \n" +
                                 $"They are willing to pay ${FormatHelpers.FormattedNumber(loan.InterestAmount.ToString())} in interest\n" +
                                 $"The Total Repayment will be ${FormatHelpers.FormattedNumber(loan.RemainingAmount.ToString())}");
            }

            return(builder.Build());
        }
Example #8
0
        public DiscordEmbed GetContributions(DiscordGuild guild, int?max = null)
        {
            var data = MultiBotDb.Transactions.AsQueryable()
                       .Join(
                MultiBotDb.Mcmember,
                trans => trans.UserId,
                mem => mem.UserId,
                (trans, mem) => new
            {
                memberName = mem.Username,
                orgId      = mem.OrgId.GetValueOrDefault(),
                amount     = trans.Amount,
                merits     = trans.Merits
            }
                ).Where(x => x.orgId == new OrgController().GetOrgId(guild) && (x.amount != 0 || x.merits != 0)).OrderByDescending(x => x.amount).ToList();

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder();

            if (max == null)
            {
                builder.Title = $"{guild.Name} - All Contributions";
                foreach (var t in data)
                {
                    builder.AddField(t.memberName, $"**CREDITS:** {FormatHelpers.FormattedNumber(t.amount.ToString())} " +
                                     $"\n**Merits:** {FormatHelpers.FormattedNumber(t.merits.ToString())}");
                }
            }
            else
            {
                builder.Title = $"{guild.Name} - Top {max} Contributions";
                for (int i = 0; i < max; i++)
                {
                    var t = data[i];
                    builder.AddField(t.memberName, $"**CREDITS:** {FormatHelpers.FormattedNumber(t.amount.ToString())} " +
                                     $"\n**Merits:** {FormatHelpers.FormattedNumber(t.merits.ToString())}");
                }
            }


            return(builder.Build());
        }
Example #9
0
        public DiscordEmbed GetFleetRequests(DiscordGuild guild)
        {
            DiscordEmbedBuilder builder = new DiscordEmbedBuilder();

            builder.Title       = $"{guild.Name} Fleet Requests";
            builder.Timestamp   = DateTime.Now;
            builder.Description = "The below lists are ships deemed imperative by command to advance the org";
            var fleetReqs = GetOrgFleetRequests(guild);

            foreach (var req in fleetReqs)
            {
                builder.AddField(req.Name, $"Req Id: {req.Id} Total Cost: {FormatHelpers.FormattedNumber(req.TotalPrice.ToString())} \n" +
                                 $"Remaining Balance: {FormatHelpers.FormattedNumber(req.RemainingPrice.ToString())}");
            }
            Random rand   = new Random();
            var    imgNum = rand.Next(0, fleetReqs.Count);

            builder.ImageUrl = fleetReqs[imgNum].ImgUrl;
            builder.WithFooter("Only one image can be shown. The Image is chosen randomly from the list of reqested ships");
            return(builder.Build());
        }