-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscordServiceCollectionExtensions.cs
More file actions
41 lines (36 loc) · 1.53 KB
/
Copy pathDiscordServiceCollectionExtensions.cs
File metadata and controls
41 lines (36 loc) · 1.53 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
38
39
40
41
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using RustPlusBot.Discord.Notifications;
using RustPlusBot.Discord.Posting;
namespace RustPlusBot.Discord;
/// <summary>DI registration for the Discord layer.</summary>
public static class DiscordServiceCollectionExtensions
{
/// <summary>Registers the socket client, interaction service, and the hosted bot service.</summary>
/// <param name="services">The service collection to add to.</param>
/// <returns>The same service collection, for chaining.</returns>
public static IServiceCollection AddDiscordBot(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
var socketConfig = new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.Guilds | GatewayIntents.GuildMessages | GatewayIntents.MessageContent,
AlwaysDownloadUsers = false,
};
services.AddSingleton(socketConfig);
services.AddSingleton<DiscordSocketClient>();
services.AddSingleton(sp => new InteractionService(
sp.GetRequiredService<DiscordSocketClient>(),
new InteractionServiceConfig
{
DefaultRunMode = RunMode.Async
}));
services.AddSingleton<IUserDmSender, DiscordUserDmSender>();
services.AddSingleton<RenderGate>();
services.AddSingleton<DiscordChannelMessenger>();
services.AddHostedService<DiscordBotService>();
return services;
}
}