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:
spiral
2021-11-17 20:41:02 -05:00
parent 45258d519e
commit e7f36eb31f
24 changed files with 134 additions and 126 deletions

View File

@@ -41,7 +41,7 @@ namespace PluralKit.Bot
if (logChannel == null)
return;
var triggerChannel = _cache.GetChannel(proxiedMessage.Channel);
var triggerChannel = await _cache.GetChannel(proxiedMessage.Channel);
var system = await _repo.GetSystem(ctx.SystemId.Value);
var member = await _repo.GetMember(proxiedMessage.Member);
@@ -78,7 +78,7 @@ namespace PluralKit.Bot
if (logChannel == null || logChannel.Type != Channel.ChannelType.GuildText) return null;
// Check bot permissions
var perms = _bot.PermissionsIn(logChannel.Id);
var perms = await _bot.PermissionsIn(logChannel.Id);
if (!perms.HasFlag(PermissionSet.SendMessages | PermissionSet.EmbedLinks))
{
_logger.Information(
@@ -93,7 +93,7 @@ namespace PluralKit.Bot
private async Task<Channel?> FindLogChannel(ulong guildId, ulong channelId)
{
// TODO: fetch it directly on cache miss?
if (_cache.TryGetChannel(channelId, out var channel))
if (await _cache.TryGetChannel(channelId, out var channel))
return channel;
// Channel doesn't exist or we don't have permission to access it, let's remove it from the database too

View File

@@ -86,10 +86,10 @@ namespace PluralKit.Bot
public async ValueTask HandleLoggerBotCleanup(Message msg)
{
var channel = _cache.GetChannel(msg.ChannelId);
var channel = await _cache.GetChannel(msg.ChannelId);
if (channel.Type != Channel.ChannelType.GuildText) return;
if (!_bot.PermissionsIn(channel.Id).HasFlag(PermissionSet.ManageMessages)) return;
if (!(await _bot.PermissionsIn(channel.Id)).HasFlag(PermissionSet.ManageMessages)) return;
// If this message is from a *webhook*, check if the name matches one of the bots we know
// TODO: do we need to do a deeper webhook origin check, or would that be too hard on the rate limit?

View File

@@ -52,7 +52,7 @@ namespace PluralKit.Bot
await foreach (var guild in _cache.GetAllGuilds())
{
guildCount++;
foreach (var channel in _cache.GetGuildChannels(guild.Id))
foreach (var channel in await _cache.GetGuildChannels(guild.Id))
{
if (DiscordUtils.IsValidGuildChannel(channel))
channelCount++;

View File

@@ -89,7 +89,7 @@ namespace PluralKit.Bot
};
ulong? threadId = null;
var root = _cache.GetRootChannel(channelId);
var root = await _cache.GetRootChannel(channelId);
if (root.Id != channelId)
threadId = channelId;
@@ -102,7 +102,7 @@ namespace PluralKit.Bot
private async Task<Message> ExecuteWebhookInner(Webhook webhook, ProxyRequest req, bool hasRetried = false)
{
var guild = _cache.GetGuild(req.GuildId);
var guild = await _cache.GetGuild(req.GuildId);
var content = req.Content.Truncate(2000);
var allowedMentions = content.ParseMentions();