Updated a few things
Signed-off-by: Emotion <emotion@emotionchild.com>
This commit is contained in:
parent
218672665c
commit
12557ea609
5 changed files with 45 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
using Ellie.Services.Database.Models;
|
||||||
|
|
||||||
namespace Ellie.Modules.Utility.Services;
|
namespace Ellie.Modules.Utility.Services;
|
||||||
|
|
||||||
public interface IRemindService
|
public interface IRemindService
|
||||||
|
@ -8,5 +10,6 @@ public interface IRemindService
|
||||||
ulong? guildId,
|
ulong? guildId,
|
||||||
bool isPrivate,
|
bool isPrivate,
|
||||||
DateTime time,
|
DateTime time,
|
||||||
string message);
|
string message,
|
||||||
|
ReminderType reminderType);
|
||||||
}
|
}
|
|
@ -9,4 +9,11 @@ public class Reminder : DbEntity
|
||||||
public ulong UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
public bool IsPrivate { get; set; }
|
public bool IsPrivate { get; set; }
|
||||||
|
public ReminderType Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ReminderType
|
||||||
|
{
|
||||||
|
User,
|
||||||
|
Timely
|
||||||
}
|
}
|
|
@ -149,10 +149,24 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
ctx.Guild?.Id,
|
ctx.Guild?.Id,
|
||||||
true,
|
true,
|
||||||
when,
|
when,
|
||||||
GetText(strs.timely_time));
|
GetText(strs.timely_time),
|
||||||
|
ReminderType.Timely);
|
||||||
|
|
||||||
await smc.RespondConfirmAsync(_eb, GetText(strs.remind_timely(tt)), ephemeral: true);
|
await smc.RespondConfirmAsync(_eb, GetText(strs.remind_timely(tt)), ephemeral: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EllieInteraction CreateRemindMeInteraction(int period)
|
||||||
|
{
|
||||||
|
return _inter
|
||||||
|
.Create(ctx.User.Id,
|
||||||
|
new SimpleInteraction<DateTime>(
|
||||||
|
new ButtonBuilder(
|
||||||
|
label: "Remind me",
|
||||||
|
emote: Emoji.Parse("⏰"),
|
||||||
|
customId: "timely:remind_me"),
|
||||||
|
RemindTimelyAction,
|
||||||
|
DateTime.UtcNow.Add(TimeSpan.FromHours(period))));
|
||||||
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
public async Task Timely()
|
public async Task Timely()
|
||||||
|
@ -164,12 +178,20 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
await ReplyErrorLocalizedAsync(strs.timely_none);
|
await ReplyErrorLocalizedAsync(strs.timely_none);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var inter = CreateRemindMeInteraction(period);
|
||||||
|
|
||||||
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem)
|
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 now = DateTime.UtcNow;
|
||||||
var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,19 +201,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
|
|
||||||
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
|
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
|
||||||
|
|
||||||
var inter = _inter
|
|
||||||
.Create(ctx.User.Id,
|
|
||||||
new SimpleInteraction<DateTime>(
|
|
||||||
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);
|
await ReplyConfirmLocalizedAsync(strs.timely(N(val), period), inter);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task TimelyReset()
|
public async Task TimelyReset()
|
||||||
|
@ -924,7 +936,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
var values = Enum.GetValues<GambleTestTarget>()
|
var values = Enum.GetValues<GambleTestTarget>()
|
||||||
.Select(x => $"`{x}`")
|
.Select(x => $"`{x}`")
|
||||||
.Join(", ");
|
.Join(", ");
|
||||||
|
|
||||||
await SendConfirmAsync(GetText(strs.available_tests), values);
|
await SendConfirmAsync(GetText(strs.available_tests), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,13 @@ public class GamblingService : IEService, IReadyExecutor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool UserHasTimelyReminder(ulong userId)
|
||||||
|
{
|
||||||
|
var db = _db.GetDbContext();
|
||||||
|
return db.GetTable<Reminder>().Any(x => x.UserId == userId
|
||||||
|
&& x.Type == ReminderType.Timely);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task RemoveAllTimelyClaimsAsync()
|
public async Task RemoveAllTimelyClaimsAsync()
|
||||||
=> await _cache.RemoveAsync(_timelyKey);
|
=> await _cache.RemoveAsync(_timelyKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ helpText: |-
|
||||||
"inline": false
|
"inline": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Nadeko Support Server",
|
"name": "Ellie Support Server",
|
||||||
"value": "https://discord.elliebot.net/ ",
|
"value": "https://discord.elliebot.net/ ",
|
||||||
"inline": true
|
"inline": true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue