-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandServiceCollectionExtensions.cs
More file actions
37 lines (31 loc) · 1.65 KB
/
Copy pathCommandServiceCollectionExtensions.cs
File metadata and controls
37 lines (31 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.Extensions.DependencyInjection;
using RustPlusBot.Features.Commands.Dispatching;
using RustPlusBot.Features.Commands.Handlers;
using RustPlusBot.Features.Commands.Hosting;
using RustPlusBot.Features.Commands.Localization;
namespace RustPlusBot.Features.Commands;
/// <summary>DI registration for the in-game command framework.</summary>
public static class CommandServiceCollectionExtensions
{
/// <summary>Registers the dispatcher, cooldown, localizer, handlers, and hosted service.</summary>
/// <param name="services">The service collection to add to.</param>
/// <returns>The same service collection, for chaining.</returns>
public static IServiceCollection AddCommands(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.AddSingleton<CommandCooldown>();
services.AddSingleton<BotUptime>();
// CommandLocalizationCatalog has a required member, so register the prebuilt Default instance.
services.AddSingleton(CommandLocalizationCatalog.Default);
services.AddSingleton<ICommandLocalizer, CommandLocalizer>();
services.AddScoped<ICommandHandler, MuteCommandHandler>();
services.AddScoped<ICommandHandler, UnmuteCommandHandler>();
services.AddScoped<ICommandHandler, UptimeCommandHandler>();
services.AddScoped<ICommandHandler, PopCommandHandler>();
services.AddScoped<ICommandHandler, WipeCommandHandler>();
services.AddScoped<ICommandHandler, TimeCommandHandler>();
services.AddScoped<CommandDispatcher>();
services.AddHostedService<CommandsHostedService>();
return services;
}
}