Added EditServer(icon), Renamed AvatarImageType to ImageType
This commit is contained in:
@@ -40,7 +40,7 @@ namespace Discord.API
|
||||
public bool IsPrivate;
|
||||
[JsonProperty("position")]
|
||||
public int? Position;
|
||||
[JsonProperty(PropertyName = "topic")]
|
||||
[JsonProperty("topic")]
|
||||
public string Topic;
|
||||
[JsonProperty("permission_overwrites")]
|
||||
public PermissionOverwrite[] PermissionOverwrites;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum AvatarImageType
|
||||
public enum ImageType
|
||||
{
|
||||
None,
|
||||
Jpeg,
|
||||
|
||||
@@ -72,11 +72,11 @@ namespace Discord.API
|
||||
|
||||
public class EditMemberRequest
|
||||
{
|
||||
[JsonProperty(PropertyName = "mute", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonProperty("mute", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool? Mute;
|
||||
[JsonProperty(PropertyName = "deaf", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonProperty("deaf", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool? Deaf;
|
||||
[JsonProperty(PropertyName = "roles", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonProperty("roles", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IEnumerable<string> Roles;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ namespace Discord.API
|
||||
public string Name;
|
||||
[JsonProperty("region", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Region;
|
||||
[JsonProperty("icon", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Icon;
|
||||
}
|
||||
public sealed class EditServerResponse : GuildInfo { }
|
||||
|
||||
|
||||
@@ -29,15 +29,15 @@ namespace Discord.API
|
||||
//Edit
|
||||
internal sealed class EditUserRequest
|
||||
{
|
||||
[JsonProperty(PropertyName = "password")]
|
||||
[JsonProperty("password")]
|
||||
public string CurrentPassword;
|
||||
[JsonProperty(PropertyName = "email", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Email;
|
||||
[JsonProperty(PropertyName = "new_password")]
|
||||
[JsonProperty("new_password")]
|
||||
public string Password;
|
||||
[JsonProperty(PropertyName = "username", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonProperty("username", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Username;
|
||||
[JsonProperty(PropertyName = "avatar", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonProperty("avatar", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Avatar;
|
||||
}
|
||||
public sealed class EditUserResponse : UserInfo { }
|
||||
|
||||
@@ -279,31 +279,22 @@ namespace Discord
|
||||
|
||||
return _rest.Delete<DeleteServerResponse>(Endpoints.Server(serverId));
|
||||
}
|
||||
public Task<EditServerResponse> EditServer(string serverId, string name = null, string region = null)
|
||||
public Task<EditServerResponse> EditServer(string serverId, string name = null, string region = null, ImageType iconType = ImageType.Png, byte[] icon = null)
|
||||
{
|
||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
||||
|
||||
var request = new EditServerRequest { Name = name, Region = region };
|
||||
var request = new EditServerRequest { Name = name, Region = region, Icon = Base64Picture(iconType, icon) };
|
||||
return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request);
|
||||
}
|
||||
|
||||
//User
|
||||
public Task<EditUserResponse> EditUser(string currentPassword = "",
|
||||
string username = null, string email = null, string password = null,
|
||||
AvatarImageType avatarType = AvatarImageType.Png, byte[] avatar = null)
|
||||
ImageType avatarType = ImageType.Png, byte[] avatar = null)
|
||||
{
|
||||
if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword));
|
||||
|
||||
string avatarBase64 = null;
|
||||
if (avatarType == AvatarImageType.None)
|
||||
avatarBase64 = "";
|
||||
else if (avatar != null)
|
||||
{
|
||||
string base64 = Convert.ToBase64String(avatar);
|
||||
string type = avatarType == AvatarImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64";
|
||||
avatarBase64 = $"data:{type},{base64}";
|
||||
}
|
||||
var request = new EditUserRequest { CurrentPassword = currentPassword, Username = username, Email = email, Password = password, Avatar = avatarBase64 };
|
||||
|
||||
var request = new EditUserRequest { CurrentPassword = currentPassword, Username = username, Email = email, Password = password, Avatar = Base64Picture(avatarType, avatar) };
|
||||
return _rest.Patch<EditUserResponse>(Endpoints.UserMe, request);
|
||||
}
|
||||
|
||||
@@ -312,5 +303,18 @@ namespace Discord
|
||||
=> _rest.Get<GetRegionsResponse>(Endpoints.VoiceRegions);
|
||||
/*public Task<GetIceResponse> GetVoiceIce()
|
||||
=> _rest.Get<GetIceResponse>(Endpoints.VoiceIce);*/
|
||||
|
||||
private string Base64Picture(ImageType type, byte[] data)
|
||||
{
|
||||
if (type == ImageType.None)
|
||||
return "";
|
||||
else if (data != null)
|
||||
{
|
||||
string base64 = Convert.ToBase64String(data);
|
||||
string imageType = type == ImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64";
|
||||
return $"data:{imageType},{base64}";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ namespace Discord
|
||||
//Profile
|
||||
public Task<EditUserResponse> EditProfile(string currentPassword = "",
|
||||
string username = null, string email = null, string password = null,
|
||||
AvatarImageType avatarType = AvatarImageType.Png, byte[] avatar = null)
|
||||
ImageType avatarType = ImageType.Png, byte[] avatar = null)
|
||||
{
|
||||
if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword));
|
||||
|
||||
@@ -727,18 +727,16 @@ namespace Discord
|
||||
}
|
||||
|
||||
/// <summary> Edits the provided server, changing only non-null attributes. </summary>
|
||||
public Task EditServer(Server server)
|
||||
=> EditServer(server?.Id);
|
||||
public Task EditServer(string serverId, string name = null, string region = null, ImageType iconType = ImageType.Png, byte[] icon = null)
|
||||
=> EditServer(_servers[serverId], name: name, region: region, iconType: iconType, icon: icon);
|
||||
/// <summary> Edits the provided server, changing only non-null attributes. </summary>
|
||||
public async Task EditServer(string serverId, string name = null, string region = null)
|
||||
public async Task EditServer(Server server, string name = null, string region = null, ImageType iconType = ImageType.Png, byte[] icon = null)
|
||||
{
|
||||
CheckReady();
|
||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
||||
CheckReady();
|
||||
if (server == null) throw new ArgumentNullException(nameof(server));
|
||||
|
||||
var response = await _api.EditServer(serverId, name: name, region: region);
|
||||
var server = _servers[response.Id];
|
||||
if (server != null)
|
||||
server.Update(response);
|
||||
var response = await _api.EditServer(server.Id, name: name ?? server.Name, region: region, iconType: iconType, icon: icon);
|
||||
server.Update(response);
|
||||
}
|
||||
|
||||
/// <summary> Leaves the provided server, destroying it if you are the owner. </summary>
|
||||
|
||||
Reference in New Issue
Block a user