|
|
@@ -0,0 +1,123 @@ |
|
|
|
using Discord.Rest; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Immutable; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Model = Discord.API.Rpc.Channel; |
|
|
|
|
|
|
|
namespace Discord.Rpc |
|
|
|
{ |
|
|
|
public class RpcGroupChannel : RpcChannel, IRpcMessageChannel, IRpcAudioChannel, IRpcPrivateChannel, IGroupChannel |
|
|
|
{ |
|
|
|
public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; } |
|
|
|
public IReadOnlyCollection<RpcVoiceState> VoiceStates { get; private set; } |
|
|
|
|
|
|
|
internal RpcGroupChannel(DiscordRpcClient discord, ulong id) |
|
|
|
: base(discord, id) |
|
|
|
{ |
|
|
|
} |
|
|
|
internal new static RpcGroupChannel Create(DiscordRpcClient discord, Model model) |
|
|
|
{ |
|
|
|
var entity = new RpcGroupChannel(discord, model.Id); |
|
|
|
entity.Update(model); |
|
|
|
return entity; |
|
|
|
} |
|
|
|
internal override void Update(Model model) |
|
|
|
{ |
|
|
|
base.Update(model); |
|
|
|
CachedMessages = model.Messages.Select(x => RpcMessage.Create(Discord, Id, x)).ToImmutableArray(); |
|
|
|
VoiceStates = model.VoiceStates.Select(x => RpcVoiceState.Create(Discord, x)).ToImmutableArray(); |
|
|
|
} |
|
|
|
|
|
|
|
public Task LeaveAsync(RequestOptions options = null) |
|
|
|
=> ChannelHelper.DeleteAsync(this, Discord, options); |
|
|
|
|
|
|
|
//TODO: Use RPC cache |
|
|
|
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null) |
|
|
|
=> ChannelHelper.GetMessageAsync(this, Discord, id, null, options); |
|
|
|
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) |
|
|
|
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, null, options); |
|
|
|
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) |
|
|
|
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, null, 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, null, options); |
|
|
|
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) |
|
|
|
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); |
|
|
|
|
|
|
|
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null) |
|
|
|
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); |
|
|
|
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) |
|
|
|
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); |
|
|
|
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) |
|
|
|
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, null, options); |
|
|
|
|
|
|
|
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null) |
|
|
|
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); |
|
|
|
|
|
|
|
public Task TriggerTypingAsync(RequestOptions options = null) |
|
|
|
=> ChannelHelper.TriggerTypingAsync(this, Discord, options); |
|
|
|
public IDisposable EnterTypingState(RequestOptions options = null) |
|
|
|
=> ChannelHelper.EnterTypingState(this, Discord, options); |
|
|
|
|
|
|
|
public override string ToString() => Id.ToString(); |
|
|
|
private string DebuggerDisplay => $"({Id}, Group)"; |
|
|
|
|
|
|
|
//IPrivateChannel |
|
|
|
IReadOnlyCollection<IUser> IPrivateChannel.Recipients { get { throw new NotSupportedException(); } } |
|
|
|
|
|
|
|
//IMessageChannel |
|
|
|
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) |
|
|
|
{ |
|
|
|
if (mode == CacheMode.AllowDownload) |
|
|
|
return await GetMessageAsync(id, options); |
|
|
|
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); |
|
|
|
|
|
|
|
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) |
|
|
|
=> await SendFileAsync(filePath, text, isTTS, options); |
|
|
|
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) |
|
|
|
=> await SendFileAsync(stream, filename, text, isTTS, options); |
|
|
|
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) |
|
|
|
=> await SendMessageAsync(text, isTTS, options); |
|
|
|
IDisposable IMessageChannel.EnterTypingState(RequestOptions options) |
|
|
|
=> EnterTypingState(options); |
|
|
|
|
|
|
|
//IChannel |
|
|
|
string IChannel.Name { get { throw new NotSupportedException(); } } |
|
|
|
|
|
|
|
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) |
|
|
|
{ |
|
|
|
throw new NotSupportedException(); |
|
|
|
} |
|
|
|
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) |
|
|
|
{ |
|
|
|
throw new NotSupportedException(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |