further refine splitting of logs
This commit is contained in:
parent
8eaf94f634
commit
2bf8d9018d
@ -228,7 +228,7 @@ public class DiscordLogGenerator {
|
||||
|
||||
int curchunk = 0;
|
||||
string botheader = BotHeader().Trim() + "\n";
|
||||
// Leave room for botheder and some leeway
|
||||
// Leave room for botheader and some leeway
|
||||
int maxlength = (2000 - botheader.Length - 10);
|
||||
|
||||
// Then try to collate chunks
|
||||
@ -249,6 +249,14 @@ public class DiscordLogGenerator {
|
||||
chunks[i] = chunks[i].Insert(0, botheader);
|
||||
}
|
||||
|
||||
// Now finally check if any one chunk is bigger than max length
|
||||
for (int i = 0; i < chunks.Count; i++) {
|
||||
if (chunks[i].Length > maxcount) {
|
||||
throw new ApplicationException(
|
||||
string.Format("a chunk turned out bigger than {0}", maxcount));
|
||||
}
|
||||
}
|
||||
|
||||
return chunks.ToArray();
|
||||
}
|
||||
}
|
||||
|
@ -653,24 +653,38 @@ public partial class MainWindow : MetroWindow {
|
||||
}
|
||||
}
|
||||
|
||||
private void PostToDiscordWebhook(DiscordWebhook hook) {
|
||||
private void PostToDiscordWebhook(IEnumerable<DiscordWebhook> hooks) {
|
||||
if (string.IsNullOrEmpty(DiscordLog.Text)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DiscordLogGenerator discord = LogType.SelectedItem as DiscordLogGenerator;
|
||||
var chunks = discord.SplitLog(DiscordLog.Text);
|
||||
|
||||
DiscordLogGenerator discord = LogType.SelectedItem as DiscordLogGenerator;
|
||||
string[] chunks;
|
||||
|
||||
try {
|
||||
chunks = discord.SplitLog(DiscordLog.Text);
|
||||
} catch (Exception) {
|
||||
MessageBox.Show(
|
||||
"The log could not be split into discord appropriate length.\n" +
|
||||
"This happens with the bigger logs formats if you do lots of things in one system.\n" +
|
||||
"Try posting the log in the OneLine format.",
|
||||
"Sorry!", MessageBoxButton.OK, MessageBoxImage.Error
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var hook in hooks) {
|
||||
try {
|
||||
foreach (var chunk in chunks) {
|
||||
DiscordPoster.PostToDiscord(hook, chunk);
|
||||
}
|
||||
Log(string.Format("successfully posted to discord webhook {0}",
|
||||
hook.Name));
|
||||
Log(string.Format("successfully posted to discord webhook `{0}`", hook.Name));
|
||||
} catch (Exception ex) {
|
||||
Log(string.Format("failed to post to discord webhook {0}: {1}",
|
||||
Log(string.Format("failed to post to discord webhook `{0}`: {1}",
|
||||
hook.Name, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DiscordWebhook_Click(object sender, RoutedEventArgs e) {
|
||||
MenuItem item = sender as MenuItem;
|
||||
@ -683,12 +697,10 @@ public partial class MainWindow : MetroWindow {
|
||||
if (hook == null) {
|
||||
return;
|
||||
}
|
||||
PostToDiscordWebhook(hook);
|
||||
PostToDiscordWebhook(new DiscordWebhook[] { hook });
|
||||
}
|
||||
|
||||
private void PostToAll_Click(object sender, RoutedEventArgs e) {
|
||||
foreach (DiscordWebhook hook in Config.Global.Webhooks) {
|
||||
PostToDiscordWebhook(hook);
|
||||
}
|
||||
PostToDiscordWebhook(Config.Global.Webhooks);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user