@@ -34,7 +34,7 @@ public CommandService(
3434 // I choose the lazy solution, I choose... this.
3535 Commands . AddRange ( Directory . EnumerateFiles ( "qrmbot/lib" )
3636 . Select ( f => new QrmBotCommand (
37- f . Replace ( ".pl" , string . Empty ) ,
37+ f . Split ( "/" ) . Last ( ) . Replace ( ".pl" , string . Empty ) ,
3838 serviceProvider . GetRequiredService < Slack > ( ) ,
3939 serviceProvider . GetRequiredService < IConfiguration > ( ) ,
4040 serviceProvider . GetRequiredService < ILogger < QrmBotCommand > > ( ) ) )
@@ -54,13 +54,20 @@ public CommandService(
5454 /// <returns></returns>
5555 public async Task HandleMessage ( WebhookMessage message , string commandSuffix = "" )
5656 {
57- // Remove leading forward-slash and any optional suffix
58- var messageCommand = message . Command . Substring ( 1 ) ;
59- messageCommand = messageCommand . Substring ( 0 , messageCommand . Length - commandSuffix . Length ) ;
57+ try
58+ {
59+ // Remove leading forward-slash and any optional suffix
60+ var messageCommand = message . Command . Substring ( 1 ) ;
61+ messageCommand = messageCommand . Substring ( 0 , messageCommand . Length - commandSuffix . Length ) ;
6062
61- var command = Commands . Find ( ( c ) => c . CommandText == messageCommand ) ;
63+ var command = Commands . Find ( ( c ) => c . CommandText == messageCommand ) ;
6264
63- await command . Execute ( message ) ;
65+ await command . Execute ( message ) ;
66+ }
67+ catch ( Exception exception )
68+ {
69+ Logger . LogError ( exception , "Error running command: {}" , message . Command ) ;
70+ }
6471 }
6572
6673 /// <summary>
@@ -75,6 +82,14 @@ public async Task HandleInteractive(InteractiveMessage message)
7582 {
7683 var command = Commands . Find ( ( c ) => c . CommandText == message . CallbackId ) ;
7784
78- await command . ExecuteInteractive ( message ) ;
85+ try
86+ {
87+ Logger . LogError ( "Test: {}" , message . CallbackId ) ;
88+ await command . ExecuteInteractive ( message ) ;
89+ }
90+ catch ( Exception exception )
91+ {
92+ Logger . LogError ( exception , "Error running command: {}" , message . CallbackId ) ;
93+ }
7994 }
8095}
0 commit comments