-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #4
- Loading branch information
Showing
7 changed files
with
127 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Reflection; | ||
using Discord; | ||
using Discord.Interactions; | ||
using Microsoft.Extensions.Options; | ||
|
||
public class CommandManager( | ||
IOptions<AppSettings> appSettings, | ||
InteractionService interactionService, | ||
IServiceProvider serviceProvider) | ||
{ | ||
public AppSettings AppSettings { get; } = appSettings.Value; | ||
public InteractionService InteractionService { get; } = interactionService; | ||
public IServiceProvider ServiceProvider { get; } = serviceProvider; | ||
|
||
public IReadOnlyCollection<IApplicationCommand> Commands { get; private set; } = []; | ||
|
||
public IApplicationCommand GetCommand(string name) | ||
{ | ||
var command = Commands.FirstOrDefault(c => c.Name == name); | ||
if (command is null) | ||
{ | ||
throw new ArgumentException($"Command '{name}' not found.", nameof(name)); | ||
} | ||
return command; | ||
} | ||
|
||
public async Task RegisterCommandsAsync() | ||
{ | ||
await InteractionService.AddModulesAsync(Assembly.GetEntryAssembly(), ServiceProvider); | ||
|
||
if (!AppSettings.GuildIds.Any()) | ||
{ | ||
Commands = await InteractionService.RegisterCommandsGloballyAsync(true); | ||
} | ||
else | ||
{ | ||
foreach (var guildId in AppSettings.GuildIds) | ||
{ | ||
Commands = await InteractionService.RegisterCommandsToGuildAsync(guildId, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters