refactor!: revert 63e775855a

This commit is contained in:
Oliver Booth 2024-06-01 18:11:53 +01:00
parent 2669b5083d
commit e71494ef83
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
7 changed files with 15 additions and 26 deletions

View File

@ -13,6 +13,6 @@ public sealed class RequireBotOwnerAttribute : PreExecutionCheckAttribute
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(context.Avatar.UserId == context.Client.CurrentUser?.Id);
return Task.FromResult(context.Avatar.User == context.Client.CurrentUser);
}
}

View File

@ -52,6 +52,6 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(UserIds.Contains(context.Avatar.UserId));
return Task.FromResult(UserIds.Any(i => context.Avatar.User.Id == i));
}
}

View File

@ -47,14 +47,14 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
public IReadOnlyList<string> Names { get; }
/// <inheritdoc />
protected internal override async Task<bool> PerformAsync(CommandContext context)
protected internal override Task<bool> PerformAsync(CommandContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
VirtualParadiseUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false);
return Names.Contains(user.Name);
VirtualParadiseUser user = context.Avatar.User;
return Task.FromResult(Names.Contains(user.Name));
}
}

View File

@ -13,7 +13,6 @@ namespace VpSharp.Entities;
public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
{
private readonly VirtualParadiseClient _client;
private VirtualParadiseUser? _user;
internal VirtualParadiseAvatar(VirtualParadiseClient client, int session)
{
@ -61,10 +60,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
public int Type { get; internal set; }
/// <summary>
/// Gets the user ID associated with this avatar.
/// Gets the user associated with this avatar.
/// </summary>
/// <value>The user ID.</value>
public int UserId { get; internal set; }
/// <value>The user.</value>
public VirtualParadiseUser User { get; internal set; } = null!;
/// <summary>
/// Determines if two <see cref="VirtualParadiseAvatar" /> instances are equal.
@ -151,7 +150,7 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
return true;
}
return Session == other.Session && UserId.Equals(other.UserId);
return Session == other.Session && User.Equals(other.User);
}
/// <inheritdoc />
@ -164,20 +163,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
public override int GetHashCode()
{
// ReSharper disable NonReadonlyMemberInGetHashCode
return HashCode.Combine(Session, UserId);
return HashCode.Combine(Session, User);
// 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>
@ -480,6 +469,6 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <inheritdoc />
public override string ToString()
{
return $"Avatar #{Session}; User #{UserId} ({Name})";
return $"Avatar #{Session}; {User.Name} ({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.UserId = avatar.UserId;
existing.User = avatar.User;
return existing;
});
}
@ -62,8 +62,7 @@ public sealed partial class VirtualParadiseClient
{
Name = vp_string(sender, StringAttribute.AvatarName),
Location = new Location(CurrentWorld!, position, rotation),
Application = new Application(applicationName, applicationVersion),
UserId = vp_int(sender, IntegerAttribute.UserId)
Application = new Application(applicationName, applicationVersion)
};
}
}

View File

@ -89,6 +89,7 @@ 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

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