Exemplo n.º 1
0
 private async Task <string?> GetResponse(CommandParameter <T> param, Command?cmd)
 {
     if (cmd == null)
     {
         return("Not sure what you were trying to do? That is not an available command. Try '!help' or '!help <command>'");
     }
     else if (cmd.RequiresMod && !await param.SenderIsMod())
     {
         return("You're not allowed to use that command");
     }
     else //Get the appropriate response depending on command-type
     {
         _logger.LogInformation("Executing command: {0}", cmd.Name);
         return(cmd switch
         {
             SpecialCommand <CommandParameter> sp => await sp.Handle(param),
             SpecialCommand s => await s.Handle(),
             _ => cmd.Response,
         });
Exemplo n.º 2
0
        public async Task <T> Handle(CommandParameter <T> request, CancellationToken cancellationToken)
        {
            string response;
            var    cmd = CommandUtils.GetExistingCommand(request.PrefixedWords[0]);

            if (cmd == null)
            {
                response = "Not sure what you were trying to do? That is not an available command. Try '!help' or '!help <command>'";
            }
            else if (cmd.RequiresMod && !await request.SenderIsMod())
            {
                response = "You're not allowed to use that command";
            }
            else //Get the appropriate response depending on command-type
            {
                _logger.LogInformation("Executing command: {0}", cmd.Name);
                switch (cmd)
                {
                case SpecialCommand <CommandParameter> sp:
                    response = await sp.Handle(request);

                    break;

                case SpecialCommand s:
                    response = await s.Handle();

                    break;

                default:
                    response = cmd.Response;
                    break;
                }
            }

            return(request.Message.CloneWithMessage(response));
        }