@@ -135,8 +135,8 @@ namespace Discord | |||||
public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, IEnumerable<object> roles = null) | public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, IEnumerable<object> roles = null) | ||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
if (serverId == null) throw new NullReferenceException(nameof(serverId)); | |||||
if (userId == null) throw new NullReferenceException(nameof(userId)); | |||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||||
if (userId == null) throw new ArgumentNullException(nameof(userId)); | |||||
var newRoles = CollectionHelper.FlattenRoles(roles); | var newRoles = CollectionHelper.FlattenRoles(roles); | ||||
return _api.EditMember(serverId, userId, mute: mute, deaf: deaf, roles: newRoles); | return _api.EditMember(serverId, userId, mute: mute, deaf: deaf, roles: newRoles); | ||||
@@ -228,8 +228,8 @@ namespace Discord | |||||
public async Task<Message[]> DownloadMessages(string channelId, int count, string beforeMessageId = null, bool cache = true) | public async Task<Message[]> DownloadMessages(string channelId, int count, string beforeMessageId = null, bool cache = true) | ||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
if (channelId == null) throw new NullReferenceException(nameof(channelId)); | |||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); | |||||
if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||||
if (count < 0) throw new ArgumentNullException(nameof(count)); | |||||
if (count == 0) return new Message[0]; | if (count == 0) return new Message[0]; | ||||
Channel channel = _channels[channelId]; | Channel channel = _channels[channelId]; | ||||
@@ -33,9 +33,9 @@ namespace Discord | |||||
private async Task SetChannelPermissions(Channel channel, string targetId, string targetType, PackedChannelPermissions allow = null, PackedChannelPermissions deny = null) | private async Task SetChannelPermissions(Channel channel, string targetId, string targetType, PackedChannelPermissions allow = null, PackedChannelPermissions deny = null) | ||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
if (channel == null) throw new NullReferenceException(nameof(channel)); | |||||
if (targetId == null) throw new NullReferenceException(nameof(targetId)); | |||||
if (targetType == null) throw new NullReferenceException(nameof(targetType)); | |||||
if (channel == null) throw new ArgumentNullException(nameof(channel)); | |||||
if (targetId == null) throw new ArgumentNullException(nameof(targetId)); | |||||
if (targetType == null) throw new ArgumentNullException(nameof(targetType)); | |||||
uint allowValue = allow?.RawValue ?? 0; | uint allowValue = allow?.RawValue ?? 0; | ||||
uint denyValue = deny?.RawValue ?? 0; | uint denyValue = deny?.RawValue ?? 0; | ||||
@@ -108,9 +108,9 @@ namespace Discord | |||||
private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, string idType) | private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, string idType) | ||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
if (channel == null) throw new NullReferenceException(nameof(channel)); | |||||
if (userOrRoleId == null) throw new NullReferenceException(nameof(userOrRoleId)); | |||||
if (idType == null) throw new NullReferenceException(nameof(idType)); | |||||
if (channel == null) throw new ArgumentNullException(nameof(channel)); | |||||
if (userOrRoleId == null) throw new ArgumentNullException(nameof(userOrRoleId)); | |||||
if (idType == null) throw new ArgumentNullException(nameof(idType)); | |||||
try | try | ||||
{ | { | ||||
@@ -80,7 +80,7 @@ namespace Discord | |||||
public async Task<Role> CreateRole(string serverId, string name) | public async Task<Role> CreateRole(string serverId, string name) | ||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
if (serverId == null) throw new NullReferenceException(nameof(serverId)); | |||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||||
var response = await _api.CreateRole(serverId).ConfigureAwait(false); | var response = await _api.CreateRole(serverId).ConfigureAwait(false); | ||||
var role = _roles.GetOrAdd(response.Id, serverId); | var role = _roles.GetOrAdd(response.Id, serverId); | ||||
@@ -91,20 +91,19 @@ namespace Discord | |||||
return role; | return role; | ||||
} | } | ||||
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) | |||||
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) | |||||
{ | { | ||||
CheckReady(); | |||||
if (serverId == null) throw new NullReferenceException(nameof(serverId)); | |||||
if (roleId == null) throw new NullReferenceException(nameof(roleId)); | |||||
CheckReady(); | |||||
if (role == null) throw new ArgumentNullException(nameof(role)); | |||||
var response = await _api.EditRole(serverId, roleId, name: name, | |||||
permissions: permissions?.RawValue, color: color?.RawValue, hoist: hoist); | |||||
var role = _roles[response.Id]; | |||||
if (role != null) | |||||
role.Update(response); | |||||
//TODO: check this null workaround later, should be fixed on Discord's end soon | |||||
var response = await _api.EditRole(role.ServerId, role.Id, | |||||
name: name ?? role.Name, | |||||
permissions: permissions?.RawValue ?? role.Permissions.RawValue, | |||||
color: color?.RawValue, | |||||
hoist: hoist); | |||||
if (position != null) | if (position != null) | ||||
{ | { | ||||
@@ -136,8 +135,8 @@ namespace Discord | |||||
public Task DeleteRole(string serverId, string roleId) | public Task DeleteRole(string serverId, string roleId) | ||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
if (serverId == null) throw new NullReferenceException(nameof(serverId)); | |||||
if (roleId == null) throw new NullReferenceException(nameof(roleId)); | |||||
if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||||
if (roleId == null) throw new ArgumentNullException(nameof(roleId)); | |||||
return _api.DeleteRole(serverId, roleId); | return _api.DeleteRole(serverId, roleId); | ||||
} | } | ||||