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; } public int Position { get; internal set; } public override string ToString() => $@"<@&{Id}>"; 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; Position = role.Position ?? 0; Server = server; Colour = new DiscordColour(role.Colour ?? int.MinValue); } public void Delete() { RestResponse resp = client.RestClient.Request(RestRequestMethod.DELETE, RestEndpoints.GuildRole(Server.Id, Id)); if (resp.Status != 204) throw new DiscordException("Failed to delete role!"); } public void Edit(string name = null, DiscordPermission? perms = null, DiscordColour colour = null, bool? hoist = null, bool? mentionable = null) { RestResponse role = client.RestClient.Request(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 DiscordException($"{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; } } }