Skip to content

Commit 7f8d6f1

Browse files
committed
Make SoundboardSound have a CDN asset
1 parent 7dc8bae commit 7f8d6f1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/src/http/cdn/cdn_asset.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ enum CdnFormat {
2424
/// The Lottie format.
2525
///
2626
/// This is only available to sticker endpoints where [Sticker.formatType] is [StickerFormatType.lottie].
27-
lottie._('lottie');
27+
lottie._('lottie'),
28+
29+
/// The mp3/ogg format.
30+
///
31+
/// This is only available to soundboard endpoints.
32+
mp3._('');
2833

2934
/// The extension to use on the CDN endpoint for this format.
3035
final String extension;
@@ -75,7 +80,11 @@ class CdnAsset {
7580
for (final part in base.parts) {
7681
route.add(part);
7782
}
78-
route.add(HttpRoutePart('$hash.${format.extension}'));
83+
84+
// Soundboard assets don't have any extension.
85+
final ext = format == CdnFormat.mp3 ? '' : '.${format.extension}';
86+
87+
route.add(HttpRoutePart('$hash$ext'));
7988

8089
return CdnRequest(route, queryParameters: {if (size != null) 'size': size.toString()});
8190
}

lib/src/models/soundboard/soundboard.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:nyxx/src/http/cdn/cdn_asset.dart';
12
import 'package:nyxx/src/http/managers/soundboard_manager.dart';
3+
import 'package:nyxx/src/http/route.dart';
24
import 'package:nyxx/src/models/emoji.dart';
35
import 'package:nyxx/src/models/guild/guild.dart';
46
import 'package:nyxx/src/models/snowflake.dart';
@@ -10,6 +12,16 @@ class PartialSoundboardSound extends WritableSnowflakeEntity<SoundboardSound> {
1012
final SoundboardManager manager;
1113

1214
PartialSoundboardSound({required super.id, required this.manager});
15+
16+
/// The sound asset for this soundboard sound.
17+
CdnAsset get sound => CdnAsset(
18+
client: manager.client,
19+
base: HttpRoute()..soundboardSounds(),
20+
// We can't use .soundboardSounds(id: id.toString()) because hash would be empty, adding an empty string will populate
21+
// `route.segments` which will join it with a trailing slash and Discord doesn't handle trailing slashes.
22+
hash: id.toString(),
23+
defaultFormat: CdnFormat.mp3,
24+
);
1325
}
1426

1527
class SoundboardSound extends PartialSoundboardSound {

0 commit comments

Comments
 (0)