Large refactor and project restructuring
This commit is contained in:
32
PluralKit.Bot/Utils/DiscordUtils.cs
Normal file
32
PluralKit.Bot/Utils/DiscordUtils.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
public static class DiscordUtils
|
||||
{
|
||||
public static string NameAndMention(this IUser user) {
|
||||
return $"{user.Username}#{user.Discriminator} ({user.Mention})";
|
||||
}
|
||||
|
||||
public static async Task<ChannelPermissions> PermissionsIn(this IChannel channel)
|
||||
{
|
||||
switch (channel)
|
||||
{
|
||||
case IDMChannel _:
|
||||
return ChannelPermissions.DM;
|
||||
case IGroupChannel _:
|
||||
return ChannelPermissions.Group;
|
||||
case IGuildChannel gc:
|
||||
var currentUser = await gc.Guild.GetCurrentUserAsync();
|
||||
return currentUser.GetPermissions(gc);
|
||||
default:
|
||||
return ChannelPermissions.None;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> HasPermission(this IChannel channel, ChannelPermission permission) =>
|
||||
(await PermissionsIn(channel)).Has(permission);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user