diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 56779ccbb..7a4effbf9 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -1,7 +1,6 @@ #nullable disable using LinqToDB; using LinqToDB.EntityFrameworkCore; -using NadekoBot.Db; using NadekoBot.Db.Models; using NadekoBot.Modules.Gambling.Bank; using NadekoBot.Modules.Gambling.Common; @@ -149,6 +148,7 @@ public partial class Gambling : GamblingModule await smc.RespondConfirmAsync(_sender, GetText(strs.remind_timely(tt)), ephemeral: true); } + // Creates timely reminder button, parameter in hours. private NadekoInteractionBase CreateRemindMeInteraction(int period) => _inter .Create(ctx.User.Id, @@ -158,6 +158,17 @@ public partial class Gambling : GamblingModule customId: "timely:remind_me"), (smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromHours(period))) ); + + // Creates timely reminder button, parameter in milliseconds. + private NadekoInteractionBase CreateRemindMeInteraction(double ms) + => _inter + .Create(ctx.User.Id, + new ButtonBuilder( + label: "Remind me", + emote: Emoji.Parse("⏰"), + customId: "timely:remind_me"), + (smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromMilliseconds(ms))) + ); [Cmd] public async Task Timely() @@ -170,22 +181,26 @@ public partial class Gambling : GamblingModule return; } - var inter = CreateRemindMeInteraction(period); - - if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem) + if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder) { + // Get correct time form remainder + var interaction = CreateRemindMeInteraction(remainder.TotalMilliseconds); + // Removes timely button if there is a timely reminder in DB if (_service.UserHasTimelyReminder(ctx.User.Id)) { - inter = null; + interaction = null; } var now = DateTime.UtcNow; - var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative); - await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(inter).SendAsync(); + var relativeTag = TimestampTag.FromDateTime(now.Add(remainder), TimestampTagStyles.Relative); + await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(interaction).SendAsync(); return; } + var inter = CreateRemindMeInteraction(period); + + var result = await _ps.TryGetFeatureLimitAsync(_timelyKey, ctx.User.Id, 0); var patron = await _ps.GetPatronAsync(ctx.User.Id);