mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
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:
@@ -1,4 +1,6 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Utility.Services;
|
namespace NadekoBot.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,11 +149,25 @@ 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 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]
|
[Cmd]
|
||||||
public async Task Timely()
|
public async Task Timely()
|
||||||
{
|
{
|
||||||
@@ -165,11 +179,19 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
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,16 +201,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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()
|
public async Task RemoveAllTimelyClaimsAsync()
|
||||||
=> await _cache.RemoveAsync(_timelyKey);
|
=> await _cache.RemoveAsync(_timelyKey);
|
||||||
}
|
}
|
@@ -49,7 +49,8 @@ public partial class Utility
|
|||||||
if (!await RemindInternal(target,
|
if (!await RemindInternal(target,
|
||||||
meorhere == MeOrHere.Me || ctx.Guild is null,
|
meorhere == MeOrHere.Me || ctx.Guild is null,
|
||||||
remindData.Time,
|
remindData.Time,
|
||||||
remindData.What))
|
remindData.What,
|
||||||
|
ReminderType.User))
|
||||||
await ReplyErrorLocalizedAsync(strs.remind_too_long);
|
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);
|
await ReplyErrorLocalizedAsync(strs.remind_too_long);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +173,8 @@ public partial class Utility
|
|||||||
ulong targetId,
|
ulong targetId,
|
||||||
bool isPrivate,
|
bool isPrivate,
|
||||||
TimeSpan ts,
|
TimeSpan ts,
|
||||||
string message)
|
string message,
|
||||||
|
ReminderType reminderType)
|
||||||
{
|
{
|
||||||
var time = DateTime.UtcNow + ts;
|
var time = DateTime.UtcNow + ts;
|
||||||
|
|
||||||
|
@@ -232,7 +232,8 @@ public class RemindService : INService, IReadyExecutor, IRemindService
|
|||||||
ulong? guildId,
|
ulong? guildId,
|
||||||
bool isPrivate,
|
bool isPrivate,
|
||||||
DateTime time,
|
DateTime time,
|
||||||
string message)
|
string message,
|
||||||
|
ReminderType reminderType)
|
||||||
{
|
{
|
||||||
var rem = new Reminder
|
var rem = new Reminder
|
||||||
{
|
{
|
||||||
@@ -242,6 +243,7 @@ public class RemindService : INService, IReadyExecutor, IRemindService
|
|||||||
IsPrivate = isPrivate,
|
IsPrivate = isPrivate,
|
||||||
When = time,
|
When = time,
|
||||||
Message = message,
|
Message = message,
|
||||||
|
Type = reminderType
|
||||||
};
|
};
|
||||||
|
|
||||||
await using var ctx = _db.GetDbContext();
|
await using var ctx = _db.GetDbContext();
|
||||||
|
3633
src/NadekoBot/Migrations/Mysql/20230813113816_timely-reminder-type.Designer.cs
generated
Normal file
3633
src/NadekoBot/Migrations/Mysql/20230813113816_timely-reminder-type.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -2112,6 +2112,10 @@ namespace NadekoBot.Db.Migrations.Mysql
|
|||||||
.HasColumnType("bigint unsigned")
|
.HasColumnType("bigint unsigned")
|
||||||
.HasColumnName("serverid");
|
.HasColumnName("serverid");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasColumnName("type");
|
||||||
|
|
||||||
b.Property<ulong>("UserId")
|
b.Property<ulong>("UserId")
|
||||||
.HasColumnType("bigint unsigned")
|
.HasColumnType("bigint unsigned")
|
||||||
.HasColumnName("userid");
|
.HasColumnName("userid");
|
||||||
|
3781
src/NadekoBot/Migrations/Postgresql/20230813113832_timely-reminder-type.Designer.cs
generated
Normal file
3781
src/NadekoBot/Migrations/Postgresql/20230813113832_timely-reminder-type.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -17,7 +17,7 @@ namespace NadekoBot.Db.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "6.0.7")
|
.HasAnnotation("ProductVersion", "7.0.4")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
@@ -2212,6 +2212,10 @@ namespace NadekoBot.Db.Migrations
|
|||||||
.HasColumnType("numeric(20,0)")
|
.HasColumnType("numeric(20,0)")
|
||||||
.HasColumnName("serverid");
|
.HasColumnName("serverid");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("type");
|
||||||
|
|
||||||
b.Property<decimal>("UserId")
|
b.Property<decimal>("UserId")
|
||||||
.HasColumnType("numeric(20,0)")
|
.HasColumnType("numeric(20,0)")
|
||||||
.HasColumnName("userid");
|
.HasColumnName("userid");
|
||||||
|
2914
src/NadekoBot/Migrations/Sqlite/20230813110732_timely-reminder-type.Designer.cs
generated
Normal file
2914
src/NadekoBot/Migrations/Sqlite/20230813110732_timely-reminder-type.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1648,6 +1648,9 @@ namespace NadekoBot.Db.Migrations.Sqlite
|
|||||||
b.Property<ulong>("ServerId")
|
b.Property<ulong>("ServerId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<ulong>("UserId")
|
b.Property<ulong>("UserId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user