Added CreateRole and EditRole responses
This commit is contained in:
@@ -48,6 +48,10 @@ namespace Discord.API
|
|||||||
//Profile
|
//Profile
|
||||||
public sealed class EditProfileResponse : SelfUserInfo { }
|
public sealed class EditProfileResponse : SelfUserInfo { }
|
||||||
|
|
||||||
|
//Roles
|
||||||
|
public sealed class CreateRoleResponse : RoleInfo { }
|
||||||
|
public sealed class EditRoleResponse : RoleInfo { }
|
||||||
|
|
||||||
//Servers
|
//Servers
|
||||||
public sealed class CreateServerResponse : GuildInfo { }
|
public sealed class CreateServerResponse : GuildInfo { }
|
||||||
public sealed class DeleteServerResponse : GuildInfo { }
|
public sealed class DeleteServerResponse : GuildInfo { }
|
||||||
|
|||||||
@@ -256,12 +256,11 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Roles
|
//Roles
|
||||||
public Task CreateRole(string serverId)
|
public Task<RoleInfo> CreateRole(string serverId)
|
||||||
{
|
{
|
||||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
||||||
|
|
||||||
//TODO: Return a response when Discord starts giving us one
|
return _rest.Post<RoleInfo>(Endpoints.ServerRoles(serverId));
|
||||||
return _rest.Post(Endpoints.ServerRoles(serverId));
|
|
||||||
}
|
}
|
||||||
public Task DeleteRole(string serverId, string roleId)
|
public Task DeleteRole(string serverId, string roleId)
|
||||||
{
|
{
|
||||||
@@ -270,13 +269,13 @@ namespace Discord
|
|||||||
|
|
||||||
return _rest.Delete(Endpoints.ServerRole(serverId, roleId));
|
return _rest.Delete(Endpoints.ServerRole(serverId, roleId));
|
||||||
}
|
}
|
||||||
public Task EditRole(string serverId, string roleId, string name = null, uint? permissions = null, uint? color = null, bool? hoist = null)
|
public Task<RoleInfo> EditRole(string serverId, string roleId, string name = null, uint? permissions = null, uint? color = null, bool? hoist = null)
|
||||||
{
|
{
|
||||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
|
||||||
if (roleId == null) throw new ArgumentNullException(nameof(roleId));
|
if (roleId == null) throw new ArgumentNullException(nameof(roleId));
|
||||||
|
|
||||||
var request = new EditRoleRequest { Name = name, Permissions = permissions, Hoist = hoist, Color = color };
|
var request = new EditRoleRequest { Name = name, Permissions = permissions, Hoist = hoist, Color = color };
|
||||||
return _rest.Patch(Endpoints.ServerRole(serverId, roleId), request);
|
return _rest.Patch<RoleInfo>(Endpoints.ServerRole(serverId, roleId), request);
|
||||||
}
|
}
|
||||||
public Task ReorderRoles(string serverId, IEnumerable<string> roleIds, int startPos = 0)
|
public Task ReorderRoles(string serverId, IEnumerable<string> roleIds, int startPos = 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -665,30 +665,34 @@ namespace Discord
|
|||||||
|
|
||||||
//Roles
|
//Roles
|
||||||
/// <summary> Note: due to current API limitations, the created role cannot be returned. </summary>
|
/// <summary> Note: due to current API limitations, the created role cannot be returned. </summary>
|
||||||
public Task CreateRole(Server server)
|
public Task<Role> CreateRole(Server server)
|
||||||
=> CreateRole(server?.Id);
|
=> CreateRole(server?.Id);
|
||||||
/// <summary> Note: due to current API limitations, the created role cannot be returned. </summary>
|
/// <summary> Note: due to current API limitations, the created role cannot be returned. </summary>
|
||||||
public Task CreateRole(string serverId)
|
public async Task<Role> CreateRole(string serverId)
|
||||||
{
|
{
|
||||||
CheckReady();
|
CheckReady();
|
||||||
if (serverId == null) throw new NullReferenceException(nameof(serverId));
|
if (serverId == null) throw new NullReferenceException(nameof(serverId));
|
||||||
|
|
||||||
return _api.CreateRole(serverId);
|
var response = await _api.CreateRole(serverId).ConfigureAwait(false);
|
||||||
|
var role = _roles.GetOrAdd(response.Id, serverId, false);
|
||||||
|
role.Update(response);
|
||||||
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task EditRole(string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
|
public Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
|
||||||
=> EditRole(_roles[roleId], name: name, permissions: permissions, color: color, hoist: hoist, position: position);
|
=> EditRole(role.ServerId, role.Id, name: name, permissions: permissions, color: color, hoist: hoist, position: position);
|
||||||
public async Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
|
public async Task EditRole(string serverId, string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
|
||||||
{
|
{
|
||||||
CheckReady();
|
CheckReady();
|
||||||
if (role == null) throw new NullReferenceException(nameof(role));
|
if (serverId == null) throw new NullReferenceException(nameof(serverId));
|
||||||
|
if (roleId == null) throw new NullReferenceException(nameof(roleId));
|
||||||
|
|
||||||
//TODO: Stop defaulting to cache variables once the server stops 500ing at us
|
var response = await _api.EditRole(serverId, roleId, name: name,
|
||||||
await _api.EditRole(role.ServerId, role.Id,
|
permissions: permissions?.RawValue, color: color?.RawValue, hoist: hoist);
|
||||||
name: name ?? role.Name,
|
|
||||||
permissions: permissions?.RawValue ?? role.Permissions.RawValue,
|
var role = _roles[response.Id];
|
||||||
color: color?.RawValue ?? role.Color.RawValue,
|
if (role != null)
|
||||||
hoist: hoist ?? role.Hoist);
|
role.Update(response);
|
||||||
|
|
||||||
if (position != null)
|
if (position != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user