add a one line discord log for simple logging

This commit is contained in:
Florian Stinglmayr 2022-12-07 23:00:38 +01:00
parent 1f673970ee
commit abdaca2524
4 changed files with 58 additions and 11 deletions

View File

@ -52,9 +52,8 @@ public class DiscordLogGenerator {
log.AppendFormat("**Date:** {0}\n", DateTime.Now.ToString("dd/MM/yyyy")); log.AppendFormat("**Date:** {0}\n", DateTime.Now.ToString("dd/MM/yyyy"));
log.AppendFormat("**Target:** {0}\n", location); log.AppendFormat("**Target:** {0}\n", location);
if (legacycount > 0) { 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("```"); log.AppendLine("```");
return log.ToString(); return log.ToString();
@ -64,6 +63,16 @@ public class DiscordLogGenerator {
return "```\n"; return "```\n";
} }
/// <summary>
/// Is called to do final adjustments to the log body of a given objective.
/// </summary>
/// <param name="objective">Objective in question.</param>
/// <param name="log">Final log as generated.</param>
/// <returns>The transformed log.</returns>
protected virtual string TransformFinalLogForObjective(Objective objective, string log) {
return log;
}
public virtual string GenerateDiscordLog(Report report) { public virtual string GenerateDiscordLog(Report report) {
StringBuilder log = new StringBuilder(); StringBuilder log = new StringBuilder();
@ -79,12 +88,12 @@ public class DiscordLogGenerator {
return ""; return "";
} }
log.AppendFormat("{0}\n", GenerateHeader()); log.AppendFormat("{0}", GenerateHeader());
foreach (Objective objective in objectives) { foreach (Objective objective in objectives) {
StringBuilder objlog = new StringBuilder(); StringBuilder objlog = new StringBuilder();
log.AppendFormat("{0}\n", GenerateObjectiveHeader(objective)); log.AppendFormat("{0}", GenerateObjectiveHeader(objective));
foreach (LogFormatter formatter in formatters) { foreach (LogFormatter formatter in formatters) {
string text = formatter.GenerateLog(objective); 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(); return log.ToString().Trim();
} }

View File

@ -29,6 +29,7 @@ public partial class MainWindow : Window {
private static readonly List<DiscordLogGenerator> logtypes = new List<DiscordLogGenerator>() { private static readonly List<DiscordLogGenerator> logtypes = new List<DiscordLogGenerator>() {
new NonaDiscordLog(), new NonaDiscordLog(),
new GenericDiscordLog(), new GenericDiscordLog(),
new OneLineDiscordLog(),
}; };
public MainWindow() { public MainWindow() {

View File

@ -55,21 +55,21 @@ public class NonaDiscordLog : DiscordLogGenerator {
log.Append(":rotating_light: `Warning`: Some actions were done in E:D Legacy\n"); log.Append(":rotating_light: `Warning`: Some actions were done in E:D Legacy\n");
} }
log.Append(":clipboard: `Conducted:`\n"); log.Append(":clipboard: `Conducted:`\n");
log.Append("```"); log.Append("```\n");
return log.ToString(); return log.ToString();
} }
protected override string GenerateObjectiveFooter(Objective objective) { protected override string GenerateObjectiveFooter(Objective objective) {
return "```"; return "```\n";
} }
protected override string GenerateHeader() { protected override string GenerateHeader() {
return string.Format(":clock2: `Date:` {0}", FormatDate()); return string.Format(":clock2: `Date:` {0}\n", FormatDate());
} }
protected override string GenerateFooter() { protected override string GenerateFooter() {
return ""; return "\n";
} }
public override string ToString() { public override string ToString() {

View File

@ -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";
}
}