mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
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:
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user