public void Publish(ReportSeverity reportSeverity) { // If we need a new line then add it. OtherUtils.ConsoleGotoNewLine(); // Give errors or warnings in standard form. var ttb = new TitledTextBuilder(); ttb.Append(_reportTitles[reportSeverity], _genreDescriptions[this.ReportGenre]); // If given, write reason. if (!this.Reason.IsNullOrEmpty()) { ttb.Append("Reason", this.Reason); } // If given, write location. if (!this.Location.IsNullOrEmpty()) { ttb.Append("Location", this.Location); } if (reportSeverity == ReportSeverity.Error) { Console.Error.WriteLine($"\n{ttb}"); } else { Console.Write($"\n{ttb}"); } }
/// <summary> /// Reports the passed exception if Insights are initialized /// </summary> /// <param name="exception">Excpetion to report.</param> /// <param name="serverity">Serverity for the to report the exception.</param> public static void Report(Exception exception, ReportSeverity serverity = ReportSeverity.Error) { if (Insights.IsInitialized) { Insights.Report(exception, serverity); } }
public Report(ReportSeverity severity, string id, string caption, string details) { _resourceId = id; _caption = caption; _details = details; _severity = severity; }
public Report(System.Exception exception) { Contract.Requires(exception != null, "e != null"); _resourceId = ResourceIds.SystemException.ToString(); _caption = string.Format("Exception: \"{0}\"", exception.Message); _details = Utilities.Xml.Persist(exception).ToString(); _severity = ReportSeverity.Error; }
public void Report(Exception ex, IDictionary extraData = null, ReportSeverity warningLevel = ReportSeverity.Warning) { Debug.WriteLine ("KINDER: Exception occurred: " + ex); if(!Insights.IsInitialized) return; Insights.Report (ex, extraData, warningLevel); }
public void Report(Exception ex, IDictionary extraData = null, ReportSeverity warningLevel = ReportSeverity.Warning) { Debug.WriteLine("KINDER: Exception occurred: " + ex); if (!Insights.IsInitialized) { return; } Insights.Report(ex, extraData, warningLevel); }
private static DiscordColor GetColor(ReportSeverity severity) { switch (severity) { case ReportSeverity.Low: return(Config.Colors.LogInfo); case ReportSeverity.Medium: return(Config.Colors.LogNotice); case ReportSeverity.High: return(Config.Colors.LogAlert); default: return(Config.Colors.LogUnknown); } }
public void Initialise(XElement xElement, IDocumentAccessor accessor) { xElement = Persistence.ThisOrSingleChild(XName, xElement); _resourceId = Utilities.Xml.GetAttribute(xElement, "id"); _caption = Utilities.Xml.GetAttribute(xElement, "caption"); var severity = Utilities.Xml.GetAttribute(xElement, "severity"); _severity = (ReportSeverity)Enum.Parse(typeof(ReportSeverity), severity); var xcData = xElement .Nodes() .OfType<XCData>() .Single(); _details = xcData.Value; }
private static DiscordEmbedBuilder MakeReportTemplate(DiscordClient client, string infraction, DiscordMessage message, ReportSeverity severity, string actionList = null) { var content = message.Content; if (message.Channel.IsPrivate) { severity = ReportSeverity.None; } var needsAttention = severity > ReportSeverity.Low; if (message.Embeds?.Any() ?? false) { if (!string.IsNullOrEmpty(content)) { content += Environment.NewLine; } var srcEmbed = message.Embeds.First(); content += $"🔤 {srcEmbed.Title}"; if (srcEmbed.Fields?.Any() ?? false) { content += $"{Environment.NewLine}{srcEmbed.Description}{Environment.NewLine}+{srcEmbed.Fields.Count} fields"; } } if (message.Attachments?.Any() ?? false) { if (!string.IsNullOrEmpty(content)) { content += Environment.NewLine; } content += string.Join(Environment.NewLine, message.Attachments.Select(a => "📎 " + a.FileName)); } if (string.IsNullOrEmpty(content)) { content = "🤔 something fishy is going on here, there was no message or attachment"; } DiscordMember author = null; try { author = client.GetMember(message.Author); } catch (Exception e) { Config.Log.Warn(e, $"Failed to get the member info for user {message.Author.Id} ({message.Author.Username})"); } var result = new DiscordEmbedBuilder { Title = infraction, Color = GetColor(severity), }.AddField("Violator", author == null ? message.Author.Mention : GetMentionWithNickname(author), true) .AddField("Channel", message.Channel.IsPrivate ? "Bot's DM" : message.Channel.Mention, true) //.AddField("Time (UTC)", message.CreationTimestamp.ToString("yyyy-MM-dd HH:mm:ss"), true) .AddField("Content of the offending item", content.Trim(EmbedPager.MaxFieldLength)); if (!string.IsNullOrEmpty(actionList)) { result.AddField("Filter Actions", actionList, true); } if (needsAttention && !message.Channel.IsPrivate) { result.AddField("Link to the message", message.JumpLink.ToString()); } #if DEBUG result.WithFooter("Test bot instance"); #endif return(result); }
public static async Task <DiscordMessage> ReportAsync(this DiscordClient client, string infraction, DiscordMessage message, IEnumerable <DiscordMember> reporters, string comment, ReportSeverity severity) { var getLogChannelTask = client.GetChannelAsync(Config.BotLogId); var embedBuilder = MakeReportTemplate(client, infraction, message, severity); var reportText = string.IsNullOrEmpty(comment) ? "" : comment.Sanitize() + Environment.NewLine; embedBuilder.Description = (reportText + embedBuilder.Description).Trim(EmbedPager.MaxDescriptionLength); var mentions = reporters.Select(GetMentionWithNickname); embedBuilder.AddField("Reporters", string.Join(Environment.NewLine, mentions)); var logChannel = await getLogChannelTask.ConfigureAwait(false); return(await logChannel.SendMessageAsync(embed : embedBuilder.Build()).ConfigureAwait(false)); }
public static string OutputSolutionFileName(string solutionFilename, ReportSeverity severity) { if (severity == ReportSeverity.Info) { Console.WriteLine("[ Check ] Checking solution '{0}'", solutionFilename); } return solutionFilename; }
public static string OutputProjectFileName(string projectFilename, ReportSeverity severity) { if (severity == ReportSeverity.Info) { Console.WriteLine("[ Check ] Checking project '{0}'", projectFilename); } return projectFilename; }
public static async Task <DiscordMessage?> ReportAsync(this DiscordClient client, string infraction, DiscordMessage message, string trigger, string?matchedOn, int?filterId, string?context, ReportSeverity severity, string?actionList = null) { var logChannel = await client.GetChannelAsync(Config.BotLogId).ConfigureAwait(false); if (logChannel is null) { return(null); } var embedBuilder = MakeReportTemplate(client, infraction, filterId, message, severity, actionList); var reportText = string.IsNullOrEmpty(trigger) ? "" : $"Triggered by: `{matchedOn ?? trigger}`{Environment.NewLine}"; if (!string.IsNullOrEmpty(context)) { reportText += $"Triggered in: ```{context.Sanitize()}```{Environment.NewLine}"; } embedBuilder.Description = reportText + embedBuilder.Description; var(contents, _) = await message.DownloadAttachmentsAsync().ConfigureAwait(false); try { if (contents?.Count > 0) { return(await logChannel.SendMessageAsync(new DiscordMessageBuilder().WithEmbed(embedBuilder.Build()).WithFiles(contents).WithAllowedMentions(Config.AllowedMentions.Nothing)).ConfigureAwait(false)); } else { return(await logChannel.SendMessageAsync(new DiscordMessageBuilder().WithEmbed(embedBuilder.Build()).WithAllowedMentions(Config.AllowedMentions.Nothing)).ConfigureAwait(false)); } } finally { if (contents?.Count > 0) { foreach (var f in contents.Values) { await f.DisposeAsync(); } } } }
public ReportEventArgs(string Message, ReportSeverity Severity) { this.Message = Message; this.Severity = Severity; }
public static async Task <DiscordMessage> ReportAsync(this DiscordClient client, string infraction, DiscordMessage message, string trigger, string context, ReportSeverity severity) { var getLogChannelTask = client.GetChannelAsync(Config.BotLogId); var embedBuilder = MakeReportTemplate(client, infraction, message, severity); var reportText = string.IsNullOrEmpty(trigger) ? "" : $"Triggered by: `{trigger}`{Environment.NewLine}"; if (!string.IsNullOrEmpty(context)) { reportText += $"Triggered in: ```{context.Sanitize()}```{Environment.NewLine}"; } embedBuilder.Description = reportText + embedBuilder.Description; var logChannel = await getLogChannelTask.ConfigureAwait(false); return(await logChannel.SendMessageAsync(embed : embedBuilder.Build()).ConfigureAwait(false)); }
private static DiscordEmbedBuilder MakeReportTemplate(DiscordClient client, string infraction, DiscordMessage message, ReportSeverity severity) { var content = message.Content; var needsAttention = severity > ReportSeverity.Low; if (message.Attachments.Any()) { if (!string.IsNullOrEmpty(content)) { content += Environment.NewLine; } content += string.Join(Environment.NewLine, message.Attachments.Select(a => "📎 " + a.FileName)); } if (string.IsNullOrEmpty(content)) { content = "🤔 something fishy is going on here, there was no message or attachment"; } DiscordMember author = null; try { author = client.GetMember(message.Author); } catch (Exception e) { Config.Log.Warn(e, $"Failed to get the member info for user {message.Author.Id} ({message.Author.Username})"); } var result = new DiscordEmbedBuilder { Title = infraction, Color = GetColor(severity), }.AddField("Violator", author == null ? message.Author.Mention : GetMentionWithNickname(author), true) .AddField("Channel", message.Channel.Mention, true) .AddField("Time (UTC)", message.CreationTimestamp.ToString("yyyy-MM-dd HH:mm:ss"), true) .AddField("Content of the offending item", content); if (needsAttention) { result.AddField("Link to the message", message.JumpLink.ToString()); } return(result); }
public static ReferenceIntegrityCheckReport[] OutputReports(ReferenceIntegrityCheckReport[] reports, Func<string, ReportSeverity, string> headerOutput, string fileName, ReportSeverity severity) { headerOutput(fileName, severity); foreach (var report in reports.Where(report => severity <= report.Message.Severity)) { Console.WriteLine("[ {0} ] {1}:{2}", report.Message.Severity, report.Reference.Name, report.Message.Description); } return reports; }
public static async Task <DiscordMessage> ReportAsync(this DiscordClient client, string infraction, DiscordMessage message, string trigger, string context, ReportSeverity severity, string actionList = null) { var logChannel = await client.GetChannelAsync(Config.BotLogId).ConfigureAwait(false); if (logChannel == null) { return(null); } var embedBuilder = MakeReportTemplate(client, infraction, message, severity, actionList); var reportText = string.IsNullOrEmpty(trigger) ? "" : $"Triggered by: `{trigger}`{Environment.NewLine}"; if (!string.IsNullOrEmpty(context)) { reportText += $"Triggered in: ```{context.Sanitize()}```{Environment.NewLine}"; } embedBuilder.Description = reportText + embedBuilder.Description; var(conents, _) = await message.DownloadAttachmentsAsync().ConfigureAwait(false); try { if (conents?.Count > 0) { return(await logChannel.SendMultipleFilesAsync(conents, embed : embedBuilder.Build()).ConfigureAwait(false)); } else { return(await logChannel.SendMessageAsync(embed : embedBuilder.Build()).ConfigureAwait(false)); } } finally { if (conents?.Count > 0) { foreach (var f in conents.Values) { f.Dispose(); } } } }
public void Report(Exception exception, string key, string value, ReportSeverity warningLevel = ReportSeverity.Warning) { Insights.Report(exception, key, value, warningLevel); }
public static async Task <DiscordMessage> ReportAsync(this DiscordClient client, string infraction, string description, ICollection <DiscordMember> potentialVictims, ReportSeverity severity) { var result = new DiscordEmbedBuilder { Title = infraction, Color = GetColor(severity), Description = description.Trim(EmbedPager.MaxDescriptionLength), }; if (potentialVictims?.Count > 0) { result.AddField("Potential Targets", string.Join(Environment.NewLine, potentialVictims.Select(GetMentionWithNickname)).Trim(EmbedPager.MaxFieldLength)); } var logChannel = await client.GetChannelAsync(Config.BotLogId).ConfigureAwait(false); return(await logChannel.SendMessageAsync(embed : result.Build()).ConfigureAwait(false)); }
public void Report(Exception exception, IDictionary extraData, ReportSeverity warningLevel = ReportSeverity.Warning) { Insights.Report(exception, extraData, warningLevel); }
private static DiscordColor GetColor(ReportSeverity severity) => severity switch {
public void Report(Exception exception = null, ReportSeverity warningLevel = ReportSeverity.Warning) { Insights.Report(exception, warningLevel); }