Archived
1
0
Fork 0

updates i think

This commit is contained in:
flash 2017-05-27 10:48:11 +02:00
parent 625ca8e30c
commit 063a12e804
9 changed files with 41 additions and 21 deletions

View file

@ -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();
}

View file

@ -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}";

19
Maki/DiscordException.cs Normal file
View file

@ -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)
{
}
}
}

View file

@ -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<object> resp = client.RestClient.Request<object>(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;

View file

@ -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();

View file

@ -59,6 +59,7 @@
<Compile Include="DiscordEmbedField.cs" />
<Compile Include="DiscordEmbedFooter.cs" />
<Compile Include="DiscordEmbedImage.cs" />
<Compile Include="DiscordException.cs" />
<Compile Include="DiscordGame.cs" />
<Compile Include="DiscordMember.cs" />
<Compile Include="DiscordMessage.cs" />

View file

@ -42,7 +42,7 @@ namespace Maki.Structures.Embeds
/// colour code of the embed
/// </summary>
[JsonProperty("color")]
public uint Colour;
public int Colour;
/// <summary>
/// footer information

View file

@ -11,7 +11,7 @@ namespace Maki.Structures.Rest
public DiscordPermission Perms;
[JsonProperty("color")]
public uint Colour;
public int Colour;
[JsonProperty("hoist")]
public bool Hoist;

View file

@ -23,7 +23,7 @@ namespace Maki.Structures.Roles
/// integer representation of hexadecimal color code
/// </summary>
[JsonProperty("color")]
public uint? Colour;
public int? Colour;
/// <summary>
/// if this role is pinned in the user listing