diff --git a/src/Discord.Net/DiscordClient.Channels.cs b/src/Discord.Net/DiscordClient.Channels.cs index edae2f010..33532cbcc 100644 --- a/src/Discord.Net/DiscordClient.Channels.cs +++ b/src/Discord.Net/DiscordClient.Channels.cs @@ -162,14 +162,14 @@ namespace Discord } /// Destroys the provided channel. - public async Task DestroyChannel(Channel channel) + public async Task DestroyChannel(Channel channel) { if (channel == null) throw new ArgumentNullException(nameof(channel)); CheckReady(); try { await _api.DestroyChannel(channel.Id).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } - return _channels.TryRemove(channel.Id); + //return _channels.TryRemove(channel.Id); } } } \ No newline at end of file diff --git a/src/Discord.Net/DiscordClient.Messages.cs b/src/Discord.Net/DiscordClient.Messages.cs index f4f27da7f..ee1d32647 100644 --- a/src/Discord.Net/DiscordClient.Messages.cs +++ b/src/Discord.Net/DiscordClient.Messages.cs @@ -161,7 +161,7 @@ namespace Discord /// Edits the provided message, changing only non-null attributes. /// While not required, it is recommended to include a mention reference in the text (see Mention.User). - public async Task EditMessage(Message message, string text) + public Task EditMessage(Message message, string text) { if (message == null) throw new ArgumentNullException(nameof(message)); CheckReady(); @@ -169,8 +169,7 @@ namespace Discord if (text != null && text.Length > MaxMessageSize) text = text.Substring(0, MaxMessageSize); - var model = await _api.EditMessage(message.Id, message.Channel.Id, text, Mention.GetUserIds(text)).ConfigureAwait(false); - message.Update(model); + return _api.EditMessage(message.Id, message.Channel.Id, text, Mention.GetUserIds(text)); } /// Deletes the provided message. @@ -219,7 +218,7 @@ namespace Discord msg = _messages.GetOrAdd(x.Id, x.ChannelId, x.Author.Id); else msg = _messages[x.Id] ?? new Message(this, x.Id, x.ChannelId, x.Author.Id); - msg.Update(x); + //msg.Update(x); if (Config.TrackActivity) { if (!channel.IsPrivate) diff --git a/src/Discord.Net/DiscordClient.Permissions.cs b/src/Discord.Net/DiscordClient.Permissions.cs index 34f310947..98065428e 100644 --- a/src/Discord.Net/DiscordClient.Permissions.cs +++ b/src/Discord.Net/DiscordClient.Permissions.cs @@ -39,61 +39,8 @@ namespace Discord return SetChannelPermissions(channel, role?.Id, PermissionTarget.Role, permissions?.Allow, permissions?.Deny); } - private async Task SetChannelPermissions(Channel channel, string targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null) - { - uint allowValue = allow?.RawValue ?? 0; - uint denyValue = deny?.RawValue ?? 0; - bool changed = false; - - var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != targetId).FirstOrDefault(); - if (allowValue != 0 || denyValue != 0) - { - await _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allowValue, denyValue).ConfigureAwait(false); - if (perms != null) - { - perms.Allow.SetRawValueInternal(allowValue); - perms.Deny.SetRawValueInternal(denyValue); - } - else - { - var oldPerms = channel.PermissionOverwrites.ToArray(); - var newPerms = new Channel.PermissionOverwrite[oldPerms.Length + 1]; - Array.Copy(oldPerms, newPerms, oldPerms.Length); - newPerms[oldPerms.Length] = new Channel.PermissionOverwrite(targetType, targetId, allowValue, denyValue); - channel.PermissionOverwrites = newPerms; - } - changed = true; - } - else - { - try - { - await _api.DeleteChannelPermissions(channel.Id, targetId).ConfigureAwait(false); - if (perms != null) - { - channel.PermissionOverwrites = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != targetId).ToArray(); - changed = true; - } - } - catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } - } - - if (changed) - { - if (targetType == PermissionTarget.Role) - { - var role = _roles[targetId]; - if (role != null) - channel.InvalidatePermissionsCache(role); - } - else if (targetType == PermissionTarget.User) - { - var user = _users[targetId, channel.Server?.Id]; - if (user != null) - channel.InvalidatePermissionsCache(user); - } - } - } + private Task SetChannelPermissions(Channel channel, string targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null) + => _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allow?.RawValue ?? 0, deny?.RawValue ?? 0); public Task RemoveChannelUserPermissions(Channel channel, User user) { @@ -117,22 +64,6 @@ namespace Discord { var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault(); await _api.DeleteChannelPermissions(channel.Id, userOrRoleId).ConfigureAwait(false); - if (perms != null) - { - channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).ToArray(); - - if (targetType == PermissionTarget.Role) - { - var role = _roles[userOrRoleId]; - channel.InvalidatePermissionsCache(role); - } - else if (targetType == PermissionTarget.User) - { - var user = _users[userOrRoleId, channel.Server?.Id]; - if (user != null) - channel.InvalidatePermissionsCache(user); - } - } } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } } diff --git a/src/Discord.Net/DiscordClient.Roles.cs b/src/Discord.Net/DiscordClient.Roles.cs index 09de24c7f..514aa12ab 100644 --- a/src/Discord.Net/DiscordClient.Roles.cs +++ b/src/Discord.Net/DiscordClient.Roles.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Threading.Tasks; namespace Discord @@ -62,17 +63,18 @@ namespace Discord if (name == null) throw new ArgumentNullException(nameof(name)); CheckReady(); - if (name.StartsWith("@")) + /*if (name.StartsWith("@")) { string name2 = name.Substring(1); return _roles.Where(x => x.Server.Id == server.Id && - string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) || string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase)); + string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) || + string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase)); } else - { + {*/ return _roles.Where(x => x.Server.Id == server.Id && string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); - } + //} } /// Note: due to current API limitations, the created role cannot be returned. @@ -84,10 +86,10 @@ namespace Discord var response = await _api.CreateRole(server.Id).ConfigureAwait(false); var role = _roles.GetOrAdd(response.Id, server.Id); + await _api.EditRole(server.Id, role.Id, name: name).ConfigureAwait(false); + response.Name = name; role.Update(response); - await EditRole(role, name: name).ConfigureAwait(false); - return role; } @@ -128,13 +130,14 @@ namespace Discord } } - public Task DeleteRole(Role role) + public async Task DeleteRole(Role role) { if (role == null) throw new ArgumentNullException(nameof(role)); CheckReady(); - return _api.DeleteRole(role.Server.Id, role.Id); - } + try { await _api.DeleteRole(role.Server.Id, role.Id); } + catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { } + } public Task ReorderRoles(Server server, IEnumerable roles, int startPos = 0) { diff --git a/src/Discord.Net/DiscordClient.Servers.cs b/src/Discord.Net/DiscordClient.Servers.cs index 1d5228916..ff66948f4 100644 --- a/src/Discord.Net/DiscordClient.Servers.cs +++ b/src/Discord.Net/DiscordClient.Servers.cs @@ -104,14 +104,14 @@ namespace Discord } /// Leaves the provided server, destroying it if you are the owner. - public async Task LeaveServer(Server server) + public async Task LeaveServer(Server server) { if (server == null) throw new ArgumentNullException(nameof(server)); CheckReady(); try { await _api.LeaveServer(server.Id).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } - return _servers.TryRemove(server.Id); + //return _servers.TryRemove(server.Id); } } } \ No newline at end of file diff --git a/src/Discord.Net/DiscordClient.Users.cs b/src/Discord.Net/DiscordClient.Users.cs index 3c2a813a3..dba8f06a4 100644 --- a/src/Discord.Net/DiscordClient.Users.cs +++ b/src/Discord.Net/DiscordClient.Users.cs @@ -159,9 +159,7 @@ namespace Discord string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase)); } else - { query = server.Members.Where(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)); - } if (discriminator != null) query = query.Where(x => x.Discriminator == discriminator); return query; @@ -190,10 +188,10 @@ namespace Discord public Task SetStatus(UserStatus status) { if (status == (string)null) throw new ArgumentNullException(nameof(status)); - CheckReady(); - if (status != UserStatus.Online && status != UserStatus.Idle) - throw new ArgumentException($"Invalid status, must be {UserStatus.Online} or {UserStatus.Idle}"); + throw new ArgumentException($"Invalid status, must be {UserStatus.Online} or {UserStatus.Idle}", nameof(status)); + CheckReady(); + _status = status; return SendStatus(); }