diff --git a/Maki/Discord.cs b/Maki/Discord.cs index 63a2ad3..9aff807 100644 --- a/Maki/Discord.cs +++ b/Maki/Discord.cs @@ -274,7 +274,7 @@ namespace Maki ); if (gateway.ErrorCode != RestErrorCode.Ok) - throw new Exception($"{gateway.ErrorCode}: {gateway.ErrorMessage}"); + throw new DiscordException($"{gateway.ErrorCode}: {gateway.ErrorMessage}"); Gateway = gateway.Response.Url; @@ -311,13 +311,13 @@ namespace Maki ); if (login.ErrorCode != RestErrorCode.Ok) - throw new Exception($"{login.ErrorCode}: {login.ErrorMessage}"); + throw new DiscordException($"{login.ErrorCode}: {login.ErrorMessage}"); if (login.Response.UsernameError?.Length > 0) - throw new Exception(login.Response.UsernameError.FirstOrDefault()); + throw new DiscordException(login.Response.UsernameError.FirstOrDefault()); if (login.Response.PasswordError?.Length > 0) - throw new Exception(login.Response.PasswordError.FirstOrDefault()); + throw new DiscordException(login.Response.PasswordError.FirstOrDefault()); Token = login.Response.Token; @@ -336,16 +336,16 @@ namespace Maki ); if (totp.ErrorCode != RestErrorCode.Ok) - throw new Exception($"{totp.ErrorCode}: {totp.ErrorMessage}"); + throw new DiscordException($"{totp.ErrorCode}: {totp.ErrorMessage}"); Token = totp.Response.Token; } else - throw new Exception("Token was null but MFA is false and/or ticket is empty?"); + throw new DiscordException("Token was null but MFA is false and/or ticket is empty?"); } if (string.IsNullOrEmpty(Token)) - throw new Exception("Authentication failed!"); + throw new DiscordException("Authentication failed!"); Connect(); } diff --git a/Maki/DiscordColour.cs b/Maki/DiscordColour.cs index 323538a..2d40e34 100644 --- a/Maki/DiscordColour.cs +++ b/Maki/DiscordColour.cs @@ -5,14 +5,14 @@ namespace Maki { public class DiscordColour { - public DiscordColour(uint raw) + public DiscordColour(int raw) { Raw = raw; } public DiscordColour(byte red, byte green, byte blue) { - Raw = (uint)((red << 16) + (green << 8) + blue); + Raw = (red << 16) + (green << 8) + blue; } public DiscordColour(string hex) @@ -24,30 +24,30 @@ namespace Maki if (hex.Length != 6) throw new FormatException("Invalid hex colour format!"); - + Red = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber); Green = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber); Blue = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber); } - public uint Raw = uint.MinValue; + public int Raw = int.MinValue; public byte Red { get => (byte)(Raw >> 16 & 0xFF); - set => Raw = (uint)((value << 16) + (Green << 8) + Blue); + set => Raw = (value << 16) + (Green << 8) + Blue; } public byte Green { get => (byte)(Raw >> 8 & 0xFF); - set => Raw = (uint)((Red << 16) + (value << 8) + Blue); + set => Raw = (Red << 16) + (value << 8) + Blue; } public byte Blue { get => (byte)(Raw & 0xFF); - set => Raw = (uint)((Red << 16) + (Green << 8) + value); + set => Raw = (Red << 16) + (Green << 8) + value; } public string Hex => $"{Red:X2}{Green:X2}{Blue:X2}"; diff --git a/Maki/DiscordException.cs b/Maki/DiscordException.cs new file mode 100644 index 0000000..52e255d --- /dev/null +++ b/Maki/DiscordException.cs @@ -0,0 +1,19 @@ +using System; + +namespace Maki +{ + public class DiscordException : Exception + { + public DiscordException() : base() + { + } + + public DiscordException(string msg) : base(msg) + { + } + + public DiscordException(string msg, Exception inner) : base(msg, inner) + { + } + } +} diff --git a/Maki/DiscordRole.cs b/Maki/DiscordRole.cs index 5db5969..d295641 100644 --- a/Maki/DiscordRole.cs +++ b/Maki/DiscordRole.cs @@ -30,7 +30,7 @@ namespace Maki IsMentionable = role.IsMentionable == true; Position = role.Position ?? 0; Server = server; - Colour = new DiscordColour(role.Colour ?? uint.MinValue); + Colour = new DiscordColour(role.Colour ?? int.MinValue); } public void Delete() @@ -38,7 +38,7 @@ namespace Maki RestResponse resp = client.RestClient.Request(RestRequestMethod.DELETE, RestEndpoints.GuildRole(Server.Id, Id)); if (resp.Status != 204) - throw new Exception("Failed to delete role!"); + 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) @@ -53,7 +53,7 @@ namespace Maki }); if (role.ErrorCode != RestErrorCode.Ok) - throw new Exception($"{role.ErrorCode}: {role.ErrorMessage}"); + throw new DiscordException($"{role.ErrorCode}: {role.ErrorMessage}"); Name = role.Response.Name; Perms = (DiscordPermission)role.Response.Permissions; diff --git a/Maki/DiscordServer.cs b/Maki/DiscordServer.cs index e8b5a70..7c7cbad 100644 --- a/Maki/DiscordServer.cs +++ b/Maki/DiscordServer.cs @@ -45,7 +45,7 @@ namespace Maki }); if (roleResp.ErrorCode != RestErrorCode.Ok) - throw new Exception($"{roleResp.ErrorCode}: {roleResp.ErrorMessage}"); + throw new DiscordException($"{roleResp.ErrorCode}: {roleResp.ErrorMessage}"); DiscordRole role = client.roles.Where(x => x.Id == roleResp.Response.Id).FirstOrDefault(); diff --git a/Maki/Maki.csproj b/Maki/Maki.csproj index af268e8..299ba02 100644 --- a/Maki/Maki.csproj +++ b/Maki/Maki.csproj @@ -59,6 +59,7 @@ + diff --git a/Maki/Structures/Embeds/Embed.cs b/Maki/Structures/Embeds/Embed.cs index f16e0de..475b8b3 100644 --- a/Maki/Structures/Embeds/Embed.cs +++ b/Maki/Structures/Embeds/Embed.cs @@ -42,7 +42,7 @@ namespace Maki.Structures.Embeds /// colour code of the embed /// [JsonProperty("color")] - public uint Colour; + public int Colour; /// /// footer information diff --git a/Maki/Structures/Rest/RoleCreate.cs b/Maki/Structures/Rest/RoleCreate.cs index a3cb03f..a3153b1 100644 --- a/Maki/Structures/Rest/RoleCreate.cs +++ b/Maki/Structures/Rest/RoleCreate.cs @@ -11,7 +11,7 @@ namespace Maki.Structures.Rest public DiscordPermission Perms; [JsonProperty("color")] - public uint Colour; + public int Colour; [JsonProperty("hoist")] public bool Hoist; diff --git a/Maki/Structures/Roles/Role.cs b/Maki/Structures/Roles/Role.cs index 4e0b69b..7459bd6 100644 --- a/Maki/Structures/Roles/Role.cs +++ b/Maki/Structures/Roles/Role.cs @@ -23,7 +23,7 @@ namespace Maki.Structures.Roles /// integer representation of hexadecimal color code /// [JsonProperty("color")] - public uint? Colour; + public int? Colour; /// /// if this role is pinned in the user listing