feat: shard status update, delete old messages when they expire
This commit is contained in:
parent
8e030acaf3
commit
32732d74d0
9 changed files with 302 additions and 17 deletions
|
|
@ -18,22 +18,25 @@ public class Guild
|
|||
public bool IsSystemBanned(PluralkitApiService.PkSystem system) =>
|
||||
BannedSystems.Contains(system.Id) || BannedSystems.Contains(system.Uuid.ToString());
|
||||
|
||||
public bool IsMessageIgnored(Snowflake channelId, Snowflake userId)
|
||||
public bool IsMessageIgnored(Snowflake channelId, Snowflake? userId)
|
||||
{
|
||||
if (
|
||||
Channels is { MessageDelete: 0, MessageUpdate: 0, MessageDeleteBulk: 0 }
|
||||
|| Channels.IgnoredChannels.Contains(channelId.ToUlong())
|
||||
|| Channels.IgnoredUsers.Contains(userId.ToUlong())
|
||||
|| (userId != null && Channels.IgnoredUsers.Contains(userId.Value.ToUlong()))
|
||||
)
|
||||
return true;
|
||||
|
||||
if (userId == null)
|
||||
return false;
|
||||
|
||||
if (
|
||||
Channels.IgnoredUsersPerChannel.TryGetValue(
|
||||
channelId.ToUlong(),
|
||||
out var thisChannelIgnoredUsers
|
||||
)
|
||||
)
|
||||
return thisChannelIgnoredUsers.Contains(userId.ToUlong());
|
||||
return thisChannelIgnoredUsers.Contains(userId.Value.ToUlong());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using System.Text.Json;
|
||||
using Catalogger.Backend.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Remora.Discord.API;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||
using Remora.Rest.Core;
|
||||
using DbMessage = Catalogger.Backend.Database.Models.Message;
|
||||
|
||||
namespace Catalogger.Backend.Database.Queries;
|
||||
|
|
@ -181,6 +183,21 @@ public class MessageRepository(
|
|||
return await db.IgnoredMessages.FirstOrDefaultAsync(m => m.Id == id, ct) != null;
|
||||
}
|
||||
|
||||
public const int MaxMessageAgeDays = 15;
|
||||
|
||||
public async Task<(int Messages, int IgnoredMessages)> DeleteExpiredMessagesAsync()
|
||||
{
|
||||
var cutoff = DateTimeOffset.UtcNow - TimeSpan.FromDays(MaxMessageAgeDays);
|
||||
var cutoffId = Snowflake.CreateTimestampSnowflake(cutoff, Constants.DiscordEpoch);
|
||||
|
||||
var msgCount = await db.Messages.Where(m => m.Id < cutoffId.Value).ExecuteDeleteAsync();
|
||||
var ignoredMsgCount = await db
|
||||
.IgnoredMessages.Where(m => m.Id < cutoffId.Value)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
return (msgCount, ignoredMsgCount);
|
||||
}
|
||||
|
||||
public record Message(
|
||||
ulong Id,
|
||||
ulong? OriginalId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue