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

Improved /settingslist + fixed /settings pt.1 (#65)

This PR is mainly aimed at improving /settingslist and fixing /settings

List of things to do before merging:
- [x] #62
- [x] Add the pages feature to /settingslist
- [x] Add bullets like these ->
![](https://github.com/TeamOctolings/Boyfriend/assets/95250141/fdf1a3b8-bb64-473d-9f57-bc6e34812811)

And since the development has already been taking more than 2 days, I
suggest splitting the PR into 2 parts.

List of other things that will be in the future PR:
- mctaylors#1
- Fix bot not answering when an invalid setting is specified in
/settings
- Options list for /settings

---------

Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
This commit is contained in:
Macintxsh 2023-07-25 17:53:11 +03:00 committed by GitHub
parent 397bb83ba8
commit 05fd343dce
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 15 deletions

View file

@ -168,7 +168,7 @@
<data name="CurrentSettings" xml:space="preserve">
<value>Current settings:</value>
</data>
<data name="SettingsLang" xml:space="preserve">
<data name="SettingsLanguage" xml:space="preserve">
<value>Language</value>
</data>
<data name="SettingsPrefix" xml:space="preserve">
@ -561,4 +561,19 @@
<data name="SettingsRenameHoistedUsers" xml:space="preserve">
<value>Rename members who attempt to hoist themselves</value>
</data>
<data name="Page" xml:space="preserve">
<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>
</data>
<data name="Next" xml:space="preserve">
<value>Next</value>
</data>
<data name="Previous" xml:space="preserve">
<value>Previous</value>
</data>
</root>

View file

@ -165,7 +165,7 @@
<data name="CurrentSettings" xml:space="preserve">
<value>Текущие настройки:</value>
</data>
<data name="SettingsLang" xml:space="preserve">
<data name="SettingsLanguage" xml:space="preserve">
<value>Язык</value>
</data>
<data name="SettingsPrefix" xml:space="preserve">
@ -433,7 +433,7 @@
<value>Я не смог найти этого пользователя ни в одном из серверов, в которых я есть. Проверь правильность ID и нахождение пользователя на этом сервере максимум 30 дней назад</value>
</data>
<data name="SettingsDefaultRole" xml:space="preserve">
<value>Общая роль</value>
<value>Роль по умолчанию</value>
</data>
<data name="CommandDescriptionRemind" xml:space="preserve">
<value>Добавляет напоминание</value>
@ -561,4 +561,19 @@
<data name="SettingsRenameHoistedUsers" xml:space="preserve">
<value>Переименовывать участников, которые пытаются поднять себя</value>
</data>
<data name="Page" xml:space="preserve">
<value>страница</value>
</data>
<data name="PageNotFound" xml:space="preserve">
<value>Страница не найдена!</value>
</data>
<data name="PagesAllowed" xml:space="preserve">
<value>Всего страниц существует</value>
</data>
<data name="Next" xml:space="preserve">
<value>Далее</value>
</data>
<data name="Previous" xml:space="preserve">
<value>Назад</value>
</data>
</root>

View file

@ -168,7 +168,7 @@
<data name="CurrentSettings" xml:space="preserve">
<value>настройки:</value>
</data>
<data name="SettingsLang" xml:space="preserve">
<data name="SettingsLanguage" xml:space="preserve">
<value>язык</value>
</data>
<data name="SettingsPrefix" xml:space="preserve">
@ -561,4 +561,19 @@
<data name="SettingsRenameHoistedUsers" xml:space="preserve">
<value>переобувать шизоидов пытающихся поднять себя в табе</value>
</data>
<data name="Page" xml:space="preserve">
<value>это страница</value>
</data>
<data name="PageNotFound" xml:space="preserve">
<value>если я был бы html, я бы сказал 404</value>
</data>
<data name="PagesAllowed" xml:space="preserve">
<value>ну а если быть точнее, тут всего страниц</value>
</data>
<data name="Next" xml:space="preserve">
<value>следующее</value>
</data>
<data name="Previous" xml:space="preserve">
<value>предыдущее</value>
</data>
</root>

View file

@ -68,7 +68,8 @@ public class SettingsCommandGroup : CommandGroup {
[RequireDiscordPermission(DiscordPermission.ManageGuild)]
[Description("Shows settings list for this server")]
[UsedImplicitly]
public async Task<Result> ExecuteSettingsListAsync() {
public async Task<Result> ExecuteSettingsListAsync(
[Description("Settings list page")] int page) {
if (!_context.TryGetContextIDs(out var guildId, out _, out _))
return Result.FromError(
new ArgumentNullError(nameof(_context), "Unable to retrieve necessary IDs from command context"));
@ -80,23 +81,40 @@ public class SettingsCommandGroup : CommandGroup {
var cfg = await _dataService.GetSettings(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(cfg);
return await SendSettingsListAsync(cfg, currentUser, CancellationToken);
return await SendSettingsListAsync(cfg, currentUser, page, CancellationToken);
}
private async Task<Result> SendSettingsListAsync(JsonNode cfg, IUser currentUser, CancellationToken ct = default) {
private async Task<Result> SendSettingsListAsync(JsonNode cfg, IUser currentUser, int page, CancellationToken ct = default) {
var builder = new StringBuilder();
foreach (var option in AllOptions) {
builder.Append(Markdown.InlineCode(option.Name))
.Append(": ");
builder.AppendLine(option.Display(cfg));
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 ? "●" : "○");
var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, currentUser)
.WithDescription(builder.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);
}

View file

@ -19,12 +19,13 @@ public class BoolOption : Option<bool> {
}
private static bool TryParseBool(string from, out bool value) {
from = from.ToLower();
value = false;
switch (from) {
case "1" or "y" or "yes" or "д" or "да":
case "true" or "1" or "y" or "yes" or "д" or "да":
value = true;
return true;
case "0" or "n" or "no" or "н" or "не" or "нет":
case "false" or "0" or "n" or "no" or "н" or "не" or "нет" or "нъет":
value = false;
return true;
default:

View file

@ -947,5 +947,35 @@ namespace Boyfriend {
return ResourceManager.GetString("SettingIsNow", resourceCulture);
}
}
internal static string Page {
get {
return ResourceManager.GetString("Page", resourceCulture);
}
}
internal static string PageNotFound {
get {
return ResourceManager.GetString("PageNotFound", resourceCulture);
}
}
internal static string PagesAllowed {
get {
return ResourceManager.GetString("PagesAllowed", resourceCulture);
}
}
internal static string Next {
get {
return ResourceManager.GetString("Next", resourceCulture);
}
}
internal static string Previous {
get {
return ResourceManager.GetString("Previous", resourceCulture);
}
}
}
}