mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-22 11:48:47 +00:00
refactor!: revert 63e775855a
This commit is contained in:
parent
2669b5083d
commit
e71494ef83
@ -13,6 +13,6 @@ public sealed class RequireBotOwnerAttribute : PreExecutionCheckAttribute
|
|||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(context.Avatar.UserId == context.Client.CurrentUser?.Id);
|
return Task.FromResult(context.Avatar.User == context.Client.CurrentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,6 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
|
|||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(UserIds.Contains(context.Avatar.UserId));
|
return Task.FromResult(UserIds.Any(i => context.Avatar.User.Id == i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,14 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
|
|||||||
public IReadOnlyList<string> Names { get; }
|
public IReadOnlyList<string> Names { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected internal override async Task<bool> PerformAsync(CommandContext context)
|
protected internal override Task<bool> PerformAsync(CommandContext context)
|
||||||
{
|
{
|
||||||
if (context is null)
|
if (context is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualParadiseUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false);
|
VirtualParadiseUser user = context.Avatar.User;
|
||||||
return Names.Contains(user.Name);
|
return Task.FromResult(Names.Contains(user.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ namespace VpSharp.Entities;
|
|||||||
public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||||
{
|
{
|
||||||
private readonly VirtualParadiseClient _client;
|
private readonly VirtualParadiseClient _client;
|
||||||
private VirtualParadiseUser? _user;
|
|
||||||
|
|
||||||
internal VirtualParadiseAvatar(VirtualParadiseClient client, int session)
|
internal VirtualParadiseAvatar(VirtualParadiseClient client, int session)
|
||||||
{
|
{
|
||||||
@ -61,10 +60,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
|||||||
public int Type { get; internal set; }
|
public int Type { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user ID associated with this avatar.
|
/// Gets the user associated with this avatar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The user ID.</value>
|
/// <value>The user.</value>
|
||||||
public int UserId { get; internal set; }
|
public VirtualParadiseUser User { get; internal set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if two <see cref="VirtualParadiseAvatar" /> instances are equal.
|
/// Determines if two <see cref="VirtualParadiseAvatar" /> instances are equal.
|
||||||
@ -151,7 +150,7 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Session == other.Session && UserId.Equals(other.UserId);
|
return Session == other.Session && User.Equals(other.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -164,20 +163,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
|||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||||
return HashCode.Combine(Session, UserId);
|
return HashCode.Combine(Session, User);
|
||||||
// ReSharper restore NonReadonlyMemberInGetHashCode
|
// 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>
|
/// <summary>
|
||||||
/// Sends a console message to the avatar with no name.
|
/// Sends a console message to the avatar with no name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -480,6 +469,6 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"Avatar #{Session}; User #{UserId} ({Name})";
|
return $"Avatar #{Session}; {User.Name} ({Name})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
existing.Location = avatar.Location;
|
existing.Location = avatar.Location;
|
||||||
existing.Application = avatar.Application;
|
existing.Application = avatar.Application;
|
||||||
existing.Type = avatar.Type;
|
existing.Type = avatar.Type;
|
||||||
existing.UserId = avatar.UserId;
|
existing.User = avatar.User;
|
||||||
return existing;
|
return existing;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -62,8 +62,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
{
|
{
|
||||||
Name = vp_string(sender, StringAttribute.AvatarName),
|
Name = vp_string(sender, StringAttribute.AvatarName),
|
||||||
Location = new Location(CurrentWorld!, position, rotation),
|
Location = new Location(CurrentWorld!, position, rotation),
|
||||||
Application = new Application(applicationName, applicationVersion),
|
Application = new Application(applicationName, applicationVersion)
|
||||||
UserId = vp_int(sender, IntegerAttribute.UserId)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ public sealed partial class VirtualParadiseClient
|
|||||||
private void OnAvatarAddNativeEvent(nint sender)
|
private void OnAvatarAddNativeEvent(nint sender)
|
||||||
{
|
{
|
||||||
VirtualParadiseAvatar avatar = ExtractAvatar(sender);
|
VirtualParadiseAvatar avatar = ExtractAvatar(sender);
|
||||||
|
avatar.User = GetUserAsync(vp_int(sender, IntegerAttribute.UserId)).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
avatar = AddOrUpdateAvatar(avatar);
|
avatar = AddOrUpdateAvatar(avatar);
|
||||||
_avatarJoined.OnNext(avatar);
|
_avatarJoined.OnNext(avatar);
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ public sealed partial class VirtualParadiseClient : IDisposable
|
|||||||
Application = _configuration.Application!,
|
Application = _configuration.Application!,
|
||||||
Name = $"[{_configuration.BotName}]",
|
Name = $"[{_configuration.BotName}]",
|
||||||
Location = new Location(world, Vector3d.Zero, Rotation.None),
|
Location = new Location(world, Vector3d.Zero, Rotation.None),
|
||||||
UserId = CurrentUser!.Id
|
User = CurrentUser!
|
||||||
};
|
};
|
||||||
|
|
||||||
if (CurrentWorld is not null)
|
if (CurrentWorld is not null)
|
||||||
|
Loading…
Reference in New Issue
Block a user