Skip to content

Commit

Permalink
Implement support for voice messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed May 1, 2023
1 parent 9eac98d commit f455a0a
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using JetBrains.Annotations;
using Remora.Rest.Core;

Expand Down Expand Up @@ -83,6 +84,16 @@ public interface IAttachment : IPartialAttachment
/// </summary>
new Optional<bool> IsEphemeral { get; }

/// <summary>
/// Gets the duration of the audio file.
/// </summary>
new Optional<TimeSpan> Duration { get; }

/// <summary>
/// Gets a preview of the audio contained in the audio file.
/// </summary>
new Optional<byte[]> Waveform { get; }

/// <inheritdoc/>
Optional<Snowflake> IPartialAttachment.ID => this.ID;

Expand Down Expand Up @@ -112,4 +123,10 @@ public interface IAttachment : IPartialAttachment

/// <inheritdoc/>
Optional<bool> IPartialAttachment.IsEphemeral => this.IsEphemeral;

/// <inheritdoc/>
Optional<TimeSpan> IPartialAttachment.Duration => this.Duration;

/// <inheritdoc/>
Optional<byte[]> IPartialAttachment.Waveform => this.Waveform;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using JetBrains.Annotations;
using Remora.Rest.Core;

Expand Down Expand Up @@ -58,4 +59,10 @@ public interface IPartialAttachment

/// <inheritdoc cref="IAttachment.IsEphemeral"/>
Optional<bool> IsEphemeral { get; }

/// <inheritdoc cref="IAttachment.Duration"/>
Optional<TimeSpan> Duration { get; }

/// <inheritdoc cref="IAttachment.Waveform"/>
Optional<byte[]> Waveform { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ public enum MessageFlags
/// The message will generate a mention, but will not trigger push notifications.
/// </summary>
SuppressNotifications = 1 << 12,

/// <summary>
/// The message is a voice message.
/// </summary>
IsVoiceMessage = 1 << 13
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,10 @@ public enum DiscordPermission
/// <summary>
/// Allows for using soundboard in a voice channel.
/// </summary>
UseSoundboard = 42
UseSoundboard = 42,

/// <summary>
/// Allows for sending voice messages.
/// </summary>
SendVoiceMessages = 46
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@ public enum DiscordStagePermission
ManageEvents = DiscordPermission.ManageEvents,

/// <inheritdoc cref="DiscordPermission.UseExternalStickers"/>
UseExternalStickers = DiscordPermission.UseExternalStickers
UseExternalStickers = DiscordPermission.UseExternalStickers,

/// <inheritdoc cref="DiscordPermission.SendVoiceMessages"/>
SendVoiceMessages = DiscordPermission.SendVoiceMessages
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,8 @@ public enum DiscordTextPermission
UseExternalStickers = DiscordPermission.UseExternalStickers,

/// <inheritdoc cref="DiscordPermission.SendMessagesInThreads"/>
SendMessagesInThreads = DiscordPermission.SendMessagesInThreads
SendMessagesInThreads = DiscordPermission.SendMessagesInThreads,

/// <inheritdoc cref="DiscordPermission.SendVoiceMessages"/>
SendVoiceMessages = DiscordPermission.SendVoiceMessages
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@ public enum DiscordVoicePermission
UseEmbeddedActivities = DiscordPermission.UseEmbeddedActivities,

/// <inheritdoc cref="DiscordPermission.UseSoundboard"/>
UseSoundboard = DiscordPermission.UseSoundboard
UseSoundboard = DiscordPermission.UseSoundboard,

/// <inheritdoc cref="DiscordPermission.SendVoiceMessages"/>
SendVoiceMessages = DiscordPermission.SendVoiceMessages
}
27 changes: 26 additions & 1 deletion Backend/Remora.Discord.API.Abstractions/Results/DiscordError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,35 @@ public enum DiscordError
UploadedFileNotFound = 50146,

/// <summary>
/// Cannot delete guild subscription integration.
/// Additional attachments are not possible for voice messages.
/// </summary>
VoiceMessagesDoNotSupportAdditionalContent = 50159,

/// <summary>
/// Voice messages must have an audio attachment.
/// </summary>
VoiceMessagesMustHaveASingleAudioAttachment = 50160,

/// <summary>
/// Voice messages must have additional data attached to the object.
/// </summary>
VoiceMessagesMustHaveSupportingMetadata = 50161,

/// <summary>
/// Voice messages cannot be edited.
/// </summary>
VoiceMessagesCannotBeEdited = 50162,

/// <summary>
/// Guild integrations that come from subscriptions cannot be deleted.
/// </summary>
CannotDeleteGuildSubscriptionIntegration = 50163,

/// <summary>
/// Voice messages cannot be sent in this channel.
/// </summary>
YouCannotSendVoiceMessagesInThisChannel = 50173,

/// <summary>
/// You do not have permission to send this sticker.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Rest.Core;
Expand All @@ -41,5 +42,7 @@ public record Attachment
[UriString("GET")] string ProxyUrl,
Optional<int?> Height,
Optional<int?> Width,
Optional<bool> IsEphemeral
Optional<bool> IsEphemeral,
Optional<TimeSpan> Duration,
Optional<byte[]> Waveform
) : IAttachment;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Rest.Core;
Expand All @@ -41,5 +42,7 @@ public record PartialAttachment
Optional<string> ProxyUrl = default,
Optional<int?> Height = default,
Optional<int?> Width = default,
Optional<bool> IsEphemeral = default
Optional<bool> IsEphemeral = default,
Optional<TimeSpan> Duration = default,
Optional<byte[]> Waveform = default
) : IPartialAttachment;
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ private static JsonSerializerOptions AddInviteObjectConverters(this JsonSerializ
private static JsonSerializerOptions AddMessageObjectConverters(this JsonSerializerOptions options)
{
options.AddDataObjectConverter<IAttachment, Attachment>()
.WithPropertyName(a => a.IsEphemeral, "ephemeral");
.WithPropertyName(a => a.IsEphemeral, "ephemeral")
.WithPropertyName(a => a.Duration, "duration_secs")
.WithPropertyConverter(a => a.Duration, new UnitTimeSpanConverter(TimeUnit.Seconds));

options.AddDataObjectConverter<IPartialAttachment, PartialAttachment>()
.WithPropertyName(a => a.IsEphemeral, "ephemeral");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"proxy_url": "https://www.example.org",
"height": 1,
"width": 1,
"ephemeral": true
}
"ephemeral": true,
"duration_secs": 10,
"waveform": "bm9uZQ=="
}

0 comments on commit f455a0a

Please sign in to comment.