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 ;
152using Discord . WebSocket ;
163using Microsoft . Extensions . DependencyInjection ;
174using System ;
207using System . Reflection ;
218using System . Threading . Tasks ;
229using Discord ;
10+ using SupportBot . Services ;
2311
2412namespace SupportBot
2513{
@@ -28,6 +16,9 @@ namespace SupportBot
2816 /// </summary>
2917 public class CommandHandler
3018 {
19+ private readonly DatabaseService _databaseService ;
20+ private readonly IServiceProvider _serviceProvider ;
21+
3122 /// <summary>
3223 /// The client
3324 /// </summary>
@@ -36,21 +27,18 @@ public class CommandHandler
3627 /// The commands
3728 /// </summary>
3829 private readonly CommandService _commands ;
39- /// <summary>
40- /// The services
41- /// </summary>
42- private readonly IServiceProvider _services ;
4330
4431 /// <summary>
4532 /// Initializes a new instance of the <see cref="CommandHandler"/> class.
4633 /// </summary>
4734 /// <param name="services">The services.</param>
48- public CommandHandler ( IServiceProvider services )
35+ public CommandHandler ( DiscordSocketClient client , CommandService commands , DatabaseService databaseService , IServiceProvider serviceProvider )
4936 {
50- _commands = services . GetRequiredService < CommandService > ( ) ;
37+ _databaseService = databaseService ;
38+ _serviceProvider = serviceProvider ;
39+ _commands = commands ;
5140 _commands . Log += CommandsOnLog ;
52- _client = services . GetRequiredService < DiscordSocketClient > ( ) ;
53- _services = services ;
41+ _client = client ;
5442 }
5543
5644 private static Task CommandsOnLog ( LogMessage arg )
@@ -66,7 +54,7 @@ private static Task CommandsOnLog(LogMessage arg)
6654 public async Task InstallCommandsAsync ( )
6755 {
6856 _client . MessageReceived += HandleCommandAsync ;
69- await _commands . AddModulesAsync ( Assembly . GetEntryAssembly ( ) , _services ) ;
57+ await _commands . AddModulesAsync ( Assembly . GetEntryAssembly ( ) , _serviceProvider ) ;
7058 }
7159
7260 /// <summary>
@@ -78,7 +66,7 @@ private async Task HandleCommandAsync(SocketMessage messageParam)
7866 // Don't process the command if it was a system message
7967 if ( messageParam is not SocketUserMessage message ) return ;
8068
81- if ( ! Worker . Settings . AllowedChannels . Contains ( message . Channel . Id ) )
69+ if ( ! _databaseService . GetSettings ( ) . AllowedChannels . Contains ( message . Channel . Id ) )
8270 {
8371 return ;
8472 }
0 commit comments