コード例 #1
0
ファイル: Bot.cs プロジェクト: luanrFreitas/HC
 private async void OnChatMessage(object?sender, ChatMessageEventArgs chatMessageArgs)
 {
     try
     {
         await ProcessChatMessage(sender, chatMessageArgs);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "{Time}: OnChatMessage - Error {Exception}", DateTime.UtcNow, ex.Message);
     }
 }
コード例 #2
0
ファイル: Bot.cs プロジェクト: luanrFreitas/HC
 private async Task ProcessChatMessage(object?sender, ChatMessageEventArgs chatMessageArgs)
 {
     if (sender is IChatService chatService)
     {
         var command = _serviceProvider.GetServices <IBotCommand>().SingleOrDefault(x => $"/{x.Command}".Equals(chatMessageArgs.Command, StringComparison.InvariantCultureIgnoreCase));
         if (command != null)
         {
             await command.Execute(chatService,
                                   chatMessageArgs.ChatId,
                                   chatMessageArgs.UserId,
                                   chatMessageArgs.MessageId,
                                   chatMessageArgs.Text);
         }
         else
         {
             _logger.LogTrace("Unknown command was sent");
             await chatService.SendMessage(chatMessageArgs.ChatId, UnknownCommandMessage);
         }
     }
 }