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
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<ulong>, 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<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
|
|
||||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
|
|
||||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
|
|
||||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
|
|
||||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
|
||||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
|
||||||
|
|
||||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
|
||||||
public Task<RestUserMessage> 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<RestUserMessage> 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);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options);
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
|
|
||||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task TriggerTypingAsync(RequestOptions options = null)
|
|
||||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options);
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IDisposable EnterTypingState(RequestOptions options = null)
|
|
||||||
=> ChannelHelper.EnterTypingState(this, Discord, options);
|
|
||||||
|
|
||||||
private string DebuggerDisplay => $"({Id}, Text)";
|
|
||||||
|
|
||||||
//IMessageChannel
|
|
||||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
|
||||||
{
|
|
||||||
if (mode == CacheMode.AllowDownload)
|
|
||||||
return await GetMessageAsync(id, options).ConfigureAwait(false);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
|
||||||
{
|
|
||||||
if (mode == CacheMode.AllowDownload)
|
|
||||||
return GetMessagesAsync(limit, options);
|
|
||||||
else
|
|
||||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
|
||||||
}
|
|
||||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> 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<IReadOnlyCollection<IMessage>>();
|
|
||||||
}
|
|
||||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> 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<IReadOnlyCollection<IMessage>>();
|
|
||||||
}
|
|
||||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
|
|
||||||
=> await GetPinnedMessagesAsync(options).ConfigureAwait(false);
|
|
||||||
|
|
||||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options)
|
|
||||||
=> await SendFileAsync(filePath, text, isTTS, embed, options);
|
|
||||||
|
|
||||||
async Task<IUserMessage> 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<IUserMessage> 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<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) =>
|
|
||||||
throw new NotSupportedException();
|
|
||||||
|
|
||||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) =>
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Model = Discord.API.GuildEmbed;
|
using Model = Discord.API.GuildEmbed;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord.Rest
|
||||||
{
|
{
|
||||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||||
public struct RestGuildEmbed
|
public struct RestGuildEmbed
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ using Discord.Rest;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Model = Discord.API.VoiceRegion;
|
using Model = Discord.API.VoiceRegion;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord.Rest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a REST-based voice region.
|
/// Represents a REST-based voice region.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Collections.Immutable;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Model = Discord.API.Connection;
|
using Model = Discord.API.Connection;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord.Rest
|
||||||
{
|
{
|
||||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||||
public class RestConnection : IConnection
|
public class RestConnection : IConnection
|
||||||
|
|||||||
Reference in New Issue
Block a user