Esempio n. 1
0
 public NewAutoChatCommandModel(string description, ChatCommandModel command)
 {
     this.AddCommand  = true;
     this.Description = description;
     this.Command     = command;
 }
        public override async Task CustomRun(CommandParametersModel parameters)
        {
            if (parameters.Arguments.Count() >= 3)
            {
                string commandTrigger = parameters.Arguments.ElementAt(0).ToLower();

                if (!ChatCommandModel.IsValidCommandTrigger(commandTrigger))
                {
                    await ChannelSession.Services.Chat.SendMessage("ERROR: Command trigger contain an invalid character");

                    return;
                }

                foreach (CommandModelBase command in ChannelSession.Services.Command.AllEnabledChatAccessibleCommands)
                {
                    if (command.IsEnabled)
                    {
                        if (command.Triggers.Contains(commandTrigger, StringComparer.InvariantCultureIgnoreCase))
                        {
                            await ChannelSession.Services.Chat.SendMessage("ERROR: There already exists an enabled, chat command that uses the command trigger you have specified");

                            return;
                        }
                    }
                }

                if (!int.TryParse(parameters.Arguments.ElementAt(1), out int cooldown) || cooldown < 0)
                {
                    await ChannelSession.Services.Chat.SendMessage("ERROR: Cooldown must be 0 or greater");

                    return;
                }

                StringBuilder commandTextBuilder = new StringBuilder();
                foreach (string arg in parameters.Arguments.Skip(2))
                {
                    commandTextBuilder.Append(arg + " ");
                }

                string commandText = commandTextBuilder.ToString();
                commandText = commandText.Trim(new char[] { ' ', '\'', '\"' });

                ChatCommandModel newCommand = new ChatCommandModel(commandTrigger, new HashSet <string>()
                {
                    commandTrigger
                }, includeExclamation: true, wildcards: false);
                newCommand.Requirements.AddBasicRequirements();
                newCommand.Requirements.Role.Role                 = UserRoleEnum.User;
                newCommand.Requirements.Cooldown.Type             = CooldownTypeEnum.Standard;
                newCommand.Requirements.Cooldown.IndividualAmount = cooldown;
                newCommand.Actions.Add(new ChatActionModel(commandText));
                ChannelSession.Settings.SetCommand(newCommand);
                ChannelSession.Services.Command.ChatCommands.Add(newCommand);

                if (ChannelSession.Services.Chat != null)
                {
                    await ChannelSession.Services.Chat.SendMessage("Added New Command: !" + commandTrigger);

                    ChannelSession.Services.Chat.RebuildCommandTriggers();
                }
            }
            else
            {
                await ChannelSession.Services.Chat.SendMessage("Usage: !addcommand <COMMAND TRIGGER, NO !> <COOLDOWN> <FULL COMMAND MESSAGE TEXT>");
            }
        }
Esempio n. 3
0
 public bool DoesMessageMatchWildcardTriggers(ChatMessageViewModel message, out IEnumerable <string> arguments)
 {
     return(ChatCommandModel.DoesMessageMatchWildcardTriggers(message, this.Triggers, out arguments));
 }