2020-02-22 00:54:10 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.WebSocket;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
|
{
|
|
|
|
|
public static class DiscordUtils
|
|
|
|
|
{
|
|
|
|
|
public static string NameAndMention(this IUser user) {
|
|
|
|
|
return $"{user.Username}#{user.Discriminator} ({user.Mention})";
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 00:54:10 +00:00
|
|
|
|
public static ChannelPermissions PermissionsIn(this IChannel channel)
|
2020-02-12 14:16:19 +00:00
|
|
|
|
{
|
|
|
|
|
switch (channel)
|
|
|
|
|
{
|
|
|
|
|
case IDMChannel _:
|
|
|
|
|
return ChannelPermissions.DM;
|
|
|
|
|
case IGroupChannel _:
|
|
|
|
|
return ChannelPermissions.Group;
|
2020-02-22 00:54:10 +00:00
|
|
|
|
case SocketGuildChannel gc:
|
|
|
|
|
var currentUser = gc.Guild.CurrentUser;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
return currentUser.GetPermissions(gc);
|
|
|
|
|
default:
|
|
|
|
|
return ChannelPermissions.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 00:54:10 +00:00
|
|
|
|
public static bool HasPermission(this IChannel channel, ChannelPermission permission) =>
|
|
|
|
|
PermissionsIn(channel).Has(permission);
|
2020-02-12 14:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|