cs-codex-dist-tests/Tools/BiblioTech/Program.cs

78 lines
2.3 KiB
C#
Raw Normal View History

2023-10-18 09:01:24 +00:00
using ArgsUniform;
2023-10-22 08:38:46 +00:00
using BiblioTech.Commands;
2023-10-18 09:01:24 +00:00
using Discord;
2023-10-18 07:10:04 +00:00
using Discord.WebSocket;
2023-12-18 10:27:28 +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-22 07:32:03 +00:00
public static UserRepo UserRepo { get; } = new UserRepo();
2023-12-18 10:27:28 +00:00
public static AdminChecker AdminChecker { get; private set; } = null!;
public static ILog Log { get; private set; } = null!;
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-12-18 10:27:28 +00:00
Log = new LogSplitter(
new FileLog(Path.Combine(Config.LogPath, "discordbot.log")),
new ConsoleLog()
);
2023-10-25 09:53:33 +00:00
EnsurePath(Config.DataPath);
EnsurePath(Config.UserDataPath);
EnsurePath(Config.EndpointsPath);
2023-10-22 09:10:45 +00:00
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()
{
2023-12-18 10:27:28 +00:00
Log.Log("Starting Codex Discord Bot...");
2023-10-18 09:01:24 +00:00
client = new DiscordSocketClient();
2023-12-18 10:27:28 +00:00
client.Log += ClientLog;
2023-10-18 09:01:24 +00:00
2023-10-22 08:38:46 +00:00
var associateCommand = new UserAssociateCommand();
var sprCommand = new SprCommand();
2023-10-20 07:49:23 +00:00
var handler = new CommandHandler(client,
new GetBalanceCommand(associateCommand),
new MintCommand(associateCommand),
sprCommand,
2023-10-22 08:38:46 +00:00
associateCommand,
new AdminCommand(sprCommand)
);
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();
2023-12-18 10:27:28 +00:00
AdminChecker = new AdminChecker();
Log.Log("Running...");
2023-10-18 09:01:24 +00:00
await Task.Delay(-1);
}
private static void PrintHelp()
{
2023-12-18 10:27:28 +00:00
Log.Log("BiblioTech - Codex Discord Bot");
2023-10-18 09:01:24 +00:00
}
2023-12-18 10:27:28 +00:00
private Task ClientLog(LogMessage msg)
2023-10-18 09:01:24 +00:00
{
2023-12-18 10:27:28 +00:00
Log.Log("DiscordClient: " + msg.ToString());
2023-10-18 09:01:24 +00:00
return Task.CompletedTask;
}
2023-10-25 09:53:33 +00:00
private static void EnsurePath(string path)
{
if (Directory.Exists(path)) return;
Directory.CreateDirectory(path);
}
2023-10-18 06:57:59 +00:00
}
2023-10-18 09:01:24 +00:00
}