Skip to content

Commit

Permalink
Merge pull request #722 from nyxx-discord/dev
Browse files Browse the repository at this point in the history
Deploy 6.5.0
  • Loading branch information
l7ssha authored Oct 22, 2024
2 parents bcba971 + 40002bb commit 9c94a5e
Show file tree
Hide file tree
Showing 43 changed files with 938 additions and 34 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Integration tests

on:
push:
branches-ignore:
- main
branches:
- dev
- next
pull_request:

jobs:
tests:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: Run unit tests

on:
push:
branches-ignore:
- main
branches:
- dev
- next
pull_request:

jobs:
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 6.5.0
__22.10.2024__

- feature: Add new member flags. ([`#715`](https://github.com/nyxx-discord/nyxx/pull/715)) - ([`e10d0ffb`](https://github.com/nyxx-discord/nyxx/commit/e10d0ffb680e28ed74397875bb6a0a4b2fa411f7))
- feature: Add new fields on message snapshot. ([`#716`](https://github.com/nyxx-discord/nyxx/pull/716)) - ([`57dc3282`](https://github.com/nyxx-discord/nyxx/commit/57dc32826081d60ec4fd905c939b15afe7dc7abe))
- bug: Fix serialization of `before` parameter. ([`#717`](https://github.com/nyxx-discord/nyxx/pull/717)) - ([`091c376f`](https://github.com/nyxx-discord/nyxx/commit/091c376fe80456d18e046ea047072d0271bb4384))
- feature: Recurrence rule can be set to null when updating. ([`#720`](https://github.com/nyxx-discord/nyxx/pull/720)) - ([`aaef80ac`](https://github.com/nyxx-discord/nyxx/commit/aaef80ac469331fa2da06eb776e2708813268b07))
- feature: Add support for soundboard. ([`#708`](https://github.com/nyxx-discord/nyxx/pull/708)) - ([`d93aa122`](https://github.com/nyxx-discord/nyxx/commit/d93aa122965b6d9b11f51dac377ee3c13eefac97))
- feature: Allow polls to be constructed in a interation response. ([`#719`](https://github.com/nyxx-discord/nyxx/pull/719)) - ([`db27c54d`](https://github.com/nyxx-discord/nyxx/commit/db27c54d24be1bb4010457041b7b4d09063e701d))
- feature: Add banner property to member. ([`#676](https://github.com/nyxx-discord/nyxx/pull/676)) - ([`4041b556`](https://github.com/nyxx-discord/nyxx/commit/4041b5569853d8eac6f2a165a3cb03b736e02cef))
- feature: Fix user avatar decoration, add member avatar decoration. ([`#718`](https://github.com/nyxx-discord/nyxx/pull/718)) - ([`b8e5ba7c`](https://github.com/nyxx-discord/nyxx/commit/b8e5ba7c89dbabd72821b7cd603bdab88cf0e751))
- maintenance: Update integration_tests.yml. ([`527eed5a`](https://github.com/nyxx-discord/nyxx/commit/527eed5a90c83071f5346273426bd0fd20089a60))

## 6.4.3
__08.10.2024__

Expand Down
2 changes: 1 addition & 1 deletion lib/src/api_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:oauth2/oauth2.dart';
/// Options for connecting to the Discord API.
abstract class ApiOptions {
/// The version of nyxx used in [defaultUserAgent].
static const nyxxVersion = '6.4.3';
static const nyxxVersion = '6.5.0';

/// The URL to the nyxx repository used in [defaultUserAgent].
static const nyxxRepositoryUrl = 'https://github.com/nyxx-discord/nyxx';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/builders/channel/forum_tag.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/models/channel/types/forum.dart';
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/src/utils/building_helpers.dart';

class ForumTagBuilder extends CreateBuilder<ForumTag> {
String name;
Expand All @@ -17,7 +18,6 @@ class ForumTagBuilder extends CreateBuilder<ForumTag> {
Map<String, Object?> build() => {
'name': name,
if (isModerated != null) 'moderated': isModerated,
if (emojiId != null) 'emoji_id': emojiId!.toString(),
if (emojiName != null) 'emoji_name': emojiName,
...makeEmojiMap(emojiId: emojiId, emojiName: emojiName),
};
}
15 changes: 3 additions & 12 deletions lib/src/builders/channel/guild_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:nyxx/src/models/channel/types/guild_voice.dart';
import 'package:nyxx/src/models/channel/voice_channel.dart';
import 'package:nyxx/src/models/permission_overwrite.dart';
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/src/utils/building_helpers.dart';
import 'package:nyxx/src/utils/flags.dart';

class GuildChannelBuilder<T extends GuildChannel> extends CreateBuilder<T> {
Expand Down Expand Up @@ -231,12 +232,7 @@ class ForumChannelBuilder extends GuildChannelBuilder<ForumChannel> {
if (isNsfw != null) 'nsfw': isNsfw,
if (defaultAutoArchiveDuration != null) 'default_auto_archive_duration': defaultAutoArchiveDuration!.inMinutes,
if (!identical(defaultReaction, sentinelDefaultReaction))
'default_reaction_emoji': defaultReaction == null
? null
: {
if (defaultReaction!.emojiId != null) 'emoji_id': defaultReaction!.emojiId!.toString(),
if (defaultReaction!.emojiName != null) 'emoji_name': defaultReaction!.emojiName,
},
'default_reaction_emoji': defaultReaction == null ? null : makeEmojiMap(emojiId: defaultReaction!.emojiId, emojiName: defaultReaction!.emojiName),
if (tags != null) 'available_tags': tags!.map((e) => e.build()).toList(),
if (defaultSortOrder != null) 'default_sort_order': defaultSortOrder!.value,
};
Expand Down Expand Up @@ -293,12 +289,7 @@ class ForumChannelUpdateBuilder extends GuildChannelUpdateBuilder<ForumChannel>
if (flags != null) 'flags': flags!.value,
if (tags != null) 'available_tags': tags!.map((e) => e.build()).toList(),
if (!identical(defaultReaction, sentinelDefaultReaction))
'default_reaction_emoji': defaultReaction == null
? null
: {
if (defaultReaction!.emojiId != null) 'emoji_id': defaultReaction!.emojiId!.toString(),
if (defaultReaction!.emojiName != null) 'emoji_name': defaultReaction!.emojiName,
},
'default_reaction_emoji': defaultReaction == null ? null : makeEmojiMap(emojiId: defaultReaction!.emojiId, emojiName: defaultReaction!.emojiName),
if (defaultThreadRateLimitPerUser != null) 'default_thread_rate_limit_per_user': defaultThreadRateLimitPerUser!.inSeconds,
if (defaultSortOrder != null) 'default_sort_order': defaultSortOrder!.value,
if (defaultLayout != null) 'default_forum_layout': defaultLayout!.value,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/builders/guild/scheduled_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ScheduledEventUpdateBuilder extends UpdateBuilder<ScheduledEvent> {
this.type,
this.status,
this.image,
this.recurrenceRule,
this.recurrenceRule = sentinelRecurrenceRuleBuilder,
});

@override
Expand All @@ -137,7 +137,7 @@ class ScheduledEventUpdateBuilder extends UpdateBuilder<ScheduledEvent> {
if (type != null) 'entity_type': type!.value,
if (status != null) 'status': status!.value,
if (image != null) 'image': image!.buildDataString(),
if (recurrenceRule != null) 'recurrence_rule': recurrenceRule!.build(),
if (!identical(recurrenceRule, sentinelRecurrenceRuleBuilder)) 'recurrence_rule': recurrenceRule?.build(),
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/builders/guild/welcome_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/builders/sentinels.dart';
import 'package:nyxx/src/models/guild/welcome_screen.dart';
import 'package:nyxx/src/utils/building_helpers.dart';

class WelcomeScreenUpdateBuilder extends UpdateBuilder<WelcomeScreen> {
bool? isEnabled;
Expand All @@ -20,8 +21,7 @@ class WelcomeScreenUpdateBuilder extends UpdateBuilder<WelcomeScreen> {
{
'channel_id': channel.channelId.toString(),
'description': channel.description,
'emoji_id': channel.emojiId?.toString(),
'emoji_name': channel.emojiName,
...makeEmojiMap(emojiId: channel.emojiId, emojiName: channel.emojiName),
},
],
if (!identical(description, sentinelString)) 'description': description,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builders/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ImageBuilder {
ImageBuilder.gif(this.data) : format = 'gif';

static Future<ImageBuilder> fromFile(File file, {String? format}) async {
format ??= p.extension(file.path);
format ??= p.extension(file.path).substring(1);

const formats = {
'png': 'png',
Expand Down
5 changes: 5 additions & 0 deletions lib/src/builders/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,17 @@ class MessageUpdateBuilder extends UpdateBuilder<Message> {

List<AttachmentBuilder>? attachments;

/// Can only be used when editing a deferred interaction.
PollBuilder? poll;

MessageUpdateBuilder({
this.content = sentinelString,
this.embeds = sentinelList,
this.suppressEmbeds,
this.allowedMentions,
this.components,
this.attachments = sentinelList,
this.poll,
});

@override
Expand All @@ -140,6 +144,7 @@ class MessageUpdateBuilder extends UpdateBuilder<Message> {
if (components != null) 'components': components!.map((e) => e.build()).toList(),
if (!identical(attachments, sentinelList)) 'attachments': attachments!.map((e) => e.build()).toList(),
if (suppressEmbeds != null) 'flags': (suppressEmbeds == true ? MessageFlags.suppressEmbeds.value : 0),
if (poll != null) 'poll': poll!.build(),
};
}

Expand Down
12 changes: 12 additions & 0 deletions lib/src/builders/sentinels.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:nyxx/src/builders/guild/scheduled_event.dart';
import 'package:nyxx/src/builders/image.dart';
import 'package:nyxx/src/models/channel/types/forum.dart';
import 'package:nyxx/src/models/emoji.dart';
Expand All @@ -8,6 +9,8 @@ import 'package:nyxx/src/utils/flags.dart';
// ASCII encoded "nyxx"
const sentinelInteger = 0x6E797878;

const sentinelDouble = sentinelInteger * 1.0;

// ESC-"nyxx"
const sentinelString = '\u{1B}nyxx';

Expand Down Expand Up @@ -109,3 +112,12 @@ class _SentinelEmoji implements Emoji {
}

const sentinelEmoji = _SentinelEmoji();

class _SentinelRecurrenceRuleBuilder implements RecurrenceRuleBuilder {
const _SentinelRecurrenceRuleBuilder();

@override
void noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

const sentinelRecurrenceRuleBuilder = _SentinelRecurrenceRuleBuilder();
38 changes: 38 additions & 0 deletions lib/src/builders/sound.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as p;

class SoundBuilder {
List<int> data;
String format;

SoundBuilder({required this.data, required this.format});

SoundBuilder.mp3(this.data) : format = 'mpeg';

SoundBuilder.ogg(this.data) : format = 'ogg';

static Future<SoundBuilder> fromFile(File file, {String? format}) async {
format ??= p.extension(file.path).substring(1);

const formats = {
'mp3': 'mpeg',
'mpeg': 'mpeg',
'ogg': 'ogg',
};

final actualFormat = formats[format];

if (actualFormat == null) {
throw ArgumentError.value(format, 'format', 'Unsupported format');
}

final data = await file.readAsBytes();

return SoundBuilder(data: data, format: actualFormat);
}

List<int> buildRawData() => data;

String buildDataString() => 'data:audio/$format;base64,${base64Encode(data)}';
}
47 changes: 47 additions & 0 deletions lib/src/builders/soundboard.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/builders/sentinels.dart';
import 'package:nyxx/src/builders/sound.dart';
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/src/models/soundboard/soundboard.dart';
import 'package:nyxx/src/utils/building_helpers.dart';

class SoundboardSoundBuilder extends CreateBuilder<SoundboardSound> {
String name;

SoundBuilder sound;

double? volume;

String? emojiName;

Snowflake? emojiId;

SoundboardSoundBuilder({required this.name, required this.sound, this.volume, this.emojiName, this.emojiId});

@override
Map<String, Object?> build() => {
'name': name,
'sound': sound.buildDataString(),
if (volume != null) 'volume': volume,
...makeEmojiMap(emojiId: emojiId, emojiName: emojiName),
};
}

class SoundboardSoundUpdateBuilder extends UpdateBuilder<SoundboardSound> {
String name;

double? volume;

String? emojiName;

Snowflake? emojiId;

SoundboardSoundUpdateBuilder({required this.name, this.volume = sentinelDouble, this.emojiName = sentinelString, this.emojiId = sentinelSnowflake});

@override
Map<String, Object?> build() => {
'name': name,
if (volume != sentinelDouble) 'volume': volume,
if (!(identical(emojiName, sentinelString) || identical(emojiId, sentinelSnowflake))) ...makeEmojiMap(emojiId: emojiId, emojiName: emojiName),
};
}
11 changes: 10 additions & 1 deletion lib/src/client_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:nyxx/src/models/guild/scheduled_event.dart';
import 'package:nyxx/src/models/message/message.dart';
import 'package:nyxx/src/models/role.dart';
import 'package:nyxx/src/models/sku.dart';
import 'package:nyxx/src/models/soundboard/soundboard.dart';
import 'package:nyxx/src/models/sticker/global_sticker.dart';
import 'package:nyxx/src/models/sticker/guild_sticker.dart';
import 'package:nyxx/src/models/subscription.dart';
Expand Down Expand Up @@ -143,9 +144,15 @@ class RestClientOptions extends ClientOptions {
/// The [CacheConfig] to use for the [Application.skus] manager.
final CacheConfig<Sku> skuConfig;

/// Tje [CacheConfig] to use for the [Sku.subscriptions] manager.
/// The [CacheConfig] to use for the [Sku.subscriptions] manager.
final CacheConfig<Subscription> subscriptionConfig;

/// The [CacheConfig] to use for the [NyxxRest.soundboard] manager.
final CacheConfig<SoundboardSound> globalSoundboardCacheConfig;

/// The [CacheConfig] to use for the [Guild.soundboard] manager.
final CacheConfig<SoundboardSound> soundboardCacheConfig;

/// Create a new [RestClientOptions].
const RestClientOptions({
super.plugins,
Expand Down Expand Up @@ -187,6 +194,8 @@ class RestClientOptions extends ClientOptions {
this.entitlementConfig = _defaultCacheConfig,
this.skuConfig = _defaultCacheConfig,
this.subscriptionConfig = _defaultCacheConfig,
this.globalSoundboardCacheConfig = _smallCacheConfig,
this.soundboardCacheConfig = _smallCacheConfig,
});
}

Expand Down
7 changes: 7 additions & 0 deletions lib/src/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,10 @@ class ClientClosedError extends Error {
@override
String toString() => 'Client is closed';
}

class SoundboardSoundNotFoundException extends NyxxException {
/// The ID of the sound.
final Snowflake soundId;

SoundboardSoundNotFoundException(this.soundId) : super('Soundboard sound $soundId not found');
}
16 changes: 16 additions & 0 deletions lib/src/event_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:nyxx/src/models/gateway/events/invite.dart';
import 'package:nyxx/src/models/gateway/events/message.dart';
import 'package:nyxx/src/models/gateway/events/presence.dart';
import 'package:nyxx/src/models/gateway/events/ready.dart';
import 'package:nyxx/src/models/gateway/events/soundboard.dart';
import 'package:nyxx/src/models/gateway/events/stage_instance.dart';
import 'package:nyxx/src/models/gateway/events/voice.dart';
import 'package:nyxx/src/models/gateway/events/webhook.dart';
Expand Down Expand Up @@ -261,4 +262,19 @@ mixin EventMixin implements Nyxx {

/// A [Stream] of [MessagePollVoteRemoveEvent]s received by this client.
Stream<MessagePollVoteRemoveEvent> get onMessagePollVoteRemove => onEvent.whereType<MessagePollVoteRemoveEvent>();

/// A [Stream] of [SoundboardSoundDeleteEvent]s received by this client.
Stream<SoundboardSoundDeleteEvent> get onSoundboardSoundDelete => onEvent.whereType<SoundboardSoundDeleteEvent>();

/// A [Stream] of [SoundboardSoundUpdateEvent]s received by this client.
Stream<SoundboardSoundUpdateEvent> get onSoundboardSoundUpdate => onEvent.whereType<SoundboardSoundUpdateEvent>();

/// A [Stream] of [SoundboardSoundCreateEvent]s received by this client.
Stream<SoundboardSoundCreateEvent> get onSoundboardSoundCreate => onEvent.whereType<SoundboardSoundCreateEvent>();

/// A [Stream] of [SoundboardSoundsUpdateEvent]s received by this client.
Stream<SoundboardSoundsUpdateEvent> get onSoundboardSoundsUpdate => onEvent.whereType<SoundboardSoundsUpdateEvent>();

/// A [Stream] of [VoiceChannelEffectSendEvent]s received by this client.
Stream<VoiceChannelEffectSendEvent> get onVoiceChannelEffectSend => onEvent.whereType<VoiceChannelEffectSendEvent>();
}
Loading

0 comments on commit 9c94a5e

Please sign in to comment.