mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
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:
parent
45258d519e
commit
e7f36eb31f
24 changed files with 134 additions and 126 deletions
|
|
@ -71,8 +71,8 @@ namespace PluralKit.Bot
|
|||
public Cluster Cluster => _cluster;
|
||||
public MessageContext MessageContext => _messageContext;
|
||||
|
||||
public PermissionSet BotPermissions => _provider.Resolve<Bot>().PermissionsIn(_channel.Id);
|
||||
public PermissionSet UserPermissions => _cache.PermissionsFor(_message);
|
||||
public Task<PermissionSet> BotPermissions => _provider.Resolve<Bot>().PermissionsIn(_channel.Id);
|
||||
public Task<PermissionSet> UserPermissions => _cache.PermissionsFor(_message);
|
||||
|
||||
public DiscordApiClient Rest => _rest;
|
||||
|
||||
|
|
@ -85,11 +85,13 @@ namespace PluralKit.Bot
|
|||
|
||||
public async Task<Message> Reply(string text = null, Embed embed = null, AllowedMentions? mentions = null)
|
||||
{
|
||||
if (!BotPermissions.HasFlag(PermissionSet.SendMessages))
|
||||
var botPerms = await BotPermissions;
|
||||
|
||||
if (!botPerms.HasFlag(PermissionSet.SendMessages))
|
||||
// Will be "swallowed" during the error handler anyway, this message is never shown.
|
||||
throw new PKError("PluralKit does not have permission to send messages in this channel.");
|
||||
|
||||
if (embed != null && !BotPermissions.HasFlag(PermissionSet.EmbedLinks))
|
||||
if (embed != null && !botPerms.HasFlag(PermissionSet.EmbedLinks))
|
||||
throw new PKError("PluralKit does not have permission to send embeds in this channel. Please ensure I have the **Embed Links** permission enabled.");
|
||||
|
||||
var msg = await _rest.CreateMessage(_channel.Id, new MessageRequest
|
||||
|
|
|
|||
|
|
@ -52,16 +52,16 @@ namespace PluralKit.Bot
|
|||
return ctx;
|
||||
}
|
||||
|
||||
public static Context CheckAuthorPermission(this Context ctx, PermissionSet neededPerms, string permissionName)
|
||||
public static async Task<Context> CheckAuthorPermission(this Context ctx, PermissionSet neededPerms, string permissionName)
|
||||
{
|
||||
if ((ctx.UserPermissions & neededPerms) != neededPerms)
|
||||
if ((await ctx.UserPermissions & neededPerms) != neededPerms)
|
||||
throw new PKError($"You must have the \"{permissionName}\" permission in this server to use this command.");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public static async Task<bool> CheckPermissionsInGuildChannel(this Context ctx, Channel channel, PermissionSet neededPerms)
|
||||
{
|
||||
var guild = ctx.Cache.GetGuild(channel.GuildId.Value);
|
||||
var guild = await ctx.Cache.GetGuild(channel.GuildId.Value);
|
||||
if (guild == null)
|
||||
return false;
|
||||
|
||||
|
|
|
|||
|
|
@ -152,19 +152,19 @@ namespace PluralKit.Bot
|
|||
}
|
||||
}
|
||||
|
||||
public static Task<Channel> MatchChannel(this Context ctx)
|
||||
public static async Task<Channel> MatchChannel(this Context ctx)
|
||||
{
|
||||
if (!MentionUtils.TryParseChannel(ctx.PeekArgument(), out var id))
|
||||
return Task.FromResult<Channel>(null);
|
||||
return null;
|
||||
|
||||
if (!ctx.Cache.TryGetChannel(id, out var channel))
|
||||
return Task.FromResult<Channel>(null);
|
||||
if (!await ctx.Cache.TryGetChannel(id, out var channel))
|
||||
return null;
|
||||
|
||||
if (!DiscordUtils.IsValidGuildChannel(channel))
|
||||
return Task.FromResult<Channel>(null);
|
||||
return null;
|
||||
|
||||
ctx.PopArgument();
|
||||
return Task.FromResult(channel);
|
||||
return channel;
|
||||
}
|
||||
|
||||
public static Guild MatchGuild(this Context ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue