From abdaca2524e56d9ed3baa66023e0d44124a999ab Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Wed, 7 Dec 2022 23:00:38 +0100 Subject: [PATCH] add a one line discord log for simple logging --- EliteBGS/DiscordLogGenerator.cs | 26 ++++++++++++++++++------- EliteBGS/MainWindow.xaml.cs | 1 + EliteBGS/NonaDiscordLog.cs | 8 ++++---- EliteBGS/OneLineDiscordLog.cs | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 EliteBGS/OneLineDiscordLog.cs diff --git a/EliteBGS/DiscordLogGenerator.cs b/EliteBGS/DiscordLogGenerator.cs index 6d54642..a3c95a9 100644 --- a/EliteBGS/DiscordLogGenerator.cs +++ b/EliteBGS/DiscordLogGenerator.cs @@ -52,9 +52,8 @@ public class DiscordLogGenerator { log.AppendFormat("**Date:** {0}\n", DateTime.Now.ToString("dd/MM/yyyy")); log.AppendFormat("**Target:** {0}\n", location); if (legacycount > 0) { - log.AppendFormat("**Warning:** Some actions were performed on ED Legacy"); + log.AppendFormat("**Warning:** Some actions were performed on ED Legacy\n"); } - log.AppendLine(""); log.AppendLine("```"); return log.ToString(); @@ -64,6 +63,16 @@ public class DiscordLogGenerator { return "```\n"; } + /// + /// Is called to do final adjustments to the log body of a given objective. + /// + /// Objective in question. + /// Final log as generated. + /// The transformed log. + protected virtual string TransformFinalLogForObjective(Objective objective, string log) { + return log; + } + public virtual string GenerateDiscordLog(Report report) { StringBuilder log = new StringBuilder(); @@ -79,12 +88,12 @@ public class DiscordLogGenerator { return ""; } - log.AppendFormat("{0}\n", GenerateHeader()); + log.AppendFormat("{0}", GenerateHeader()); foreach (Objective objective in objectives) { StringBuilder objlog = new StringBuilder(); - log.AppendFormat("{0}\n", GenerateObjectiveHeader(objective)); + log.AppendFormat("{0}", GenerateObjectiveHeader(objective)); foreach (LogFormatter formatter in formatters) { string text = formatter.GenerateLog(objective); @@ -94,12 +103,15 @@ public class DiscordLogGenerator { } } - log.AppendFormat("{0}\n", objlog.ToString().Trim()); + string finallog = objlog.ToString().Trim(); + finallog = TransformFinalLogForObjective(objective, finallog); - log.AppendFormat("{0}\n", GenerateObjectiveFooter(objective)); + log.AppendFormat("{0}\n", finallog); + + log.AppendFormat("{0}", GenerateObjectiveFooter(objective)); } - log.AppendFormat("{0}\n", GenerateFooter()); + log.AppendFormat("{0}", GenerateFooter()); return log.ToString().Trim(); } diff --git a/EliteBGS/MainWindow.xaml.cs b/EliteBGS/MainWindow.xaml.cs index 2a19d18..002a6a9 100644 --- a/EliteBGS/MainWindow.xaml.cs +++ b/EliteBGS/MainWindow.xaml.cs @@ -29,6 +29,7 @@ public partial class MainWindow : Window { private static readonly List logtypes = new List() { new NonaDiscordLog(), new GenericDiscordLog(), + new OneLineDiscordLog(), }; public MainWindow() { diff --git a/EliteBGS/NonaDiscordLog.cs b/EliteBGS/NonaDiscordLog.cs index eb1a3a5..b41ca50 100644 --- a/EliteBGS/NonaDiscordLog.cs +++ b/EliteBGS/NonaDiscordLog.cs @@ -55,21 +55,21 @@ public class NonaDiscordLog : DiscordLogGenerator { log.Append(":rotating_light: `Warning`: Some actions were done in E:D Legacy\n"); } log.Append(":clipboard: `Conducted:`\n"); - log.Append("```"); + log.Append("```\n"); return log.ToString(); } protected override string GenerateObjectiveFooter(Objective objective) { - return "```"; + return "```\n"; } protected override string GenerateHeader() { - return string.Format(":clock2: `Date:` {0}", FormatDate()); + return string.Format(":clock2: `Date:` {0}\n", FormatDate()); } protected override string GenerateFooter() { - return ""; + return "\n"; } public override string ToString() { diff --git a/EliteBGS/OneLineDiscordLog.cs b/EliteBGS/OneLineDiscordLog.cs new file mode 100644 index 0000000..35726ff --- /dev/null +++ b/EliteBGS/OneLineDiscordLog.cs @@ -0,0 +1,34 @@ +using System.Linq; + +namespace EliteBGS; + +public class OneLineDiscordLog : DiscordLogGenerator { + protected override string GenerateObjectiveHeader(Objective objective) { + if (!string.IsNullOrEmpty(objective.Faction)) { + return string.Format("{0} for {1}: ", objective.System, objective.Faction); + } else { + return string.Format("{0}: ", objective.System); + } + } + + protected override string GenerateObjectiveFooter(Objective objective) { + return ""; + } + + protected override string GenerateFooter() { + return ""; + } + + protected override string GenerateHeader() { + return ""; + } + + protected override string TransformFinalLogForObjective(Objective objective, string log) { + string[] lines = log.Split("\n", System.StringSplitOptions.RemoveEmptyEntries); + return string.Join(", ", lines); + } + + public override string ToString() { + return "One Line Report"; + } +}