Beispiel #1
0
        public async Task AjudaCmd(CommandContext ctx, [Description("Comando que você precisa de ajuda")] params string[] comando)
        {
            if (comando.Length == 0)
            {
                DiscordEmbedBuilder builder = new DiscordEmbedBuilder
                {
                    Color    = DiscordColor.Purple,
                    ImageUrl = "https://i.imgur.com/mQVFSrP.gif",
                    Title    = "Comandos atacaaaaar 😁"
                };

                Type[] types = typeof(Kurosawa).Assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    StringBuilder sb         = new StringBuilder();
                    Modulo        moduleAttr = types[i].GetCustomAttribute <Modulo>();
                    if (moduleAttr != null)
                    {
                        GroupAttribute grupo = types[i].GetCustomAttribute <GroupAttribute>();
                        if (grupo == null)
                        {
                            MethodInfo[] metodos = types[i].GetMethods();
                            for (int j = 0; j < metodos.Length; j++)
                            {
                                CommandAttribute comandoAtributo = metodos[j].GetCustomAttribute <CommandAttribute>();
                                HiddenAttribute  comandoHidden   = metodos[j].GetCustomAttribute <HiddenAttribute>();
                                if (comandoAtributo != null && comandoHidden == null)
                                {
                                    sb.Append($"`{comandoAtributo.Name}` ");
                                }
                            }
                        }
                        else
                        {
                            sb.Append($"`{grupo.Name}` ");
                        }
                        DescriptionAttribute descricao = types[i].GetCustomAttribute <DescriptionAttribute>();
                        builder.AddField($"**{moduleAttr.Nome}** {$" {moduleAttr.Icon}" ?? ""}- *{descricao.Description}*", sb.ToString(), false);
                    }
                }
                builder.WithDescription("Para mais informações sobre um módulo ou comando, digite `help {Comando}` que eu lhe informarei mais sobre ele 😄");
                await ctx.RespondAsync(embed : builder.Build());
            }
            else
            {
                await ctx.Client.GetCommandsNext().DefaultHelpAsync(ctx, comando);
            }
        }
Beispiel #2
0
        protected override void ProcessFile(ExcelWorksheet sheet, GroupStructure group)
        {
            Groups[group.Name] = group;

            int    row         = Configuration.DataStartRow;
            int    atts        = 0;
            string subtypeName = sheet.Cells[row, Configuration.DataNameColumn].Value?.ToString().Trim();

            while (!string.IsNullOrEmpty(subtypeName))
            {
                Console.WriteLine($"Processing subtype {subtypeName}");
                try
                {
                    GroupAttribute subtype = new GroupAttribute()
                    {
                        Name        = subtypeName,
                        Description = sheet.Cells[row, Configuration.DataDescriptionColumn].Value?.ToString().Trim(),
                        Guid        = GuidHelper.Create(GuidHelper.ObjClass.Attribute, subtypeName, false).ToString(),
                        Supertype   = sheet.Cells[row, Configuration.SupertypeColumn].Value?.ToString().Trim(),
                    };
                    if (Attributes.TryGetValue(subtypeName, out var other) && subtype.ToString() != other.ToString())
                    {
                        Console.WriteLine($"{subtype.Name} was already defined with a different supertype {other.ToString()}, taking into account the last one {subtype.ToString()}");
                    }
                    Attributes[subtypeName] = subtype;
                    atts++;
                    group.Items.Add(subtype);
                    row++;
                }
                catch (Exception ex) when(HandleException($"at row:{row}", ex, true))
                {
                }
                subtypeName = sheet.Cells[row, Configuration.DataNameColumn].Value?.ToString().Trim();
            }
            if (atts == 0)
            {
                throw new Exception($"Definition without content, check the {nameof(Configuration.DataStartRow)} and {nameof(Configuration.DataStartColumn)} values on the config file");
            }
        }
Beispiel #3
0
 public abstract void BeginGroup(GroupAttribute attribute);
        public BindingMember(MemberInfo propertyInfo, object baseObject, BindingMember parent = null, bool lean = false)
        {
            BoundSources = new List <BoundSource>();

            _propertyInfo = propertyInfo as PropertyInfo;
            _baseObject   = baseObject;

            PropertyName = propertyInfo.Name;

            if (lean)
            {
                return;
            }

            _defaultValueAttribute      = GetAttribute <DefaultValueAttribute>(propertyInfo);
            _limitAttribute             = GetAttribute <LimitAttribute>(propertyInfo);
            _displayNameAttribute       = GetAttribute <DisplayNameAttribute>(propertyInfo);
            _descriptionAttribute       = GetAttribute <DescriptionAttribute>(propertyInfo);
            _uiControlAttribute         = GetAttribute <UIControlAttribute>(propertyInfo);
            _categoryAttribute          = GetAttribute <CategoryAttribute>(propertyInfo);
            _advancedAttribute          = GetAttribute <AdvancedSetting>(propertyInfo);
            _limitBindingAttribute      = GetAttribute <LimitBindingAttribute>(propertyInfo);
            _isGroupControllerAttribute = GetAttribute <IsGroupController>(propertyInfo);
            _groupAttribute             = GetAttribute <GroupAttribute>(propertyInfo);

            //Core.Logger.Verbose($"Created Binding Member for {propertyInfo.Name}");

            var notify = baseObject as INotifyPropertyChanged;

            if (notify != null)
            {
                //Core.Logger.Verbose($"Registering Property Changed for {baseObject.GetType().Name} ({propertyInfo.Name})");
                notify.PropertyChanged += NotifyOnPropertyChanged;
            }

            //_bindingAttribute = GetAttribute<BindingAttribute>(propertyInfo);

            _BindingAttributes = propertyInfo.GetCustomAttributes(typeof(BindingAttribute)).OfType <BindingAttribute>().ToList();

            if (_categoryAttribute == null && parent != null && parent.Category != null)
            {
                _categoryAttribute = new CategoryAttribute(parent.Category);
            }

            // The parent property of embedded TrinitySettings objects can define a category
            // When children do not have one explicitly set.
            if (_categoryAttribute == null && parent != null && parent.Category != null)
            {
                _categoryAttribute = new CategoryAttribute(parent.Category);
            }

            // GroupControllers notify other instances that a category has changed.
            // Applicable listners can then refresh their state in the UI.
            OnCategoryChanged += categoryId =>
            {
                if (categoryId == GroupId)
                {
                    OnPropertyChanged(nameof(IsEnabled));
                }
            };

            IsNoLabel = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.NoLabel);

            //IsUseDescription = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.UseDescription);

            IsInline = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.Inline);

            if (_limitAttribute != null)
            {
                Range = new Range
                {
                    Min = _limitAttribute.Low,
                    Max = _limitAttribute.High
                };
            }

            _type = _baseObject.GetType();

            if (_limitBindingAttribute != null)
            {
                var lowSource  = _limitBindingAttribute.LowSource;
                var highSource = _limitBindingAttribute.HighSource;

                if (!BotMain.IsRunning)
                {
                    using (ZetaDia.Memory.AcquireFrame())
                    {
                        Range = new Range
                        {
                            Min                     = lowSource != null?GetMemberValue <double>(lowSource) : _limitBindingAttribute.Low,
                                                Max = highSource != null?GetMemberValue <double>(highSource) : _limitBindingAttribute.High
                        };
                    }
                }
                else
                {
                    Range = new Range
                    {
                        Min                     = lowSource != null?GetMemberValue <double>(lowSource) : _limitBindingAttribute.Low,
                                            Max = highSource != null?GetMemberValue <double>(highSource) : _limitBindingAttribute.High
                    };
                }
            }

            if (_BindingAttributes != null && _BindingAttributes.Any())
            {
                var attributes = _BindingAttributes.OrderBy(a => a.Order).ToList();
                foreach (var bindingAttr in attributes)
                {
                    var member = GetMember(bindingAttr);
                    var prop   = member as PropertyInfo;
                    if (prop == null)
                    {
                        continue;
                    }
                    var boundSource = new BoundSource
                    {
                        Member = new BindingMember(prop, baseObject, this),
                        Items  = GetBoundItems(prop, bindingAttr)
                    };
                    BoundSources.Add(boundSource);
                }
            }

            if (IsGroupController)
            {
                ChangeGroup(GroupId, Value);
            }

            Source = new BoundSource
            {
                Member = this,
                Items  = GetBoundItems(propertyInfo)
            };
        }
Beispiel #5
0
 public Loop(PropertyInfo propertyInfo, GroupAttribute gAttr, object instance = null)
     : base(propertyInfo.GetGenericType(), propertyInfo.Name, gAttr.Id)
 {
     BuildChildren(instance);
 }
        private static void BuildControl(Form form, PropertyInfo property, TheSettings theSettings)
        {
            Control control = null;

            object[] attributes = property.GetCustomAttributes(false);

            MusicPlugin.Code.Attributes.DescriptionAttribute descriptionAttribute = attributes.Select(x => x as MusicPlugin.Code.Attributes.DescriptionAttribute).Where(i => i != null).First();;
            ControlAttribute controlAttribute = attributes.Select(x => x as ControlAttribute).Where(i => i != null).First();
            HiddenAttribute  hiddenAttribute  = attributes.Select(x => x as HiddenAttribute).Where(i => i != null).First();
            GroupAttribute   groupAttribute   = attributes.Select(x => x as GroupAttribute).Where(i => i != null).First();

            if (hiddenAttribute != null)
            {
                if (hiddenAttribute.Hidden)
                {
                    return;
                }
            }

            GroupBox         groupBox         = null;
            TableLayoutPanel tableLayoutPanel = null;

            if (controlAttribute != null)
            {
                if (form.Controls[groupAttribute.Group + "GroupBoxPanel"] != null)
                {
                    groupBox         = (GroupBox)form.Controls[groupAttribute.Group + "GroupBoxPanel"].Controls[groupAttribute.Group + "GroupBox"];
                    tableLayoutPanel = (TableLayoutPanel)groupBox.Controls[0];
                }
                else
                {
                    Panel panel = new Panel()
                    {
                        Padding = new Padding(0, 5, 0, 5), Name = groupAttribute.Group + "GroupBoxPanel", AutoSize = true, Dock = DockStyle.Top
                    };
                    groupBox = new GroupBox()
                    {
                        FlatStyle = FlatStyle.Flat, Text = groupAttribute.Group, Name = groupAttribute.Group + "GroupBox", AutoSize = true, Dock = DockStyle.Fill
                    };
                    panel.Controls.Add(groupBox);
                    tableLayoutPanel = new TableLayoutPanel()
                    {
                        ColumnCount = 2, Dock = DockStyle.Fill, AutoSize = true
                    };
                    tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent)
                    {
                        Width = 45
                    });
                    tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent)
                    {
                        Width = 55
                    });
                    groupBox.Controls.Add(tableLayoutPanel);
                    form.Controls.Add(panel);
                }


                if (controlAttribute.Control.Equals(typeof(CheckBox)))
                {
                    control = new CheckBox()
                    {
                        FlatStyle = FlatStyle.Flat, Checked = (bool)property.GetValue(theSettings, null), Name = property.Name
                    };
                    (control as CheckBox).CheckedChanged += new EventHandler(ConfigureView_Changed);
                }
                else if (controlAttribute.Control.Equals(typeof(FolderTextBox)))
                {
                    control = new FolderTextBox()
                    {
                        Text = (string)property.GetValue(theSettings, null), Name = property.Name
                    };
                    (control as FolderTextBox).TextChanged += new EventHandler(ConfigureView_Changed);
                }
                else if (controlAttribute.Control.Equals(typeof(FileTextBox)))
                {
                    control = new FileTextBox()
                    {
                        Text = (string)property.GetValue(theSettings, null), Name = property.Name
                    };
                    (control as FileTextBox).TextChanged += new EventHandler(ConfigureView_Changed);
                    ExtAttribute extAttribute = attributes.Select(x => x as ExtAttribute).Where(i => i != null).First();
                    (control as FileTextBox).Ext = extAttribute.Ext;
                }
                else if (controlAttribute.Control.Equals(typeof(TextBox)))
                {
                    control = new TextBox()
                    {
                        BorderStyle = BorderStyle.FixedSingle, Text = (string)property.GetValue(theSettings, null), Name = property.Name, Width = 200
                    };
                    (control as TextBox).TextChanged += new EventHandler(ConfigureView_Changed);
                }
            }
            else
            {
                return;
            }

            tableLayoutPanel.Controls.Add(new Label()
            {
                Text = descriptionAttribute.Description, AutoSize = true, Anchor = AnchorStyles.Right
            });
            tableLayoutPanel.Controls.Add(control);
            _controlBindings.Add(control, property);
        }
Beispiel #7
0
        public Task HelpAsync()
        {
            //List<CommandInfo> commandInfos = new List<CommandInfo>();

            //foreach (ModuleInfo item in CommandHandler._commands.Modules)
            //{
            //	commandInfos.AddRange(item.GetExecutableCommandsAsync(Context, null).GetAwaiter().GetResult());
            //}


            //List<CommandDescription> Commands = new List<CommandDescription>();

            //foreach (CommandInfo info in commandInfos)
            //{
            //	info.Attributes
            //}


            MemberInfo[] Methodinfos = typeof(BasicModule).GetMethods();



            Methodinfos = Methodinfos.Concat(typeof(BotServerManagmentModule).GetMethods()).ToArray();
            Methodinfos = Methodinfos.Concat(typeof(ListSortModule).GetMethods()).ToArray();
            Methodinfos = Methodinfos.Concat(typeof(MiscCommandsModlue).GetMethods()).ToArray();


            Methodinfos = Methodinfos.Where(x => ((MethodBase)x).IsPublic).ToArray();

            List <CommandDescription> Commands = new List <CommandDescription>();

            foreach (MethodInfo info in Methodinfos)
            {
                GroupAttribute GroupName = (GroupAttribute)info.DeclaringType.GetCustomAttribute(typeof(GroupAttribute));

                CommandAttribute CommandName    = (CommandAttribute)info.GetCustomAttribute(typeof(CommandAttribute));
                SummaryAttribute CommandSummary = (SummaryAttribute)info.GetCustomAttribute(typeof(SummaryAttribute));

                if (!(CommandName is null) && !(CommandSummary is null))
                {
                    Commands.Add(new CommandDescription {
                        Groupname = GroupName?.Prefix ?? string.Empty, CommandName = CommandName.Text, CommandSummary = CommandSummary.Text
                    });
                }
            }



            EmbedBuilder builder = new EmbedBuilder()
            {
                Author = new EmbedAuthorBuilder()
                {
                    Name = "AutorName",
                    Url  = "https://www.emoji.co.uk/files/twitter-emojis/symbols-twitter/11121-negative-squared-latin-capital-letter-a.png"
                },
                Color    = Color.Purple,
                ImageUrl = Properties.AshSettings.Default.ProfilePicture,
                Title    = "Hilfe",
                Fields   = new List <EmbedFieldBuilder>()
            };


            foreach (CommandDescription description in Commands)
            {
                builder.AddField($"{description.Groupname} {description.CommandName}", description.CommandSummary, false);
            }

            return(ReplyAsync(embed: builder.Build()));
        }
        /// <summary>
        ///     If the end points of an edge belong to the same group,
        ///     i.e., have the same group attribute,
        ///     parameters are set to avoid crossings and keep the edges straight.
        /// </summary>
        public static IAttrSet Group(this IAttrSet attrSet, string value)
        {
            GroupAttribute a = new GroupAttribute(value);

            return(attrSet.Add(a));
        }