Example #1
0
        /// <summary>
        /// Creates an <see cref="EmbedBuilder"/> object for help regarding slash commands, using reflection and attribute values.
        /// </summary>
        /// <returns>A collection of <see cref="EmbedBuilder"/> objects ready to be built.</returns>
        private List <EmbedBuilder> GenerateEmbeddedSlashCommandsHelp()
        {
            List <EmbedBuilder> embeds = new();

            Emoji  moduleBullet  = new("\uD83D\uDD37");
            Emoji  commandBullet = new("\uD83D\uDD39");
            string helpImageUrl  = Configuration.GetSection("images").GetSection("help")["64"];

            EmbedBuilder helpEmbed = new EmbedBuilder().WithColor(GlobalConfiguration.Colors.Help)
                                     .WithTitle(Format.Bold("Ayuda"))
                                     .WithThumbnailUrl(helpImageUrl)
                                     .WithCurrentTimestamp();

            string helpCommands = new StringBuilder()
                                  .AppendLine($"{commandBullet} {Format.Code($"/{HELP_COMMAND}")}")
                                  .AppendLine(Format.Italics(HELP_SUMMARY))
                                  .AppendLine(GlobalConfiguration.Constants.BLANK_SPACE)
                                  .AppendLine($"{commandBullet} {Format.Code($"/{HELP_COMMAND}")} {Format.Code("<comando>")}")
                                  .AppendLine(Format.Italics(HELP_COMMAND_SUMMARY))
                                  .AppendLine(GlobalConfiguration.Constants.BLANK_SPACE)
                                  .ToString();

            helpEmbed.AddField(GlobalConfiguration.Constants.BLANK_SPACE, helpCommands);
            embeds.Add(helpEmbed);

            Dictionary <string, List <ModuleInfo> > modules = InteractionService.Modules.Where(m => m.HasAttribute <HelpTitleAttribute>())
                                                              .OrderBy(m => (m.GetAttribute <HelpOrderAttribute>()?.Order))
                                                              .GroupBy(m => m.GetAttribute <HelpTitleAttribute>()?.Title)
                                                              .Where(x => !string.IsNullOrWhiteSpace(x.Key))
                                                              .ToDictionary(x => x.Key, x => x.ToList());

            foreach (var module in modules)
            {
                for (int i = 0; i < module.Value.Count; i++)
                {
                    EmbedBuilder embed = new EmbedBuilder().WithColor(GlobalConfiguration.Colors.Help)
                                         .WithTitle(module.Value.Count > 1 ? $"{Format.Bold(module.Key)} ({i + 1}/{module.Value.Count})" : Format.Bold(module.Key))
                                         .WithThumbnailUrl(helpImageUrl)
                                         .WithCurrentTimestamp();

                    ModuleInfo    m = module.Value.ElementAt(i);
                    StringBuilder commandsBuilder = new();
                    foreach (SlashCommandInfo slashCommandInfo in m.SlashCommands)
                    {
                        string commandName        = Format.Code($"/{slashCommandInfo.Name}");
                        string commandDescription = Format.Italics(slashCommandInfo.Description).AppendLineBreak();
                        commandsBuilder.AppendLine($"{commandBullet} {commandName}").AppendLine(commandDescription);
                    }

                    embed.AddField(GlobalConfiguration.Constants.BLANK_SPACE, commandsBuilder.ToString());
                    embeds.Add(embed);
                }
            }

            return(embeds);
        }
 /// <summary>
 /// Gets the attribute, if found, from the current module.
 /// </summary>
 /// <typeparam name="T">The attribute's type.</typeparam>
 /// <param name="module">The current module.</param>
 /// <returns>The attribute if found, otherwise null.</returns>
 public static T GetAttribute <T>(this Discord.Interactions.ModuleInfo module) where T : Attribute
 {
     return(module.Attributes.Where(a => (a as T) != null).Select(a => a as T).FirstOrDefault());
 }
 /// <summary>
 /// Returns true if the current module contains the <typeparamref name="T"/> typed attribute, otherwise false.
 /// </summary>
 /// <typeparam name="T">The attribute's type.</typeparam>
 /// <param name="module">The current module.</param>
 /// <returns>True if the module has the attribute, otherwise false.</returns>
 public static bool HasAttribute <T>(this Discord.Interactions.ModuleInfo module) where T : Attribute
 {
     return(module.Attributes.Any(a => (a as T) != null));
 }
Example #4
0
 internal AutocompleteCommandInfo(AutocompleteCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
 {
     Parameters    = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
     ParameterName = builder.ParameterName;
     CommandName   = builder.CommandName;
 }
Example #5
0
        internal ModuleInfo(ModuleBuilder builder, InteractionService commandService, IServiceProvider services, ModuleInfo parent = null)
        {
            CommandService = commandService;

            Name                 = builder.Name;
            SlashGroupName       = builder.SlashGroupName;
            Description          = builder.Description;
            Parent               = parent;
            DefaultPermission    = builder.DefaultPermission;
            SlashCommands        = BuildSlashCommands(builder).ToImmutableArray();
            ContextCommands      = BuildContextCommands(builder).ToImmutableArray();
            ComponentCommands    = BuildComponentCommands(builder).ToImmutableArray();
            AutocompleteCommands = BuildAutocompleteCommands(builder).ToImmutableArray();
            ModalCommands        = BuildModalCommands(builder).ToImmutableArray();
            SubModules           = BuildSubModules(builder, commandService, services).ToImmutableArray();
            Attributes           = BuildAttributes(builder).ToImmutableArray();
            Preconditions        = BuildPreconditions(builder).ToImmutableArray();
            IsTopLevelGroup      = CheckTopLevel(parent);
            DontAutoRegister     = builder.DontAutoRegister;

            GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
        }
Example #6
0
 /// <inheritdoc/>
 public virtual void OnModuleBuilding(InteractionService commandService, ModuleInfo module)
 {
 }
 internal static ContextCommandInfo Create(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
 {
     return(builder.CommandType switch
     {
         ApplicationCommandType.User => new UserCommandInfo(builder, module, commandService),
         ApplicationCommandType.Message => new MessageCommandInfo(builder, module, commandService),
         _ => throw new InvalidOperationException("This command type is not a supported Context Command"),
     });
 internal MessageCommandInfo(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService)
     : base(builder, module, commandService)
 {
 }
Example #9
0
 internal ComponentCommandInfo(ComponentCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
 {
     Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
 }
Example #10
0
 internal SlashCommandInfo(Builders.SlashCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
 {
     Description       = builder.Description;
     DefaultPermission = builder.DefaultPermission;
     Parameters        = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
 }
Example #11
0
 internal ModalCommandInfo(Builders.ModalCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService)
 {
     Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
     Modal      = Parameters.Last().Modal;
 }