diff --git a/PluralKit.Bot/Commands/Misc.cs b/PluralKit.Bot/Commands/Misc.cs index 97d77542..6df8a8ae 100644 --- a/PluralKit.Bot/Commands/Misc.cs +++ b/PluralKit.Bot/Commands/Misc.cs @@ -128,7 +128,7 @@ namespace PluralKit.Bot { foreach (var channel in await guild.GetTextChannelsAsync()) { // TODO: do we need to hide channels here to prevent info-leaking? - var perms = await channel.PermissionsIn(); + var perms = channel.PermissionsIn(); // We use a bitfield so we can set individual permission bits in the loop ulong missingPermissionField = 0; diff --git a/PluralKit.Bot/Services/LogChannelService.cs b/PluralKit.Bot/Services/LogChannelService.cs index 3e2168ab..7e6389a1 100644 --- a/PluralKit.Bot/Services/LogChannelService.cs +++ b/PluralKit.Bot/Services/LogChannelService.cs @@ -33,9 +33,14 @@ namespace PluralKit.Bot { // Bail if we can't find the channel if (!(await _client.GetChannelAsync(guildCfg.Value.LogChannel.Value) is ITextChannel logChannel)) return; + // Bail if we don't have permission to send stuff here + if (!logChannel.HasPermission(ChannelPermission.SendMessages) || !logChannel.HasPermission(ChannelPermission.EmbedLinks)) + return; + var embed = _embed.CreateLoggedMessageEmbed(system, member, messageId, originalMsgId, sender, content, originalChannel); var url = $"https://discordapp.com/channels/{originalChannel.GuildId}/{originalChannel.Id}/{messageId}"; + await logChannel.SendMessageAsync(text: url, embed: embed); } } diff --git a/PluralKit.Bot/Services/ProxyService.cs b/PluralKit.Bot/Services/ProxyService.cs index ebebfb95..31c4f7ad 100644 --- a/PluralKit.Bot/Services/ProxyService.cs +++ b/PluralKit.Bot/Services/ProxyService.cs @@ -286,7 +286,7 @@ namespace PluralKit.Bot // Finally remove the original reaction (if we can) var user = await _client.Rest.GetUserAsync(userWhoReacted); - if (user != null && await realMessage.Channel.HasPermission(ChannelPermission.ManageMessages)) + if (user != null && realMessage.Channel.HasPermission(ChannelPermission.ManageMessages)) await realMessage.RemoveReactionAsync(reactedEmote, user); } @@ -316,7 +316,7 @@ namespace PluralKit.Bot // And finally remove the original reaction (if we can) var msgObj = await message.GetOrDownloadAsync(); - if (await msgObj.Channel.HasPermission(ChannelPermission.ManageMessages)) + if (msgObj.Channel.HasPermission(ChannelPermission.ManageMessages)) await msgObj.RemoveReactionAsync(reactedEmote, user); } diff --git a/PluralKit.Bot/Utils/DiscordUtils.cs b/PluralKit.Bot/Utils/DiscordUtils.cs index 8884ccc9..1f596789 100644 --- a/PluralKit.Bot/Utils/DiscordUtils.cs +++ b/PluralKit.Bot/Utils/DiscordUtils.cs @@ -1,6 +1,5 @@ -using System.Threading.Tasks; - -using Discord; +using Discord; +using Discord.WebSocket; namespace PluralKit.Bot { @@ -10,7 +9,7 @@ namespace PluralKit.Bot return $"{user.Username}#{user.Discriminator} ({user.Mention})"; } - public static async Task PermissionsIn(this IChannel channel) + public static ChannelPermissions PermissionsIn(this IChannel channel) { switch (channel) { @@ -18,15 +17,15 @@ namespace PluralKit.Bot return ChannelPermissions.DM; case IGroupChannel _: return ChannelPermissions.Group; - case IGuildChannel gc: - var currentUser = await gc.Guild.GetCurrentUserAsync(); + case SocketGuildChannel gc: + var currentUser = gc.Guild.CurrentUser; return currentUser.GetPermissions(gc); default: return ChannelPermissions.None; } } - public static async Task HasPermission(this IChannel channel, ChannelPermission permission) => - (await PermissionsIn(channel)).Has(permission); + public static bool HasPermission(this IChannel channel, ChannelPermission permission) => + PermissionsIn(channel).Has(permission); } } \ No newline at end of file