Nuked humanizer. Some of the strings might look worse but the output directory will no longer look terrible. Added stats for todo list command

This commit is contained in:
Kwoth
2024-05-02 22:14:25 +00:00
parent fc4858830c
commit 3ef05f8aa7
19 changed files with 104 additions and 66 deletions

View File

@@ -344,7 +344,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
return false;
}
if (sr.GetContentLength() > 8.Megabytes().Bytes)
if (sr.GetContentLength() > 8.Megabytes())
{
return false;
}

View File

@@ -1,6 +1,5 @@
#nullable disable
using CommandLine;
using Humanizer.Localisation;
using NadekoBot.Common.TypeReaders.Models;
using NadekoBot.Modules.Administration.Services;
using NadekoBot.Db.Models;
@@ -458,7 +457,7 @@ public partial class Administration
.AddField(GetText(strs.username), user?.ToString() ?? userId.ToString(), true)
.AddField("ID", userId.ToString(), true)
.AddField(GetText(strs.duration),
time.Time.Humanize(3, minUnit: TimeUnit.Minute, culture: Culture),
time.Time.ToPrettyStringHm(),
true);
if (dmFailed)

View File

@@ -396,8 +396,8 @@ public partial class Gambling : GamblingModule<GamblingService>
("rps", _, _) => $"Rock Paper Scissors - {subType}",
(null, _, _) => null,
(_, null, _) => null,
(_, _, ulong userId) => $"{type.Titleize()} - {subType.Titleize()} | [{userId}]",
_ => $"{type.Titleize()} - {subType.Titleize()}"
(_, _, ulong userId) => $"{type} - {subType} | [{userId}]",
_ => $"{type} - {subType}"
};
[Cmd]

View File

@@ -1,5 +1,4 @@
#nullable disable
using Humanizer.Localisation;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.TypeReaders;
using NadekoBot.Db;
@@ -81,7 +80,6 @@ public partial class Permissions
if (--page < 0)
return;
var channel = (ITextChannel)ctx.Channel;
var localSet = _service.GetCommandCooldowns(ctx.Guild.Id);
if (!localSet.Any())
@@ -96,7 +94,7 @@ public partial class Permissions
.Page((items, _) =>
{
var output = items.Select(x =>
$"{Format.Code(x.CommandName)}: {x.Seconds.Seconds().Humanize(maxUnit: TimeUnit.Second, culture: Culture)}");
$"{Format.Code(x.CommandName)}: {x.Seconds}s");
return _sender.CreateEmbed()
.WithOkColor()

View File

@@ -105,10 +105,7 @@ public sealed class DefaultStockDataService : IStockDataService, INService
.ToList();
}
private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture)
{
PrepareHeaderForMatch = args => args.Header.Humanize(LetterCasing.Title)
};
private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture);
public async Task<IReadOnlyCollection<CandleData>> GetCandleDataAsync(string query)
{

View File

@@ -1,9 +1,7 @@
#nullable disable
using Humanizer.Localisation;
using NadekoBot.Db;
using NadekoBot.Modules.Utility.Services;
using NadekoBot.Db.Models;
using System.Resources;
namespace NadekoBot.Modules.Utility;
@@ -118,7 +116,7 @@ public partial class Utility
var diff = when - DateTime.UtcNow;
embed.AddField(
$"#{++i + (page * 10)} {rem.When:HH:mm yyyy-MM-dd} UTC "
+ $"(in {diff.Humanize(2, minUnit: TimeUnit.Minute, culture: Culture)})",
+ $"(in {diff.ToPrettyStringHm()})",
$@"`Target:` {(rem.IsPrivate ? "DM" : "Channel")}
`TargetId:` {rem.ChannelId}
`Message:` {rem.Message?.TrimTo(50)}");
@@ -212,7 +210,7 @@ public partial class Utility
.Confirm($"\u23f0 {GetText(strs.remind(
Format.Bold(!isPrivate ? $"<#{targetId}>" : ctx.User.Username),
Format.Bold(message),
ts.Humanize(3, minUnit: TimeUnit.Second, culture: Culture),
ts.ToPrettyStringHm(),
gTime,
gTime))}")
.SendAsync();

View File

@@ -11,8 +11,7 @@ namespace NadekoBot.Modules.Utility.Services;
public class RemindService : INService, IReadyExecutor, IRemindService
{
private readonly Regex _regex =
new(
@"^(?:(?:at|on(?:\sthe)?)?\s*(?<date>(?:\d{2}:\d{2}\s)?\d{1,2}\.\d{1,2}(?:\.\d{2,4})?)|(?:in\s?)?\s*(?:(?<mo>\d+)(?:\s?(?:months?|mos?),?))?(?:(?:\sand\s|\s*)?(?<w>\d+)(?:\s?(?:weeks?|w),?))?(?:(?:\sand\s|\s*)?(?<d>\d+)(?:\s?(?:days?|d),?))?(?:(?:\sand\s|\s*)?(?<h>\d+)(?:\s?(?:hours?|h),?))?(?:(?:\sand\s|\s*)?(?<m>\d+)(?:\s?(?:minutes?|mins?|m),?))?)\s+(?:to:?\s+)?(?<what>(?:\r\n|[\r\n]|.)+)",
new(@"^(?:(?:at|on(?:\sthe)?)?\s*(?<date>(?:\d{2}:\d{2}\s)?\d{1,2}\.\d{1,2}(?:\.\d{2,4})?)|(?:in\s?)?\s*(?:(?<mo>\d+)(?:\s?(?:months?|mos?),?))?(?:(?:\sand\s|\s*)?(?<w>\d+)(?:\s?(?:weeks?|w),?))?(?:(?:\sand\s|\s*)?(?<d>\d+)(?:\s?(?:days?|d),?))?(?:(?:\sand\s|\s*)?(?<h>\d+)(?:\s?(?:hours?|h),?))?(?:(?:\sand\s|\s*)?(?<m>\d+)(?:\s?(?:minutes?|mins?|m),?))?)\s+(?:to:?\s+)?(?<what>(?:\r\n|[\r\n]|.)+)",
RegexOptions.Compiled | RegexOptions.Multiline);
private readonly DiscordSocketClient _client;
@@ -62,7 +61,7 @@ public class RemindService : INService, IReadyExecutor, IRemindService
Log.Information("Executing {ReminderCount} reminders", reminders.Count);
// make groups of 5, with 1.5 second inbetween each one to ensure against ratelimits
// make groups of 5, with 1.5 second in between each one to ensure against ratelimits
foreach (var group in reminders.Chunk(5))
{
var executedReminders = group.ToList();

View File

@@ -44,7 +44,26 @@ public partial class Utility
return;
}
await ShowTodosAsync(todos);
await Response()
.Paginated()
.Items(todos)
.PageSize(9)
.AddFooter(false)
.Page((items, _) =>
{
var eb = _sender.CreateEmbed()
.WithOkColor()
.WithTitle(GetText(strs.todo_list));
ShowTodoItem(items, eb);
eb.WithFooter(GetText(strs.todo_stats(todos.Length,
todos.Count(x => x.IsDone),
todos.Count(x => !x.IsDone))));
return eb;
})
.SendAsync();
}
@@ -81,23 +100,6 @@ public partial class Utility
}
private Task ShowTodosAsync(TodoModel[] todos)
=> Response()
.Paginated()
.Items(todos)
.PageSize(9)
.Page((items, _) =>
{
var eb = _sender.CreateEmbed()
.WithOkColor()
.WithTitle(GetText(strs.todo_list));
ShowTodoItem(items, eb);
return eb;
})
.SendAsync();
private static void ShowTodoItem(IReadOnlyCollection<TodoModel> todos, EmbedBuilder eb)
{
var sb = new StringBuilder();
@@ -155,8 +157,8 @@ public partial class Utility
.Page((items, _) =>
{
var eb = _sender.CreateEmbed()
.WithTitle(GetText(strs.todo_archive_list))
.WithOkColor();
.WithTitle(GetText(strs.todo_archive_list))
.WithOkColor();
foreach (var archivedList in items)
{
@@ -182,14 +184,19 @@ public partial class Utility
.Paginated()
.Items(list.Items)
.PageSize(9)
.AddFooter(false)
.Page((items, _) =>
{
var eb = _sender.CreateEmbed()
.WithOkColor()
.WithTitle(GetText(strs.todo_list));
.WithOkColor()
.WithTitle(GetText(strs.todo_archived_list));
ShowTodoItem(items, eb);
eb.WithFooter(GetText(strs.todo_stats(list.Items.Count,
list.Items.Count(x => x.IsDone),
list.Items.Count(x => !x.IsDone))));
return eb;
})
.SendAsync();

View File

@@ -110,7 +110,7 @@ public class ClubService : INService, IClubService
if (!temp.IsImage())
return SetClubIconResult.InvalidFileType;
if (temp.GetContentLength() > 5.Megabytes().Bytes)
if (temp.GetContentLength() > 5.Megabytes())
return SetClubIconResult.TooLarge;
}

View File

@@ -127,7 +127,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
{
_ = Task.Run(() => _levelUpQueue.RunAsync());
using var timer = new PeriodicTimer(5.Seconds());
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(5));
while (await timer.WaitForNextTickAsync())
{
await UpdateXp();
@@ -1364,7 +1364,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
using (var http = _httpFactory.CreateClient())
using (var temp = await http.GetAsync(imgUrl, HttpCompletionOption.ResponseHeadersRead))
{
if (!temp.IsImage() || temp.GetContentLength() > 11.Megabytes().Bytes)
if (!temp.IsImage() || temp.GetContentLength() > 11 * 1024 * 1024)
return;
var imgData = await temp.Content.ReadAsByteArrayAsync();