Esempio n. 1
0
        private async Task <Result> ValidateCommand(CommandInstanceModel commandInstance)
        {
            Result           validationResult = new Result();
            CommandModelBase command          = commandInstance.Command;

            if (command != null)
            {
                validationResult = await command.CustomValidation(commandInstance.Parameters);

                if (validationResult.Success)
                {
                    validationResult = await command.ValidateRequirements(commandInstance.Parameters);

                    if (!validationResult.Success && ChannelSession.Settings.RequirementErrorsCooldownType != RequirementErrorCooldownTypeEnum.PerCommand)
                    {
                        command.CommandErrorCooldown = RequirementModelBase.UpdateErrorCooldown();
                    }
                }
                else
                {
                    if (ChannelSession.Settings.RequirementErrorsCooldownType != RequirementErrorCooldownTypeEnum.None)
                    {
                        if (!string.IsNullOrEmpty(validationResult.Message) && validationResult.DisplayMessage)
                        {
                            await ChannelSession.Services.Chat.SendMessage(validationResult.Message);
                        }
                    }
                }

                if (validationResult.Success)
                {
                    if (command.Requirements != null)
                    {
                        await command.PerformRequirements(commandInstance.Parameters);

                        commandInstance.RunnerParameters = new List <CommandParametersModel>(command.GetPerformingUsers(commandInstance.Parameters));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(validationResult.Message))
                    {
                        commandInstance.ErrorMessage = validationResult.Message;
                        commandInstance.State        = CommandInstanceStateEnum.Failed;
                    }
                    else
                    {
                        commandInstance.State = CommandInstanceStateEnum.Completed;
                    }
                }
            }
            return(validationResult);
        }
        public RequirementsSetModel GetRequirements()
        {
            List <RequirementModelBase> requirements = new List <RequirementModelBase>();

            foreach (RequirementViewModelBase requirement in this.Requirements)
            {
                RequirementModelBase req = requirement.GetRequirement();
                if (req != null)
                {
                    requirements.Add(requirement.GetRequirement());
                }
            }
            return(new RequirementsSetModel(requirements));
        }