Remove RPC from main distribution (#925)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public interface IRpcAudioChannel : IAudioChannel
|
||||
{
|
||||
IReadOnlyCollection<RpcVoiceState> VoiceStates { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public interface IRpcMessageChannel : IMessageChannel
|
||||
{
|
||||
IReadOnlyCollection<RpcMessage> CachedMessages { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public interface IRpcPrivateChannel
|
||||
{
|
||||
}
|
||||
}
|
||||
43
experiment/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs
Normal file
43
experiment/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
|
||||
using Model = Discord.API.Rpc.Channel;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class RpcChannel : RpcEntity<ulong>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
internal RpcChannel(DiscordRpcClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
}
|
||||
internal static RpcChannel Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
if (model.GuildId.IsSpecified)
|
||||
return RpcGuildChannel.Create(discord, model);
|
||||
else
|
||||
return CreatePrivate(discord, model);
|
||||
}
|
||||
internal static RpcChannel CreatePrivate(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
switch (model.Type)
|
||||
{
|
||||
case ChannelType.DM:
|
||||
return RpcDMChannel.Create(discord, model);
|
||||
case ChannelType.Group:
|
||||
return RpcGroupChannel.Create(discord, model);
|
||||
default:
|
||||
throw new InvalidOperationException($"Unexpected channel type: {model.Type}");
|
||||
}
|
||||
}
|
||||
internal virtual void Update(Model model)
|
||||
{
|
||||
if (model.Name.IsSpecified)
|
||||
Name = model.Name.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.ChannelSummary;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcChannelSummary
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public string Name { get; private set; }
|
||||
public ChannelType Type { get; private set; }
|
||||
|
||||
internal RpcChannelSummary(ulong id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
internal static RpcChannelSummary Create(Model model)
|
||||
{
|
||||
var entity = new RpcChannelSummary(model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Type = model.Type;
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, {Type})";
|
||||
}
|
||||
}
|
||||
125
experiment/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs
Normal file
125
experiment/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
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 RpcDMChannel : RpcChannel, IRpcMessageChannel, IRpcPrivateChannel, IDMChannel
|
||||
{
|
||||
public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; }
|
||||
|
||||
internal RpcDMChannel(DiscordRpcClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
}
|
||||
internal static new RpcDMChannel Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
var entity = new RpcDMChannel(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();
|
||||
}
|
||||
|
||||
public Task CloseAsync(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, 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, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if FILESYSTEM
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
|
||||
#endif
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, 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}, DM)";
|
||||
|
||||
//IDMChannel
|
||||
IUser IDMChannel.Recipient { get { throw new NotSupportedException(); } }
|
||||
|
||||
//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).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);
|
||||
|
||||
#if FILESYSTEM
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false);
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
128
experiment/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs
Normal file
128
experiment/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Discord.Audio;
|
||||
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, 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, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if FILESYSTEM
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
|
||||
#endif
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, 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).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);
|
||||
|
||||
#if FILESYSTEM
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false);
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
//IAudioChannel
|
||||
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
|
||||
|
||||
//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();
|
||||
}
|
||||
}
|
||||
}
|
||||
102
experiment/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs
Normal file
102
experiment/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Rpc.Channel;
|
||||
using Discord.Rest;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class RpcGuildChannel : RpcChannel, IGuildChannel
|
||||
{
|
||||
public ulong GuildId { get; }
|
||||
public int Position { get; private set; }
|
||||
|
||||
internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId)
|
||||
: base(discord, id)
|
||||
{
|
||||
GuildId = guildId;
|
||||
}
|
||||
internal new static RpcGuildChannel Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
switch (model.Type)
|
||||
{
|
||||
case ChannelType.Text:
|
||||
return RpcTextChannel.Create(discord, model);
|
||||
case ChannelType.Voice:
|
||||
return RpcVoiceChannel.Create(discord, model);
|
||||
default:
|
||||
throw new InvalidOperationException("Unknown guild channel type");
|
||||
}
|
||||
}
|
||||
internal override void Update(Model model)
|
||||
{
|
||||
base.Update(model);
|
||||
if (model.Position.IsSpecified)
|
||||
Position = model.Position.Value;
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
|
||||
=> ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options);
|
||||
public Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
|
||||
=> ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options);
|
||||
public Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
|
||||
=> ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options);
|
||||
public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
|
||||
=> ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options);
|
||||
|
||||
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
|
||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);
|
||||
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
|
||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
//IGuildChannel
|
||||
IGuild IGuildChannel.Guild
|
||||
{
|
||||
get
|
||||
{
|
||||
//Always fails
|
||||
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
|
||||
}
|
||||
}
|
||||
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
|
||||
=> await GetInvitesAsync(options).ConfigureAwait(false);
|
||||
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
|
||||
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
|
||||
|
||||
IReadOnlyCollection<Overwrite> IGuildChannel.PermissionOverwrites { get { throw new NotSupportedException(); } }
|
||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
//IChannel
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
134
experiment/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs
Normal file
134
experiment/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Rpc.Channel;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcTextChannel : RpcGuildChannel, IRpcMessageChannel, ITextChannel
|
||||
{
|
||||
public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; }
|
||||
|
||||
public string Mention => MentionUtils.MentionChannel(Id);
|
||||
// TODO: Check if RPC includes the 'nsfw' field on Channel models
|
||||
public bool IsNsfw => ChannelHelper.IsNsfw(this);
|
||||
|
||||
internal RpcTextChannel(DiscordRpcClient discord, ulong id, ulong guildId)
|
||||
: base(discord, id, guildId)
|
||||
{
|
||||
}
|
||||
internal new static RpcVoiceChannel Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
var entity = new RpcVoiceChannel(discord, model.Id, model.GuildId.Value);
|
||||
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();
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
//TODO: Use RPC cache
|
||||
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, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if FILESYSTEM
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
|
||||
#endif
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);
|
||||
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages.Select(x => x.Id), options);
|
||||
public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options);
|
||||
|
||||
public Task TriggerTypingAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options);
|
||||
public IDisposable EnterTypingState(RequestOptions options = null)
|
||||
=> ChannelHelper.EnterTypingState(this, Discord, options);
|
||||
|
||||
//Webhooks
|
||||
public Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
|
||||
=> ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options);
|
||||
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
|
||||
=> ChannelHelper.GetWebhookAsync(this, Discord, id, options);
|
||||
public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetWebhooksAsync(this, Discord, options);
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, Text)";
|
||||
|
||||
//ITextChannel
|
||||
string ITextChannel.Topic { get { throw new NotSupportedException(); } }
|
||||
async Task<IWebhook> ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options)
|
||||
=> await CreateWebhookAsync(name, avatar, options);
|
||||
async Task<IWebhook> ITextChannel.GetWebhookAsync(ulong id, RequestOptions options)
|
||||
=> await GetWebhookAsync(id, options);
|
||||
async Task<IReadOnlyCollection<IWebhook>> ITextChannel.GetWebhooksAsync(RequestOptions options)
|
||||
=> await GetWebhooksAsync(options);
|
||||
|
||||
//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);
|
||||
|
||||
#if FILESYSTEM
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false);
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Discord.Audio;
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Rpc.Channel;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcVoiceChannel : RpcGuildChannel, IRpcAudioChannel, IVoiceChannel
|
||||
{
|
||||
public int Bitrate { get; private set; }
|
||||
public int? UserLimit { get; private set; }
|
||||
public IReadOnlyCollection<RpcVoiceState> VoiceStates { get; private set; }
|
||||
|
||||
internal RpcVoiceChannel(DiscordRpcClient discord, ulong id, ulong guildId)
|
||||
: base(discord, id, guildId)
|
||||
{
|
||||
}
|
||||
internal new static RpcVoiceChannel Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
var entity = new RpcVoiceChannel(discord, model.Id, model.GuildId.Value);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal override void Update(Model model)
|
||||
{
|
||||
base.Update(model);
|
||||
if (model.UserLimit.IsSpecified)
|
||||
UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
|
||||
if (model.Bitrate.IsSpecified)
|
||||
Bitrate = model.Bitrate.Value;
|
||||
VoiceStates = model.VoiceStates.Select(x => RpcVoiceState.Create(Discord, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
|
||||
|
||||
//IAudioChannel
|
||||
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
|
||||
}
|
||||
}
|
||||
36
experiment/Discord.Net.Rpc/Entities/Guilds/RpcGuild.cs
Normal file
36
experiment/Discord.Net.Rpc/Entities/Guilds/RpcGuild.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.Rpc.Guild;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcGuild : RpcEntity<ulong>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string IconUrl { get; private set; }
|
||||
public IReadOnlyCollection<RpcGuildUser> Users { get; private set; }
|
||||
|
||||
internal RpcGuild(DiscordRpcClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
}
|
||||
internal static RpcGuild Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
var entity = new RpcGuild(discord, model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
Name = model.Name;
|
||||
IconUrl = model.IconUrl;
|
||||
Users = model.Members.Select(x => RpcGuildUser.Create(Discord, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
30
experiment/Discord.Net.Rpc/Entities/Guilds/RpcGuildStatus.cs
Normal file
30
experiment/Discord.Net.Rpc/Entities/Guilds/RpcGuildStatus.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.GuildStatusEvent;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcGuildStatus
|
||||
{
|
||||
public RpcGuildSummary Guild { get; }
|
||||
public int Online { get; private set; }
|
||||
|
||||
internal RpcGuildStatus(ulong guildId)
|
||||
{
|
||||
Guild = new RpcGuildSummary(guildId);
|
||||
}
|
||||
internal static RpcGuildStatus Create(Model model)
|
||||
{
|
||||
var entity = new RpcGuildStatus(model.Guild.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
Online = model.Online;
|
||||
}
|
||||
|
||||
public override string ToString() => Guild.Name;
|
||||
private string DebuggerDisplay => $"{Guild.Name} ({Guild.Id}, {Online} Online)";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.GuildSummary;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcGuildSummary
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public string Name { get; private set; }
|
||||
|
||||
internal RpcGuildSummary(ulong id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
internal static RpcGuildSummary Create(Model model)
|
||||
{
|
||||
var entity = new RpcGuildSummary(model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
75
experiment/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs
Normal file
75
experiment/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Rpc.Message;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public abstract class RpcMessage : RpcEntity<ulong>, IMessage
|
||||
{
|
||||
private long _timestampTicks;
|
||||
|
||||
public IMessageChannel Channel { get; }
|
||||
public RpcUser Author { get; }
|
||||
public MessageSource Source { get; }
|
||||
|
||||
public string Content { get; private set; }
|
||||
public Color AuthorColor { get; private set; }
|
||||
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
public virtual bool IsTTS => false;
|
||||
public virtual bool IsPinned => false;
|
||||
public virtual bool IsBlocked => false;
|
||||
public virtual DateTimeOffset? EditedTimestamp => null;
|
||||
public virtual IReadOnlyCollection<Attachment> Attachments => ImmutableArray.Create<Attachment>();
|
||||
public virtual IReadOnlyCollection<Embed> Embeds => ImmutableArray.Create<Embed>();
|
||||
public virtual IReadOnlyCollection<ulong> MentionedChannelIds => ImmutableArray.Create<ulong>();
|
||||
public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>();
|
||||
public virtual IReadOnlyCollection<ulong> MentionedUserIds => ImmutableArray.Create<ulong>();
|
||||
public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>();
|
||||
public virtual ulong? WebhookId => null;
|
||||
public bool IsWebhook => WebhookId != null;
|
||||
|
||||
public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks);
|
||||
|
||||
internal RpcMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author, MessageSource source)
|
||||
: base(discord, id)
|
||||
{
|
||||
Channel = channel;
|
||||
Author = author;
|
||||
Source = source;
|
||||
}
|
||||
internal static RpcMessage Create(DiscordRpcClient discord, ulong channelId, Model model)
|
||||
{
|
||||
//model.ChannelId is always 0, needs to be passed from the event
|
||||
if (model.Type == MessageType.Default)
|
||||
return RpcUserMessage.Create(discord, channelId, model);
|
||||
else
|
||||
return RpcSystemMessage.Create(discord, channelId, model);
|
||||
}
|
||||
internal virtual void Update(Model model)
|
||||
{
|
||||
if (model.Timestamp.IsSpecified)
|
||||
_timestampTicks = model.Timestamp.Value.UtcTicks;
|
||||
|
||||
if (model.Content.IsSpecified)
|
||||
Content = model.Content.Value;
|
||||
if (model.AuthorColor.IsSpecified)
|
||||
AuthorColor = new Color(Convert.ToUInt32(model.AuthorColor.Value.Substring(1), 16));
|
||||
}
|
||||
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> MessageHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public override string ToString() => Content;
|
||||
|
||||
//IMessage
|
||||
IMessageChannel IMessage.Channel => Channel;
|
||||
MessageType IMessage.Type => MessageType.Default;
|
||||
IUser IMessage.Author => Author;
|
||||
IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments;
|
||||
IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Discord.Rest;
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.Message;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcSystemMessage : RpcMessage, ISystemMessage
|
||||
{
|
||||
public MessageType Type { get; private set; }
|
||||
|
||||
internal RpcSystemMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author)
|
||||
: base(discord, id, channel, author, MessageSource.System)
|
||||
{
|
||||
}
|
||||
internal new static RpcSystemMessage Create(DiscordRpcClient discord, ulong channelId, Model model)
|
||||
{
|
||||
var entity = new RpcSystemMessage(discord, model.Id,
|
||||
RestVirtualMessageChannel.Create(discord, channelId),
|
||||
RpcUser.Create(discord, model.Author.Value, model.WebhookId.ToNullable()));
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal override void Update(Model model)
|
||||
{
|
||||
base.Update(model);
|
||||
|
||||
Type = model.Type;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})";
|
||||
}
|
||||
}
|
||||
128
experiment/Discord.Net.Rpc/Entities/Messages/RpcUserMessage.cs
Normal file
128
experiment/Discord.Net.Rpc/Entities/Messages/RpcUserMessage.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Rpc.Message;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcUserMessage : RpcMessage, IUserMessage
|
||||
{
|
||||
private bool _isMentioningEveryone, _isTTS, _isPinned, _isBlocked;
|
||||
private long? _editedTimestampTicks;
|
||||
private ulong? _webhookId;
|
||||
private ImmutableArray<Attachment> _attachments;
|
||||
private ImmutableArray<Embed> _embeds;
|
||||
private ImmutableArray<ITag> _tags;
|
||||
|
||||
public override bool IsTTS => _isTTS;
|
||||
public override bool IsPinned => _isPinned;
|
||||
public override bool IsBlocked => _isBlocked;
|
||||
public override ulong? WebhookId => _webhookId;
|
||||
public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks);
|
||||
public override IReadOnlyCollection<Attachment> Attachments => _attachments;
|
||||
public override IReadOnlyCollection<Embed> Embeds => _embeds;
|
||||
public override IReadOnlyCollection<ulong> MentionedChannelIds => MessageHelper.FilterTagsByKey(TagType.ChannelMention, _tags);
|
||||
public override IReadOnlyCollection<ulong> MentionedRoleIds => MessageHelper.FilterTagsByKey(TagType.RoleMention, _tags);
|
||||
public override IReadOnlyCollection<ulong> MentionedUserIds => MessageHelper.FilterTagsByKey(TagType.UserMention, _tags);
|
||||
public override IReadOnlyCollection<ITag> Tags => _tags;
|
||||
public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions => ImmutableDictionary.Create<IEmote, ReactionMetadata>();
|
||||
|
||||
internal RpcUserMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author, MessageSource source)
|
||||
: base(discord, id, channel, author, source)
|
||||
{
|
||||
}
|
||||
internal new static RpcUserMessage Create(DiscordRpcClient discord, ulong channelId, Model model)
|
||||
{
|
||||
var entity = new RpcUserMessage(discord, model.Id,
|
||||
RestVirtualMessageChannel.Create(discord, channelId),
|
||||
RpcUser.Create(discord, model.Author.Value, model.WebhookId.ToNullable()),
|
||||
MessageHelper.GetSource(model));
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
|
||||
internal override void Update(Model model)
|
||||
{
|
||||
base.Update(model);
|
||||
|
||||
if (model.IsTextToSpeech.IsSpecified)
|
||||
_isTTS = model.IsTextToSpeech.Value;
|
||||
if (model.Pinned.IsSpecified)
|
||||
_isPinned = model.Pinned.Value;
|
||||
if (model.EditedTimestamp.IsSpecified)
|
||||
_editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks;
|
||||
if (model.MentionEveryone.IsSpecified)
|
||||
_isMentioningEveryone = model.MentionEveryone.Value;
|
||||
if (model.WebhookId.IsSpecified)
|
||||
_webhookId = model.WebhookId.Value;
|
||||
|
||||
if (model.IsBlocked.IsSpecified)
|
||||
_isBlocked = model.IsBlocked.Value;
|
||||
|
||||
if (model.Attachments.IsSpecified)
|
||||
{
|
||||
var value = model.Attachments.Value;
|
||||
if (value.Length > 0)
|
||||
{
|
||||
var attachments = ImmutableArray.CreateBuilder<Attachment>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
attachments.Add(Attachment.Create(value[i]));
|
||||
_attachments = attachments.ToImmutable();
|
||||
}
|
||||
else
|
||||
_attachments = ImmutableArray.Create<Attachment>();
|
||||
}
|
||||
|
||||
if (model.Embeds.IsSpecified)
|
||||
{
|
||||
var value = model.Embeds.Value;
|
||||
if (value.Length > 0)
|
||||
{
|
||||
var embeds = ImmutableArray.CreateBuilder<Embed>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
embeds.Add(value[i].ToEntity());
|
||||
_embeds = embeds.ToImmutable();
|
||||
}
|
||||
else
|
||||
_embeds = ImmutableArray.Create<Embed>();
|
||||
}
|
||||
|
||||
if (model.Content.IsSpecified)
|
||||
{
|
||||
var text = model.Content.Value;
|
||||
_tags = MessageHelper.ParseTags(text, null, null, ImmutableArray.Create<IUser>());
|
||||
model.Content = text;
|
||||
}
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options)
|
||||
=> MessageHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
public Task AddReactionAsync(IEmote emote, RequestOptions options = null)
|
||||
=> MessageHelper.AddReactionAsync(this, emote, Discord, options);
|
||||
public Task RemoveReactionAsync(IEmote emote, IUser user, RequestOptions options = null)
|
||||
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options);
|
||||
public Task RemoveAllReactionsAsync(RequestOptions options = null)
|
||||
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
|
||||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null)
|
||||
=> MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options);
|
||||
|
||||
public Task PinAsync(RequestOptions options)
|
||||
=> MessageHelper.PinAsync(this, Discord, options);
|
||||
public Task UnpinAsync(RequestOptions options)
|
||||
=> MessageHelper.UnpinAsync(this, Discord, options);
|
||||
|
||||
public string Resolve(int startIndex, TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name,
|
||||
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)
|
||||
=> MentionUtils.Resolve(this, startIndex, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling);
|
||||
public string Resolve(TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name,
|
||||
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)
|
||||
=> MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling);
|
||||
|
||||
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})";
|
||||
}
|
||||
}
|
||||
17
experiment/Discord.Net.Rpc/Entities/RpcEntity.cs
Normal file
17
experiment/Discord.Net.Rpc/Entities/RpcEntity.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public abstract class RpcEntity<T> : IEntity<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
internal DiscordRpcClient Discord { get; }
|
||||
public T Id { get; }
|
||||
|
||||
internal RpcEntity(DiscordRpcClient discord, T id)
|
||||
{
|
||||
Discord = discord;
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
experiment/Discord.Net.Rpc/Entities/UserVoiceProperties.cs
Normal file
18
experiment/Discord.Net.Rpc/Entities/UserVoiceProperties.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class UserVoiceProperties
|
||||
{
|
||||
[JsonProperty("userId")]
|
||||
internal ulong UserId { get; set; }
|
||||
[JsonProperty("pan")]
|
||||
public Optional<Pan> Pan { get; set; }
|
||||
[JsonProperty("volume")]
|
||||
public Optional<int> Volume { get; set; }
|
||||
[JsonProperty("mute")]
|
||||
public Optional<bool> Mute { get; set; }
|
||||
}
|
||||
}
|
||||
25
experiment/Discord.Net.Rpc/Entities/Users/Pan.cs
Normal file
25
experiment/Discord.Net.Rpc/Entities/Users/Pan.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.Pan;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public struct Pan
|
||||
{
|
||||
public float Left { get; }
|
||||
public float Right { get; }
|
||||
|
||||
public Pan(float left, float right)
|
||||
{
|
||||
Left = left;
|
||||
Right = right;
|
||||
}
|
||||
internal static Pan Create(Model model)
|
||||
{
|
||||
return new Pan(model.Left, model.Right);
|
||||
}
|
||||
|
||||
public override string ToString() => $"Left = {Left}, Right = {Right}";
|
||||
private string DebuggerDisplay => $"Left = {Left}, Right = {Right}";
|
||||
}
|
||||
}
|
||||
29
experiment/Discord.Net.Rpc/Entities/Users/RpcGuildUser.cs
Normal file
29
experiment/Discord.Net.Rpc/Entities/Users/RpcGuildUser.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Model = Discord.API.Rpc.GuildMember;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class RpcGuildUser : RpcUser
|
||||
{
|
||||
private UserStatus _status;
|
||||
|
||||
public override UserStatus Status => _status;
|
||||
//public object Acitivity { get; private set; }
|
||||
|
||||
internal RpcGuildUser(DiscordRpcClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
}
|
||||
internal static RpcGuildUser Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
var entity = new RpcGuildUser(discord, model.User.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
base.Update(model.User);
|
||||
_status = model.Status;
|
||||
//Activity = model.Activity;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
experiment/Discord.Net.Rpc/Entities/Users/RpcUser.cs
Normal file
65
experiment/Discord.Net.Rpc/Entities/Users/RpcUser.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.User;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcUser : RpcEntity<ulong>, IUser
|
||||
{
|
||||
public bool IsBot { get; private set; }
|
||||
public string Username { get; private set; }
|
||||
public ushort DiscriminatorValue { get; private set; }
|
||||
public string AvatarId { get; private set; }
|
||||
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||
public string Mention => MentionUtils.MentionUser(Id);
|
||||
public virtual bool IsWebhook => false;
|
||||
public virtual IActivity Activity => null;
|
||||
public virtual UserStatus Status => UserStatus.Offline;
|
||||
|
||||
internal RpcUser(DiscordRpcClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
{
|
||||
}
|
||||
internal static RpcUser Create(DiscordRpcClient discord, Model model)
|
||||
=> Create(discord, model, null);
|
||||
internal static RpcUser Create(DiscordRpcClient discord, Model model, ulong? webhookId)
|
||||
{
|
||||
RpcUser entity;
|
||||
if (webhookId.HasValue)
|
||||
entity = new RpcWebhookUser(discord, model.Id, webhookId.Value);
|
||||
else
|
||||
entity = new RpcUser(discord, model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal virtual void Update(Model model)
|
||||
{
|
||||
if (model.Avatar.IsSpecified)
|
||||
AvatarId = model.Avatar.Value;
|
||||
if (model.Discriminator.IsSpecified)
|
||||
DiscriminatorValue = ushort.Parse(model.Discriminator.Value);
|
||||
if (model.Bot.IsSpecified)
|
||||
IsBot = model.Bot.Value;
|
||||
if (model.Username.IsSpecified)
|
||||
Username = model.Username.Value;
|
||||
}
|
||||
|
||||
public Task<RestDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null)
|
||||
=> UserHelper.CreateDMChannelAsync(this, Discord, options);
|
||||
|
||||
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
|
||||
public override string ToString() => $"{Username}#{Discriminator}";
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
|
||||
//IUser
|
||||
async Task<IDMChannel> IUser.GetOrCreateDMChannelAsync(RequestOptions options)
|
||||
=> await GetOrCreateDMChannelAsync(options);
|
||||
}
|
||||
}
|
||||
79
experiment/Discord.Net.Rpc/Entities/Users/RpcVoiceState.cs
Normal file
79
experiment/Discord.Net.Rpc/Entities/Users/RpcVoiceState.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.ExtendedVoiceState;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcVoiceState : IVoiceState
|
||||
{
|
||||
[Flags]
|
||||
private enum Flags : byte
|
||||
{
|
||||
Normal = 0x00,
|
||||
Suppressed = 0x01,
|
||||
Muted = 0x02,
|
||||
Deafened = 0x04,
|
||||
SelfMuted = 0x08,
|
||||
SelfDeafened = 0x10,
|
||||
}
|
||||
|
||||
private Flags _voiceStates;
|
||||
|
||||
public RpcUser User { get; }
|
||||
public string Nickname { get; private set; }
|
||||
public int Volume { get; private set; }
|
||||
public bool IsMuted2 { get; private set; }
|
||||
public Pan Pan { get; private set; }
|
||||
|
||||
public bool IsMuted => (_voiceStates & Flags.Muted) != 0;
|
||||
public bool IsDeafened => (_voiceStates & Flags.Deafened) != 0;
|
||||
public bool IsSuppressed => (_voiceStates & Flags.Suppressed) != 0;
|
||||
public bool IsSelfMuted => (_voiceStates & Flags.SelfMuted) != 0;
|
||||
public bool IsSelfDeafened => (_voiceStates & Flags.SelfDeafened) != 0;
|
||||
|
||||
internal RpcVoiceState(DiscordRpcClient discord, ulong userId)
|
||||
{
|
||||
User = new RpcUser(discord, userId);
|
||||
}
|
||||
internal static RpcVoiceState Create(DiscordRpcClient discord, Model model)
|
||||
{
|
||||
var entity = new RpcVoiceState(discord, model.User.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
if (model.VoiceState.IsSpecified)
|
||||
{
|
||||
Flags voiceStates = Flags.Normal;
|
||||
if (model.VoiceState.Value.Mute)
|
||||
voiceStates |= Flags.Muted;
|
||||
if (model.VoiceState.Value.Deaf)
|
||||
voiceStates |= Flags.Deafened;
|
||||
if (model.VoiceState.Value.SelfMute)
|
||||
voiceStates |= Flags.SelfMuted;
|
||||
if (model.VoiceState.Value.SelfDeaf)
|
||||
voiceStates |= Flags.SelfDeafened;
|
||||
if (model.VoiceState.Value.Suppress)
|
||||
voiceStates |= Flags.Suppressed;
|
||||
_voiceStates = voiceStates;
|
||||
}
|
||||
User.Update(model.User);
|
||||
if (model.Nickname.IsSpecified)
|
||||
Nickname = model.Nickname.Value;
|
||||
if (model.Volume.IsSpecified)
|
||||
Volume = model.Volume.Value;
|
||||
if (model.Mute.IsSpecified)
|
||||
IsMuted2 = model.Mute.Value;
|
||||
if (model.Pan.IsSpecified)
|
||||
Pan = Pan.Create(model.Pan.Value);
|
||||
}
|
||||
|
||||
public override string ToString() => User.ToString();
|
||||
private string DebuggerDisplay => $"{User} ({_voiceStates})";
|
||||
|
||||
string IVoiceState.VoiceSessionId { get { throw new NotSupportedException(); } }
|
||||
IVoiceChannel IVoiceState.VoiceChannel { get { throw new NotSupportedException(); } }
|
||||
}
|
||||
}
|
||||
25
experiment/Discord.Net.Rpc/Entities/Users/RpcWebhookUser.cs
Normal file
25
experiment/Discord.Net.Rpc/Entities/Users/RpcWebhookUser.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.User;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RpcWebhookUser : RpcUser
|
||||
{
|
||||
public ulong WebhookId { get; }
|
||||
|
||||
public override bool IsWebhook => true;
|
||||
|
||||
internal RpcWebhookUser(DiscordRpcClient discord, ulong id, ulong webhookId)
|
||||
: base(discord, id)
|
||||
{
|
||||
WebhookId = webhookId;
|
||||
}
|
||||
internal static RpcWebhookUser Create(DiscordRpcClient discord, Model model, ulong webhookId)
|
||||
{
|
||||
var entity = new RpcWebhookUser(discord, model.Id, webhookId);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
experiment/Discord.Net.Rpc/Entities/VoiceDevice.cs
Normal file
25
experiment/Discord.Net.Rpc/Entities/VoiceDevice.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.VoiceDevice;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public struct VoiceDevice
|
||||
{
|
||||
public string Id { get; }
|
||||
public string Name { get; }
|
||||
|
||||
internal VoiceDevice(string id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
internal static VoiceDevice Create(Model model)
|
||||
{
|
||||
return new VoiceDevice(model.Id, model.Name);
|
||||
}
|
||||
|
||||
public override string ToString() => $"{Name}";
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class VoiceDeviceProperties
|
||||
{
|
||||
public Optional<string> DeviceId { get; set; }
|
||||
public Optional<float> Volume { get; set; }
|
||||
public Optional<VoiceDevice[]> AvailableDevices { get; set; }
|
||||
}
|
||||
}
|
||||
11
experiment/Discord.Net.Rpc/Entities/VoiceModeProperties.cs
Normal file
11
experiment/Discord.Net.Rpc/Entities/VoiceModeProperties.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class VoiceModeProperties
|
||||
{
|
||||
public Optional<string> Type { get; set; }
|
||||
public Optional<bool> AutoThreshold { get; set; }
|
||||
public Optional<float> Threshold { get; set; }
|
||||
public Optional<VoiceShortcut[]> Shortcut { get; set; }
|
||||
public Optional<float> Delay { get; set; }
|
||||
}
|
||||
}
|
||||
14
experiment/Discord.Net.Rpc/Entities/VoiceProperties.cs
Normal file
14
experiment/Discord.Net.Rpc/Entities/VoiceProperties.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class VoiceProperties
|
||||
{
|
||||
public VoiceDeviceProperties Input { get; set; }
|
||||
public VoiceDeviceProperties Output { get; set; }
|
||||
public VoiceModeProperties Mode { get; set; }
|
||||
public Optional<bool> AutomaticGainControl { get; set; }
|
||||
public Optional<bool> EchoCancellation { get; set; }
|
||||
public Optional<bool> NoiseSuppression { get; set; }
|
||||
public Optional<bool> QualityOfService { get; set; }
|
||||
public Optional<bool> SilenceWarning { get; set; }
|
||||
}
|
||||
}
|
||||
76
experiment/Discord.Net.Rpc/Entities/VoiceSettings.cs
Normal file
76
experiment/Discord.Net.Rpc/Entities/VoiceSettings.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.Rpc.VoiceSettings;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public class VoiceSettings
|
||||
{
|
||||
public string InputDeviceId { get; private set; }
|
||||
public float InputVolume { get; private set; }
|
||||
public IReadOnlyCollection<VoiceDevice> AvailableInputDevices { get; private set; }
|
||||
|
||||
public string OutputDeviceId { get; private set; }
|
||||
public float OutputVolume { get; private set; }
|
||||
public IReadOnlyCollection<VoiceDevice> AvailableOutputDevices { get; private set; }
|
||||
|
||||
public bool AutomaticGainControl { get; private set; }
|
||||
public bool EchoCancellation { get; private set; }
|
||||
public bool NoiseSuppression { get; private set; }
|
||||
public bool QualityOfService { get; private set; }
|
||||
public bool SilenceWarning { get; private set; }
|
||||
|
||||
public string ActivationMode { get; private set; }
|
||||
public bool AutoThreshold { get; private set; }
|
||||
public float Threshold { get; private set; }
|
||||
public IReadOnlyCollection<VoiceShortcut> Shortcuts { get; private set; }
|
||||
public float Delay { get; private set; }
|
||||
|
||||
internal VoiceSettings() { }
|
||||
internal static VoiceSettings Create(Model model)
|
||||
{
|
||||
var entity = new VoiceSettings();
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
if (model.AutomaticGainControl.IsSpecified)
|
||||
AutomaticGainControl = model.AutomaticGainControl.Value;
|
||||
if (model.EchoCancellation.IsSpecified)
|
||||
EchoCancellation = model.EchoCancellation.Value;
|
||||
if (model.NoiseSuppression.IsSpecified)
|
||||
NoiseSuppression = model.NoiseSuppression.Value;
|
||||
if (model.QualityOfService.IsSpecified)
|
||||
QualityOfService = model.QualityOfService.Value;
|
||||
if (model.SilenceWarning.IsSpecified)
|
||||
SilenceWarning = model.SilenceWarning.Value;
|
||||
|
||||
if (model.Input.DeviceId.IsSpecified)
|
||||
InputDeviceId = model.Input.DeviceId.Value;
|
||||
if (model.Input.Volume.IsSpecified)
|
||||
InputVolume = model.Input.Volume.Value;
|
||||
if (model.Input.AvailableDevices.IsSpecified)
|
||||
AvailableInputDevices = model.Input.AvailableDevices.Value.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
|
||||
|
||||
if (model.Output.DeviceId.IsSpecified)
|
||||
OutputDeviceId = model.Output.DeviceId.Value;
|
||||
if (model.Output.Volume.IsSpecified)
|
||||
OutputVolume = model.Output.Volume.Value;
|
||||
if (model.Output.AvailableDevices.IsSpecified)
|
||||
AvailableInputDevices = model.Output.AvailableDevices.Value.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
|
||||
|
||||
if (model.Mode.Type.IsSpecified)
|
||||
ActivationMode = model.Mode.Type.Value;
|
||||
if (model.Mode.AutoThreshold.IsSpecified)
|
||||
AutoThreshold = model.Mode.AutoThreshold.Value;
|
||||
if (model.Mode.Threshold.IsSpecified)
|
||||
Threshold = model.Mode.Threshold.Value;
|
||||
if (model.Mode.Shortcut.IsSpecified)
|
||||
Shortcuts = model.Mode.Shortcut.Value.Select(x => VoiceShortcut.Create(x)).ToImmutableArray();
|
||||
if (model.Mode.Delay.IsSpecified)
|
||||
Delay = model.Mode.Delay.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
experiment/Discord.Net.Rpc/Entities/VoiceShortcut.cs
Normal file
27
experiment/Discord.Net.Rpc/Entities/VoiceShortcut.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Rpc.VoiceShortcut;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public struct VoiceShortcut
|
||||
{
|
||||
public VoiceShortcutType Type { get; }
|
||||
public int Code { get; }
|
||||
public string Name { get; }
|
||||
|
||||
internal VoiceShortcut(VoiceShortcutType type, int code, string name)
|
||||
{
|
||||
Type = type;
|
||||
Code = code;
|
||||
Name = name;
|
||||
}
|
||||
internal static VoiceShortcut Create(Model model)
|
||||
{
|
||||
return new VoiceShortcut(model.Type.Value, model.Code.Value, model.Name.Value);
|
||||
}
|
||||
|
||||
public override string ToString() => $"{Name}";
|
||||
private string DebuggerDisplay => $"{Name} ({Code}, {Type})";
|
||||
}
|
||||
}
|
||||
10
experiment/Discord.Net.Rpc/Entities/VoiceShortcutType.cs
Normal file
10
experiment/Discord.Net.Rpc/Entities/VoiceShortcutType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public enum VoiceShortcutType
|
||||
{
|
||||
KeyboardKey = 0,
|
||||
MouseButton = 1,
|
||||
KeyboardModifierKey = 2,
|
||||
GamepadButton = 3
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user