From 7dd2268982c4f269c1e361c7745d22139fc7f2d7 Mon Sep 17 00:00:00 2001 From: Still Hsu <341464@gmail.com> Date: Tue, 6 Nov 2018 07:32:30 +0800 Subject: [PATCH] lint: Discord Namespace Clean-up (#1185) * Remove RpcException * Move RestConnection to Discord.Net.Rest * Remove RpcVirtualMessageChannel * Move REST objects to Discord.Net.Rest * Fix Discord.Rest namespace --- src/Discord.Net.Core/Net/RpcException.cs | 17 --- .../Channels/RpcVirtualMessageChannel.cs | 110 ------------------ .../Entities/Guilds/RestGuildEmbed.cs | 2 +- .../Entities/Guilds/RestVoiceRegion.cs | 2 +- .../Entities/Users/RestConnection.cs | 2 +- 5 files changed, 3 insertions(+), 130 deletions(-) delete mode 100644 src/Discord.Net.Core/Net/RpcException.cs delete mode 100644 src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs diff --git a/src/Discord.Net.Core/Net/RpcException.cs b/src/Discord.Net.Core/Net/RpcException.cs deleted file mode 100644 index 195fad73f..000000000 --- a/src/Discord.Net.Core/Net/RpcException.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace Discord -{ - public class RpcException : Exception - { - public int ErrorCode { get; } - public string Reason { get; } - - public RpcException(int errorCode, string reason = null) - : base($"The server sent error {errorCode}{(reason != null ? $": \"{reason}\"" : "")}") - { - ErrorCode = errorCode; - Reason = reason; - } - } -} diff --git a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs deleted file mode 100644 index ce37af6b4..000000000 --- a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace Discord.Rest -{ - [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - internal class RestVirtualMessageChannel : RestEntity, IMessageChannel - { - public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); - public string Mention => MentionUtils.MentionChannel(Id); - - internal RestVirtualMessageChannel(BaseDiscordClient discord, ulong id) - : base(discord, id) - { - } - internal static RestVirtualMessageChannel Create(BaseDiscordClient discord, ulong id) - { - return new RestVirtualMessageChannel(discord, id); - } - - public Task GetMessageAsync(ulong id, RequestOptions options = null) - => ChannelHelper.GetMessageAsync(this, Discord, id, options); - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options); - public Task> GetPinnedMessagesAsync(RequestOptions options = null) - => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); - - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); - - /// - public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); - /// - public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); - - /// - public Task TriggerTypingAsync(RequestOptions options = null) - => ChannelHelper.TriggerTypingAsync(this, Discord, options); - /// - public IDisposable EnterTypingState(RequestOptions options = null) - => ChannelHelper.EnterTypingState(this, Discord, options); - - private string DebuggerDisplay => $"({Id}, Text)"; - - //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) - { - if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options).ConfigureAwait(false); - else - return null; - } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) - { - if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(limit, options); - else - return AsyncEnumerable.Empty>(); - } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) - { - if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessageId, dir, limit, options); - else - return AsyncEnumerable.Empty>(); - } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) - { - if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessage, dir, limit, options); - else - return AsyncEnumerable.Empty>(); - } - async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options).ConfigureAwait(false); - - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, embed, options); - - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options) - => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); - - //IChannel - string IChannel.Name => - throw new NotSupportedException(); - - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => - throw new NotSupportedException(); - - Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => - throw new NotSupportedException(); - } -} diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs index 00f3fae69..41c76eb06 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using Model = Discord.API.GuildEmbed; -namespace Discord +namespace Discord.Rest { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public struct RestGuildEmbed diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestVoiceRegion.cs b/src/Discord.Net.Rest/Entities/Guilds/RestVoiceRegion.cs index 7a03b68d4..a363f051b 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestVoiceRegion.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestVoiceRegion.cs @@ -2,7 +2,7 @@ using Discord.Rest; using System.Diagnostics; using Model = Discord.API.VoiceRegion; -namespace Discord +namespace Discord.Rest { /// /// Represents a REST-based voice region. diff --git a/src/Discord.Net.Rest/Entities/Users/RestConnection.cs b/src/Discord.Net.Rest/Entities/Users/RestConnection.cs index 0c91493d2..1afb813c0 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestConnection.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestConnection.cs @@ -3,7 +3,7 @@ using System.Collections.Immutable; using System.Diagnostics; using Model = Discord.API.Connection; -namespace Discord +namespace Discord.Rest { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestConnection : IConnection