@@ -27,6 +27,16 @@ namespace Discord
|
||||
/// </summary>
|
||||
public bool IsThumbnail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration of a voice message. <see langword="null"/> if the attachment is not a voice message.
|
||||
/// </summary>
|
||||
public double? DurationSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets bytearray representing a sampled waveform. <see langword="null"/> if the attachment is not a voice message.
|
||||
/// </summary>
|
||||
public byte[] Waveform { get; set; }
|
||||
|
||||
#pragma warning disable IDISP008
|
||||
/// <summary>
|
||||
/// Gets the stream containing the file content.
|
||||
@@ -44,7 +54,7 @@ namespace Discord
|
||||
/// <param name="description">The description of the attachment.</param>
|
||||
/// <param name="isSpoiler">Whether or not the attachment is a spoiler.</param>
|
||||
/// <param name="isThumbnail">Whether or not this attachment should be a thumbnail for a media channel post.</param>
|
||||
public FileAttachment(Stream stream, string fileName, string description = null, bool isSpoiler = false, bool isThumbnail = false)
|
||||
public FileAttachment(Stream stream, string fileName, string description = null, bool isSpoiler = false, bool isThumbnail = false, double? durationSeconds = null, byte[] waveform = null)
|
||||
{
|
||||
_isDisposed = false;
|
||||
FileName = fileName;
|
||||
@@ -57,6 +67,8 @@ namespace Discord
|
||||
}
|
||||
catch { }
|
||||
IsSpoiler = isSpoiler;
|
||||
DurationSeconds = durationSeconds;
|
||||
Waveform = waveform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,7 +103,7 @@ namespace Discord
|
||||
/// <exception cref="FileNotFoundException">The file specified in <paramref name="path" /> was not found.
|
||||
/// </exception>
|
||||
/// <exception cref="IOException">An I/O error occurred while opening the file. </exception>
|
||||
public FileAttachment(string path, string fileName = null, string description = null, bool isSpoiler = false, bool isThumbnail = false)
|
||||
public FileAttachment(string path, string fileName = null, string description = null, bool isSpoiler = false, bool isThumbnail = false, double? durationSeconds = null, byte[] waveform = null)
|
||||
{
|
||||
_isDisposed = false;
|
||||
Stream = File.OpenRead(path);
|
||||
@@ -99,6 +111,8 @@ namespace Discord
|
||||
Description = description;
|
||||
IsSpoiler = isSpoiler;
|
||||
IsThumbnail = isThumbnail;
|
||||
DurationSeconds = durationSeconds;
|
||||
Waveform = waveform;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace Discord
|
||||
/// </summary>
|
||||
public string Waveform { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bytearray representing a sampled waveform. <see langword="null"/> if the attachment is not a voice message.
|
||||
/// </summary>
|
||||
public byte[] WaveformBytes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets flags related to this to this attachment.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Discord.Net.Converters;
|
||||
using Discord.Net.Rest;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -34,6 +35,9 @@ namespace Discord.API.Rest
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
|
||||
if (Files.Any(x => x.Waveform is not null && x.DurationSeconds is not null))
|
||||
Flags = Flags.GetValueOrDefault(MessageFlags.None) | MessageFlags.VoiceMessage;
|
||||
|
||||
var payload = new Dictionary<string, object>();
|
||||
if (Content.IsSpecified)
|
||||
payload["content"] = Content.Value;
|
||||
@@ -71,7 +75,11 @@ namespace Discord.API.Rest
|
||||
{
|
||||
id = (ulong)n,
|
||||
filename = filename,
|
||||
description = attachment.Description ?? Optional<string>.Unspecified
|
||||
description = attachment.Description ?? Optional<string>.Unspecified,
|
||||
duration_secs = attachment.DurationSeconds ?? Optional<double>.Unspecified,
|
||||
waveform = attachment.Waveform is null
|
||||
? Optional<string>.Unspecified
|
||||
: Convert.ToBase64String(attachment.Waveform)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace Discord.API.Rest
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
|
||||
if (Files.Any(x => x.Waveform is not null && x.DurationSeconds is not null))
|
||||
Flags = Flags.GetValueOrDefault(MessageFlags.None) | MessageFlags.VoiceMessage;
|
||||
|
||||
var payload = new Dictionary<string, object>();
|
||||
payload["type"] = Type;
|
||||
@@ -79,7 +81,11 @@ namespace Discord.API.Rest
|
||||
{
|
||||
id = (ulong)n,
|
||||
filename = filename,
|
||||
description = attachment.Description ?? Optional<string>.Unspecified
|
||||
description = attachment.Description ?? Optional<string>.Unspecified,
|
||||
duration_secs = attachment.DurationSeconds ?? Optional<double>.Unspecified,
|
||||
waveform = attachment.Waveform is null
|
||||
? Optional<string>.Unspecified
|
||||
: Convert.ToBase64String(attachment.Waveform)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Discord.Net.Converters;
|
||||
using Discord.Net.Rest;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
@@ -35,6 +37,9 @@ namespace Discord.API.Rest
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
|
||||
if (Files.Any(x => x.Waveform is not null && x.DurationSeconds is not null))
|
||||
Flags = Flags.GetValueOrDefault(MessageFlags.None) | MessageFlags.VoiceMessage;
|
||||
|
||||
var payload = new Dictionary<string, object>();
|
||||
if (Content.IsSpecified)
|
||||
payload["content"] = Content.Value;
|
||||
@@ -76,7 +81,11 @@ namespace Discord.API.Rest
|
||||
{
|
||||
id = (ulong)n,
|
||||
filename = filename,
|
||||
description = attachment.Description ?? Optional<string>.Unspecified
|
||||
description = attachment.Description ?? Optional<string>.Unspecified,
|
||||
duration_secs = attachment.DurationSeconds ?? Optional<double>.Unspecified,
|
||||
waveform = attachment.Waveform is null
|
||||
? Optional<string>.Unspecified
|
||||
: Convert.ToBase64String(attachment.Waveform)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Buffers.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
@@ -35,6 +36,8 @@ namespace Discord
|
||||
/// <inheritdoc />
|
||||
public string Waveform { get; }
|
||||
/// <inheritdoc />
|
||||
public byte[] WaveformBytes { get; }
|
||||
/// <inheritdoc />
|
||||
public double? Duration { get; }
|
||||
|
||||
/// <inheritdoc cref="IAttachment.ClipParticipants" />
|
||||
@@ -69,6 +72,8 @@ namespace Discord
|
||||
Title = title;
|
||||
ClipParticipants = clipParticipants;
|
||||
ClipCreatedAt = clipCreatedAt;
|
||||
if (waveform is not null)
|
||||
WaveformBytes = Convert.FromBase64String(waveform);
|
||||
}
|
||||
|
||||
internal static Attachment Create(Model model, BaseDiscordClient discord)
|
||||
|
||||
Reference in New Issue
Block a user