mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Merge branch 'v5' into 'v5'
Fix for timely reminder text See merge request Kwoth/nadekobot!332
This commit is contained in:
@@ -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<GamblingService>
|
||||
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<GamblingService>
|
||||
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<GamblingService>
|
||||
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);
|
||||
|
||||
|
Reference in New Issue
Block a user