CheckDownloadCommand.cs
1 using BiblioTech.CodexChecking; 2 using BiblioTech.Options; 3 4 namespace BiblioTech.Commands 5 { 6 public class CheckDownloadCommand : BaseCommand 7 { 8 private readonly CodexTwoWayChecker checker; 9 10 private readonly StringOption contentOption = new StringOption( 11 name: "content", 12 description: "Content of the downloaded file", 13 isRequired: false); 14 15 public CheckDownloadCommand(CodexTwoWayChecker checker) 16 { 17 this.checker = checker; 18 } 19 20 public override string Name => "checkdownload"; 21 public override string StartingMessage => "Connecting to the testnet... Please be patient... " + RandomBusyMessage.Get(); 22 public override string Description => "Checks the download connectivity of your Codex node."; 23 public override CommandOption[] Options => [contentOption]; 24 25 protected override async Task Invoke(CommandContext context) 26 { 27 var user = context.Command.User; 28 var content = await contentOption.Parse(context); 29 try 30 { 31 var handler = new CheckResponseHandler(context, user); 32 if (string.IsNullOrEmpty(content)) 33 { 34 await checker.StartDownloadCheck(handler, user.Id); 35 } 36 else 37 { 38 if (content.Length > 1024) 39 { 40 await context.Followup("Provided content is too long!"); 41 return; 42 } 43 await checker.VerifyDownloadCheck(handler, user.Id, content); 44 } 45 } 46 catch (Exception ex) 47 { 48 await RespondWithError(context, ex); 49 } 50 } 51 52 private async Task RespondWithError(CommandContext context, Exception ex) 53 { 54 await Program.AdminChecker.SendInAdminChannel("Exception during CheckDownloadCommand: " + ex); 55 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."); 56 } 57 } 58 }