Fixes debugPeer response formatting

This commit is contained in:
benbierens 2023-11-08 13:33:48 +01:00
parent d1403c04c4
commit 180bf3fd35
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 24 additions and 23 deletions

View File

@ -110,17 +110,9 @@ namespace BiblioTech.Commands
} }
var report = string.Join(Environment.NewLine, Program.UserRepo.GetInteractionReport(user)); var report = string.Join(Environment.NewLine, Program.UserRepo.GetInteractionReport(user));
if (report.Length > 1900)
{
var filename = $"user-{user.Username}.log";
await context.FollowupWithAttachement(filename, report);
}
else
{
await context.Followup(report); await context.Followup(report);
} }
} }
}
public class DeployListCommand : SubCommandOption public class DeployListCommand : SubCommandOption
{ {
@ -293,7 +285,8 @@ namespace BiblioTech.Commands
var nl = Environment.NewLine; var nl = Environment.NewLine;
var content = new List<string> var content = new List<string>
{ {
$"{DateTime.UtcNow.ToString("o")} - {group.Count()} Codex nodes." $"{DateTime.UtcNow.ToString("o")} - {group.Count()} Codex nodes.",
$"Deployment name: '{name}'"
}; };
foreach (var node in group) foreach (var node in group)
@ -311,8 +304,7 @@ namespace BiblioTech.Commands
} }
} }
var filename = $"netinfo-{NoWhitespaces(name)}.log"; await context.Followup(string.Join(nl, content));
await context.FollowupWithAttachement(filename, string.Join(nl, content.ToArray()));
}); });
} }
} }
@ -336,29 +328,32 @@ namespace BiblioTech.Commands
await OnDeployment(context, async (group, name) => await OnDeployment(context, async (group, name) =>
{ {
await context.Followup($"Calling debug/peer for '{peerId}' on {group.Count()} Codex nodes."); var nl = Environment.NewLine;
var content = new List<string>
{
$"{DateTime.UtcNow.ToString("o")} - {group.Count()} Codex nodes.",
$"Deployment name: '{name}'"
};
content.Add($"Calling debug/peer for '{peerId}' on {group.Count()} Codex nodes.");
foreach (var node in group) foreach (var node in group)
{ {
try try
{ {
var info = node.GetDebugPeer(peerId); var info = node.GetDebugPeer(peerId);
var nl = Environment.NewLine;
var json = JsonConvert.SerializeObject(info, Formatting.Indented); var json = JsonConvert.SerializeObject(info, Formatting.Indented);
var jsonInsert = $"{nl}```{nl}{json}{nl}```{nl}"; var jsonInsert = $"{nl}```{nl}{json}{nl}```{nl}";
await context.Followup($"Node '{node.GetName()}' responded with {jsonInsert}"); content.Add($"Node '{node.GetName()}' responded with {jsonInsert}");
} }
catch (Exception ex) catch (Exception ex)
{ {
await context.Followup($"Node '{node.GetName()}' failed to respond with exception: " + ex); content.Add($"Node '{node.GetName()}' failed to respond with exception: " + ex);
}
}
});
} }
} }
private static string NoWhitespaces(string s) await context.Followup(string.Join(nl, content));
{ });
return s.Replace(" ", "-"); }
} }
} }
} }

View File

@ -50,7 +50,7 @@ namespace BiblioTech.Commands
var i = random.Next(0, sprCache.Count); var i = random.Next(0, sprCache.Count);
var spr = sprCache[i]; var spr = sprCache[i];
await context.Followup($"Your SPR: '{spr}'"); await context.Followup($"Your SPR: `{spr}`");
} }
private bool ShouldUpdate() private bool ShouldUpdate()

View File

@ -15,13 +15,19 @@ namespace BiblioTech.Options
public async Task Followup(string message) public async Task Followup(string message)
{ {
if (message.Length > 1900)
{
await FollowupWithAttachement("codexdiscordbot_file.txt", message);
return;
}
await Command.ModifyOriginalResponseAsync(m => await Command.ModifyOriginalResponseAsync(m =>
{ {
m.Content = message; m.Content = message;
}); });
} }
public async Task FollowupWithAttachement(string filename, string content) private async Task FollowupWithAttachement(string filename, string content)
{ {
using var fileStream = new MemoryStream(); using var fileStream = new MemoryStream();
using var streamWriter = new StreamWriter(fileStream); using var streamWriter = new StreamWriter(fileStream);