Пример #1
0
        public async Task Help(
            [Summary("[Optional] The page to load.")] int page = 1)
        {
            var help = await _commandHandler.BuildHelpAsync(Context).ConfigureAwait(false);

            var resultMax = (_pageSize - help.Count % _pageSize) + help.Count;
            var pages     = resultMax / _pageSize;

            if (page < 1 || page > pages)
            {
                page = 1;
            }

            var helpPage = help.Skip((page - 1) * _pageSize).Take(_pageSize);

            var helpText = new StringBuilder();

            helpText.AppendLine($"{Format.Bold("Command").PadRight(20)}{Format.Bold("Parameters").PadRight(20)}{Format.Bold("Summary")}");
            foreach (var helpItem in helpPage.SelectMany(a => a.Commands))
            {
                var command = $"{_config.PrefixChar}{helpItem.Alias}";
                helpText.AppendLine($"{command.PadRight(20)}{string.Join(", ", helpItem.Parameters.Select(a => a.Name)).PadRight(20)}{helpItem.Summary}");
            }

            helpText.AppendLine($"Page {page} of {pages}. Use {_config.PrefixChar}help # to view the other pages.");

            await Context.User.SendMessageAsync(Format.Code(helpText.ToString())).ConfigureAwait(false);
        }
Пример #2
0
        public async Task AddPermission(string command, ulong roleId)
        {
            command = command.ToLower();

            var role = Context.Guild.Roles.SingleOrDefault(a => a.Id == roleId);

            if (role == null)
            {
                await ReplyAsync("Role not found.").ConfigureAwait(false);

                return;
            }

            var commands = await _handler.BuildHelpAsync(Context).ConfigureAwait(false);

            if (command != "*" && !commands.SelectMany(a => a.Commands).Any(a => a.Alias == command))
            {
                await ReplyAsync("Command either does not exist, or you do not already have permissions to it.").ConfigureAwait(false);

                return;
            }

            await Configuration.Modify <PermissionsConfig>(_config.ConfigKey, async a =>
            {
                if (!a.Permissions.ContainsKey(command))
                {
                    a.Permissions.Add(command, new List <ulong>());
                }

                if (a.Permissions[command].Contains(roleId))
                {
                    await ReplyAsync($"`{role.Name}` is already enabled for {command}").ConfigureAwait(false);
                    return;
                }

                a.Permissions[command].Add(role.Id);

                await ReplyAsync($"{command} enabled for `{role.Name}`").ConfigureAwait(false);
            }, Context.Guild.Id).ConfigureAwait(false);
        }