feat: role delete logging, used invite logging, also some random changes
This commit is contained in:
parent
4f54077c68
commit
c906a4d6b6
18 changed files with 386 additions and 76 deletions
|
|
@ -8,14 +8,14 @@ namespace Catalogger.Backend.Cache.RedisCache;
|
|||
|
||||
public class RedisInviteCache(RedisService redisService) : IInviteCache
|
||||
{
|
||||
public async Task<IEnumerable<IInvite>> TryGetAsync(Snowflake guildId)
|
||||
public async Task<IEnumerable<IInviteWithMetadata>> TryGetAsync(Snowflake guildId)
|
||||
{
|
||||
var redisInvites =
|
||||
await redisService.GetAsync<List<RedisInvite>>(InvitesKey(guildId)) ?? [];
|
||||
return redisInvites.Select(r => r.ToRemoraInvite());
|
||||
}
|
||||
|
||||
public async Task SetAsync(Snowflake guildId, IEnumerable<IInvite> invites) =>
|
||||
public async Task SetAsync(Snowflake guildId, IEnumerable<IInviteWithMetadata> invites) =>
|
||||
await redisService.SetAsync(InvitesKey(guildId), invites.Select(RedisInvite.FromIInvite));
|
||||
|
||||
private static string InvitesKey(Snowflake guildId) => $"guild-invites:{guildId}";
|
||||
|
|
@ -25,24 +25,39 @@ internal record RedisInvite(
|
|||
string Code,
|
||||
RedisPartialGuild? Guild,
|
||||
RedisPartialChannel? Channel,
|
||||
int Uses,
|
||||
int MaxUses,
|
||||
TimeSpan MaxAge,
|
||||
bool IsTemporary,
|
||||
DateTimeOffset CreatedAt,
|
||||
RedisUser? Inviter,
|
||||
DateTimeOffset? ExpiresAt
|
||||
)
|
||||
{
|
||||
public static RedisInvite FromIInvite(IInvite invite) =>
|
||||
public static RedisInvite FromIInvite(IInviteWithMetadata invite) =>
|
||||
new(
|
||||
invite.Code,
|
||||
invite.Guild.Map(RedisPartialGuild.FromIPartialGuild).OrDefault(),
|
||||
invite.Channel != null ? RedisPartialChannel.FromIPartialChannel(invite.Channel) : null,
|
||||
invite.Uses,
|
||||
invite.MaxUses,
|
||||
invite.MaxAge,
|
||||
invite.IsTemporary,
|
||||
invite.CreatedAt,
|
||||
invite.Inviter.Map(RedisUser.FromIUser).OrDefault(),
|
||||
invite.ExpiresAt.OrDefault()
|
||||
);
|
||||
|
||||
public Invite ToRemoraInvite() =>
|
||||
public InviteWithMetadata ToRemoraInvite() =>
|
||||
new(
|
||||
Code,
|
||||
Guild?.ToRemoraPartialGuild() ?? new Optional<IPartialGuild>(),
|
||||
Channel?.ToRemoraPartialChannel(),
|
||||
Uses,
|
||||
MaxUses,
|
||||
MaxAge,
|
||||
IsTemporary,
|
||||
CreatedAt,
|
||||
Inviter?.ToRemoraUser() ?? new Optional<IUser>(),
|
||||
ExpiresAt: ExpiresAt
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue