1
- // ***********************************************************************
2
- // Assembly : SupportBot
3
- // Author : Nathan Pipes
4
- // Created : 01-24-2020
5
- //
6
- // Last Modified By : Nathan Pipes
7
- // Last Modified On : 02-23-2021
8
- // ***********************************************************************
9
- // <copyright file="CommandHandler.cs" company="NPipes">
10
- // Copyright (c) NPipes. All rights reserved.
11
- // </copyright>
12
- // <summary></summary>
13
- // ***********************************************************************
14
- using Discord . Commands ;
1
+ using Discord . Commands ;
15
2
using Discord . WebSocket ;
16
3
using Microsoft . Extensions . DependencyInjection ;
17
4
using System ;
20
7
using System . Reflection ;
21
8
using System . Threading . Tasks ;
22
9
using Discord ;
10
+ using SupportBot . Services ;
23
11
24
12
namespace SupportBot
25
13
{
@@ -28,6 +16,9 @@ namespace SupportBot
28
16
/// </summary>
29
17
public class CommandHandler
30
18
{
19
+ private readonly DatabaseService _databaseService ;
20
+ private readonly IServiceProvider _serviceProvider ;
21
+
31
22
/// <summary>
32
23
/// The client
33
24
/// </summary>
@@ -36,21 +27,18 @@ public class CommandHandler
36
27
/// The commands
37
28
/// </summary>
38
29
private readonly CommandService _commands ;
39
- /// <summary>
40
- /// The services
41
- /// </summary>
42
- private readonly IServiceProvider _services ;
43
30
44
31
/// <summary>
45
32
/// Initializes a new instance of the <see cref="CommandHandler"/> class.
46
33
/// </summary>
47
34
/// <param name="services">The services.</param>
48
- public CommandHandler ( IServiceProvider services )
35
+ public CommandHandler ( DiscordSocketClient client , CommandService commands , DatabaseService databaseService , IServiceProvider serviceProvider )
49
36
{
50
- _commands = services . GetRequiredService < CommandService > ( ) ;
37
+ _databaseService = databaseService ;
38
+ _serviceProvider = serviceProvider ;
39
+ _commands = commands ;
51
40
_commands . Log += CommandsOnLog ;
52
- _client = services . GetRequiredService < DiscordSocketClient > ( ) ;
53
- _services = services ;
41
+ _client = client ;
54
42
}
55
43
56
44
private static Task CommandsOnLog ( LogMessage arg )
@@ -66,7 +54,7 @@ private static Task CommandsOnLog(LogMessage arg)
66
54
public async Task InstallCommandsAsync ( )
67
55
{
68
56
_client . MessageReceived += HandleCommandAsync ;
69
- await _commands . AddModulesAsync ( Assembly . GetEntryAssembly ( ) , _services ) ;
57
+ await _commands . AddModulesAsync ( Assembly . GetEntryAssembly ( ) , _serviceProvider ) ;
70
58
}
71
59
72
60
/// <summary>
@@ -78,7 +66,7 @@ private async Task HandleCommandAsync(SocketMessage messageParam)
78
66
// Don't process the command if it was a system message
79
67
if ( messageParam is not SocketUserMessage message ) return ;
80
68
81
- if ( ! Worker . Settings . AllowedChannels . Contains ( message . Channel . Id ) )
69
+ if ( ! _databaseService . GetSettings ( ) . AllowedChannels . Contains ( message . Channel . Id ) )
82
70
{
83
71
return ;
84
72
}
0 commit comments