From a6df26af677ffb3ca0796a0160dee252ba3333ea Mon Sep 17 00:00:00 2001 From: Macintosh II <95250141+mctaylors@users.noreply.github.com> Date: Wed, 26 Jul 2023 21:07:05 +0300 Subject: [PATCH] Resolving issues on #65 (#72) Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com> --- locale/Messages.resx | 4 +-- locale/Messages.ru.resx | 4 +-- locale/Messages.tt-ru.resx | 2 +- src/Commands/SettingsCommandGroup.cs | 54 +++++++++++++++------------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/locale/Messages.resx b/locale/Messages.resx index 72ad974..974d87f 100644 --- a/locale/Messages.resx +++ b/locale/Messages.resx @@ -562,13 +562,13 @@ Rename members who attempt to hoist themselves - page + Page Page not found! - There are total pages + There are {0} total pages Next diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx index 1d703ed..b5eacac 100644 --- a/locale/Messages.ru.resx +++ b/locale/Messages.ru.resx @@ -562,13 +562,13 @@ Переименовывать участников, которые пытаются поднять себя - страница + Страница Страница не найдена! - Всего страниц существует + Всего есть {0} страниц(-ы) Далее diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx index 0fd4ebc..d7d7520 100644 --- a/locale/Messages.tt-ru.resx +++ b/locale/Messages.tt-ru.resx @@ -568,7 +568,7 @@ если я был бы html, я бы сказал 404 - ну а если быть точнее, тут всего страниц + ну а если быть точнее, тут всего {0} страниц(-ы) следующее diff --git a/src/Commands/SettingsCommandGroup.cs b/src/Commands/SettingsCommandGroup.cs index 48d7b0d..9bfbc95 100644 --- a/src/Commands/SettingsCommandGroup.cs +++ b/src/Commands/SettingsCommandGroup.cs @@ -85,37 +85,43 @@ public class SettingsCommandGroup : CommandGroup { } private async Task SendSettingsListAsync(JsonNode cfg, IUser currentUser, int page, CancellationToken ct = default) { - var builder = new StringBuilder(); + var description = new StringBuilder(); var footer = new StringBuilder(); - const int optionsPerList = 7; - var totalPages = (AllOptions.Length + optionsPerList - 1)/optionsPerList; - for (var i = optionsPerList * page - optionsPerList; i <= optionsPerList * page - 1; i++) { - try { - builder.AppendLine($"Settings{AllOptions[i].Name}".Localized()) - .Append(Markdown.InlineCode(AllOptions[i].Name)) - .Append(": ") - .AppendLine(AllOptions[i].Display(cfg)) - .AppendLine(); - } catch { /* hilariously ignored */ } - } - footer.Append($"{Messages.Page} {page}/{totalPages} "); - for (var i = 1; i <= totalPages; i++) footer.Append(i == page ? "●" : "○"); + const int optionsPerPage = 10; - var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, currentUser) - .WithDescription(builder.ToString()) - .WithColour(ColorsList.Default) - .WithFooter(footer.ToString()) - .Build(); + var totalPages = (AllOptions.Length + optionsPerPage - 1) / optionsPerPage; + var lastOptionOnPage = Math.Min(optionsPerPage * page, AllOptions.Length); + var firstOptionOnPage = optionsPerPage * page - optionsPerPage; - if (optionsPerList * page - optionsPerList >= AllOptions.Length) { - embed = new EmbedBuilder().WithSmallTitle(Messages.PageNotFound, currentUser) - .WithDescription($"{Messages.PagesAllowed}: {Markdown.Bold(totalPages.ToString())}") + if (firstOptionOnPage >= AllOptions.Length) { + var embed = new EmbedBuilder().WithSmallTitle(Messages.PageNotFound, currentUser) + .WithDescription(string.Format(Messages.PagesAllowed, Markdown.Bold(totalPages.ToString()))) .WithColour(ColorsList.Red) .Build(); - } - return await _feedbackService.SendContextualEmbedResultAsync(embed, ct); + return await _feedbackService.SendContextualEmbedResultAsync(embed, ct); + } else { + footer.Append($"{Messages.Page} {page}/{totalPages} "); + for (var i = 0; i < totalPages; i++) footer.Append(i + 1 == page ? "●" : "○"); + + for (var i = firstOptionOnPage; i < lastOptionOnPage; i++) { + var optionName = AllOptions[i].Name; + var optionValue = AllOptions[i].Display(cfg); + + description.AppendLine($"- {$"Settings{optionName}".Localized()}") + .Append($" - {Markdown.InlineCode(optionName)}: ") + .AppendLine(optionValue); + } + + var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, currentUser) + .WithDescription(description.ToString()) + .WithColour(ColorsList.Default) + .WithFooter(footer.ToString()) + .Build(); + + return await _feedbackService.SendContextualEmbedResultAsync(embed, ct); + } } ///