Example #1
0
        private static DiscordEmbedBuilder FormatFilter(Piracystring filter, string error = null, int highlight = -1)
        {
            var field  = 1;
            var result = new DiscordEmbedBuilder
            {
                Title = "Filter preview",
                Color = string.IsNullOrEmpty(error) ? Config.Colors.Help : Config.Colors.Maintenance,
            };

            if (!string.IsNullOrEmpty(error))
            {
                result.AddField("Entry error", error);
            }

            var validTrigger = string.IsNullOrEmpty(filter.String) || filter.String.Length < Config.MinimumPiracyTriggerLength ? "⚠ " : "";

            result.AddFieldEx(validTrigger + "Trigger", filter.String, highlight == field++, true)
            .AddFieldEx("Context", filter.Context.ToString(), highlight == field++, true)
            .AddFieldEx("Actions", filter.Actions.ToFlagsString(), highlight == field++, true)
            .AddFieldEx("Validation", filter.ValidatingRegex, highlight == field++, true);
            if (filter.Actions.HasFlag(FilterAction.SendMessage))
            {
                result.AddFieldEx("Message", filter.CustomMessage, highlight == field, true);
            }
            field++;
            if (filter.Actions.HasFlag(FilterAction.ShowExplain))
            {
                var validExplainTerm = string.IsNullOrEmpty(filter.ExplainTerm) ? "⚠ " : "";
                result.AddFieldEx(validExplainTerm + "Explain", filter.ExplainTerm, highlight == field, true);
            }
#if DEBUG
            result.WithFooter("Test bot instance");
#endif
            return(result);
        }
Example #2
0
        private static DiscordEmbedBuilder FormatEvent(EventSchedule evt, string error = null, int highlight = -1)
        {
            var start  = evt.Start.AsUtc();
            var field  = 1;
            var result = new DiscordEmbedBuilder
            {
                Title = "Schedule entry preview",
                Color = string.IsNullOrEmpty(error) ? Config.Colors.Help : Config.Colors.Maintenance,
            };

            if (!string.IsNullOrEmpty(error))
            {
                result.AddField("Entry error", error);
            }
            var currentTime = DateTime.UtcNow;

            if (evt.Start > currentTime.Ticks)
            {
                result.WithFooter($"Starts in {FormatCountdown(evt.Start.AsUtc() - currentTime)}");
            }
            else if (evt.End > currentTime.Ticks)
            {
                result.WithFooter($"Ends in {FormatCountdown(evt.End.AsUtc() - currentTime)}");
            }
            var eventDuration  = evt.End.AsUtc() - start;
            var durationFormat = eventDuration.TotalDays > 0 ? @"d\d\ h\h\ m\m" : @"h\h\ m\m";

            result
            .AddFieldEx("Start time", evt.Start == 0 ? "-" : start.ToString("u"), highlight == field++, true)
            .AddFieldEx("Duration", evt.Start == evt.End ? "-" : eventDuration.ToString(durationFormat), highlight == field++, true)
            .AddFieldEx("Event name", string.IsNullOrEmpty(evt.EventName) ? "-" : evt.EventName, highlight == field++, true)
            .AddFieldEx("Schedule entry title", string.IsNullOrEmpty(evt.Name) ? "-" : evt.Name, highlight == field++, true);
#if DEBUG
            result.WithFooter("Test bot instance");
#endif
            return(result);
        }