2023-04-19 10:06:10 +02:00
|
|
|
|
using EliteBGS.LogGenerator;
|
2024-09-17 19:53:17 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-04-19 10:06:10 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2024-09-17 19:53:17 +02:00
|
|
|
|
using System.Windows.Documents;
|
2023-04-19 10:06:10 +02:00
|
|
|
|
|
|
|
|
|
namespace EliteBGS;
|
2022-12-07 23:00:38 +01:00
|
|
|
|
|
|
|
|
|
public class OneLineDiscordLog : DiscordLogGenerator {
|
|
|
|
|
protected override string GenerateObjectiveHeader(Objective objective) {
|
|
|
|
|
if (!string.IsNullOrEmpty(objective.Faction)) {
|
2022-12-16 21:48:16 +01:00
|
|
|
|
return string.Format("**{0}** for **{1}**: ", objective.System, objective.Faction);
|
2022-12-07 23:00:38 +01:00
|
|
|
|
} else {
|
2022-12-16 21:48:16 +01:00
|
|
|
|
return string.Format("**{0}**: ", objective.System);
|
2022-12-07 23:00:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string GenerateObjectiveFooter(Objective objective) {
|
2023-04-19 10:06:10 +02:00
|
|
|
|
return "\n";
|
2022-12-07 23:00:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string GenerateFooter() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string GenerateHeader() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 19:53:17 +02:00
|
|
|
|
public override string[] SplitLog(string log, int maxcount = 2000) {
|
|
|
|
|
string[] lines = log.Split('\n');
|
|
|
|
|
List<string> chunks = new();
|
|
|
|
|
string chunk = string.Empty;
|
|
|
|
|
|
2024-09-17 19:54:35 +02:00
|
|
|
|
// Optimisation
|
|
|
|
|
if (log.Length <= maxcount) {
|
|
|
|
|
return new string[] { log };
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 19:53:17 +02:00
|
|
|
|
for (int i = 0; i < lines.Length; i++) {
|
|
|
|
|
string line = lines[i];
|
|
|
|
|
if ((chunk.Length + line.Length) > maxcount || i == lines.Length - 1) {
|
|
|
|
|
chunks.Add(chunk.Trim());
|
|
|
|
|
chunk = string.Empty;
|
|
|
|
|
chunk = chunk.Insert(0, BotHeader()).Trim();
|
|
|
|
|
} else {
|
|
|
|
|
chunk = chunk + "\n" + line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chunks.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 10:06:10 +02:00
|
|
|
|
public override string GenerateDiscordLog(Report report) {
|
|
|
|
|
StringBuilder log = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
if (report == null) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var objectives = report.Objectives
|
|
|
|
|
.Where(x => x.IsEnabled && x.Transactions.Count() > 0)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
if (objectives == null || objectives.Count() <= 0) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 20:11:51 +02:00
|
|
|
|
log.AppendFormat("{0}", BotHeader());
|
2024-05-02 20:07:10 +02:00
|
|
|
|
|
2023-04-19 10:06:10 +02:00
|
|
|
|
foreach (Objective objective in objectives) {
|
|
|
|
|
log.AppendFormat("{0}", GenerateObjectiveHeader(objective));
|
|
|
|
|
|
|
|
|
|
foreach (LogFormatter formatter in formatters) {
|
|
|
|
|
string text = formatter.GenerateSummary(objective);
|
|
|
|
|
text = text.Trim();
|
|
|
|
|
if (!string.IsNullOrEmpty(text)) {
|
|
|
|
|
log.AppendFormat("{0}; ", text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.AppendFormat("{0}", GenerateObjectiveFooter(objective));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.AppendFormat("{0}", GenerateFooter());
|
|
|
|
|
|
|
|
|
|
return log.ToString().Trim();
|
2022-12-07 23:00:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
2024-05-02 20:07:10 +02:00
|
|
|
|
return "One Line";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name {
|
|
|
|
|
get { return "OneLine"; }
|
2022-12-07 23:00:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|