1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-23 00:28:48 +00:00

Compare commits

...

3 Commits

8 changed files with 30 additions and 16 deletions

View File

@ -9,6 +9,6 @@ public sealed class RequireBotOwnerAttribute : PreExecutionCheckAttribute
protected internal override Task<bool> PerformAsync(CommandContext context)
{
ArgumentNullException.ThrowIfNull(context);
return Task.FromResult(context.Avatar.User.Id == context.Client.CurrentUser?.Id);
return Task.FromResult(context.Avatar.UserId == context.Client.CurrentUser?.Id);
}
}

View File

@ -40,6 +40,6 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
protected internal override Task<bool> PerformAsync(CommandContext context)
{
ArgumentNullException.ThrowIfNull(context);
return Task.FromResult(UserIds.Contains(context.Avatar.User.Id));
return Task.FromResult(UserIds.Contains(context.Avatar.UserId));
}
}

View File

@ -1,4 +1,6 @@
namespace VpSharp.Commands.Attributes.ExecutionChecks;
using VpSharp.Entities;
namespace VpSharp.Commands.Attributes.ExecutionChecks;
#pragma warning disable CA1019 // Define accessors for attribute arguments
@ -37,9 +39,10 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
public IReadOnlyList<string> Names { get; }
/// <inheritdoc />
protected internal override Task<bool> PerformAsync(CommandContext context)
protected internal override async Task<bool> PerformAsync(CommandContext context)
{
ArgumentNullException.ThrowIfNull(context);
return Task.FromResult(Names.Contains(context.Avatar.User.Name));
VirtualParadiseUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false);
return Names.Contains(user.Name);
}
}

View File

@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionPrefix>1.0.0</VersionPrefix>
<Authors>Oliver Booth</Authors>
<NeutralLanguage>en</NeutralLanguage>
<RepositoryUrl>https://github.com/oliverbooth/VpSharp</RepositoryUrl>

View File

@ -13,6 +13,7 @@ namespace VpSharp.Entities;
public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
{
private readonly VirtualParadiseClient _client;
private VirtualParadiseUser? _user;
internal VirtualParadiseAvatar(VirtualParadiseClient client, int session)
{
@ -60,10 +61,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
public int Type { get; internal set; }
/// <summary>
/// Gets the user associated with this avatar.
/// Gets the user ID associated with this avatar.
/// </summary>
/// <value>The user.</value>
public VirtualParadiseUser User { get; internal set; } = null!;
/// <value>The user ID.</value>
public int UserId { get; internal set; }
/// <summary>
/// Determines if two <see cref="VirtualParadiseAvatar" /> instances are equal.
@ -150,7 +151,7 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
return true;
}
return Session == other.Session && User.Equals(other.User);
return Session == other.Session && UserId.Equals(other.UserId);
}
/// <inheritdoc />
@ -163,10 +164,20 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
public override int GetHashCode()
{
// ReSharper disable NonReadonlyMemberInGetHashCode
return HashCode.Combine(Session, User);
return HashCode.Combine(Session, UserId);
// ReSharper restore NonReadonlyMemberInGetHashCode
}
/// <summary>
/// Gets the user associated with this avatar.
/// </summary>
/// <returns>The user.</returns>
public async Task<VirtualParadiseUser> GetUserAsync()
{
_user ??= await _client.GetUserAsync(UserId).ConfigureAwait(false);
return _user;
}
/// <summary>
/// Sends a console message to the avatar with no name.
/// </summary>
@ -449,6 +460,6 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <inheritdoc />
public override string ToString()
{
return $"Avatar #{Session}; {User.Name} ({Name})";
return $"Avatar #{Session}; User #{UserId} ({Name})";
}
}

View File

@ -36,7 +36,7 @@ public sealed partial class VirtualParadiseClient
existing.Location = avatar.Location;
existing.Application = avatar.Application;
existing.Type = avatar.Type;
existing.User = avatar.User;
existing.UserId = avatar.UserId;
return existing;
});
}
@ -62,7 +62,8 @@ public sealed partial class VirtualParadiseClient
{
Name = vp_string(sender, StringAttribute.AvatarName),
Location = new Location(CurrentWorld!, position, rotation),
Application = new Application(applicationName, applicationVersion)
Application = new Application(applicationName, applicationVersion),
UserId = vp_int(sender, IntegerAttribute.UserId)
};
}
}

View File

@ -89,7 +89,6 @@ public sealed partial class VirtualParadiseClient
private void OnAvatarAddNativeEvent(nint sender)
{
VirtualParadiseAvatar avatar = ExtractAvatar(sender);
avatar.User = GetUserAsync(vp_int(sender, IntegerAttribute.UserId)).ConfigureAwait(false).GetAwaiter().GetResult();
avatar = AddOrUpdateAvatar(avatar);
_avatarJoined.OnNext(avatar);
}

View File

@ -397,7 +397,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
Application = _configuration.Application!,
Name = $"[{_configuration.BotName}]",
Location = new Location(world, Vector3d.Zero, Rotation.None),
User = CurrentUser!
UserId = CurrentUser!.Id
};
if (CurrentWorld is not null)