Rename BotHasPermission to a more descriptive name

This commit is contained in:
Ske 2020-05-02 15:29:36 +02:00
parent ca57d10f7c
commit 720755844f
8 changed files with 13 additions and 14 deletions

View File

@ -98,7 +98,7 @@ namespace PluralKit.Bot
// Once we've sent it to Sentry, report it to the user (if we have permission to)
var reportChannel = handler.ErrorChannelFor(evt);
if (reportChannel != null && reportChannel.BotHasPermission(Permissions.SendMessages))
if (reportChannel != null && reportChannel.BotHasAllPermissions(Permissions.SendMessages))
{
var eid = sentryEvent.EventId;
await reportChannel.SendMessageAsync(

View File

@ -64,11 +64,11 @@ namespace PluralKit.Bot
public Task<DiscordMessage> Reply(string text = null, DiscordEmbed embed = null)
{
if (!this.BotHasPermission(Permissions.SendMessages))
if (!this.BotHasAllPermissions(Permissions.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 && !this.BotHasPermission(Permissions.EmbedLinks))
if (embed != null && !this.BotHasAllPermissions(Permissions.EmbedLinks))
throw new PKError("PluralKit does not have permission to send embeds in this channel. Please ensure I have the **Embed Links** permission enabled.");
return Channel.SendMessageAsync(text, embed: embed);

View File

@ -118,7 +118,7 @@ namespace PluralKit.Bot
catch (PKError e)
{
// User-facing errors, print to the channel properly formatted
if (msg.Channel.Guild == null || msg.Channel.BotHasPermission(Permissions.SendMessages))
if (msg.Channel.Guild == null || msg.Channel.BotHasAllPermissions(Permissions.SendMessages))
await msg.Channel.SendMessageAsync($"{Emojis.Error} {e.Message}");
}

View File

@ -47,8 +47,7 @@ namespace PluralKit.Bot {
if (channel.Type != ChannelType.Text) return;
// Bail if we don't have permission to send stuff here
var neededPermissions = Permissions.SendMessages | Permissions.EmbedLinks;
if ((channel.BotPermissions() & neededPermissions) != neededPermissions)
if (!channel.BotHasAllPermissions(Permissions.SendMessages | Permissions.EmbedLinks))
return;
var embed = _embed.CreateLoggedMessageEmbed(system, member, messageId, originalMsgId, sender, content, originalChannel);

View File

@ -67,7 +67,7 @@ namespace PluralKit.Bot
// Bail if not enabled, or if we don't have permission here
if (!cachedGuild.LogCleanupEnabled) return;
if (msg.Channel.Type != ChannelType.Text) return;
if (!msg.Channel.BotHasPermission(Permissions.ManageMessages)) return;
if (!msg.Channel.BotHasAllPermissions(Permissions.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

@ -287,7 +287,7 @@ namespace PluralKit.Bot
await args.Channel.SendMessageAsync($"Psst, **{msg.Member.DisplayName ?? msg.Member.Name}** (<@{msg.Message.Sender}>), you have been pinged by <@{args.User.Id}>.", embed: embed.Build());
// Finally remove the original reaction (if we can)
if (args.Channel.BotHasPermission(Permissions.ManageMessages))
if (args.Channel.BotHasAllPermissions(Permissions.ManageMessages))
await args.Message.DeleteReactionAsync(args.Emoji, args.User);
}
@ -323,7 +323,7 @@ namespace PluralKit.Bot
public async Task HandleMessageDeletionByReaction(MessageReactionAddEventArgs args)
{
// Bail if we don't have permission to delete
if (!args.Channel.BotHasPermission(Permissions.ManageMessages)) return;
if (!args.Channel.BotHasAllPermissions(Permissions.ManageMessages)) return;
// Find the message in the database
var storedMessage = await _data.GetMessage(args.Message.Id);

View File

@ -109,7 +109,7 @@ namespace PluralKit.Bot {
if (currentPage < 0) currentPage += pageCount;
// If we can, remove the user's reaction (so they can press again quickly)
if (ctx.BotHasPermission(Permissions.ManageMessages)) await msg.DeleteReactionAsync(reaction.Emoji, reaction.User);
if (ctx.BotHasAllPermissions(Permissions.ManageMessages)) await msg.DeleteReactionAsync(reaction.Emoji, reaction.User);
// Edit the embed with the new page
var embed = await MakeEmbedForPage(currentPage);
@ -119,7 +119,7 @@ namespace PluralKit.Bot {
// "escape hatch", clean up as if we hit X
}
if (ctx.BotHasPermission(Permissions.ManageMessages)) await msg.DeleteAllReactionsAsync();
if (ctx.BotHasAllPermissions(Permissions.ManageMessages)) await msg.DeleteAllReactionsAsync();
}
// If we get a "NotFound" error, the message has been deleted and thus not our problem
catch (NotFoundException) { }
@ -208,8 +208,8 @@ namespace PluralKit.Bot {
public static Permissions BotPermissions(this Context ctx) => ctx.Channel.BotPermissions();
public static bool BotHasPermission(this Context ctx, Permissions permission) =>
ctx.Channel.BotHasPermission(permission);
public static bool BotHasAllPermissions(this Context ctx, Permissions permission) =>
ctx.Channel.BotHasAllPermissions(permission);
public static async Task BusyIndicator(this Context ctx, Func<Task> f, string emoji = "\u23f3" /* hourglass */)
{

View File

@ -58,7 +58,7 @@ namespace PluralKit.Bot
return Permissions.None;
}
public static bool BotHasPermission(this DiscordChannel channel, Permissions permissionSet) =>
public static bool BotHasAllPermissions(this DiscordChannel channel, Permissions permissionSet) =>
(BotPermissions(channel) & permissionSet) == permissionSet;
public static Instant SnowflakeToInstant(ulong snowflake) =>