59 lines
2.1 KiB
C#
Raw Normal View History

using BiblioTech.CodexChecking;
using BiblioTech.Options;
namespace BiblioTech.Commands
{
public class CheckDownloadCommand : BaseCommand
{
private readonly CodexTwoWayChecker checker;
private readonly StringOption contentOption = new StringOption(
name: "content",
description: "Content of the downloaded file",
isRequired: false);
public CheckDownloadCommand(CodexTwoWayChecker checker)
{
this.checker = checker;
}
public override string Name => "checkdownload";
2025-06-10 12:37:28 +02:00
public override string StartingMessage => "Connecting to the testnet... Please be patient... " + RandomBusyMessage.Get();
public override string Description => "Checks the download connectivity of your Codex node.";
public override CommandOption[] Options => [contentOption];
protected override async Task Invoke(CommandContext context)
{
var user = context.Command.User;
var content = await contentOption.Parse(context);
try
{
var handler = new CheckResponseHandler(context, user);
if (string.IsNullOrEmpty(content))
{
await checker.StartDownloadCheck(handler, user.Id);
}
else
{
2025-04-11 08:58:39 +02:00
if (content.Length > 1024)
{
await context.Followup("Provided content is too long!");
return;
}
await checker.VerifyDownloadCheck(handler, user.Id, content);
}
}
catch (Exception ex)
{
await RespondWithError(context, ex);
}
}
private async Task RespondWithError(CommandContext context, Exception ex)
{
await Program.AdminChecker.SendInAdminChannel("Exception during CheckDownloadCommand: " + ex);
await context.Followup("I'm sorry to report something has gone wrong in an unexpected way. Error details are already posted in the admin channel.");
}
}
}