2023-10-18 09:01:24 +00:00
|
|
|
|
using ArgsUniform;
|
2023-10-22 08:38:46 +00:00
|
|
|
|
using BiblioTech.Commands;
|
2023-10-18 12:59:39 +00:00
|
|
|
|
using Core;
|
2023-10-18 09:01:24 +00:00
|
|
|
|
using Discord;
|
2023-10-18 07:10:04 +00:00
|
|
|
|
using Discord.WebSocket;
|
2023-10-18 12:59:39 +00:00
|
|
|
|
using Logging;
|
2023-10-18 07:10:04 +00:00
|
|
|
|
|
2023-10-18 09:01:24 +00:00
|
|
|
|
namespace BiblioTech
|
2023-10-18 06:57:59 +00:00
|
|
|
|
{
|
2023-10-18 09:01:24 +00:00
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
private DiscordSocketClient client = null!;
|
2023-10-18 07:10:04 +00:00
|
|
|
|
|
2023-10-18 09:01:24 +00:00
|
|
|
|
public static Configuration Config { get; private set; } = null!;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
public static DeploymentsFilesMonitor DeploymentFilesMonitor { get; } = new DeploymentsFilesMonitor();
|
2023-10-22 07:32:03 +00:00
|
|
|
|
public static UserRepo UserRepo { get; } = new UserRepo();
|
2023-10-22 08:38:46 +00:00
|
|
|
|
public static AdminChecker AdminChecker { get; } = new AdminChecker();
|
2023-10-18 07:10:04 +00:00
|
|
|
|
|
2023-10-18 09:01:24 +00:00
|
|
|
|
public static Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
|
2023-10-18 09:21:06 +00:00
|
|
|
|
Config = uniformArgs.Parse();
|
2023-10-18 07:10:04 +00:00
|
|
|
|
|
2023-10-22 09:10:45 +00:00
|
|
|
|
if (!Directory.Exists(Config.UserDataPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Config.UserDataPath);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-18 09:01:24 +00:00
|
|
|
|
return new Program().MainAsync();
|
|
|
|
|
}
|
2023-10-18 06:57:59 +00:00
|
|
|
|
|
2023-10-18 09:01:24 +00:00
|
|
|
|
public async Task MainAsync()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Starting Codex Discord Bot...");
|
|
|
|
|
client = new DiscordSocketClient();
|
|
|
|
|
client.Log += Log;
|
|
|
|
|
|
2023-10-18 12:59:39 +00:00
|
|
|
|
ProjectPlugin.Load<CodexPlugin.CodexPlugin>();
|
2023-10-20 07:49:23 +00:00
|
|
|
|
ProjectPlugin.Load<GethPlugin.GethPlugin>();
|
|
|
|
|
ProjectPlugin.Load<CodexContractsPlugin.CodexContractsPlugin>();
|
|
|
|
|
|
2023-10-18 12:59:39 +00:00
|
|
|
|
var entryPoint = new EntryPoint(new ConsoleLog(), new KubernetesWorkflow.Configuration(
|
2023-10-20 08:14:56 +00:00
|
|
|
|
kubeConfigFile: null,
|
2023-10-18 12:59:39 +00:00
|
|
|
|
operationTimeout: TimeSpan.FromMinutes(5),
|
|
|
|
|
retryDelay: TimeSpan.FromSeconds(10),
|
|
|
|
|
kubernetesNamespace: "not-applicable"), "datafiles");
|
2023-10-18 11:48:15 +00:00
|
|
|
|
|
2023-10-20 07:49:23 +00:00
|
|
|
|
var monitor = new DeploymentsFilesMonitor();
|
2023-10-18 12:59:39 +00:00
|
|
|
|
|
2023-10-20 08:14:56 +00:00
|
|
|
|
var ci = entryPoint.CreateInterface();
|
|
|
|
|
|
2023-10-22 08:38:46 +00:00
|
|
|
|
var associateCommand = new UserAssociateCommand();
|
2023-10-20 07:49:23 +00:00
|
|
|
|
var handler = new CommandHandler(client,
|
2023-10-22 08:38:46 +00:00
|
|
|
|
new ClearUserAssociationCommand(),
|
|
|
|
|
new GetBalanceCommand(monitor, ci, associateCommand),
|
2023-10-22 09:10:45 +00:00
|
|
|
|
new MintCommand(monitor, ci, associateCommand),
|
2023-10-22 08:38:46 +00:00
|
|
|
|
new ReportHistoryCommand(),
|
|
|
|
|
associateCommand,
|
2023-10-20 09:20:38 +00:00
|
|
|
|
new DeploymentsCommand(monitor)
|
|
|
|
|
);
|
2023-10-18 09:01:24 +00:00
|
|
|
|
|
2023-10-18 11:48:15 +00:00
|
|
|
|
await client.LoginAsync(TokenType.Bot, Config.ApplicationToken);
|
2023-10-18 09:01:24 +00:00
|
|
|
|
await client.StartAsync();
|
|
|
|
|
Console.WriteLine("Running...");
|
|
|
|
|
await Task.Delay(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void PrintHelp()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("BiblioTech - Codex Discord Bot");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task Log(LogMessage msg)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(msg.ToString());
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2023-10-18 06:57:59 +00:00
|
|
|
|
}
|
2023-10-18 09:01:24 +00:00
|
|
|
|
}
|