Skip to content

Commit

Permalink
Update for the breaking change discord has made + v3 is cringe (#2951)
Browse files Browse the repository at this point in the history
* update for the breaking change discord made + v3 is fucked

* this could've bee a cool surprise 4 everyone
  • Loading branch information
Misha-133 authored Jun 29, 2024
1 parent cb79f04 commit 8afea2c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace Discord;
/// <inheritdoc />
public ulong UserId { get; }

/// <inheritdoc />
public IUser User { get; }

/// <inheritdoc />
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }

Expand All @@ -32,13 +35,14 @@ namespace Discord;
public string Name { get; }

internal ApplicationCommandInteractionMetadata(ulong id, InteractionType type, ulong userId, IReadOnlyDictionary<ApplicationIntegrationType, ulong> integrationOwners,
ulong? originalResponseMessageId, string name)
ulong? originalResponseMessageId, string name, IUser user)
{
Id = id;
Type = type;
UserId = userId;
IntegrationOwners = integrationOwners;
OriginalResponseMessageId = originalResponseMessageId;
Name = name;
User = user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public interface IMessageInteractionMetadata : ISnowflakeEntity
/// </summary>
ulong UserId { get; }

/// <summary>
/// Gets the user who triggered the interaction.
/// </summary>
IUser User { get; }

/// <summary>
/// Gets the Ids for installation contexts related to the interaction.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace Discord;
/// <inheritdoc />
public ulong UserId { get; }

/// <inheritdoc />
public IUser User { get; }

/// <inheritdoc />
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }

Expand All @@ -32,14 +35,15 @@ namespace Discord;
public ulong InteractedMessageId { get; }

internal MessageComponentInteractionMetadata(ulong id, InteractionType type, ulong userId, IReadOnlyDictionary<ApplicationIntegrationType, ulong> integrationOwners,
ulong? originalResponseMessageId, ulong interactedMessageId)
ulong? originalResponseMessageId, ulong interactedMessageId, IUser user)
{
Id = id;
Type = type;
UserId = userId;
IntegrationOwners = integrationOwners;
OriginalResponseMessageId = originalResponseMessageId;
InteractedMessageId = interactedMessageId;
User = user;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace Discord;
/// <inheritdoc />
public ulong UserId { get; }

/// <inheritdoc />
public IUser User { get; }

/// <inheritdoc />
public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }

Expand All @@ -32,13 +35,14 @@ namespace Discord;
public IMessageInteractionMetadata TriggeringInteractionMetadata { get; }

internal ModalSubmitInteractionMetadata(ulong id, InteractionType type, ulong userId, IReadOnlyDictionary<ApplicationIntegrationType, ulong> integrationOwners,
ulong? originalResponseMessageId, IMessageInteractionMetadata triggeringInteractionMetadata)
ulong? originalResponseMessageId, IMessageInteractionMetadata triggeringInteractionMetadata, IUser user)
{
Id = id;
Type = type;
UserId = userId;
IntegrationOwners = integrationOwners;
OriginalResponseMessageId = originalResponseMessageId;
TriggeringInteractionMetadata = triggeringInteractionMetadata;
User = user;
}
}
6 changes: 3 additions & 3 deletions src/Discord.Net.Rest/API/Common/MessageInteractionMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class MessageInteractionMetadata

[JsonProperty("type")]
public InteractionType Type { get; set; }

[JsonProperty("user_id")]
public ulong UserId { get; set; }
[JsonProperty("user")]
public User User { get; set; }

[JsonProperty("authorizing_integration_owners")]
public Dictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal static RestMessage Create(BaseDiscordClient discord, IMessageChannel ch
if (model.Type == MessageType.Default ||
model.Type == MessageType.Reply ||
model.Type == MessageType.ApplicationCommand ||
model.Type == MessageType.ContextMenuCommand ||
model.Type == MessageType.ThreadStarterMessage)
return RestUserMessage.Create(discord, channel, author, model);
else
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal override void Update(Model model)
ResolvedData = new MessageResolvedData(users, members, roles, channels);
}
if (model.InteractionMetadata.IsSpecified)
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata();
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata(Discord);

if (model.Poll.IsSpecified)
Poll = model.Poll.Value.ToEntity();
Expand Down
17 changes: 10 additions & 7 deletions src/Discord.Net.Rest/Extensions/InteractionMetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,39 @@ namespace Discord.Rest;

internal static class InteractionMetadataExtensions
{
public static IMessageInteractionMetadata ToInteractionMetadata(this API.MessageInteractionMetadata metadata)
public static IMessageInteractionMetadata ToInteractionMetadata(this API.MessageInteractionMetadata metadata, BaseDiscordClient discord)
{
switch (metadata.Type)
{
case InteractionType.ApplicationCommand:
return new ApplicationCommandInteractionMetadata(
metadata.Id,
metadata.Type,
metadata.UserId,
metadata.User.Id,
metadata.IntegrationOwners.ToImmutableDictionary(),
metadata.OriginalResponseMessageId.IsSpecified ? metadata.OriginalResponseMessageId.Value : null,
metadata.Name.GetValueOrDefault(null));
metadata.Name.GetValueOrDefault(null),
RestUser.Create(discord, metadata.User));

case InteractionType.MessageComponent:
return new MessageComponentInteractionMetadata(
metadata.Id,
metadata.Type,
metadata.UserId,
metadata.User.Id,
metadata.IntegrationOwners.ToImmutableDictionary(),
metadata.OriginalResponseMessageId.IsSpecified ? metadata.OriginalResponseMessageId.Value : null,
metadata.InteractedMessageId.GetValueOrDefault(0));
metadata.InteractedMessageId.GetValueOrDefault(0),
RestUser.Create(discord, metadata.User));

case InteractionType.ModalSubmit:
return new ModalSubmitInteractionMetadata(
metadata.Id,
metadata.Type,
metadata.UserId,
metadata.User.Id,
metadata.IntegrationOwners.ToImmutableDictionary(),
metadata.OriginalResponseMessageId.IsSpecified ? metadata.OriginalResponseMessageId.Value : null,
metadata.TriggeringInteractionMetadata.GetValueOrDefault(null)?.ToInteractionMetadata());
metadata.TriggeringInteractionMetadata.GetValueOrDefault(null)?.ToInteractionMetadata(discord),
RestUser.Create(discord, metadata.User));

default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ internal override void Update(ClientState state, Model model)
}

if (model.InteractionMetadata.IsSpecified)
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata();
InteractionMetadata = model.InteractionMetadata.Value.ToInteractionMetadata(Discord);

if (model.Poll.IsSpecified)
Poll = model.Poll.Value.ToEntity();
Expand Down

0 comments on commit 8afea2c

Please sign in to comment.