Skip to content

Commit

Permalink
Drop reminder type
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed Oct 14, 2024
1 parent 4dd8f2b commit 148268a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Commands/Common/ReminderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public async ValueTask SetAsync(CommandContext context, string expiresAt, [Remai
}

ReminderModel reminderModel = context.Channel is DiscordThreadChannel threadChannel
? await ReminderModel.CreateAsync(Ulid.NewUlid(now), context.User.Id, context.Guild?.Id ?? 0, threadChannel.ParentId.GetValueOrDefault(), threadChannel.Id, messageId, expires, ReminderType.OneTime, TimeSpan.Zero, content)
: await ReminderModel.CreateAsync(Ulid.NewUlid(now), context.User.Id, context.Guild?.Id ?? 0, context.Channel.Id, 0, messageId, expires, ReminderType.OneTime, TimeSpan.Zero, content);
? await ReminderModel.CreateAsync(Ulid.NewUlid(now), context.User.Id, context.Guild?.Id ?? 0, threadChannel.ParentId.GetValueOrDefault(), threadChannel.Id, messageId, expires, TimeSpan.Zero, content)
: await ReminderModel.CreateAsync(Ulid.NewUlid(now), context.User.Id, context.Guild?.Id ?? 0, context.Channel.Id, 0, messageId, expires, TimeSpan.Zero, content);

_reminderManager.AddToCache(reminderModel.Id, reminderModel.ExpiresAt);
await context.RespondAsync($"Reminder set! I'll ping you {Formatter.Timestamp(expires - now)}.");
Expand Down
16 changes: 5 additions & 11 deletions src/Database/Models/ReminderModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public sealed record ReminderModel : IExpirableModel<ReminderModel, Ulid>
public required ulong ThreadId { get; init; }
public required ulong MessageId { get; init; }
public required DateTimeOffset ExpiresAt { get; init; }
public required ReminderType Type { get; init; }
public required TimeSpan Interval { get; init; }
public required string Content { get; init; }

Expand All @@ -87,20 +86,18 @@ static ReminderModel()
thread_id BIGINT NOT NULL,
message_id BIGINT NOT NULL,
expires_at TIMESTAMPTZ NOT NULL,
type SMALLINT NOT NULL,
interval INTERVAL NOT NULL,
content TEXT NOT NULL
);");

_createReminder = new NpgsqlCommand(@"INSERT INTO reminders (id, user_id, guild_id, channel_id, thread_id, message_id, expires_at, type, interval, content) VALUES (@id, @user_id, @guild_id, @channel_id, @thread_id, @message_id, @expires_at, @type, @interval, @content);");
_createReminder = new NpgsqlCommand(@"INSERT INTO reminders (id, user_id, guild_id, channel_id, thread_id, message_id, expires_at, interval, content) VALUES (@id, @user_id, @guild_id, @channel_id, @thread_id, @message_id, @expires_at, @interval, @content);");
_createReminder.Parameters.Add(new NpgsqlParameter("id", NpgsqlTypes.NpgsqlDbType.Text));
_createReminder.Parameters.Add(new NpgsqlParameter("user_id", NpgsqlTypes.NpgsqlDbType.Bigint));
_createReminder.Parameters.Add(new NpgsqlParameter("guild_id", NpgsqlTypes.NpgsqlDbType.Bigint));
_createReminder.Parameters.Add(new NpgsqlParameter("channel_id", NpgsqlTypes.NpgsqlDbType.Bigint));
_createReminder.Parameters.Add(new NpgsqlParameter("thread_id", NpgsqlTypes.NpgsqlDbType.Bigint));
_createReminder.Parameters.Add(new NpgsqlParameter("message_id", NpgsqlTypes.NpgsqlDbType.Bigint));
_createReminder.Parameters.Add(new NpgsqlParameter("expires_at", NpgsqlTypes.NpgsqlDbType.TimestampTz));
_createReminder.Parameters.Add(new NpgsqlParameter("type", NpgsqlTypes.NpgsqlDbType.Smallint));
_createReminder.Parameters.Add(new NpgsqlParameter("interval", NpgsqlTypes.NpgsqlDbType.Interval));
_createReminder.Parameters.Add(new NpgsqlParameter("content", NpgsqlTypes.NpgsqlDbType.Text));

Expand All @@ -115,7 +112,7 @@ content TEXT NOT NULL
_listReminders.Parameters.Add(new NpgsqlParameter("offset", NpgsqlTypes.NpgsqlDbType.Bigint));
}

public static async ValueTask<ReminderModel> CreateAsync(Ulid id, ulong userId, ulong guildId, ulong channelId, ulong threadId, ulong messageId, DateTimeOffset expiresAt, ReminderType type, TimeSpan interval, string content)
public static async ValueTask<ReminderModel> CreateAsync(Ulid id, ulong userId, ulong guildId, ulong channelId, ulong threadId, ulong messageId, DateTimeOffset expiresAt, TimeSpan interval, string content)
{
await _semaphore.WaitAsync();
try
Expand All @@ -127,7 +124,6 @@ public static async ValueTask<ReminderModel> CreateAsync(Ulid id, ulong userId,
_createReminder.Parameters["thread_id"].Value = (long)threadId;
_createReminder.Parameters["message_id"].Value = (long)messageId;
_createReminder.Parameters["expires_at"].Value = expiresAt.UtcDateTime;
_createReminder.Parameters["type"].Value = (short)type;
_createReminder.Parameters["interval"].Value = interval;
_createReminder.Parameters["content"].Value = content;
await _createReminder.ExecuteNonQueryAsync();
Expand All @@ -140,7 +136,6 @@ public static async ValueTask<ReminderModel> CreateAsync(Ulid id, ulong userId,
ThreadId = threadId,
MessageId = messageId,
ExpiresAt = expiresAt,
Type = type,
Interval = interval,
Content = content
};
Expand Down Expand Up @@ -230,10 +225,9 @@ public static async ValueTask PrepareAsync(NpgsqlConnection connection)
ChannelId = (ulong)reader.GetInt64(3),
MessageId = (ulong)reader.GetInt64(4),
ExpiresAt = (DateTimeOffset)reader.GetDateTime(5),
Type = (ReminderType)reader.GetByte(6),
Interval = reader.GetTimeSpan(7),
Content = reader.GetString(8),
ThreadId = (ulong)reader.GetInt64(9),
Interval = reader.GetTimeSpan(6),
Content = reader.GetString(7),
ThreadId = (ulong)reader.GetInt64(8),
}) is not null;

public static async ValueTask<bool> ExpireAsync(ReminderModel expirable, IServiceProvider serviceProvider)
Expand Down
15 changes: 0 additions & 15 deletions src/Database/Models/ReminderType.cs

This file was deleted.

0 comments on commit 148268a

Please sign in to comment.