Added CreateRole and EditRole responses

This commit is contained in:
RogueException
2015-10-16 23:37:43 -03:00
parent bcb33b54ac
commit f087eeabf4
3 changed files with 26 additions and 19 deletions

View File

@@ -47,6 +47,10 @@ namespace Discord.API
//Profile
public sealed class EditProfileResponse : SelfUserInfo { }
//Roles
public sealed class CreateRoleResponse : RoleInfo { }
public sealed class EditRoleResponse : RoleInfo { }
//Servers
public sealed class CreateServerResponse : GuildInfo { }

View File

@@ -256,12 +256,11 @@ namespace Discord
}
//Roles
public Task CreateRole(string serverId)
public Task<RoleInfo> CreateRole(string serverId)
{
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
//TODO: Return a response when Discord starts giving us one
return _rest.Post(Endpoints.ServerRoles(serverId));
return _rest.Post<RoleInfo>(Endpoints.ServerRoles(serverId));
}
public Task DeleteRole(string serverId, string roleId)
{
@@ -270,13 +269,13 @@ namespace Discord
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 (roleId == null) throw new ArgumentNullException(nameof(roleId));
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)
{

View File

@@ -665,30 +665,34 @@ namespace Discord
//Roles
/// <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);
/// <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();
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)
=> EditRole(_roles[roleId], 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 Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
=> EditRole(role.ServerId, role.Id, name: name, permissions: permissions, color: color, hoist: hoist, position: position);
public async Task EditRole(string serverId, string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
{
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));
var response = await _api.EditRole(serverId, roleId, name: name,
permissions: permissions?.RawValue, color: color?.RawValue, hoist: hoist);
//TODO: Stop defaulting to cache variables once the server stops 500ing at us
await _api.EditRole(role.ServerId, role.Id,
name: name ?? role.Name,
permissions: permissions?.RawValue ?? role.Permissions.RawValue,
color: color?.RawValue ?? role.Color.RawValue,
hoist: hoist ?? role.Hoist);
var role = _roles[response.Id];
if (role != null)
role.Update(response);
if (position != null)
{