public async Task HelpCmd()
        {
            var cmds = (await _permService.CService.Commands
                        .Where(c => !c.Attributes.Any(p => p is HiddenAttribute))
                        .CheckConditions(Context, _services, _permService).ConfigureAwait(false));

            if (await UseFancy().ConfigureAwait(false))
            {
                //using (var config = _permService.ReadOnlyConfig)
                using var config = _permService.LoadConfig();
                if (await config.GetHidePermCommands(Context.Guild).ConfigureAwait(false))
                {
                    cmds = cmds.Where(c => c.Module.Name != PermModuleName);
                }

                var app = await Context.Client.GetApplicationInfoAsync().ConfigureAwait(false);

                await _permService.AddNewFancy(await new FancyHelpMessage(Context.Channel, Context.User, cmds.ToList(), app).SendMessage().ConfigureAwait(false));
            }
            else
            {
                var grouped = cmds.GroupBy(c => c.Module.Name)
                              .Select(g => $"{g.Key}:\n\t`{String.Join("`, `", g.Select(c => c.Aliases.FirstOrDefault()).Distinct())}`");

                var sb = new StringBuilder("You can use the following commands:\n")
                         .AppendLine($"{String.Join("\n", grouped)}\n")
                         .Append("You can use `help <command>` for more information on that command.");

                await ReplyAsync(sb.ToString()).ConfigureAwait(false);
            }
        }
Пример #2
0
        public static async Task <IEnumerable <CommandInfo> > CheckConditions(
            this IEnumerable <CommandInfo> commands,
            ICommandContext ctx,
            IServiceProvider svcs,
            PermissionsService permsvc)
        {
            var ret = new List <CommandInfo>();

            foreach (var cmd in commands)
            {
                var preconditionResult = await cmd.CheckPreconditionsAsync(ctx, svcs).ConfigureAwait(false);

                if (preconditionResult.IsSuccess)
                {
                    if (cmd.Module.Name == PermissionsModule.PermModuleName)
                    {
                        //using (var config = permsvc.ReadOnlyConfig)
                        using (var config = permsvc.LoadConfig())
                        {
                            bool shouldHide = await config.GetHidePermCommands(ctx.Guild).ConfigureAwait(false);

                            if (cmd.Name != nameof(PermissionsModule.HelpCmd) && shouldHide)
                            {
                                continue;
                            }
                        }
                    }
                    ret.Add(cmd);
                }
            }
            return(ret);
        }