Remove RPC from main distribution (#925)
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user