refactor: cache own user ID in IDiscordCache

- remove Cluster.User
- remove Cluster.Application (it was only being used as an alternative to Cluster.User for some reason)
- move Bot.PermissionsIn to DiscordCacheExtensions
This commit is contained in:
spiral
2021-11-21 19:42:35 -05:00
parent 24ac0725af
commit 7a5ba8246e
17 changed files with 61 additions and 40 deletions

View File

@@ -77,19 +77,6 @@ namespace PluralKit.Bot
}, null, timeTillNextWholeMinute, TimeSpan.FromMinutes(1));
}
public async Task<PermissionSet> PermissionsIn(ulong channelId)
{
var channel = await _cache.GetRootChannel(channelId);
if (channel.GuildId != null)
{
var member = await _cache.TryGetSelfMember(channel.GuildId.Value);
return await _cache.PermissionsFor(channelId, _cluster.User?.Id ?? default, member);
}
return PermissionSet.Dm;
}
private async Task OnEventReceived(Shard shard, IGatewayEvent evt)
{
await _cache.TryUpdateSelfMember(shard, evt);
@@ -249,7 +236,7 @@ namespace PluralKit.Bot
if (reportChannel == null)
return;
var botPerms = await PermissionsIn(reportChannel.Value);
var botPerms = await _cache.PermissionsIn(reportChannel.Value);
if (botPerms.HasFlag(PermissionSet.SendMessages | PermissionSet.EmbedLinks))
await _errorMessageService.SendErrorMessage(reportChannel.Value, sentryEvent.EventId.ToString());
}