From 12557ea6099b5f6a7257095be2764038227ba6cd Mon Sep 17 00:00:00 2001 From: Emotion Date: Wed, 23 Aug 2023 23:22:42 +1200 Subject: [PATCH] Updated a few things Signed-off-by: Emotion --- .../Services/IRemindService.cs | 5 ++- src/Ellie.Bot.Db/Models/Reminder.cs | 7 ++++ .../Gambling/Gambling.cs | 40 ++++++++++++------- .../Gambling/GamblingService.cs | 7 ++++ src/Ellie/data/bot.yml | 2 +- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/Ellie.Bot.Common/Services/IRemindService.cs b/src/Ellie.Bot.Common/Services/IRemindService.cs index a4c3114..dd90328 100644 --- a/src/Ellie.Bot.Common/Services/IRemindService.cs +++ b/src/Ellie.Bot.Common/Services/IRemindService.cs @@ -1,4 +1,6 @@ #nullable disable +using Ellie.Services.Database.Models; + namespace Ellie.Modules.Utility.Services; public interface IRemindService @@ -8,5 +10,6 @@ public interface IRemindService ulong? guildId, bool isPrivate, DateTime time, - string message); + string message, + ReminderType reminderType); } \ No newline at end of file diff --git a/src/Ellie.Bot.Db/Models/Reminder.cs b/src/Ellie.Bot.Db/Models/Reminder.cs index e497b23..897fbb8 100644 --- a/src/Ellie.Bot.Db/Models/Reminder.cs +++ b/src/Ellie.Bot.Db/Models/Reminder.cs @@ -9,4 +9,11 @@ public class Reminder : DbEntity public ulong UserId { get; set; } public string Message { get; set; } public bool IsPrivate { get; set; } + public ReminderType Type { get; set; } +} + +public enum ReminderType +{ + User, + Timely } \ No newline at end of file diff --git a/src/Ellie.Bot.Modules.Gambling/Gambling/Gambling.cs b/src/Ellie.Bot.Modules.Gambling/Gambling/Gambling.cs index 141864a..204003b 100644 --- a/src/Ellie.Bot.Modules.Gambling/Gambling/Gambling.cs +++ b/src/Ellie.Bot.Modules.Gambling/Gambling/Gambling.cs @@ -149,10 +149,24 @@ public partial class Gambling : GamblingModule ctx.Guild?.Id, true, when, - GetText(strs.timely_time)); + GetText(strs.timely_time), + ReminderType.Timely); await smc.RespondConfirmAsync(_eb, GetText(strs.remind_timely(tt)), ephemeral: true); } + + private EllieInteraction CreateRemindMeInteraction(int period) + { + return _inter + .Create(ctx.User.Id, + new SimpleInteraction( + new ButtonBuilder( + label: "Remind me", + emote: Emoji.Parse("⏰"), + customId: "timely:remind_me"), + RemindTimelyAction, + DateTime.UtcNow.Add(TimeSpan.FromHours(period)))); + } [Cmd] public async Task Timely() @@ -164,12 +178,20 @@ public partial class Gambling : GamblingModule await ReplyErrorLocalizedAsync(strs.timely_none); return; } + + var inter = CreateRemindMeInteraction(period); if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem) { + // Removes timely button if there is a timely reminder in DB + if (_service.UserHasTimelyReminder(ctx.User.Id)) + { + inter = null; + } + var now = DateTime.UtcNow; var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative); - await ReplyPendingLocalizedAsync(strs.timely_already_claimed(relativeTag)); + await ReplyPendingLocalizedAsync(strs.timely_already_claimed(relativeTag), inter); return; } @@ -179,19 +201,9 @@ public partial class Gambling : GamblingModule await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim")); - var inter = _inter - .Create(ctx.User.Id, - new SimpleInteraction( - new ButtonBuilder( - label: "Remind me", - emote: Emoji.Parse("⏰"), - customId: "timely:remind_me"), - RemindTimelyAction, - DateTime.UtcNow.Add(TimeSpan.FromHours(period)))); - await ReplyConfirmLocalizedAsync(strs.timely(N(val), period), inter); } - + [Cmd] [OwnerOnly] public async Task TimelyReset() @@ -924,7 +936,7 @@ public partial class Gambling : GamblingModule var values = Enum.GetValues() .Select(x => $"`{x}`") .Join(", "); - + await SendConfirmAsync(GetText(strs.available_tests), values); } diff --git a/src/Ellie.Bot.Modules.Gambling/Gambling/GamblingService.cs b/src/Ellie.Bot.Modules.Gambling/Gambling/GamblingService.cs index f6ba92e..9ba2bac 100644 --- a/src/Ellie.Bot.Modules.Gambling/Gambling/GamblingService.cs +++ b/src/Ellie.Bot.Modules.Gambling/Gambling/GamblingService.cs @@ -209,6 +209,13 @@ public class GamblingService : IEService, IReadyExecutor } } + public bool UserHasTimelyReminder(ulong userId) + { + var db = _db.GetDbContext(); + return db.GetTable().Any(x => x.UserId == userId + && x.Type == ReminderType.Timely); + } + public async Task RemoveAllTimelyClaimsAsync() => await _cache.RemoveAsync(_timelyKey); } diff --git a/src/Ellie/data/bot.yml b/src/Ellie/data/bot.yml index 386050b..af4722a 100644 --- a/src/Ellie/data/bot.yml +++ b/src/Ellie/data/bot.yml @@ -63,7 +63,7 @@ helpText: |- "inline": false }, { - "name": "Nadeko Support Server", + "name": "Ellie Support Server", "value": "https://discord.elliebot.net/ ", "inline": true }