コード例 #1
0
        public async Task <Embed> GetMaintenance()
        {
            List <NewsItem> items = await NewsAPI.Latest(Categories.Maintenance);

            Instant  now       = TimeUtils.Now;
            NewsItem?nextMaint = null;
            Instant? bestStart = null;

            foreach (NewsItem item in items)
            {
                Instant?start = item.GetStart();
                Instant?end   = item.GetEnd();

                if (start == null || end == null)
                {
                    continue;
                }

                if (!item.Title.Contains("All Worlds"))
                {
                    continue;
                }

                if (start < bestStart)
                {
                    continue;
                }

                if (start < now.Minus(Duration.FromDays(14)))
                {
                    continue;
                }

                bestStart = start;
                nextMaint = item;
            }

            if (nextMaint != null)
            {
                EmbedBuilder builder = new EmbedBuilder();
                builder.ThumbnailUrl = "https://img.finalfantasyxiv.com/lds/h/F/DlQYVw2bqzA5ZOCfXKZ-Qe1IZU.svg";
                builder.Title        = nextMaint.Title;

                Instant?start = nextMaint.GetStart();
                Instant?end   = nextMaint.GetEnd();

                if (start == null || end == null)
                {
                    throw new Exception();
                }

                Duration timeUntilStart = (Duration)(start - now);
                Duration timeUntilEnd   = (Duration)(end - now);

                if (timeUntilStart.TotalMinutes > 0)
                {
                    builder.Description = "Starts In: " + TimeUtils.GetDurationString(start - now);
                }
                else if (timeUntilEnd.TotalMinutes > 0)
                {
                    builder.Description = "Ends In: " + TimeUtils.GetDurationString(end - now);
                }
                else
                {
                    builder.Description = "Completed: " + TimeUtils.GetDurationString(now - end) + " ago.";
                }

                builder.AddField("Starts", TimeUtils.GetDateTimeString(start));
                builder.AddField("Ends", TimeUtils.GetDateTimeString(end));
                builder.AddField("Duration", TimeUtils.GetDurationString(end - start));
                return(builder.Build());
            }

            throw new UserException("I couldn't find any maintenance.");
        }
コード例 #2
0
        public async Task GetMaintenance(CommandMessage message)
        {
            List <NewsItem> items = await NewsAPI.Latest(Categories.Maintenance);

            Instant  now       = TimeUtils.Now;
            NewsItem?nextMaint = null;
            Instant? bestStart = null;

            foreach (NewsItem item in items)
            {
                Instant?start = item.GetStart();
                Instant?end   = item.GetEnd();

                if (start == null || end == null)
                {
                    continue;
                }

                if (!item.Title.Contains("All Worlds"))
                {
                    continue;
                }

                if (start < bestStart)
                {
                    continue;
                }

                if (start < now.Minus(Duration.FromDays(14)))
                {
                    continue;
                }

                bestStart = start;
                nextMaint = item;
            }

            if (nextMaint != null)
            {
                EmbedBuilder builder = new EmbedBuilder
                {
                    ThumbnailUrl = "http://na.lodestonenews.com/images/maintenance.png",
                    ////ThumbnailUrl = "https://img.finalfantasyxiv.com/lds/h/F/DlQYVw2bqzA5ZOCfXKZ-Qe1IZU.svg",
                    Title = nextMaint.Title,
                    Url   = nextMaint.Url,
                };

                Instant?start = nextMaint.GetStart();
                Instant?end   = nextMaint.GetEnd();

                if (start == null || end == null)
                {
                    throw new Exception();
                }

                Duration timeUntilStart = (Duration)(start - now);
                Duration timeUntilEnd   = (Duration)(end - now);

                if (timeUntilStart.TotalMinutes > 0)
                {
                    builder.Description = "Starts In: " + TimeUtils.GetDurationString(start - now);
                }
                else if (timeUntilEnd.TotalMinutes > 0)
                {
                    builder.Description = "Ends In: " + TimeUtils.GetDurationString(end - now);
                }
                else
                {
                    builder.Description = "Completed: " + TimeUtils.GetDurationString(now - end) + " ago.";
                }

                ////builder.AddField("Starts", TimeUtils.GetDateTimeString(start));
                ////builder.AddField("Ends", TimeUtils.GetDateTimeString(end));
                builder.AddField("Starts", await TimeUtils.GetTimeList(message.Guild.Id, start));
                builder.AddField("Ends", await TimeUtils.GetTimeList(message.Guild.Id, end));
                builder.AddField("Duration", TimeUtils.GetDurationString(end - start) ?? "Unknown");

                await message.Channel.SendMessageAsync(embed : builder.Build(), messageReference : message.MessageReference);

                return;
            }

            throw new UserException("I couldn't find any maintenance.");
        }