mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-01 11:39:55 +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 ->

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:
parent
397bb83ba8
commit
05fd343dce
6 changed files with 109 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
30
src/Messages.Designer.cs
generated
30
src/Messages.Designer.cs
generated
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue