/// <summary> /// Sends as many embeds as necessary based on a list of embed fields. Adhering to the maximum of 25 embed fields per embed /// </summary> /// <param name="title">The title applied to all embeds</param> /// <param name="embeds">List of embed field builders</param> /// <param name="description">The description applied to all embeds</param> public async static Task SendSafeEmbedList(this ISocketMessageChannel channel, string title, List <EmbedFieldBuilder> embeds, string description = null) { List <EmbedBuilder> embedMessages = new List <EmbedBuilder>(); EmbedBuilder CurrentBuilder = null; for (int i = 0; i < embeds.Count; i++) { if (i % 25 == 0) { CurrentBuilder = new EmbedBuilder { Color = BotCore.EmbedColor, Title = title }; if (!string.IsNullOrEmpty(description)) { CurrentBuilder.Description = description; } embedMessages.Add(CurrentBuilder); } EmbedFieldBuilder embed = embeds[i]; if (CurrentBuilder != null) { CurrentBuilder.AddField(embed); } } foreach (EmbedBuilder embedMessage in embedMessages) { await channel.SendEmbedAsync(embedMessage); } }
/// <summary> /// The GetWarnings method returns an array of embeds detailing the user's warnings, time of warning, and moderator (if enabled). /// </summary> /// <param name="User">The user whose warnings you wish to receive.</param> /// <param name="RunBy">The user who has run the given warnings command.</param> /// <param name="Mention">The stringified mention for the target user.</param> /// <param name="Username">The target user's username in the given context.</param> /// <param name="ShowIssuer">Whether or not the moderators should be shown in the log. Enabled for moderators, disabled for DMed records.</param> /// <returns>An array of embeds containing the given user's warnings.</returns> public EmbedBuilder[] GetWarnings(ulong User, ulong RunBy, string Mention, string Username, bool ShowIssuer) { Infraction[] Infractions = InfractionsDB.GetInfractions(User); if (Infractions.Length <= 0) { return new EmbedBuilder[1] { BuildEmbed(EmojiEnum.Love) .WithTitle("No issued infractions!") .WithDescription($"{Mention} has a clean slate!\n" + $"Go give {(User == RunBy ? "yourself" : "them")} a pat on the back. <3") } } ; List <EmbedBuilder> Embeds = new (); DexterProfile DexterProfile = InfractionsDB.GetOrCreateProfile(User); EmbedBuilder CurrentBuilder = BuildEmbed(EmojiEnum.Love) .WithTitle($"{Username}'s Infractions - {Infractions.Length} {(Infractions.Length == 1 ? "Entry" : "Entries")} and {DexterProfile.InfractionAmount} {(DexterProfile.InfractionAmount == 1 ? "Point" : "Points")}.") .WithDescription($"All times are displayed in {TimeZoneInfo.Local.DisplayName}"); for (int Index = 0; Index < Infractions.Length; Index++) { Infraction Infraction = Infractions[Index]; IUser Issuer = Client.GetUser(Infraction.Issuer); long TimeOfIssue = Infraction.TimeOfIssue; DateTimeOffset Time = DateTimeOffset.FromUnixTimeSeconds(TimeOfIssue > 253402300799 ? TimeOfIssue / 1000 : TimeOfIssue); EmbedFieldBuilder Field = new EmbedFieldBuilder() .WithName($"{(Infraction.InfractionTime == 0 ? "Warning" : $"{TimeSpan.FromSeconds(Infraction.InfractionTime).Humanize().Titleize()} Mute")} {Index + 1} (ID {Infraction.InfractionID}), {(Infraction.PointCost > 0 ? "-" : "")}{Infraction.PointCost} {(Infraction.PointCost == 1 ? "Point" : "Points")}.") .WithValue($"{(ShowIssuer ? $":cop: {(Issuer != null ? Issuer.GetUserInformation() : $"Unknown ({Infraction.Issuer})")}\n" : "")}" + $":calendar: {Time:M/d/yyyy h:mm:ss}\n" + $":notepad_spiral: {Infraction.Reason}" ); if (Index % 5 == 0 && Index != 0) { Embeds.Add(CurrentBuilder); CurrentBuilder = new EmbedBuilder().AddField(Field).WithColor(Color.Green); } else { try { CurrentBuilder.AddField(Field); } catch (Exception) { Embeds.Add(CurrentBuilder); CurrentBuilder = new EmbedBuilder().AddField(Field).WithColor(Color.Green); } } } Embeds.Add(CurrentBuilder); return(Embeds.ToArray()); }