Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public async Task <Tuple <DiscordEmbed, WorkOrders> > GetWorkOrders(CommandContext ctx, string workOrderType)
        {
            try
            {
                WorkOrders order     = null;
                var        orderType = await GetWorkOrderType(ctx, workOrderType);

                var wOrders = MultiBotDb.WorkOrders.Where(x => x.OrgId == new OrgController().GetOrgId(ctx.Guild) && x.WorkOrderTypeId == orderType.Id && !x.isCompleted).ToList();

                DiscordEmbedBuilder builder = new DiscordEmbedBuilder();
                var type = FormatHelpers.Capitalize(orderType.Name);

                builder.Title       = $"{ctx.Guild.Name} {type} Dispatch";
                builder.Description = $"There are {wOrders.Count} {type} Work Orders, here's one that may interest you?";
                builder.Timestamp   = DateTime.Now;

                if (wOrders.Count > 0)
                {
                    Random rand      = new Random();
                    int    randOrder = rand.Next(0, wOrders.Count);
                    order = wOrders[randOrder];

                    var           workOrderMember = GetWorkOrderMembers(order.Id);
                    StringBuilder membersStr      = new StringBuilder();

                    builder.AddField("Location", order.Location);
                    StringBuilder reqString = new StringBuilder();
                    foreach (WorkOrderRequirements req in GetRequirements(order.Id))
                    {
                        reqString.Append($"\u200b\nRequirement ID: {req.Id}\n");
                        reqString.Append($"Material: {req.Material}\n");
                        reqString.Append($"Amount: {req.Amount} SCU\n");
                    }

                    if (workOrderMember.Count > 0)
                    {
                        membersStr.Append($"\n\nAccepted Members:");
                        foreach (WorkOrderMembers mem in workOrderMember)
                        {
                            var memberController = new MemberController();
                            var member           = memberController.GetMemberById(mem.MemberId).Username;
                            membersStr.Append($"\n{memberController.GetMemberById(mem.MemberId).Username}");
                        }
                    }

                    builder.AddField($"Work Order Id: {order.Id} {membersStr.ToString()}", $"\n{order.Description}\n{reqString.ToString()}");

                    builder.WithFooter("If you would like to accept this dispatch please respond with ✅" +
                                       "\n to decline and see another use X" +
                                       "\n If you are not interested in a dispatch at this time simply do nothing at all and the request will time out");
                }
                else
                {
                    builder.AddField($"Unfortnately there are no {FormatHelpers.Capitalize(orderType.Name)} Work Orders", "No open Work Orders");
                }

                builder.WithImageUrl(orderType.ImgUrl);
                return(new Tuple <DiscordEmbed, WorkOrders>(builder.Build(), order));
            } catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
        public async Task <DiscordEmbed> GetWorkOrderByMember(CommandContext ctx)
        {
            var mbDb = new MultiBotDb();

            try
            {
                Mcmember mem = new MemberController().GetMemberbyDcId(ctx.Member, ctx.Guild);
                List <WorkOrderMembers> memberOrders = mbDb.WorkOrderMembers.AsQueryable().Where(x => x.MemberId == mem.UserId).ToList();
                List <WorkOrders>       wOrders      = new List <WorkOrders>();

                foreach (var o in memberOrders)
                {
                    var order = mbDb.WorkOrders.AsQueryable().Where(x => x.Id == o.WorkOrderId).FirstOrDefault();
                    if (!order.isCompleted)
                    {
                        wOrders.Add(order);
                    }
                }

                DiscordEmbedBuilder builder = new DiscordEmbedBuilder();

                builder.Title       = $"{ctx.Guild.Name} Open Work Orders - {ctx.Member.Nickname}";
                builder.Description = $"You have {wOrders.Count} open work orders?";
                builder.Timestamp   = DateTime.Now;

                if (memberOrders.Count > 0 || wOrders.Count > 0)
                {
                    foreach (var order in wOrders)
                    {
                        StringBuilder reqString       = new StringBuilder();
                        var           workOrderMember = GetWorkOrderMembers(order.Id);
                        StringBuilder membersStr      = new StringBuilder();

                        foreach (WorkOrderRequirements req in GetRequirements(order.Id))
                        {
                            reqString.Append($"\u200b\nRequirement ID: {req.Id}\n");
                            reqString.Append($"Material: {req.Material}\n");
                            reqString.Append($"Amount: {req.Amount} Units (Units = SCU when ship mining/trading)\n");
                        }
                        membersStr.Append($"\n\nAccepted Members:");

                        foreach (WorkOrderMembers acceptedMember in workOrderMember)
                        {
                            var memberController = new MemberController();
                            var member           = memberController.GetMemberById(acceptedMember.MemberId).Username;
                            membersStr.Append($"\n{memberController.GetMemberById(acceptedMember.MemberId).Username}");
                        }

                        builder.AddField($"__________________________________________" +
                                         $" \nWork Order Id: {order.Id} \n Location: {order.Location} {membersStr.ToString()}", $"\n{order.Description}\n{reqString.ToString()}");
                    }
                }
                else
                {
                    builder.AddField($"Unfortnately  Work Orders", "No open Work Orders");
                    return(builder.Build());
                }


                builder.WithFooter("If you would like to accept this dispatch please respond with ✅" +
                                   "\n to decline and see another use X" +
                                   "\n If you are not interested in a dispatch at this time simply do nothing at all and the request will time out");
                builder.WithImageUrl("https://massivelyop.com/wp-content/uploads/2020/09/star-citizen-cargo-deck-768x253.png");
                return(builder.Build());
            }
            catch (Exception e)
            {
                tHelper.LogException($"Method: GetWorkOrders; Org: {ctx.Guild.Name}; Message: {ctx.Message}; User:{ctx.Member.Nickname}", e);
                Console.WriteLine(e);
                return(null);
            }
        }