Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 15 additions & 32 deletions NetCord/InteractionResolvedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,37 @@ public class InteractionResolvedData

public InteractionResolvedData(JsonInteractionResolvedData jsonModel, ulong? guildId, RestClient client)
{
var users = jsonModel.Users;
if (users is not null)
if (jsonModel.Users is { } users)
{
var guildUsers = jsonModel.GuildUsers;
if (guildUsers is not null)
if (jsonModel.GuildUsers is { } guildUsers)
{
Dictionary<ulong, User> resultUsers = [];
using (var enumerator = users.GetEnumerator())
{
var max = users.Count - guildUsers.Count;
for (var i = 0; i < max; i++)
{
enumerator.MoveNext();
var current = enumerator.Current;
resultUsers.Add(current.Key, new(current.Value, client));
}
var guildIdValue = guildId.GetValueOrDefault();

var guildIdValue = guildId.GetValueOrDefault();
foreach (var guildUser in guildUsers)
Users = users.ToDictionary(u => u.Key, u =>
{
if (guildUsers.TryGetValue(u.Key, out var guildUser))
{
enumerator.MoveNext();
var current = enumerator.Current;

var guildUserModel = guildUser.Value;
guildUserModel.User = current.Value;
resultUsers.Add(current.Key, new GuildInteractionUser(guildUserModel, guildIdValue, client));
guildUser.User = u.Value;
return new GuildInteractionUser(guildUser, guildIdValue, client);
}
}
Users = resultUsers;
else
return new User(u.Value, client);
});
}
else
Users = users.ToDictionary(u => u.Key, u => new User(u.Value, client));
}

var roles = jsonModel.Roles;
if (roles is not null)
if (jsonModel.Roles is { } roles)
Roles = roles.ToDictionary(r => r.Key, r => new Role(r.Value, guildId.GetValueOrDefault(), client));

var channels = jsonModel.Channels;
if (channels is not null)
if (jsonModel.Channels is { } channels)
Channels = channels.ToDictionary(c => c.Key, c => Channel.CreateFromJson(c.Value, client));

var messages = jsonModel.Messages;
if (messages is not null)
if (jsonModel.Messages is { } messages)
Messages = messages.ToDictionary(m => m.Key, m => new RestMessage(m.Value, client));

var attachments = jsonModel.Attachments;
if (attachments is not null)
if (jsonModel.Attachments is { } attachments)
Attachments = attachments.ToDictionary(c => c.Key, c => Attachment.CreateFromJson(c.Value, client));
}
}
12 changes: 6 additions & 6 deletions NetCord/JsonModels/JsonInteractionResolvedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ namespace NetCord.JsonModels;
public class JsonInteractionResolvedData
{
[JsonPropertyName("users")]
public IReadOnlyDictionary<ulong, JsonUser>? Users { get; set; }
public Dictionary<ulong, JsonUser>? Users { get; set; }

[JsonPropertyName("members")]
public IReadOnlyDictionary<ulong, JsonGuildUser>? GuildUsers { get; set; }
public Dictionary<ulong, JsonGuildUser>? GuildUsers { get; set; }

[JsonPropertyName("roles")]
public IReadOnlyDictionary<ulong, JsonRole>? Roles { get; set; }
public Dictionary<ulong, JsonRole>? Roles { get; set; }

[JsonPropertyName("channels")]
public IReadOnlyDictionary<ulong, JsonChannel>? Channels { get; set; }
public Dictionary<ulong, JsonChannel>? Channels { get; set; }

[JsonPropertyName("messages")]
public IReadOnlyDictionary<ulong, JsonMessage>? Messages { get; set; }
public Dictionary<ulong, JsonMessage>? Messages { get; set; }

[JsonPropertyName("attachments")]
public IReadOnlyDictionary<ulong, JsonAttachment>? Attachments { get; set; }
public Dictionary<ulong, JsonAttachment>? Attachments { get; set; }
}
Loading