Exemplo n.º 1
0
        public static void DisplayFullCommandDescription(TriggerBase trigger, CommandBase command)
        {
            trigger.Reply(trigger.Bold("{0}") + "{1} - {2}",
                          string.Join("/", command.Aliases),
                          command is SubCommandContainer && (command as SubCommandContainer).Count > 0
                              ? string.Format(" ({0} subcmds)", (command as SubCommandContainer).Count(trigger.CanAccessCommand))
                              : "",
                          command.Description);

            if (!(command is SubCommandContainer))
            {
                trigger.Reply("  -> " + command.Aliases.First() + " " + command.GetSafeUsage());
            }

            if (command.Parameters != null)
            {
                foreach (var commandParameter in command.Parameters)
                {
                    DisplayCommandParameter(trigger, commandParameter);
                }
            }

            if (!(command is SubCommandContainer))
            {
                return;
            }

            foreach (var subCommand in command as SubCommandContainer)
            {
                if (trigger.CanAccessCommand(subCommand))
                {
                    DisplayFullSubCommandDescription(trigger, command, subCommand);
                }
            }
        }
Exemplo n.º 2
0
        public override void Execute(TriggerBase trigger)
        {
            var cmdStr    = trigger.Get <string>("command");
            var subcmdStr = trigger.Get <string>("subcmd");

            if (cmdStr == string.Empty)
            {
                foreach (var command in CommandManager.Instance.AvailableCommands.Where(command => !(command is SubCommand)).Where(trigger.CanAccessCommand))
                {
                    DisplayCommandDescription(trigger, command);
                }
            }
            else
            {
                CommandBase command = CommandManager.Instance.GetCommand(cmdStr);

                if (command == null || !trigger.CanAccessCommand(command))
                {
                    trigger.Reply("Command '{0}' doesn't exist", cmdStr);
                    return;
                }

                if (subcmdStr == string.Empty)
                {
                    DisplayFullCommandDescription(trigger, command);
                }
                else
                {
                    if (!(command is SubCommandContainer))
                    {
                        trigger.Reply("Command '{0}' has no sub commands", cmdStr);
                        return;
                    }

                    var subcommand = (command as SubCommandContainer)[subcmdStr];

                    if (subcommand == null || subcommand.RequiredRole > trigger.UserRole)
                    {
                        trigger.Reply("Command '{0} {1}' doesn't exist", cmdStr, subcmdStr);
                        return;
                    }

                    DisplayFullSubCommandDescription(trigger, command, subcommand);
                }
            }
        }
Exemplo n.º 3
0
        public override void Execute(TriggerBase trigger)
        {
            var role = trigger.Get <RoleEnum>("role");
            var cmd  = trigger.Get <string>("command");

            role = role != RoleEnum.None && role <= trigger.UserRole ?
                   role : trigger.UserRole;

            IEnumerable <CommandBase> availableCommands =
                CommandManager.Instance.AvailableCommands.Where(command => !(command is SubCommand));

            if (cmd != string.Empty)
            {
                var command = CommandManager.Instance.GetCommand(cmd);

                if (command == null || !trigger.CanAccessCommand(command))
                {
                    trigger.ReplyError("Cannot found '{0}'", command);
                    return;
                }

                if (command is SubCommandContainer)
                {
                    availableCommands = (command as SubCommandContainer); // if a command is specified we display his childrens
                }
                else
                {
                    availableCommands = new [] { command }
                };
            }

            var commands = from entry in availableCommands
                           where entry.RequiredRole <= role || (!trigger.IsArgumentDefined("role") && trigger.CanAccessCommand(entry))
                           select entry;

            trigger.Reply(string.Join(", ", from entry in commands
                                      select(entry is SubCommandContainer ?
                                             string.Format(trigger.CanFormat ? "<b>{0}</b>({1})" : "{0}({1})", entry.Aliases.First(), (entry as SubCommandContainer).Count)
                                                : entry.Aliases.First())));
        }
    }