コード例 #1
0
ファイル: CallInfo.cs プロジェクト: MildanWorld/Titanbot
        private CallInfo(MethodInfo method, CommandInfo info)
        {
            Method = method;
            if (!CallAttribute.ExistsOn(Method))
            {
                throw new InvalidOperationException($"Cannot create CallInfo from {Method} as it does not have the [Call] attribute");
            }
            Usage = UsageAttribute.GetFor(Method);
            DefaultPermissions = DefaultPermissionAttribute.GetPermFor(Method);
            PermissionKey      = DefaultPermissionAttribute.GetKeyFor(Method).ToLower();
            RequiredContexts   = RequireContextAttribute.GetFor(Method);
            RequireOwner       = RequireOwnerAttribute.ExistsOn(Method);
            ShowTyping         = !HideTypingAttribute.ExistsOn(Method);
            SubCall            = CallAttribute.GetFor(Method);
            Aliases            = AliasAttribute.GetFor(Method);
            Hidden             = HiddenAttribute.ExistsOn(Method);
            Parent             = info;
            Parameters         = null;
            Flags = null;
            ArgumentPermatations = null;

            var args = ArgumentInfo.BuildFrom(this);

            if (args.SkipWhile(p => p.Flag == null).Select(p => p.Flag).Contains(null))
            {
                throw new InvalidOperationException("All optional arguments after the first flag must also be flags");
            }
            Parameters           = args.TakeWhile(a => a.Flag == null).ToArray();
            Flags                = args.SkipWhile(a => a.Flag == null).Select(a => a.Flag).ToArray();
            ArgumentPermatations = ArgumentInfo.BuildPermetations(this).ToList().AsReadOnly();
        }
コード例 #2
0
ファイル: CommandInfo.cs プロジェクト: MildanWorld/Titanbot
 private CommandInfo(Type type)
 {
     if (!type.IsSubclassOf(typeof(Command)))
     {
         throw new InvalidOperationException($"Cannot create CommandInfo from {type}");
     }
     CommandType        = type;
     Group              = GroupAttribute.GetFor(type);
     Name               = NameAttribute.GetFor(type);
     Alias              = AliasAttribute.GetFor(type);
     Description        = DescriptionAttribute.GetFor(type);
     DefaultPermissions = DefaultPermissionAttribute.GetPermFor(type);
     RequiredContexts   = RequireContextAttribute.GetFor(type);
     PermissionKey      = DefaultPermissionAttribute.GetKeyFor(type);
     Note               = NotesAttribute.GetFor(type);
     RequireOwner       = RequireOwnerAttribute.ExistsOn(type);
     RequireGuild       = RequireGuildAttribute.GetFor(type);
     Hidden             = false;
     Calls              = null;
     Calls              = CallInfo.BuildFrom(this).ToList().AsReadOnly();
     Hidden             = HiddenAttribute.ExistsOn(type) || Calls.All(c => c.Hidden);
 }