Ejemplo n.º 1
0
 public CommandManager()
 {
     CommandSystem  = new XCommandSystem();
     PluginCommands = new Dictionary <Plugin, IList <BotCommand> >();
     Util.Init(ref dynamicCommands);
     Util.Init(ref CommandPaths);
 }
Ejemplo n.º 2
0
        public override ICommandResult Execute(ExecutionInformation info, IEnumerable <ICommand> arguments, IEnumerable <CommandResultType> returnTypes)
        {
            string result;

            if (!arguments.Any())
            {
                if (returnTypes.Contains(CommandResultType.Command))
                {
                    return(new CommandCommandResult(this));
                }
                result = string.Empty;
            }
            else
            {
                var comResult = arguments.First().Execute(info, Enumerable.Empty <ICommand>(), new CommandResultType[] { CommandResultType.String });
                result = ((StringCommandResult)comResult).Content;
            }

            var commandResults = XCommandSystem.FilterList(commands, result);

            if (commandResults.Skip(1).Any())
            {
                throw new CommandException("Ambiguous command, possible names: " + string.Join(", ", commandResults.Select(g => g.Key)), CommandExceptionReason.AmbiguousCall);
            }

            var argSubList = arguments.Skip(1).ToArray();

            return(commandResults.First().Value.Execute(info, argSubList, returnTypes));
        }
Ejemplo n.º 3
0
        public virtual ICommandResult Execute(ExecutionInformation info, IReadOnlyList <ICommand> arguments, IReadOnlyList <CommandResultType> returnTypes)
        {
            string result;

            if (arguments.Count == 0)
            {
                if (returnTypes.Contains(CommandResultType.Command))
                {
                    return(new CommandCommandResult(this));
                }
                result = string.Empty;
            }
            else
            {
                var comResult = arguments[0].Execute(info, StaticList.Empty <ICommand>(), new[] { CommandResultType.String });
                result = ((StringCommandResult)comResult).Content;
            }

            var commandResults = XCommandSystem.FilterList(commands, result).ToArray();

            if (commandResults.Length > 1)
            {
                throw new CommandException("Ambiguous command, possible names: " + string.Join(", ", commandResults.Select(g => g.Key)), CommandExceptionReason.AmbiguousCall);
            }
            if (commandResults.Length == 0)
            {
                throw new CommandException("No matching command", CommandExceptionReason.AmbiguousCall);
            }


            var argSubList = arguments.TrySegment(1);

            return(commandResults[0].Value.Execute(info, argSubList, returnTypes));
        }
Ejemplo n.º 4
0
 public CommandManager()
 {
     CommandSystem = new XCommandSystem();
     Util.Init(out baseCommands);
     Util.Init(out commandPaths);
     Util.Init(out dynamicCommands);
     Util.Init(out pluginCommands);
 }
Ejemplo n.º 5
0
 public CommandManager(RightsManager rightsManager)
 {
     CommandSystem = new XCommandSystem();
     Util.Init(out aliasPaths);
     Util.Init(out commandPaths);
     Util.Init(out baggedCommands);
     this.rightsManager = rightsManager;
 }
Ejemplo n.º 6
0
 public CommandManager()
 {
     CommandSystem = new XCommandSystem();
     Util.Init(ref baseCommands);
     Util.Init(ref commandPaths);
     Util.Init(ref dynamicCommands);
     Util.Init(ref pluginCommands);
 }
Ejemplo n.º 7
0
        private static object ConvertParam(string value, Type targetType)
        {
            if (targetType == typeof(string))
            {
                return(value);
            }
            if (targetType.IsEnum)
            {
                var enumVals = Enum.GetValues(targetType).Cast <Enum>();
                var result   = XCommandSystem.FilterList(enumVals.Select(x => new KeyValuePair <string, Enum>(x.ToString(), x)), value).Select(x => x.Value).FirstOrDefault();
                if (result == null)
                {
                    throw new CommandException($"Invalid parameter \"{value}\"", CommandExceptionReason.MissingParameter);
                }
                return(result);
            }
            if (targetType.IsConstructedGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                targetType = targetType.GenericTypeArguments[0];
            }

            return(Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture));
        }
Ejemplo n.º 8
0
 public CommandManager()
 {
     CommandSystem = new XCommandSystem();
     Util.Init(out commandPaths);
     Util.Init(out baggedCommands);
 }