예제 #1
0
 private void AttemptToRunCommand(CommandReceivedEventArgs e, IBotCommand botCommand, IChatClient chatClient1)
 {
     try
     {
         if (e.ChatUser.CanUserRunCommand(botCommand))
         {
             botCommand.Process(chatClient1, e);
         }
         else
         {
             chatClient1.SendMessage(
                 $"Sorry, {e.ChatUser.DisplayName}! You don't have permission to use the !{e.CommandWord} command.");
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
     }
 }
예제 #2
0
        private CommandUsage AttemptToRunCommand(CommandReceivedEventArgs e, IBotCommand botCommand,
                                                 IChatClient chatClient1)
        {
            try
            {
                _logger.LogInformation($"{e.ChatUser.DisplayName} is running the {botCommand.GetType().Name} command.");

                if (e.ChatUser.CanRunCommand(botCommand))
                {
                    return(botCommand.Process(chatClient1, e));
                }

                chatClient1.SendMessage(
                    $"Sorry, {e.ChatUser.DisplayName}! You don't have permission to use the !{e.CommandWord} command.");
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to run a command.");
            }

            return(null);
        }