Don't attempt to send log messages if the bot doesn't have permissions

This commit is contained in:
Ske
2020-02-22 01:54:10 +01:00
parent 493f7b12e5
commit 8d3be79d33
4 changed files with 15 additions and 11 deletions

View File

@@ -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<ChannelPermissions> 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<bool> HasPermission(this IChannel channel, ChannelPermission permission) =>
(await PermissionsIn(channel)).Has(permission);
public static bool HasPermission(this IChannel channel, ChannelPermission permission) =>
PermissionsIn(channel).Has(permission);
}
}