feat: async cache
this breaks logging bot permissions to Sentry. we haven't had a need to check those recently (permissions issues were because of broken cache), so this is fine for now this should be re-added in the future though
This commit is contained in:
@@ -9,44 +9,44 @@ namespace Myriad.Extensions
|
||||
{
|
||||
public static class CacheExtensions
|
||||
{
|
||||
public static Guild GetGuild(this IDiscordCache cache, ulong guildId)
|
||||
public static async Task<Guild> GetGuild(this IDiscordCache cache, ulong guildId)
|
||||
{
|
||||
if (!cache.TryGetGuild(guildId, out var guild))
|
||||
if (!await cache.TryGetGuild(guildId, out var guild))
|
||||
throw new KeyNotFoundException($"Guild {guildId} not found in cache");
|
||||
return guild;
|
||||
}
|
||||
|
||||
public static Channel GetChannel(this IDiscordCache cache, ulong channelId)
|
||||
public static async Task<Channel> GetChannel(this IDiscordCache cache, ulong channelId)
|
||||
{
|
||||
if (!cache.TryGetChannel(channelId, out var channel))
|
||||
if (!await cache.TryGetChannel(channelId, out var channel))
|
||||
throw new KeyNotFoundException($"Channel {channelId} not found in cache");
|
||||
return channel;
|
||||
}
|
||||
|
||||
public static Channel? GetChannelOrNull(this IDiscordCache cache, ulong channelId)
|
||||
public static async Task<Channel?> GetChannelOrNull(this IDiscordCache cache, ulong channelId)
|
||||
{
|
||||
if (cache.TryGetChannel(channelId, out var channel))
|
||||
if (await cache.TryGetChannel(channelId, out var channel))
|
||||
return channel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static User GetUser(this IDiscordCache cache, ulong userId)
|
||||
public static async Task<User> GetUser(this IDiscordCache cache, ulong userId)
|
||||
{
|
||||
if (!cache.TryGetUser(userId, out var user))
|
||||
if (!await cache.TryGetUser(userId, out var user))
|
||||
throw new KeyNotFoundException($"User {userId} not found in cache");
|
||||
return user;
|
||||
}
|
||||
|
||||
public static Role GetRole(this IDiscordCache cache, ulong roleId)
|
||||
public static async Task<Role> GetRole(this IDiscordCache cache, ulong roleId)
|
||||
{
|
||||
if (!cache.TryGetRole(roleId, out var role))
|
||||
if (!await cache.TryGetRole(roleId, out var role))
|
||||
throw new KeyNotFoundException($"Role {roleId} not found in cache");
|
||||
return role;
|
||||
}
|
||||
|
||||
public static async ValueTask<User?> GetOrFetchUser(this IDiscordCache cache, DiscordApiClient rest, ulong userId)
|
||||
{
|
||||
if (cache.TryGetUser(userId, out var cacheUser))
|
||||
if (await cache.TryGetUser(userId, out var cacheUser))
|
||||
return cacheUser;
|
||||
|
||||
var restUser = await rest.GetUser(userId);
|
||||
@@ -57,7 +57,7 @@ namespace Myriad.Extensions
|
||||
|
||||
public static async ValueTask<Channel?> GetOrFetchChannel(this IDiscordCache cache, DiscordApiClient rest, ulong channelId)
|
||||
{
|
||||
if (cache.TryGetChannel(channelId, out var cacheChannel))
|
||||
if (await cache.TryGetChannel(channelId, out var cacheChannel))
|
||||
return cacheChannel;
|
||||
|
||||
var restChannel = await rest.GetChannel(channelId);
|
||||
@@ -68,7 +68,7 @@ namespace Myriad.Extensions
|
||||
|
||||
public static async Task<Channel> GetOrCreateDmChannel(this IDiscordCache cache, DiscordApiClient rest, ulong recipientId)
|
||||
{
|
||||
if (cache.TryGetDmChannel(recipientId, out var cacheChannel))
|
||||
if (await cache.TryGetDmChannel(recipientId, out var cacheChannel))
|
||||
return cacheChannel;
|
||||
|
||||
var restChannel = await rest.CreateDm(recipientId);
|
||||
@@ -76,13 +76,13 @@ namespace Myriad.Extensions
|
||||
return restChannel;
|
||||
}
|
||||
|
||||
public static Channel GetRootChannel(this IDiscordCache cache, ulong channelOrThread)
|
||||
public static async Task<Channel> GetRootChannel(this IDiscordCache cache, ulong channelOrThread)
|
||||
{
|
||||
var channel = cache.GetChannel(channelOrThread);
|
||||
var channel = await cache.GetChannel(channelOrThread);
|
||||
if (!channel.IsThread())
|
||||
return channel;
|
||||
|
||||
var parent = cache.GetChannel(channel.ParentId!.Value);
|
||||
var parent = await cache.GetChannel(channel.ParentId!.Value);
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user