Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add soundmoijs #736

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/src/http/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class MessageManager extends Manager<Message> {
resolved: maybeParse(raw['resolved'], (Map<String, Object?> raw) => client.interactions.parseResolvedData(raw, guildId: guildId, channelId: channelId)),
poll: maybeParse(raw['poll'], parsePoll),
call: maybeParse(raw['call'], parseMessageCall),
soundboardSounds: snapshot.soundboardSounds,
);
}

Expand Down Expand Up @@ -408,6 +409,11 @@ class MessageManager extends Manager<Message> {
type: MessageType(raw['type'] as int),
stickers: parseMany(raw['sticker_items'] as List? ?? [], client.stickers.parseStickerItem),
components: maybeParseMany(raw['components'], parseMessageComponent),
soundboardSounds: maybeParseMany(raw['soundboard_sounds'] as List?, (Map<String, Object?> raw) {
final guildId = maybeParse(raw['guild_id'], Snowflake.parse);

return client.guilds[guildId ?? Snowflake.zero].soundboard.parse(raw);
}),
);
}

Expand Down
9 changes: 9 additions & 0 deletions lib/src/models/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:nyxx/src/models/channel/text_channel.dart';
import 'package:nyxx/src/models/message/role_subscription_data.dart';
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/src/models/snowflake_entity/snowflake_entity.dart';
import 'package:nyxx/src/models/soundboard/soundboard.dart';
import 'package:nyxx/src/models/sticker/sticker.dart';
import 'package:nyxx/src/models/user/user.dart';
import 'package:nyxx/src/models/webhook.dart';
Expand Down Expand Up @@ -204,6 +205,9 @@ class Message extends PartialMessage implements MessageSnapshot {
/// Information about a call in a DM channel.
final MessageCall? call;

@override
final List<SoundboardSound>? soundboardSounds;

/// {@macro message}
/// @nodoc
Message({
Expand Down Expand Up @@ -242,6 +246,7 @@ class Message extends PartialMessage implements MessageSnapshot {
required this.resolved,
required this.poll,
required this.call,
required this.soundboardSounds,
});

/// The webhook that sent this message if it was sent by a webhook, `null` otherwise.
Expand Down Expand Up @@ -498,6 +503,9 @@ class MessageSnapshot with ToStringHelper {
/// A list of components in this message.
final List<MessageComponent>? components;

/// A list of soundmojis sent.
final List<SoundboardSound>? soundboardSounds;

/// @nodoc
MessageSnapshot({
required this.timestamp,
Expand All @@ -511,6 +519,7 @@ class MessageSnapshot with ToStringHelper {
required this.roleMentionIds,
required this.stickers,
required this.components,
required this.soundboardSounds,
});
}

Expand Down
24 changes: 24 additions & 0 deletions test/unit/http/managers/message_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ final sampleForwardedMessage = {
},
'attachments': [],
'guild_id': '1033681997136146462',
'soundboard_sounds': [
{
'name': 'User Banned',
'sound_id': '1143974146414481529',
'volume': .85,
'emoji_id': null,
'emoji_name': '💥',
'guild_id': '1234567891234567890',
'available': true
}
],
};

void checkForwardedMessage(Message message) {
Expand Down Expand Up @@ -302,6 +313,19 @@ void checkForwardedMessage(Message message) {
expect(message.resolved, isNull);
expect(message.poll, isNull);
expect(message.call, isNull);
expect(message.soundboardSounds, [
wrapMatcher((SoundboardSound soundboardSound) {
expect(soundboardSound.emoji, isA<TextEmoji>());
expect(soundboardSound.emoji!.name, '💥');
expect(soundboardSound.name, 'User Banned');
expect(soundboardSound.guildId, equals(const Snowflake(1234567891234567890)));
expect(soundboardSound.volume, equals(0.85));
expect(soundboardSound.isAvailable, equals(true));
expect(soundboardSound.id, equals(const Snowflake(1143974146414481529)));

return true;
})
]);
}

final sampleMessageInteractionMetadata = {
Expand Down