2023-10-20 08:14:56 +00:00
|
|
|
|
using CodexContractsPlugin;
|
|
|
|
|
using Core;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
using Discord.WebSocket;
|
2023-10-20 08:14:56 +00:00
|
|
|
|
using GethPlugin;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
|
|
|
|
namespace BiblioTech
|
|
|
|
|
{
|
|
|
|
|
public abstract class BaseNetCommand : BaseCommand
|
|
|
|
|
{
|
|
|
|
|
private readonly DeploymentsFilesMonitor monitor;
|
2023-10-20 08:14:56 +00:00
|
|
|
|
private readonly CoreInterface ci;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
2023-10-20 08:14:56 +00:00
|
|
|
|
public BaseNetCommand(DeploymentsFilesMonitor monitor, CoreInterface ci)
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
|
|
|
|
this.monitor = monitor;
|
2023-10-20 08:14:56 +00:00
|
|
|
|
this.ci = ci;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task Invoke(SocketSlashCommand command)
|
|
|
|
|
{
|
|
|
|
|
var deployments = monitor.GetDeployments();
|
|
|
|
|
if (deployments.Length == 0)
|
|
|
|
|
{
|
2023-10-20 09:20:38 +00:00
|
|
|
|
await command.FollowupAsync("No deployments are currently available.");
|
2023-10-20 07:49:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (deployments.Length > 1)
|
|
|
|
|
{
|
2023-10-20 09:20:38 +00:00
|
|
|
|
await command.FollowupAsync("Multiple deployments are online. I don't know which one to pick!");
|
2023-10-20 07:49:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-20 08:14:56 +00:00
|
|
|
|
var codexDeployment = deployments.Single();
|
|
|
|
|
var gethDeployment = codexDeployment.GethDeployment;
|
|
|
|
|
var contractsDeployment = codexDeployment.CodexContractsDeployment;
|
|
|
|
|
|
|
|
|
|
var gethNode = ci.WrapGethDeployment(gethDeployment);
|
|
|
|
|
var contracts = ci.WrapCodexContractsDeployment(contractsDeployment);
|
|
|
|
|
|
|
|
|
|
await Execute(command, gethNode, contracts);
|
2023-10-20 07:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-20 08:14:56 +00:00
|
|
|
|
protected abstract Task Execute(SocketSlashCommand command, IGethNode gethNode, ICodexContracts contracts);
|
2023-10-20 07:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|