1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

Resolving issues on #65 (#72)

Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
This commit is contained in:
Macintxsh 2023-07-26 21:07:05 +03:00 committed by GitHub
parent 8f95e4cd2c
commit a6df26af67
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 29 deletions

View file

@ -562,13 +562,13 @@
<value>Rename members who attempt to hoist themselves</value>
</data>
<data name="Page" xml:space="preserve">
<value>page</value>
<value>Page</value>
</data>
<data name="PageNotFound" xml:space="preserve">
<value>Page not found!</value>
</data>
<data name="PagesAllowed" xml:space="preserve">
<value>There are total pages</value>
<value>There are {0} total pages</value>
</data>
<data name="Next" xml:space="preserve">
<value>Next</value>

View file

@ -562,13 +562,13 @@
<value>Переименовывать участников, которые пытаются поднять себя</value>
</data>
<data name="Page" xml:space="preserve">
<value>страница</value>
<value>Страница</value>
</data>
<data name="PageNotFound" xml:space="preserve">
<value>Страница не найдена!</value>
</data>
<data name="PagesAllowed" xml:space="preserve">
<value>Всего страниц существует</value>
<value>Всего есть {0} страниц(-ы)</value>
</data>
<data name="Next" xml:space="preserve">
<value>Далее</value>

View file

@ -568,7 +568,7 @@
<value>если я был бы html, я бы сказал 404</value>
</data>
<data name="PagesAllowed" xml:space="preserve">
<value>ну а если быть точнее, тут всего страниц</value>
<value>ну а если быть точнее, тут всего {0} страниц(-ы)</value>
</data>
<data name="Next" xml:space="preserve">
<value>следующее</value>

View file

@ -85,38 +85,44 @@ public class SettingsCommandGroup : CommandGroup {
}
private async Task<Result> 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 */ }
const int optionsPerPage = 10;
var totalPages = (AllOptions.Length + optionsPerPage - 1) / optionsPerPage;
var lastOptionOnPage = Math.Min(optionsPerPage * page, AllOptions.Length);
var firstOptionOnPage = optionsPerPage * page - optionsPerPage;
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);
} 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);
}
footer.Append($"{Messages.Page} {page}/{totalPages} ");
for (var i = 1; i <= totalPages; i++) footer.Append(i == page ? "●" : "○");
var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, currentUser)
.WithDescription(builder.ToString())
.WithDescription(description.ToString())
.WithColour(ColorsList.Default)
.WithFooter(footer.ToString())
.Build();
if (optionsPerList * page - optionsPerList >= AllOptions.Length) {
embed = new EmbedBuilder().WithSmallTitle(Messages.PageNotFound, currentUser)
.WithDescription($"{Messages.PagesAllowed}: {Markdown.Bold(totalPages.ToString())}")
.WithColour(ColorsList.Red)
.Build();
}
return await _feedbackService.SendContextualEmbedResultAsync(embed, ct);
}
}
/// <summary>
/// A slash command that modifies per-guild GuildSettings.