Discord Bot Changes

1. Added ServerId to Delegate
2. Change Delegate storage to use DI.
This commit is contained in:
Brett Hewitson 2021-12-04 14:35:07 +10:00
parent c4bf4906ea
commit c5775181b3
6 changed files with 31 additions and 23 deletions

View file

@ -21,6 +21,7 @@ namespace ServerManagerTool.Discord
{
internal ServerManagerBot()
{
Started = false;
}
private bool Started
@ -29,7 +30,7 @@ namespace ServerManagerTool.Discord
set;
}
public async Task StartAsync(string commandPrefix, string discordToken, string dataDirectory, HandleCommandDelegate handleCommandCallback, CancellationToken token)
public async Task StartAsync(string discordToken, string commandPrefix, string dataDirectory, HandleCommandDelegate handleCommandCallback, CancellationToken token)
{
if (Started)
{
@ -37,7 +38,7 @@ namespace ServerManagerTool.Discord
}
Started = true;
if (string.IsNullOrWhiteSpace(commandPrefix) || string.IsNullOrWhiteSpace(discordToken))
if (string.IsNullOrWhiteSpace(commandPrefix) || string.IsNullOrWhiteSpace(discordToken) || handleCommandCallback is null)
{
return;
}
@ -104,7 +105,8 @@ namespace ServerManagerTool.Discord
.AddSingleton<StartupService>()
.AddSingleton<ShutdownService>()
.AddSingleton<Random>()
.AddSingleton(config);
.AddSingleton(config)
.AddSingleton(handleCommandCallback);
// Create the service provider
using (var provider = services.BuildServiceProvider())
@ -114,8 +116,6 @@ namespace ServerManagerTool.Discord
await provider?.GetRequiredService<StartupService>().StartAsync();
provider?.GetRequiredService<CommandHandlerService>();
DiscordBot.HandleCommandCallback = handleCommandCallback;
try
{
// Prevent the application from closing