Skip to content

Commit

Permalink
Migrate linePardoned to Set
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Feb 22, 2025
1 parent add4e9d commit 716ee70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ Program.cfgjson.GitListDirectory is not null

string reason = "Too many lines in a single message";

if (!Program.db.HashExists("linePardoned", message.Author.Id.ToString()))
if (!Program.db.SetContains("linePardoned", message.Author.Id.ToString()))
{
await Program.db.HashSetAsync("linePardoned", member.Id.ToString(), false);
await Program.db.SetAddAsync("linePardoned", member.Id.ToString());
string output;
if (wasAutoModBlock)
output = $"{Program.cfgjson.Emoji.Information} {message.Author.Mention}, your message contained too many lines.\n" +
Expand Down
3 changes: 2 additions & 1 deletion Events/ReadyEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ public static async Task OnStartup(DiscordClient client)
try
{
await Migrations.JoinwatchMigration.MigrateJoinwatchesToNotesAsync();
await Migrations.LinePardonMigrations.MigrateLinePardeonToSetAsync();
}
catch (Exception ex)
{
client.Logger.LogError(ex, "Failed to migrate joinwatches to notes!");
client.Logger.LogError(ex, "Failed to run migrations!");
}

client.Logger.LogInformation(CliptokEventID, "Startup event complete, logged in as {user}", $"{DiscordHelpers.UniqueUsername(client.CurrentUser)}");
Expand Down
23 changes: 23 additions & 0 deletions Migrations/LinePardonMigrations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Cliptok.Migrations
{
class LinePardonMigrations
{
public static async Task MigrateLinePardeonToSetAsync()
{
if (!Program.db.KeyExists("linePardoned") || Program.db.KeyType("linePardoned") == RedisType.Set)
return;

// archive old data
await Program.db.KeyRenameAsync("linePardoned", "linePardonedOld");

// migrate to set
var linePardonList = await Program.db.HashGetAllAsync("linePardonedOld");
foreach (var line in linePardonList)
{
await Program.db.SetAddAsync("linePardoned", line.Name);
}

Program.discord.Logger.LogInformation(Program.CliptokEventID, "Successfully migrated {count} line pardons to set.", linePardonList.Length);
}
}
}

0 comments on commit 716ee70

Please sign in to comment.