@@ -14,7 +14,7 @@ public sealed class DiscordService : IDiscordService
1414 private readonly IMediator _bus ;
1515 private readonly DiscordSocketClient _client ;
1616 private readonly ILogger < DiscordService > _logger ;
17- private readonly string _token ;
17+ private readonly ApplicationSettings _options ;
1818
1919 public DiscordService (
2020 DiscordSocketClient client ,
@@ -24,7 +24,7 @@ public DiscordService(
2424 _client = client ;
2525 _logger = logger ;
2626 _bus = bus ;
27- _token = options . Value . DiscordToken ;
27+ _options = options . Value ;
2828 }
2929
3030 public async Task StartAsync ( )
@@ -33,7 +33,7 @@ public async Task StartAsync()
3333 _client . Ready += ReadyAsync ;
3434 _client . MessageReceived += MessageReceivedAsync ;
3535
36- await _client . LoginAsync ( TokenType . Bot , _token ) ;
36+ await _client . LoginAsync ( TokenType . Bot , _options . DiscordToken ) ;
3737 await _client . StartAsync ( ) ;
3838 }
3939
@@ -50,12 +50,19 @@ private async Task MessageReceivedAsync(SocketMessage message)
5050 {
5151 return ;
5252 }
53-
53+
5454 var command = message . GetCommand ( ) ;
5555
5656 if ( command is null )
5757 {
58- _logger . LogWarning ( "Unhandled command: {Command}" , message . Content ) ;
58+ _logger . LogDebug ( "Command not found: {Message}" , message . Content ) ;
59+ return ;
60+ }
61+
62+ if ( ! string . IsNullOrWhiteSpace ( _options . AdminUser ) && message . Author . Username != _options . AdminUser )
63+ {
64+ _logger . LogDebug ( "Unauthorized user: {User}" , message . Author . Username ) ;
65+ await message . Channel . SendMessageAsync ( "You are not authorized to use this bot." ) ;
5966 return ;
6067 }
6168
0 commit comments