Skip to content

Commit

Permalink
Implement data structures for forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Dec 8, 2024
1 parent 1b3c84a commit e226d8f
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public interface IMessage : IPartialMessage
/// </summary>
new Optional<IMessageReference> MessageReference { get; }

/// <summary>
/// Gets the message associated with <see cref="MessageReference"/>. Sent with forwarded messages.
/// </summary>
new Optional<IReadOnlyList<IMessageSnapshot>> MessageSnapshots { get; }

/// <summary>
/// Gets a set of bitwise flags describing extra features of the message.
/// </summary>
Expand Down Expand Up @@ -270,6 +275,9 @@ public interface IMessage : IPartialMessage
/// <inheritdoc/>
Optional<IMessageReference> IPartialMessage.MessageReference => this.MessageReference;

/// <inheritdoc/>
Optional<IReadOnlyList<IMessageSnapshot>> IPartialMessage.MessageSnapshots => this.MessageSnapshots;

/// <inheritdoc/>
Optional<MessageFlags> IPartialMessage.Flags => this.Flags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace Remora.Discord.API.Abstractions.Objects;
[PublicAPI]
public interface IMessageReference
{
/// <summary>
/// Gets the type of message reference provided.
/// </summary>
Optional<MessageReferenceType> Type { get; }

/// <summary>
/// Gets the ID of the originating message.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// IMessageSnapshot.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents a message at a specific point in time.
/// </summary>
[PublicAPI]
public interface IMessageSnapshot
{
/// <summary>
/// Gets the message that has been referenced.
/// </summary>
IPartialMessage Message { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public interface IPartialMessage
/// <inheritdoc cref="IMessage.MessageReference" />
Optional<IMessageReference> MessageReference { get; }

/// <inheritdoc cref="IMessage.MessageSnapshots" />
Optional<IReadOnlyList<IMessageSnapshot>> MessageSnapshots { get; }

/// <inheritdoc cref="IMessage.Flags" />
Optional<MessageFlags> Flags { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// MessageReferenceType.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Enumerates the message reference types provided by Discord.
/// </summary>
[PublicAPI]
public enum MessageReferenceType
{
/// <summary>
/// A reference used by replies.
/// </summary>
Default = 0,

/// <summary>
/// A reference used to point to a message at a point in time.
/// </summary>
Forward = 1,
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public record MessageCreate
Optional<IMessageReference> MessageReference = default,
Optional<MessageFlags> Flags = default,
Optional<IMessage?> ReferencedMessage = default,
Optional<IReadOnlyList<IMessageSnapshot>> MessageSnapshots = default,
Optional<IMessageInteraction> Interaction = default,
Optional<IChannel> Thread = default,
Optional<IReadOnlyList<IMessageComponent>> Components = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public record MessageUpdate
Optional<IPartialApplication> Application = default,
Optional<Snowflake> ApplicationID = default,
Optional<IMessageReference> MessageReference = default,
Optional<IReadOnlyList<IMessageSnapshot>> MessageSnapshots = default,
Optional<MessageFlags> Flags = default,
Optional<IMessage?> ReferencedMessage = default,
Optional<IMessageInteraction> Interaction = default,
Expand Down
1 change: 1 addition & 0 deletions Backend/Remora.Discord.API/API/Objects/Messages/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public record Message
Optional<IMessageReference> MessageReference = default,
Optional<MessageFlags> Flags = default,
Optional<IMessage?> ReferencedMessage = default,
Optional<IReadOnlyList<IMessageSnapshot>> MessageSnapshots = default,
Optional<IMessageInteraction> Interaction = default,
Optional<IChannel> Thread = default,
Optional<IReadOnlyList<IMessageComponent>> Components = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Remora.Discord.API.Objects;
[PublicAPI]
public record MessageReference
(
Optional<MessageReferenceType> Type = default,
Optional<Snowflake> MessageID = default,
Optional<Snowflake> ChannelID = default,
Optional<Snowflake> GuildID = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public record PartialMessage
Optional<IPartialApplication> Application = default,
Optional<Snowflake> ApplicationID = default,
Optional<IMessageReference> MessageReference = default,
Optional<IReadOnlyList<IMessageSnapshot>> MessageSnapshots = default,
Optional<MessageFlags> Flags = default,
Optional<IMessage?> ReferencedMessage = default,
Optional<IMessageInteraction> Interaction = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"pinned": true,
"type": 1
},
"message_snapshots": [],
"interaction": {
"id": "999999999999999999",
"type": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"message_reference": {},
"flags": 1,
"referenced_message": null,
"message_snapshots": null,
"interaction": {
"id": "999999999999999999",
"type": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"pinned": true,
"type": 1
},
"message_snapshots": [],
"interaction": {
"id": "999999999999999999",
"type": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"message_reference": {},
"flags": 1,
"referenced_message": null,
"message_snapshots": null,
"interaction": {
"id": "999999999999999999",
"type": 1,
Expand Down

0 comments on commit e226d8f

Please sign in to comment.