mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 17:20:14 +00:00
fix(bot): throw better errors for (some) failed cache lookups
This commit is contained in:
parent
dfd3cba6dd
commit
e4f04b5bd5
2 changed files with 13 additions and 6 deletions
|
|
@ -50,7 +50,8 @@ public static class CacheExtensions
|
||||||
if (!channel.IsThread())
|
if (!channel.IsThread())
|
||||||
return channel;
|
return channel;
|
||||||
|
|
||||||
var parent = await cache.GetChannel(guildId, channel.ParentId!.Value);
|
var parent = await cache.TryGetChannel(guildId, channel.ParentId!.Value);
|
||||||
|
if (parent == null) throw new Exception($"failed to find parent channel for thread {channelOrThread} in cache");
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,13 +52,19 @@ public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
||||||
if (!evt.Content.HasValue || !evt.Author.HasValue || !evt.Member.HasValue)
|
if (!evt.Content.HasValue || !evt.Author.HasValue || !evt.Member.HasValue)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var guildIdMaybe = evt.GuildId.HasValue ? evt.GuildId.Value ?? 0 : 0;
|
// we only use message edit event for proxying, so ignore messages from DMs
|
||||||
|
if (!evt.GuildId.HasValue || evt.GuildId.Value == null) return;
|
||||||
|
ulong guildId = evt.GuildId!.Value!.Value;
|
||||||
|
|
||||||
var channel = await _cache.GetChannel(guildIdMaybe, evt.ChannelId); // todo: is this correct for message update?
|
var channel = await _cache.TryGetChannel(guildId, evt.ChannelId); // todo: is this correct for message update?
|
||||||
|
if (channel == null)
|
||||||
|
throw new Exception("could not find self channel in MessageEdited event");
|
||||||
if (!DiscordUtils.IsValidGuildChannel(channel))
|
if (!DiscordUtils.IsValidGuildChannel(channel))
|
||||||
return;
|
return;
|
||||||
var rootChannel = await _cache.GetRootChannel(guildIdMaybe, channel.Id);
|
var rootChannel = await _cache.GetRootChannel(guildId, channel.Id);
|
||||||
var guild = await _cache.GetGuild(channel.GuildId!.Value);
|
var guild = await _cache.TryGetGuild(channel.GuildId!.Value);
|
||||||
|
if (guild == null)
|
||||||
|
throw new Exception("could not find self guild in MessageEdited event");
|
||||||
var lastMessage = _lastMessageCache.GetLastMessage(evt.ChannelId)?.Current;
|
var lastMessage = _lastMessageCache.GetLastMessage(evt.ChannelId)?.Current;
|
||||||
|
|
||||||
// Only react to the last message in the channel
|
// Only react to the last message in the channel
|
||||||
|
|
@ -73,7 +79,7 @@ public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var equivalentEvt = await GetMessageCreateEvent(evt, lastMessage, channel);
|
var equivalentEvt = await GetMessageCreateEvent(evt, lastMessage, channel);
|
||||||
var botPermissions = await _cache.BotPermissionsIn(guildIdMaybe, channel.Id);
|
var botPermissions = await _cache.BotPermissionsIn(guildId, channel.Id);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue