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> <value>Rename members who attempt to hoist themselves</value>
</data> </data>
<data name="Page" xml:space="preserve"> <data name="Page" xml:space="preserve">
<value>page</value> <value>Page</value>
</data> </data>
<data name="PageNotFound" xml:space="preserve"> <data name="PageNotFound" xml:space="preserve">
<value>Page not found!</value> <value>Page not found!</value>
</data> </data>
<data name="PagesAllowed" xml:space="preserve"> <data name="PagesAllowed" xml:space="preserve">
<value>There are total pages</value> <value>There are {0} total pages</value>
</data> </data>
<data name="Next" xml:space="preserve"> <data name="Next" xml:space="preserve">
<value>Next</value> <value>Next</value>

View file

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

View file

@ -568,7 +568,7 @@
<value>если я был бы html, я бы сказал 404</value> <value>если я был бы html, я бы сказал 404</value>
</data> </data>
<data name="PagesAllowed" xml:space="preserve"> <data name="PagesAllowed" xml:space="preserve">
<value>ну а если быть точнее, тут всего страниц</value> <value>ну а если быть точнее, тут всего {0} страниц(-ы)</value>
</data> </data>
<data name="Next" xml:space="preserve"> <data name="Next" xml:space="preserve">
<value>следующее</value> <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) { 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(); var footer = new StringBuilder();
const int optionsPerList = 7;
var totalPages = (AllOptions.Length + optionsPerList - 1)/optionsPerList; const int optionsPerPage = 10;
for (var i = optionsPerList * page - optionsPerList; i <= optionsPerList * page - 1; i++) {
try { var totalPages = (AllOptions.Length + optionsPerPage - 1) / optionsPerPage;
builder.AppendLine($"Settings{AllOptions[i].Name}".Localized()) var lastOptionOnPage = Math.Min(optionsPerPage * page, AllOptions.Length);
.Append(Markdown.InlineCode(AllOptions[i].Name)) var firstOptionOnPage = optionsPerPage * page - optionsPerPage;
.Append(": ")
.AppendLine(AllOptions[i].Display(cfg)) if (firstOptionOnPage >= AllOptions.Length) {
.AppendLine(); var embed = new EmbedBuilder().WithSmallTitle(Messages.PageNotFound, currentUser)
} catch { /* hilariously ignored */ } .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) var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, currentUser)
.WithDescription(builder.ToString()) .WithDescription(description.ToString())
.WithColour(ColorsList.Default) .WithColour(ColorsList.Default)
.WithFooter(footer.ToString()) .WithFooter(footer.ToString())
.Build(); .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); return await _feedbackService.SendContextualEmbedResultAsync(embed, ct);
} }
}
/// <summary> /// <summary>
/// A slash command that modifies per-guild GuildSettings. /// A slash command that modifies per-guild GuildSettings.