62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
|
using Maki.Rest;
|
|||
|
using Maki.Structures.Rest;
|
|||
|
using Maki.Structures.Roles;
|
|||
|
using System;
|
|||
|
|
|||
|
namespace Maki
|
|||
|
{
|
|||
|
public class DiscordRole
|
|||
|
{
|
|||
|
public readonly ulong Id;
|
|||
|
public readonly DiscordServer Server;
|
|||
|
public readonly DiscordColour Colour;
|
|||
|
private readonly Discord client;
|
|||
|
|
|||
|
public string Name { get; internal set; }
|
|||
|
public DiscordPermission Perms { get; internal set; }
|
|||
|
public bool IsHoisted { get; internal set; }
|
|||
|
public bool IsMentionable { get; internal set; }
|
|||
|
|
|||
|
internal DiscordRole(Discord discord, Role role, DiscordServer server)
|
|||
|
{
|
|||
|
client = discord;
|
|||
|
Id = role.Id;
|
|||
|
Name = role.Name;
|
|||
|
Perms = (DiscordPermission)role.Permissions;
|
|||
|
IsHoisted = role.IsHoisted == true;
|
|||
|
IsMentionable = role.IsMentionable == true;
|
|||
|
Server = server;
|
|||
|
Colour = new DiscordColour(role.Colour ?? uint.MinValue);
|
|||
|
}
|
|||
|
|
|||
|
public void Delete()
|
|||
|
{
|
|||
|
RestResponse<object> resp = client.RestClient.Request<object>(RestRequestMethod.DELETE, RestEndpoints.GuildRole(Server.Id, Id));
|
|||
|
|
|||
|
if (resp.Status != 204)
|
|||
|
throw new Exception("Failed to delete role!");
|
|||
|
}
|
|||
|
|
|||
|
public void Edit(string name = null, DiscordPermission? perms = null, DiscordColour colour = null, bool? hoist = null, bool? mentionable = null)
|
|||
|
{
|
|||
|
RestResponse<Role> role = client.RestClient.Request<Role>(RestRequestMethod.PATCH, RestEndpoints.GuildRole(Server.Id, Id), new RoleCreate
|
|||
|
{
|
|||
|
Name = name ?? Name,
|
|||
|
Perms = perms ?? Perms,
|
|||
|
Colour = colour == null ? 0 : colour.Raw,
|
|||
|
Hoist = hoist ?? IsHoisted,
|
|||
|
Mentionable = mentionable ?? IsMentionable
|
|||
|
});
|
|||
|
|
|||
|
if (role.ErrorCode != RestErrorCode.Ok)
|
|||
|
throw new Exception($"{role.ErrorCode}: {role.ErrorMessage}");
|
|||
|
|
|||
|
Name = role.Response.Name;
|
|||
|
Perms = (DiscordPermission)role.Response.Permissions;
|
|||
|
Colour.Raw = role.Response.Colour ?? 0;
|
|||
|
IsHoisted = role.Response.IsHoisted == true;
|
|||
|
IsMentionable = role.Response.IsMentionable == true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|