Skip to content

Commit 4cb9aad

Browse files
committed
updatesss
1 parent 40882b9 commit 4cb9aad

File tree

14 files changed

+119
-41
lines changed

14 files changed

+119
-41
lines changed

src/Discord.Net.Core/CDN.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,7 @@ public static string GetApplicationIconUrl(ulong appId, string iconId)
3737
/// A URL pointing to the soundboard sound.
3838
/// </returns>
3939
public static string GetSoundboardSoundUrl(ulong soundId)
40-
=> $"{DiscordConfig.CDNUrl}soundboard-sounds/{soundId}";
41-
42-
/// <summary>
43-
/// Returns a soundboard default sound URL.
44-
/// </summary>
45-
/// <param name="soundName">The name of the sound.</param>
46-
/// <returns>
47-
/// A URL pointing to the soundboard default sound.
48-
/// </returns>
49-
public static string GetSoundboardDefaultSoundUrl(string soundName)
50-
=> soundName != null ? $"{DiscordConfig.CDNUrl}soundboard-default-sounds/{soundName}" : null;
40+
=> $"{DiscordConfig.CDNUrl}soundboard-sounds/{soundId}.mp3";
5141

5242
/// <summary>
5343
/// Returns a user avatar URL.
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,75 @@
11
using System;
2+
using System.Diagnostics;
23

34
namespace Discord;
45

56
/// <summary>
67
/// Represents a soundboard sound.
78
/// </summary>
9+
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
810
public class SoundboardSound : ISnowflakeEntity
911
{
1012
/// <inheritdoc />
11-
public ulong Id { get; }
13+
public ulong Id => SoundId;
14+
15+
/// <summary>
16+
/// Gets the Id of the sound.
17+
/// </summary>
18+
public ulong SoundId { get; }
1219

1320
/// <inheritdoc />
21+
/// <remarks>
22+
/// May be inaccurate for default sounds.
23+
/// </remarks>
1424
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
1525

1626
/// <summary>
17-
///
27+
/// Gets the name of the sound.
1828
/// </summary>
1929
public string Name { get; }
2030

2131
/// <summary>
22-
///
32+
/// Gets the Id of the author of the sound.
2333
/// </summary>
2434
public ulong AuthorId { get; }
2535

2636
/// <summary>
27-
///
37+
/// Gets the author of the sound.
2838
/// </summary>
2939
public IUser Author { get; }
3040

3141
/// <summary>
32-
///
42+
/// Gets the icon of the sound.
3343
/// </summary>
3444
/// <remarks>
3545
/// Custom emojis will only have Id property filled due to limited data returned by discord.
3646
/// </remarks>
3747
public IEmote Emoji { get; }
3848

3949
/// <summary>
40-
///
50+
/// Gets the volume of the sound.
4151
/// </summary>
42-
public string OverridePath { get; }
52+
public double Volume { get; }
4353

4454
/// <summary>
45-
///
55+
/// Gets whether the sound is available or not.
4656
/// </summary>
47-
public double Volume { get; }
57+
public bool? Available { get; }
4858

4959
/// <summary>
50-
///
60+
/// Gets the Id of the guild this sound belongs to. <see langword="null"/> if not available.
5161
/// </summary>
52-
public bool? Available { get; }
62+
public ulong? GuildId { get; }
5363

54-
internal SoundboardSound(ulong id, string name, ulong authorId, double volume, string overridePath = null, string emojiName = null, ulong? emojiId = null, IUser author = null, bool? available = null)
64+
internal SoundboardSound(ulong soundId, string name, ulong authorId, double volume, ulong? guildId = null,
65+
string emojiName = null, ulong? emojiId = null, IUser author = null, bool? available = null)
5566
{
56-
Id = id;
67+
GuildId = guildId;
68+
SoundId = soundId;
5769
Name = name;
5870
AuthorId = authorId;
5971
Author = author;
6072
Available = available;
61-
OverridePath = overridePath;
6273
Volume = volume;
6374

6475
if (emojiId is not null)
@@ -68,4 +79,12 @@ internal SoundboardSound(ulong id, string name, ulong authorId, double volume, s
6879
else
6980
Emoji = null;
7081
}
82+
83+
private string DebuggerDisplay => $"{Name} ({SoundId})";
84+
85+
/// <summary>
86+
/// Gets the url for the sound.
87+
/// </summary>
88+
public string GetUrl()
89+
=> CDN.GetSoundboardSoundUrl(SoundId);
7190
}

src/Discord.Net.Core/IDiscordClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,10 @@ IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> GetEntitlementsAsync(int? li
349349
/// Returns all SKUs for a given application.
350350
/// </summary>
351351
Task<IReadOnlyCollection<SKU>> GetSKUsAsync(RequestOptions options = null);
352+
353+
/// <summary>
354+
/// Returns all default soundboard sounds.
355+
/// </summary>
356+
Task<IReadOnlyCollection<SoundboardSound>> GetDefaultSoundboardSoundsAsync(RequestOptions options = null);
352357
}
353358
}

src/Discord.Net.Rest/API/Common/SoundboardSound.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace Discord.API;
44

55
internal class SoundboardSound
66
{
7-
[JsonProperty("id")]
8-
public ulong Id { get; set; }
7+
[JsonProperty("sound_id")]
8+
public ulong SoundId { get; set; }
99

1010
[JsonProperty("name")]
1111
public string Name { get; set; }
@@ -19,8 +19,8 @@ internal class SoundboardSound
1919
[JsonProperty("emoji_name")]
2020
public Optional<string> EmojiName { get; set; }
2121

22-
[JsonProperty("override_path")]
23-
public string OverridePath { get; set; }
22+
[JsonProperty("guild_id")]
23+
public Optional<ulong> GuildId { get; set; }
2424

2525
[JsonProperty("user_id")]
2626
public ulong UserId { get; set; }
@@ -29,5 +29,5 @@ internal class SoundboardSound
2929
public Optional<User> User { get; set; }
3030

3131
[JsonProperty("available")]
32-
public Optional<bool> Available { get; set; }
32+
public Optional<bool> IsAvailable { get; set; }
3333
}

src/Discord.Net.Rest/BaseDiscordClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> IDiscordClient.GetEntitlemen
283283
/// </summary>
284284
Task<IReadOnlyCollection<SKU>> IDiscordClient.GetSKUsAsync(RequestOptions options) => Task.FromResult<IReadOnlyCollection<SKU>>(Array.Empty<SKU>());
285285

286+
/// <inheritdoc cref="IDiscordClient.GetDefaultSoundboardSoundsAsync" />
287+
Task<IReadOnlyCollection<SoundboardSound>> IDiscordClient.GetDefaultSoundboardSoundsAsync(RequestOptions options)
288+
=> Task.FromResult<IReadOnlyCollection<SoundboardSound>>(ImmutableArray.Create<SoundboardSound>());
289+
286290
#endregion
287291
}
288292
}

src/Discord.Net.Rest/ClientHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,16 @@ public static async Task<IReadOnlyCollection<SKU>> ListSKUsAsync(BaseDiscordClie
440440
}
441441

442442
#endregion
443+
444+
#region Soundboard
445+
446+
public static async Task<IReadOnlyCollection<SoundboardSound>> GetDefaultSoundboardSoundsAsync(BaseDiscordClient client, RequestOptions options = null)
447+
{
448+
var models = await client.ApiClient.GetDefaultSoundboardSoundsAsync(options).ConfigureAwait(false);
449+
450+
return models.Select(x => x.ToEntity(discord: client)).ToImmutableArray();
451+
}
452+
453+
#endregion
443454
}
444455
}

src/Discord.Net.Rest/DiscordRestApiClient.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,15 +2814,22 @@ public Task<SKU[]> ListSKUsAsync(RequestOptions options = null)
28142814

28152815
#region Soundboard
28162816

2817-
public async Task<SoundboardSound> CreateSoundboardSoundAsync(ulong guildId, CreateSoundboardSoundParams args, RequestOptions options = null)
2817+
public Task<SoundboardSound> CreateSoundboardSoundAsync(ulong guildId, CreateSoundboardSoundParams args, RequestOptions options = null)
28182818
{
28192819
Preconditions.NotEqual(guildId, 0, nameof(guildId));
28202820
Preconditions.NotNull(args, nameof(args));
28212821

28222822
options = RequestOptions.CreateOrClone(options);
28232823
var ids = new BucketIds(guildId: guildId);
28242824

2825-
return await SendJsonAsync<SoundboardSound>("POST", () => $"guilds/{guildId}/soundboard-sounds", args, ids, options: options).ConfigureAwait(false);
2825+
return SendJsonAsync<SoundboardSound>("POST", () => $"guilds/{guildId}/soundboard-sounds", args, ids, options: options);
2826+
}
2827+
2828+
public Task<SoundboardSound[]> GetDefaultSoundboardSoundsAsync(RequestOptions options = null)
2829+
{
2830+
var ids = new BucketIds();
2831+
2832+
return SendAsync<SoundboardSound[]>("GET", () => "soundboard-default-sounds", ids: ids, options: options);
28262833
}
28272834

28282835
#endregion

src/Discord.Net.Rest/DiscordRestClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ public IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> GetEntitlementsAsync(
296296
public Task<IReadOnlyCollection<SKU>> GetSKUsAsync(RequestOptions options = null)
297297
=> ClientHelper.ListSKUsAsync(this, options);
298298

299+
/// <inheritdoc />
300+
public Task<IReadOnlyCollection<SoundboardSound>> GetDefaultSoundboardSoundsAsync(RequestOptions options = null)
301+
=> ClientHelper.GetDefaultSoundboardSoundsAsync(this, options);
302+
299303
#endregion
300304

301305
#region IDiscordClient

src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,15 +1408,7 @@ public static async Task<SoundboardSound> CreateSoundboardSoundAsync(BaseDiscord
14081408

14091409
var model = await client.ApiClient.CreateSoundboardSoundAsync(guild.Id, args, options);
14101410

1411-
return new SoundboardSound(model.Id,
1412-
model.Name,
1413-
model.UserId,
1414-
model.Volume,
1415-
model.OverridePath,
1416-
model.Name,
1417-
model.EmojiId.GetValueOrDefault(null),
1418-
model.User.IsSpecified ? RestUser.Create(client, model.User.Value) : null,
1419-
model.Available.IsSpecified ? model.Available.Value : null);
1411+
return model.ToEntity(discord: client);
14201412
}
14211413

14221414
#endregion

src/Discord.Net.Rest/Extensions/EntityExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,20 @@ public static API.Message ToMessage(this API.InteractionResponse model, IDiscord
222222
Id = interaction.Id,
223223
};
224224
}
225+
226+
public static SoundboardSound ToEntity(this API.SoundboardSound model, IUser cachedAuthor = null, BaseDiscordClient discord = null)
227+
=> new(model.SoundId,
228+
model.Name,
229+
model.UserId,
230+
model.Volume,
231+
model.GuildId.IsSpecified
232+
? model.GuildId.Value
233+
: null,
234+
model.EmojiName.GetValueOrDefault(null),
235+
model.EmojiId.GetValueOrDefault(null),
236+
cachedAuthor ?? (model.User.IsSpecified
237+
? RestUser.Create(discord, model.User.Value)
238+
: null),
239+
model.IsAvailable.GetValueOrDefault(true));
225240
}
226241
}

0 commit comments

Comments
 (0)