Added IWebhookUser and MessageSource

This commit is contained in:
RogueException
2017-03-30 23:29:30 -03:00
parent e7401eda68
commit bf0be82d15
32 changed files with 371 additions and 96 deletions

View File

@@ -13,6 +13,7 @@ namespace Discord.Rpc
public IMessageChannel Channel { get; }
public RpcUser Author { get; }
public MessageSource Source { get; }
public string Content { get; private set; }
public Color AuthorColor { get; private set; }
@@ -33,11 +34,12 @@ namespace Discord.Rpc
public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks);
internal RpcMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author)
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)
{

View File

@@ -10,14 +10,14 @@ namespace Discord.Rpc
public MessageType Type { get; private set; }
internal RpcSystemMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author)
: base(discord, id, channel, 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));
RpcUser.Create(discord, model.Author.Value, model.WebhookId.ToNullable()));
entity.Update(model);
return entity;
}

View File

@@ -31,15 +31,16 @@ namespace Discord.Rpc
public override IReadOnlyCollection<ITag> Tags => _tags;
public IReadOnlyDictionary<Emoji, ReactionMetadata> Reactions => ImmutableDictionary.Create<Emoji, ReactionMetadata>();
internal RpcUserMessage(DiscordRpcClient discord, ulong id, RestVirtualMessageChannel channel, RpcUser author)
: base(discord, id, channel, author)
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));
RpcUser.Create(discord, model.Author.Value, model.WebhookId.ToNullable()),
MessageHelper.GetSource(model));
entity.Update(model);
return entity;
}

View File

@@ -14,11 +14,10 @@ namespace Discord.Rpc
public ushort DiscriminatorValue { get; private set; }
public string AvatarId { get; private set; }
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
public string Discriminator => DiscriminatorValue.ToString("D4");
public string Mention => MentionUtils.MentionUser(Id);
public virtual bool IsWebhook => false;
public virtual Game? Game => null;
public virtual UserStatus Status => UserStatus.Offline;
@@ -27,8 +26,14 @@ namespace Discord.Rpc
{
}
internal static RpcUser Create(DiscordRpcClient discord, Model model)
=> Create(discord, model, null);
internal static RpcUser Create(DiscordRpcClient discord, Model model, ulong? webhookId)
{
var entity = new RpcUser(discord, model.Id);
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;
}
@@ -47,6 +52,9 @@ namespace Discord.Rpc
public Task<RestDMChannel> CreateDMChannelAsync(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" : "")})";

View 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;
}
}
}