public static String CreateModlogDescription(this DiscordUser user, ModlogEntryType type, Boolean paged = true) { _ = user.TryFetchModlog(out UserModlog modlog); modlog.Modlog.Reverse(); // display newest first String description = ""; if (paged) { for (Int32 b = 0; b < modlog.ModlogEntryCount; b++) { if (modlog.Modlog[b].Type == type) { description += $"{modlog.Modlog[b].Type.ToString().ToUpper()}: {modlog.Modlog[b].Time:yyyy/MM/dd HH:mm:ss} - {modlog.Modlog[b].Reason}\n\n"; } } } else { for (Int32 b = 0; b < Convert.ToInt16(InsanityBot.Config["insanitybot.commands.modlog.max_modlog_entries_per_embed"]); b++) { if (modlog.Modlog[b].Type == type) { description += $"{modlog.Modlog[b].Type.ToString().ToUpper()}: {modlog.Modlog[b].Time:yyyy/MM/dd HH:mm:ss} - {modlog.Modlog[b].Reason}\n\n"; } } if (modlog.ModlogEntryCount > Convert.ToInt16(InsanityBot.Config["insanitybot.commands.modlog.max_modlog_entries_per_embed"])) { description += InsanityBot.LanguageConfig["insanitybot.commands.modlog.overflow"]; } } return(description); }
/// <summary> /// Attempts to add a modlog entry to a specific user, time being inferred. Returns true if successful. /// </summary> public static Task <Boolean> TryAddModlogEntry(this DiscordUser user, ModlogEntryType type, String reason) { if (user == null) { throw new ArgumentException("Could not add modlog entry to nonexistent user", nameof(user)); } try { (user as DiscordMember).AddModlogEntry(type, reason); return(Task.FromResult(true)); } catch (Exception e) { Console.WriteLine($"{e}: {e.Message}\n{e.StackTrace}"); return(Task.FromResult(false)); } }
/// <summary> /// Adds a new modlog entry to the file /// </summary> /// <param name="type">Modlog Type of the new entry</param> /// <param name="reason">Reason for the infraction</param> public static void AddModlogEntry(this DiscordMember member, ModlogEntryType type, String reason) { try { UserModlog user = Deserialize(member.Username, member.Id); if (user == null) { Console.WriteLine("bad"); } user.Modlog.Add(new ModlogEntry { Type = type, Time = DateTime.UtcNow, Reason = reason }); user.ModlogEntryCount++; Serialize(user, member.Id); } catch (Exception e) { Console.WriteLine($"{e}: {e.Message}\n\n{e.StackTrace}"); } }