mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-22 19:58:48 +00:00
refactor!: extract interface for Message
This commit also amends the previous commit, where files relevant for User were missed
This commit is contained in:
parent
3841ad13aa
commit
ff298a8af5
@ -9,7 +9,7 @@ namespace VpSharp.Commands;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class CommandContext
|
public sealed class CommandContext
|
||||||
{
|
{
|
||||||
internal CommandContext(VirtualParadiseClient client, Avatar avatar, string commandName, string alias,
|
internal CommandContext(VirtualParadiseClient client, IAvatar avatar, string commandName, string alias,
|
||||||
string rawArguments)
|
string rawArguments)
|
||||||
{
|
{
|
||||||
Client = client;
|
Client = client;
|
||||||
@ -36,7 +36,7 @@ public sealed class CommandContext
|
|||||||
/// Gets the avatar who executed the command.
|
/// Gets the avatar who executed the command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The executing avatar.</value>
|
/// <value>The executing avatar.</value>
|
||||||
public Avatar Avatar { get; }
|
public IAvatar Avatar { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the client which raised the event.
|
/// Gets the client which raised the event.
|
||||||
@ -65,10 +65,11 @@ public sealed class CommandContext
|
|||||||
/// regular chat message.
|
/// regular chat message.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The message which was sent.</returns>
|
/// <returns>The message which was sent.</returns>
|
||||||
public Task<Message> RespondAsync(string message, bool ephemeral = false)
|
public async Task<IMessage> RespondAsync(string message, bool ephemeral = false)
|
||||||
{
|
{
|
||||||
return ephemeral
|
return ephemeral
|
||||||
? Avatar.SendMessageAsync(Client.CurrentAvatar?.Name, message, FontStyle.Regular, Color.Black)
|
? await Avatar.SendMessageAsync(Client.CurrentAvatar?.Name, message, FontStyle.Regular, Color.Black)
|
||||||
: Client.SendMessageAsync(message);
|
.ConfigureAwait(false)
|
||||||
|
: await Client.SendMessageAsync(message).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,14 +176,14 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected internal override Task OnMessageReceived(Message message)
|
protected internal override Task OnMessageReceived(IMessage message)
|
||||||
{
|
{
|
||||||
if (message is null)
|
if (message is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(message));
|
throw new ArgumentNullException(nameof(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.Type != MessageType.ChatMessage)
|
if (message is IUserMessage)
|
||||||
{
|
{
|
||||||
return base.OnMessageReceived(message);
|
return base.OnMessageReceived(message);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ public abstract class VirtualParadiseClientExtension
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when a chat message is received.
|
/// Called when a chat message is received.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">An object containing event data.</param>
|
/// <param name="message">The message which was received.</param>
|
||||||
protected internal virtual Task OnMessageReceived(Message message)
|
protected internal virtual Task OnMessageReceived(IMessage message)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace VpSharp.Entities;
|
|||||||
public sealed class Avatar : IEquatable<Avatar>, IAvatar
|
public sealed class Avatar : IEquatable<Avatar>, IAvatar
|
||||||
{
|
{
|
||||||
private readonly VirtualParadiseClient _client;
|
private readonly VirtualParadiseClient _client;
|
||||||
private User? _user;
|
private IUser? _user;
|
||||||
|
|
||||||
internal Avatar(VirtualParadiseClient client, int session)
|
internal Avatar(VirtualParadiseClient client, int session)
|
||||||
{
|
{
|
||||||
@ -172,7 +172,7 @@ public sealed class Avatar : IEquatable<Avatar>, IAvatar
|
|||||||
/// Gets the user associated with this avatar.
|
/// Gets the user associated with this avatar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The user.</returns>
|
/// <returns>The user.</returns>
|
||||||
public async Task<User> GetUserAsync()
|
public async Task<IUser> GetUserAsync()
|
||||||
{
|
{
|
||||||
_user ??= await _client.GetUserAsync(UserId).ConfigureAwait(false);
|
_user ??= await _client.GetUserAsync(UserId).ConfigureAwait(false);
|
||||||
return _user;
|
return _user;
|
||||||
@ -196,7 +196,7 @@ public sealed class Avatar : IEquatable<Avatar>, IAvatar
|
|||||||
/// -or-
|
/// -or-
|
||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public Task<Message> SendMessageAsync(string message, FontStyle fontStyle, Color color)
|
public Task<IConsoleMessage> SendMessageAsync(string message, FontStyle fontStyle, Color color)
|
||||||
{
|
{
|
||||||
return SendMessageAsync(null, message, fontStyle, color);
|
return SendMessageAsync(null, message, fontStyle, color);
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ public sealed class Avatar : IEquatable<Avatar>, IAvatar
|
|||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
/// <remarks>Passing <see langword="null" /> to <paramref name="name" /> will hide the name from the recipient.</remarks>
|
/// <remarks>Passing <see langword="null" /> to <paramref name="name" /> will hide the name from the recipient.</remarks>
|
||||||
public Task<Message> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color)
|
public Task<IConsoleMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color)
|
||||||
{
|
{
|
||||||
if (message is null)
|
if (message is null)
|
||||||
{
|
{
|
||||||
@ -267,13 +267,12 @@ public sealed class Avatar : IEquatable<Avatar>, IAvatar
|
|||||||
avatar = _client.CurrentAvatar!;
|
avatar = _client.CurrentAvatar!;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(new Message(
|
return Task.FromResult((IConsoleMessage)new ConsoleMessage(
|
||||||
MessageType.ConsoleMessage,
|
|
||||||
name,
|
|
||||||
message,
|
|
||||||
avatar,
|
avatar,
|
||||||
fontStyle,
|
avatar.Name,
|
||||||
color
|
message,
|
||||||
|
color,
|
||||||
|
fontStyle
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
VpSharp/src/Entities/ConsoleMessage.cs
Normal file
30
VpSharp/src/Entities/ConsoleMessage.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a chat message that was sent by a user.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ConsoleMessage : Message, IConsoleMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="UserMessage" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="author">The author of the message.</param>
|
||||||
|
/// <param name="name">The apparent sender's name of the message.</param>
|
||||||
|
/// <param name="content">The content of the message.</param>
|
||||||
|
/// <param name="color">A <see cref="System.Drawing.Color" /> value representing the color of the message.</param>
|
||||||
|
/// <param name="fontStyle">A <see cref="FontStyle" /> value representing the font style of the message.</param>
|
||||||
|
public ConsoleMessage(IAvatar author, string name, string content, Color color, FontStyle fontStyle)
|
||||||
|
: base(author, name, content)
|
||||||
|
{
|
||||||
|
Color = color;
|
||||||
|
Style = fontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Color Color { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public FontStyle Style { get; }
|
||||||
|
}
|
@ -70,7 +70,7 @@ public interface IAvatar
|
|||||||
/// Gets the user associated with this avatar.
|
/// Gets the user associated with this avatar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The user.</returns>
|
/// <returns>The user.</returns>
|
||||||
Task<User> GetUserAsync();
|
Task<IUser> GetUserAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a console message to the avatar with no name.
|
/// Sends a console message to the avatar with no name.
|
||||||
@ -90,7 +90,7 @@ public interface IAvatar
|
|||||||
/// -or-
|
/// -or-
|
||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
Task<Message> SendMessageAsync(string message, FontStyle fontStyle, Color color);
|
Task<IConsoleMessage> SendMessageAsync(string message, FontStyle fontStyle, Color color);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a console message to the avatar.
|
/// Sends a console message to the avatar.
|
||||||
@ -112,7 +112,7 @@ public interface IAvatar
|
|||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
/// <remarks>Passing <see langword="null" /> to <paramref name="name" /> will hide the name from the recipient.</remarks>
|
/// <remarks>Passing <see langword="null" /> to <paramref name="name" /> will hide the name from the recipient.</remarks>
|
||||||
Task<Message> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color);
|
Task<IConsoleMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a URI to this avatar.
|
/// Sends a URI to this avatar.
|
||||||
|
21
VpSharp/src/Entities/IConsoleMessage.cs
Normal file
21
VpSharp/src/Entities/IConsoleMessage.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a console message.
|
||||||
|
/// </summary>
|
||||||
|
public interface IConsoleMessage : IMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the color of the message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>A <see cref="System.Drawing.Color" /> value representing the color.</value>
|
||||||
|
Color Color { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the font style of the message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>A <see cref="FontStyle" /> value representing the font style.</value>
|
||||||
|
FontStyle Style { get; }
|
||||||
|
}
|
25
VpSharp/src/Entities/IMessage.cs
Normal file
25
VpSharp/src/Entities/IMessage.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a message.
|
||||||
|
/// </summary>
|
||||||
|
public interface IMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the author of the message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The avatar which authored the message.</value>
|
||||||
|
IAvatar Author { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the content of the message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The content.</value>
|
||||||
|
string Content { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the apparent sender's name of the message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The sender's name.</value>
|
||||||
|
string Name { get; }
|
||||||
|
}
|
71
VpSharp/src/Entities/IUser.cs
Normal file
71
VpSharp/src/Entities/IUser.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using VpSharp.Exceptions;
|
||||||
|
|
||||||
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
|
public interface IUser
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the email address of this user.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The email address of this user.</value>
|
||||||
|
string EmailAddress { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ID of this user.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user's ID.</value>
|
||||||
|
int Id { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the date and time at which this user was last online.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>A <see cref="DateTimeOffset" /> representing the date and time this user was last online.</value>
|
||||||
|
DateTimeOffset LastLogin { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of this user.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user's name.</value>
|
||||||
|
string Name { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the duration for which this user has been online.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>A <see cref="TimeSpan" /> representing the duration for which this user has been online.</value>
|
||||||
|
TimeSpan OnlineTime { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the date and time at which this user was registered.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>A <see cref="DateTimeOffset" /> representing the date and time this user was registered.</value>
|
||||||
|
DateTimeOffset RegistrationTime { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if two <see cref="User" /> instances are equal.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">The other instance.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// <see langword="true" /> if this instance is equal to <paramref name="other" />; otherwise, <see langword="false" />.
|
||||||
|
/// </returns>
|
||||||
|
bool Equals(User? other);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invites this user to a specified location.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="location">
|
||||||
|
/// The invitation location. If <see langword="null" />, the client's current location is used.
|
||||||
|
/// </param>
|
||||||
|
Task<InviteResponse> InviteAsync(Location? location = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a to join request to the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="suppressTeleport">
|
||||||
|
/// If <see langword="true" />, the client's avatar will not teleport to the requested location automatically.
|
||||||
|
/// Be careful, there is no way to retrieve
|
||||||
|
/// </param>
|
||||||
|
/// <returns>The result of the request.</returns>
|
||||||
|
/// <exception cref="UserNotFoundException">This user is invalid and cannot be joined.</exception>
|
||||||
|
/// <exception cref="InvalidOperationException">An unexpected error occurred trying to join the user.</exception>
|
||||||
|
Task<JoinResult> JoinAsync(bool suppressTeleport = false);
|
||||||
|
}
|
6
VpSharp/src/Entities/IUserMessage.cs
Normal file
6
VpSharp/src/Entities/IUserMessage.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a chat message that was sent by a user.
|
||||||
|
/// </summary>
|
||||||
|
public interface IUserMessage : IMessage;
|
@ -1,67 +1,29 @@
|
|||||||
using System.Drawing;
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
namespace VpSharp.Entities;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a message.
|
/// Represents a message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Message
|
public abstract class Message : IMessage
|
||||||
{
|
{
|
||||||
internal Message(
|
/// <summary>
|
||||||
MessageType type,
|
/// Initializes a new instance of the <see cref="Message" /> class.
|
||||||
string? name,
|
/// </summary>
|
||||||
string content,
|
/// <param name="author">The author of the message.</param>
|
||||||
IAvatar author,
|
/// <param name="name">The apparent sender's name of the message.</param>
|
||||||
FontStyle style,
|
/// <param name="content">The content of the message.</param>
|
||||||
Color color)
|
protected Message(IAvatar author, string name, string content)
|
||||||
{
|
{
|
||||||
Type = type;
|
|
||||||
Name = string.IsNullOrWhiteSpace(name) ? null : name;
|
|
||||||
Content = content;
|
|
||||||
Author = author;
|
Author = author;
|
||||||
Style = style;
|
Content = content;
|
||||||
Color = color;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the message author.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The message author.</value>
|
|
||||||
public IAvatar Author { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the message content.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The message content.</value>
|
|
||||||
public string Content { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the message name.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The message name. This will always be equal to the name of the <see cref="Author" /> for chat messages.</value>
|
|
||||||
public string? Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the message color.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The message color. This will always be <see cref="System.Drawing.Color.Black" /> for chat messages.</value>
|
|
||||||
public Color Color { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the message font style.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The message font style. This will always be <see cref="FontStyle.Regular" /> for chat messages.</value>
|
|
||||||
public FontStyle Style { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the type of this message.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The type of this message.</value>
|
|
||||||
public MessageType Type { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public IAvatar Author { get; }
|
||||||
{
|
|
||||||
return $"Message {Author}; Type {Type}; Content {Content}";
|
/// <inheritdoc />
|
||||||
}
|
public string Content { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Name { get; }
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public abstract class ObjectBuilder
|
|||||||
/// This property may only be set during an object load, and will throw <see cref="InvalidOperationException" /> at
|
/// This property may only be set during an object load, and will throw <see cref="InvalidOperationException" /> at
|
||||||
/// any other point.
|
/// any other point.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public Option<User> Owner { get; set; }
|
public Option<IUser> Owner { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the position of the object.
|
/// Gets or sets the position of the object.
|
||||||
@ -90,7 +90,7 @@ public abstract class ObjectBuilder
|
|||||||
throw new InvalidOperationException("Owner can only be assigned during an object load.");
|
throw new InvalidOperationException("Owner can only be assigned during an object load.");
|
||||||
}
|
}
|
||||||
|
|
||||||
User oldOwner = TargetObject.Owner;
|
IUser oldOwner = TargetObject.Owner;
|
||||||
_ = vp_int_set(handle, ObjectUserId, Owner.ValueOr(oldOwner).Id);
|
_ = vp_int_set(handle, ObjectUserId, Owner.ValueOr(oldOwner).Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ namespace VpSharp.Entities;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a Virtual Paradise user.
|
/// Represents a Virtual Paradise user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class User : IEquatable<User>
|
public sealed class User : IEquatable<User>, IUser
|
||||||
{
|
{
|
||||||
private readonly VirtualParadiseClient _client;
|
private readonly VirtualParadiseClient _client;
|
||||||
|
|
||||||
|
17
VpSharp/src/Entities/UserMessage.cs
Normal file
17
VpSharp/src/Entities/UserMessage.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace VpSharp.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a chat message that was sent by a user.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class UserMessage : Message, IUserMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="UserMessage" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="author">The author of the message.</param>
|
||||||
|
/// <param name="content">The content of the message.</param>
|
||||||
|
public UserMessage(IAvatar author, string content)
|
||||||
|
: base(author, author.Name, content)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,7 @@ public abstract class VirtualParadiseObject : IEquatable<VirtualParadiseObject>
|
|||||||
/// Gets the owner of this object.
|
/// Gets the owner of this object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The owner of this object.</value>
|
/// <value>The owner of this object.</value>
|
||||||
public User Owner { get; internal set; } = null!;
|
public IUser Owner { get; internal set; } = null!;
|
||||||
|
|
||||||
internal byte[] Data { get; set; } = Array.Empty<byte>();
|
internal byte[] Data { get; set; } = Array.Empty<byte>();
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
|
|||||||
VirtualParadiseClient client,
|
VirtualParadiseClient client,
|
||||||
int requestId,
|
int requestId,
|
||||||
string name,
|
string name,
|
||||||
User user,
|
IUser user,
|
||||||
Location location)
|
Location location)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
@ -42,7 +42,7 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
|
|||||||
/// Gets the user which sent the request.
|
/// Gets the user which sent the request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The user which sent the request.</value>
|
/// <value>The user which sent the request.</value>
|
||||||
public User User { get; }
|
public IUser User { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a value indicating whether two <see cref="InviteRequest" /> instances are equal.
|
/// Returns a value indicating whether two <see cref="InviteRequest" /> instances are equal.
|
||||||
|
@ -12,7 +12,7 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
|
|||||||
private readonly VirtualParadiseClient _client;
|
private readonly VirtualParadiseClient _client;
|
||||||
private readonly int _requestId;
|
private readonly int _requestId;
|
||||||
|
|
||||||
internal JoinRequest(VirtualParadiseClient client, int requestId, string name, User user)
|
internal JoinRequest(VirtualParadiseClient client, int requestId, string name, IUser user)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
User = user;
|
User = user;
|
||||||
@ -30,7 +30,7 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
|
|||||||
/// Gets the user which sent the request.
|
/// Gets the user which sent the request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The user which sent the request.</value>
|
/// <value>The user which sent the request.</value>
|
||||||
public User User { get; }
|
public IUser User { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a value indicating whether two <see cref="JoinRequest" /> instances are equal.
|
/// Returns a value indicating whether two <see cref="JoinRequest" /> instances are equal.
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
namespace VpSharp;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// An enumeration of message types.
|
|
||||||
/// </summary>
|
|
||||||
public enum MessageType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A chat message sent by an avatar.
|
|
||||||
/// </summary>
|
|
||||||
ChatMessage,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A console message sent by a bot.
|
|
||||||
/// </summary>
|
|
||||||
ConsoleMessage
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
private readonly Subject<AvatarTypeChangedEventArgs> _avatarTypeChanged = new();
|
private readonly Subject<AvatarTypeChangedEventArgs> _avatarTypeChanged = new();
|
||||||
private readonly Subject<InviteRequest> _inviteRequestReceived = new();
|
private readonly Subject<InviteRequest> _inviteRequestReceived = new();
|
||||||
private readonly Subject<JoinRequest> _joinRequestReceived = new();
|
private readonly Subject<JoinRequest> _joinRequestReceived = new();
|
||||||
private readonly Subject<Message> _messageReceived = new();
|
private readonly Subject<IMessage> _messageReceived = new();
|
||||||
private readonly Subject<ObjectBumpEventArgs> _objectBump = new();
|
private readonly Subject<ObjectBumpEventArgs> _objectBump = new();
|
||||||
private readonly Subject<ObjectChangedEventArgs> _objectChanged = new();
|
private readonly Subject<ObjectChangedEventArgs> _objectChanged = new();
|
||||||
private readonly Subject<ObjectClickedEventArgs> _objectClicked = new();
|
private readonly Subject<ObjectClickedEventArgs> _objectClicked = new();
|
||||||
@ -83,7 +83,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a chat message or console message has been received.
|
/// Occurs when a chat message or console message has been received.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IObservable<Message> MessageReceived
|
public IObservable<IMessage> MessageReceived
|
||||||
{
|
{
|
||||||
get => _messageReceived;
|
get => _messageReceived;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
|
|
||||||
private void OnChatNativeEvent(nint sender)
|
private void OnChatNativeEvent(nint sender)
|
||||||
{
|
{
|
||||||
Message message;
|
IMessage message;
|
||||||
|
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
@ -61,6 +61,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
string content = vp_string(sender, StringAttribute.ChatMessage);
|
string content = vp_string(sender, StringAttribute.ChatMessage);
|
||||||
|
|
||||||
int type = vp_int(sender, IntegerAttribute.ChatType);
|
int type = vp_int(sender, IntegerAttribute.ChatType);
|
||||||
|
IAvatar avatar = GetAvatar(session)!;
|
||||||
|
|
||||||
Color color = Color.Black;
|
Color color = Color.Black;
|
||||||
var style = FontStyle.Regular;
|
var style = FontStyle.Regular;
|
||||||
@ -72,10 +73,12 @@ public sealed partial class VirtualParadiseClient
|
|||||||
int b = vp_int(sender, IntegerAttribute.ChatColorBlue);
|
int b = vp_int(sender, IntegerAttribute.ChatColorBlue);
|
||||||
color = Color.FromArgb(r, g, b);
|
color = Color.FromArgb(r, g, b);
|
||||||
style = (FontStyle)vp_int(sender, IntegerAttribute.ChatEffects);
|
style = (FontStyle)vp_int(sender, IntegerAttribute.ChatEffects);
|
||||||
|
message = new ConsoleMessage(avatar, name, content, color, style);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = new UserMessage(avatar, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAvatar avatar = GetAvatar(session)!;
|
|
||||||
message = new Message((MessageType)type, name, content, avatar, style, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_messageReceived.OnNext(message);
|
_messageReceived.OnNext(message);
|
||||||
@ -332,7 +335,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
userId = vp_int(sender, IntegerAttribute.FriendUserId);
|
userId = vp_int(sender, IntegerAttribute.FriendUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = await GetUserAsync(userId).ConfigureAwait(false);
|
var user = (User)await GetUserAsync(userId).ConfigureAwait(false);
|
||||||
_friends.AddOrUpdate(userId, user, (_, _) => user);
|
_friends.AddOrUpdate(userId, user, (_, _) => user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +551,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
name = vp_string(NativeInstanceHandle, StringAttribute.JoinName);
|
name = vp_string(NativeInstanceHandle, StringAttribute.JoinName);
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = await GetUserAsync(userId).ConfigureAwait(false);
|
IUser user = await GetUserAsync(userId).ConfigureAwait(false);
|
||||||
var joinRequest = new JoinRequest(this, requestId, name, user);
|
var joinRequest = new JoinRequest(this, requestId, name, user);
|
||||||
_joinRequestReceived.OnNext(joinRequest);
|
_joinRequestReceived.OnNext(joinRequest);
|
||||||
}
|
}
|
||||||
@ -582,7 +585,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
World world = (await GetWorldAsync(worldName).ConfigureAwait(false))!;
|
World world = (await GetWorldAsync(worldName).ConfigureAwait(false))!;
|
||||||
User user = await GetUserAsync(userId).ConfigureAwait(false);
|
IUser user = await GetUserAsync(userId).ConfigureAwait(false);
|
||||||
|
|
||||||
var location = new Location(world, position, rotation);
|
var location = new Location(world, position, rotation);
|
||||||
var request = new InviteRequest(this, requestId, avatarName, user, location);
|
var request = new InviteRequest(this, requestId, avatarName, user, location);
|
||||||
|
@ -16,7 +16,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The user whose ID is equal to <paramref name="userId" />, or <see langword="null" /> if no match was found.
|
/// The user whose ID is equal to <paramref name="userId" />, or <see langword="null" /> if no match was found.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<User> GetUserAsync(int userId)
|
public async Task<IUser> GetUserAsync(int userId)
|
||||||
{
|
{
|
||||||
if (_users.TryGetValue(userId, out User? user))
|
if (_users.TryGetValue(userId, out User? user))
|
||||||
{
|
{
|
||||||
|
@ -83,9 +83,9 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
/// Gets the current user to which this client is logged in.
|
/// Gets the current user to which this client is logged in.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// An instance of <see cref="User" />, or <see langword="null" /> if this client is not logged in.
|
/// An instance of <see cref="IUser" />, or <see langword="null" /> if this client is not logged in.
|
||||||
/// </value>
|
/// </value>
|
||||||
public User? CurrentUser { get; internal set; }
|
public IUser? CurrentUser { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the world to which this client is currently connected.
|
/// Gets the world to which this client is currently connected.
|
||||||
@ -565,7 +565,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
/// -or-
|
/// -or-
|
||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public Task<Message> SendMessageAsync(string message)
|
public Task<IUserMessage> SendMessageAsync(string message)
|
||||||
{
|
{
|
||||||
if (message is null)
|
if (message is null)
|
||||||
{
|
{
|
||||||
@ -593,14 +593,9 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IAvatar? avatar = CurrentAvatar;
|
return Task.FromResult((IUserMessage)new UserMessage(
|
||||||
return Task.FromResult(new Message(
|
CurrentAvatar!,
|
||||||
MessageType.ChatMessage,
|
message
|
||||||
avatar!.Name,
|
|
||||||
message,
|
|
||||||
avatar,
|
|
||||||
FontStyle.Regular,
|
|
||||||
Color.Black
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +615,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
/// -or-
|
/// -or-
|
||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public Task<Message> SendMessageAsync(string message, FontStyle fontStyle, Color color)
|
public Task<IConsoleMessage> SendMessageAsync(string message, FontStyle fontStyle, Color color)
|
||||||
{
|
{
|
||||||
return SendMessageAsync(null, message, fontStyle, color);
|
return SendMessageAsync(null, message, fontStyle, color);
|
||||||
}
|
}
|
||||||
@ -642,7 +637,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
/// -or-
|
/// -or-
|
||||||
/// <para><paramref name="message" /> is too long to send.</para>
|
/// <para><paramref name="message" /> is too long to send.</para>
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public Task<Message> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color)
|
public Task<IConsoleMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color)
|
||||||
{
|
{
|
||||||
if (message is null)
|
if (message is null)
|
||||||
{
|
{
|
||||||
@ -680,13 +675,13 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(new Message(
|
IAvatar avatar = CurrentAvatar!;
|
||||||
MessageType.ConsoleMessage,
|
return Task.FromResult((IConsoleMessage)new ConsoleMessage(
|
||||||
name,
|
avatar,
|
||||||
|
avatar.Name,
|
||||||
message,
|
message,
|
||||||
CurrentAvatar!,
|
color,
|
||||||
fontStyle,
|
fontStyle
|
||||||
color
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user