Add timely reminder button*

* Add a check in Timely command that removes the reminder button if there already is a timely reminder in DB.
* Add ReminderType in db/models. As well as migrations.
* Set Normal reminders to be of `ReminderType.User`, and Timely reminders to be of `ReminderType.Timely`
This commit is contained in:
Cata
2023-08-20 13:28:16 +00:00
committed by Kwoth
parent 3c3d082112
commit cdf9adc8a4
15 changed files with 10478 additions and 19 deletions

View File

@@ -1,4 +1,6 @@
#nullable disable
using NadekoBot.Services.Database.Models;
namespace NadekoBot.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);
}

View File

@@ -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
}

View File

@@ -149,11 +149,25 @@ public partial class Gambling : GamblingModule<GamblingService>
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 NadekoInteraction 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]
public async Task Timely()
{
@@ -165,11 +179,19 @@ public partial class Gambling : GamblingModule<GamblingService>
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,16 +201,6 @@ public partial class Gambling : GamblingModule<GamblingService>
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);
}

View File

@@ -209,6 +209,13 @@ public class GamblingService : INService, 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()
=> await _cache.RemoveAsync(_timelyKey);
}

View File

@@ -49,7 +49,8 @@ public partial class Utility
if (!await RemindInternal(target,
meorhere == MeOrHere.Me || ctx.Guild is null,
remindData.Time,
remindData.What))
remindData.What,
ReminderType.User))
await ReplyErrorLocalizedAsync(strs.remind_too_long);
}
@@ -73,7 +74,7 @@ public partial class Utility
}
if (!await RemindInternal(channel.Id, false, remindData.Time, remindData.What))
if (!await RemindInternal(channel.Id, false, remindData.Time, remindData.What, ReminderType.User))
await ReplyErrorLocalizedAsync(strs.remind_too_long);
}
@@ -172,7 +173,8 @@ public partial class Utility
ulong targetId,
bool isPrivate,
TimeSpan ts,
string message)
string message,
ReminderType reminderType)
{
var time = DateTime.UtcNow + ts;

View File

@@ -232,7 +232,8 @@ public class RemindService : INService, IReadyExecutor, IRemindService
ulong? guildId,
bool isPrivate,
DateTime time,
string message)
string message,
ReminderType reminderType)
{
var rem = new Reminder
{
@@ -242,6 +243,7 @@ public class RemindService : INService, IReadyExecutor, IRemindService
IsPrivate = isPrivate,
When = time,
Message = message,
Type = reminderType
};
await using var ctx = _db.GetDbContext();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Db.Migrations.Mysql
{
/// <inheritdoc />
public partial class timelyremindertype : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "type",
table: "reminders",
type: "int",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "type",
table: "reminders");
}
}
}

View File

@@ -2112,6 +2112,10 @@ namespace NadekoBot.Db.Migrations.Mysql
.HasColumnType("bigint unsigned")
.HasColumnName("serverid");
b.Property<int>("Type")
.HasColumnType("int")
.HasColumnName("type");
b.Property<ulong>("UserId")
.HasColumnType("bigint unsigned")
.HasColumnName("userid");

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Db.Migrations
{
/// <inheritdoc />
public partial class timelyremindertype : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "type",
table: "reminders",
type: "integer",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "type",
table: "reminders");
}
}
}

View File

@@ -17,7 +17,7 @@ namespace NadekoBot.Db.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.7")
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -2212,6 +2212,10 @@ namespace NadekoBot.Db.Migrations
.HasColumnType("numeric(20,0)")
.HasColumnName("serverid");
b.Property<int>("Type")
.HasColumnType("integer")
.HasColumnName("type");
b.Property<decimal>("UserId")
.HasColumnType("numeric(20,0)")
.HasColumnName("userid");

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NadekoBot.Db.Migrations.Sqlite
{
/// <inheritdoc />
public partial class timelyremindertype : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Type",
table: "Reminders",
type: "INTEGER",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Type",
table: "Reminders");
}
}
}

View File

@@ -1648,6 +1648,9 @@ namespace NadekoBot.Db.Migrations.Sqlite
b.Property<ulong>("ServerId")
.HasColumnType("INTEGER");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<ulong>("UserId")
.HasColumnType("INTEGER");