public async Task <DiscordEmbed> CreateJobBoard(CommandContext ctx, string workOrderType)
        {
            try
            {
                var orderType = await GetWorkOrderType(ctx, workOrderType);

                var wOrders = MultiBotDb.WorkOrders.AsQueryable().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} - Job Board";

                builder.Description = $"This is the {ctx.Guild.Name} Job Board listing all available orders and missions issued by our members.\nFeel free to accept any missions you find worthwhile.\n-------------------------------------------------------------------";



                builder.Color = DiscordColor.Orange;
                if (wOrders.Count == 0)
                {
                    builder.AddField("No Work Orders", "Check back later");
                    builder.Timestamp = DateTime.Now;
                    return(builder.Build());
                }
                else
                {
                    for (int i = 0; i < wOrders.Count; i++)
                    {
                        var    req       = GetRequirements(wOrders[i].Id);
                        string reqString = "";
                        foreach (var r in req)
                        {
                            reqString = reqString + $"\n**Material:** {r.Material} \n**Amount:** {r.Amount}\n";
                        }

                        builder.AddField(((GetWorkOrderMembers(wOrders[i].Id).Count > 0)?"[ACCEPTED] ": "") + "ID:" + wOrders[i].Id + " - " + wOrders[i].Name, $"{wOrders[i].Description} \n\n**Location:** {wOrders[i].Location} {reqString} \n-------------------------------------------------------------------");
                    }
                    builder.WithFooter("If you'd like to view more about the order, Type !view <ID> \nIf you'd like to accept an order, Type !accept <ID>\nIf you'd like to log work for an order, Type !log <ID>\n");
                    builder.Timestamp = DateTime.Now;
                    return(builder.Build());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                await ctx.RespondAsync($"Send wnr the following error: {e}");

                return(null);
            }
        }
Esempio n. 2
0
        //public static Address TryParse(string address)
        //{
        //	try
        //	{
        //		Address a = new Address();

        //		string[] split = address.Split('\n');

        //		a._street = split[0].TrimEnd();

        //		string split1 = split[1].TrimEnd();

        //		int index = split1.IndexOf(',');
        //		a._city = split1.Remove(index);
        //		a._state = split1.Substring(index + 2, split1.IndexOf(' ', index + 2) - (index + 2));
        //		index = split1.IndexOf(' ', index + 2) + 1;

        //		int space = split1.IndexOf(' ', index);
        //		if (space == -1)
        //			space = split1.Length;

        //		if (char.IsNumber(split1[index]))
        //		{
        //			a._zip = split1.Substring(index, space - index);

        //			index = space + 1;
        //			if (index < split1.Length)
        //			{
        //				if (char.IsLetter(split1[index]))
        //				{
        //					space = split1.IndexOf(' ', index);
        //					if (space == -1)
        //						space = split1.Length;

        //					a._country = split1.Substring(index, space - index);
        //				}
        //			}
        //		}
        //		else if (char.IsLetter(split1[index]))
        //		{
        //			a._country = split1.Substring(index, space - index);

        //			index = space + 1;
        //			if (index < split1.Length)
        //			{
        //				if (char.IsNumber(split1[index]))
        //				{
        //					space = split1.IndexOf(' ', index);
        //					if (space == -1)
        //						space = split1.Length;

        //					a._zip = split1.Substring(index, space - index);
        //				}
        //			}
        //		}

        //		if (split.Length >= 3)
        //		{
        //			string split2 = split[2].TrimEnd();

        //			bool lastUsed = false;

        //			if (a._zip == "")
        //			{
        //				if (RegexUtilities.IsValidZipCode(split2))
        //				{
        //					a._zip = split2;
        //					lastUsed = true;
        //				}
        //			}

        //			if (!lastUsed && a._country == "")
        //				a._country = split2;
        //		}

        //		return a;
        //	}
        //	catch { }

        //	return null;
        //}

        /// <summary>
        /// Tries to parse a string as a <see cref="Daytimer.DatabaseHelpers.Contacts.Address"/>.
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static Address TryParse(string address)
        {
            try
            {
                string country = "";

                int zipIndex = -1;

                for (int i = address.Length - 1; i >= 0; i--)
                {
                    if (char.IsNumber(address[i]))
                    {
                        zipIndex = i + 1;
                        break;
                    }
                }

                if (zipIndex != -1 && zipIndex < address.Length)
                {
                    country = address.Substring(zipIndex).Trim();
                    address = address.Remove(zipIndex);
                }

                Address a = new Address();
                USAddressParseResult result = new USAddressParser().ParseAddress(address);

                if (result == null)
                {
                    return(null);
                }

                a._city    = FormatHelpers.Capitalize(result.City);
                a._state   = result.State;
                a._street  = FormatHelpers.Capitalize(result.StreetLine) + ".";
                a._zip     = result.Zip;
                a._country = country;

                return(a);
            }
            catch { }

            return(null);
        }
Esempio n. 3
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);
            }
        }