This commit is contained in:
2023-02-11 10:37:40 -03:00
parent 79b1a0e15e
commit c0f7c8cc1d
6 changed files with 268 additions and 159 deletions

View File

@@ -9,8 +9,15 @@ namespace TextCommandFramework
{
class Program
{
private static string TOKEN = Environment.GetEnvironmentVariable("TOKEN");
static void Main(string[] args)
{
if (TOKEN == null)
{
throw new Exception("Discord Bot Token was not found.");
}
new Program().MainAsync().GetAwaiter().GetResult();
}
@@ -18,12 +25,6 @@ namespace TextCommandFramework
{
using (var services = ConfigureServices())
{
var token = Environment.GetEnvironmentVariable("TOKEN");
if (token == null)
{
throw new Exception("Discord Bot Token was not found.");
}
var client = services.GetRequiredService<DiscordSocketClient>();
@@ -32,8 +33,8 @@ namespace TextCommandFramework
client.Ready += () => Client_Ready(client);
services.GetRequiredService<CommandService>().Log += LogAsync;
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
await Connect(client);
client.Disconnected += async (ex) => await Connect(client);
await services.GetRequiredService<CommandHandlingService>().InitializeAsync();
@@ -41,6 +42,12 @@ namespace TextCommandFramework
}
}
public async Task Connect(DiscordSocketClient client)
{
await client.LoginAsync(TokenType.Bot, TOKEN);
await client.StartAsync();
}
private async Task Client_Ready(DiscordSocketClient client)
{
var announceLoginGuild = ulong.Parse(Environment.GetEnvironmentVariable("ANNOUNCE_LOGIN_GUILD") ?? "0");
@@ -85,6 +92,7 @@ namespace TextCommandFramework
})
.AddSingleton<DiscordSocketClient>()
.AddSingleton<CommandService>()
.AddSingleton<YoutubeService>()
.AddSingleton<PlayerService>()
.AddSingleton<CommandHandlingService>()
.AddSingleton<HttpClient>()