2017-05-14 12:02:51 +00:00
|
|
|
|
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; }
|
2017-05-21 01:08:34 +00:00
|
|
|
|
public int Position { get; internal set; }
|
2017-05-14 12:02:51 +00:00
|
|
|
|
|
2017-05-17 22:33:09 +00:00
|
|
|
|
public override string ToString() => $@"<@&{Id}>";
|
|
|
|
|
|
2017-05-14 12:02:51 +00:00
|
|
|
|
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;
|
2017-05-21 01:08:34 +00:00
|
|
|
|
Position = role.Position ?? 0;
|
2017-05-14 12:02:51 +00:00
|
|
|
|
Server = server;
|
2017-05-27 08:48:11 +00:00
|
|
|
|
Colour = new DiscordColour(role.Colour ?? int.MinValue);
|
2017-05-14 12:02:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete()
|
|
|
|
|
{
|
|
|
|
|
RestResponse<object> resp = client.RestClient.Request<object>(RestRequestMethod.DELETE, RestEndpoints.GuildRole(Server.Id, Id));
|
|
|
|
|
|
|
|
|
|
if (resp.Status != 204)
|
2017-05-27 08:48:11 +00:00
|
|
|
|
throw new DiscordException("Failed to delete role!");
|
2017-05-14 12:02:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
2017-05-27 08:48:11 +00:00
|
|
|
|
throw new DiscordException($"{role.ErrorCode}: {role.ErrorMessage}");
|
2017-05-14 12:02:51 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|