Skip to content

Commit

Permalink
Implement newly documented features since the start of the rewrite. (#…
Browse files Browse the repository at this point in the history
…562)

* Implement select menu default values

* Implement entitlements

* Export entitlement classes

* Add tests for entitlements

* Fix imports

* Add entitlements test

* Add entitlements to interaction structure

* Add resolved data to message component interaction data

* Add PREMIUM_REQUIRED interaction response type

* Add SKU structure

* Add missing fields to application object

* Add update current application endpoint

* Add new audit log entry types

* Add integration_type field to audit log entry info

* Add resolved data to message object

* Add isVoiceMessage flag

* Add missing reaction fields

* Add missing attachment fields

* Add guild media channel type

* Add missing guild features

* Add missing stage instance builder parameters

* Add user avatar decoration

* Add withCounts to list current user guilds endpoint

* Add missing fields to MessageReactionAddEvent

* Add missing fields to Role object

* Implement team member roles

* Rename ThreadAggregate to ThreadsOnlyChannel

* Update application manager tests

* Add flags to sample role

* Update tests
  • Loading branch information
abitofevrything authored Sep 30, 2023
1 parent c31514b commit 141e444
Show file tree
Hide file tree
Showing 47 changed files with 1,242 additions and 49 deletions.
17 changes: 13 additions & 4 deletions lib/nyxx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export 'src/errors.dart'
ShardDisconnectedError,
RoleNotFoundException,
AuditLogEntryNotFoundException,
EntitlementNotFoundException,
OutOfRemainingSessionsError,
IntegrationNotFoundException,
AlreadyAcknowledgedError,
Expand Down Expand Up @@ -64,6 +65,8 @@ export 'src/builders/sticker.dart' show StickerBuilder, StickerUpdateBuilder;
export 'src/builders/application_command.dart'
show ApplicationCommandBuilder, ApplicationCommandUpdateBuilder, CommandOptionBuilder, CommandOptionChoiceBuilder;
export 'src/builders/interaction_response.dart' show InteractionResponseBuilder, ModalBuilder, InteractionCallbackType;
export 'src/builders/entitlement.dart' show TestEntitlementBuilder, TestEntitlementType;
export 'src/builders/application.dart' show ApplicationUpdateBuilder;

export 'src/cache/cache.dart' show Cache, CacheConfig;

Expand Down Expand Up @@ -94,6 +97,7 @@ export 'src/http/managers/audit_log_manager.dart' show AuditLogManager;
export 'src/http/managers/sticker_manager.dart' show GuildStickerManager, GlobalStickerManager;
export 'src/http/managers/application_command_manager.dart' show ApplicationCommandManager, GlobalApplicationCommandManager, GuildApplicationCommandManager;
export 'src/http/managers/interaction_manager.dart' show InteractionManager;
export 'src/http/managers/entitlement_manager.dart' show EntitlementManager;

export 'src/gateway/gateway.dart' show Gateway;
export 'src/gateway/message.dart' show Disconnecting, Dispose, ErrorReceived, EventReceived, GatewayMessage, Send, ShardData, ShardMessage;
Expand All @@ -112,6 +116,7 @@ export 'src/models/channel/channel.dart' show Channel, ChannelFlags, PartialChan
export 'src/models/channel/followed_channel.dart' show FollowedChannel;
export 'src/models/channel/guild_channel.dart' show GuildChannel;
export 'src/models/channel/has_threads_channel.dart' show HasThreadsChannel;
export 'src/models/channel/thread_aggregate.dart' show ThreadsOnlyChannel;
export 'src/models/channel/text_channel.dart' show PartialTextChannel, TextChannel;
export 'src/models/channel/thread_list.dart' show ThreadList;
export 'src/models/channel/thread.dart' show PartialThreadMember, Thread, ThreadMember;
Expand All @@ -129,13 +134,14 @@ export 'src/models/channel/types/guild_text.dart' show GuildTextChannel;
export 'src/models/channel/types/guild_voice.dart' show GuildVoiceChannel;
export 'src/models/channel/types/private_thread.dart' show PrivateThread;
export 'src/models/channel/types/public_thread.dart' show PublicThread;
export 'src/models/channel/types/guild_media.dart' show GuildMediaChannel;
export 'src/models/message/activity.dart' show MessageActivity, MessageActivityType;
export 'src/models/message/attachment.dart' show Attachment;
export 'src/models/message/attachment.dart' show Attachment, AttachmentFlags;
export 'src/models/message/author.dart' show MessageAuthor;
export 'src/models/message/channel_mention.dart' show ChannelMention;
export 'src/models/message/embed.dart' show Embed, EmbedAuthor, EmbedField, EmbedFooter, EmbedImage, EmbedProvider, EmbedThumbnail, EmbedVideo;
export 'src/models/message/message.dart' show Message, MessageFlags, PartialMessage, MessageType, MessageInteraction;
export 'src/models/message/reaction.dart' show Reaction;
export 'src/models/message/reaction.dart' show Reaction, ReactionCountDetails;
export 'src/models/message/reference.dart' show MessageReference;
export 'src/models/message/role_subscription_data.dart' show RoleSubscriptionData;
export 'src/models/message/component.dart'
Expand Down Expand Up @@ -189,7 +195,7 @@ export 'src/models/guild/auto_moderation.dart'
TriggerType;
export 'src/models/voice/voice_state.dart' show VoiceState;
export 'src/models/voice/voice_region.dart' show VoiceRegion;
export 'src/models/role.dart' show PartialRole, Role, RoleTags;
export 'src/models/role.dart' show PartialRole, Role, RoleTags, RoleFlags;
export 'src/models/gateway/gateway.dart' show GatewayBot, GatewayConfiguration, SessionStartLimit;
export 'src/models/gateway/event.dart'
show
Expand Down Expand Up @@ -260,6 +266,7 @@ export 'src/models/gateway/events/ready.dart' show ReadyEvent, ResumedEvent;
export 'src/models/gateway/events/stage_instance.dart' show StageInstanceCreateEvent, StageInstanceDeleteEvent, StageInstanceUpdateEvent;
export 'src/models/gateway/events/voice.dart' show VoiceServerUpdateEvent, VoiceStateUpdateEvent;
export 'src/models/gateway/events/webhook.dart' show WebhooksUpdateEvent;
export 'src/models/gateway/events/entitlement.dart' show EntitlementCreateEvent, EntitlementDeleteEvent, EntitlementUpdateEvent;
export 'src/models/presence.dart'
show Activity, ActivityAssets, ActivityButton, ActivityFlags, ActivityParty, ActivitySecrets, ActivityTimestamps, ClientStatus, ActivityType, UserStatus;
export 'src/models/emoji.dart' show Emoji, GuildEmoji, PartialEmoji, TextEmoji;
Expand All @@ -270,7 +277,7 @@ export 'src/models/sticker/sticker_pack.dart' show StickerPack;
export 'src/models/commands/application_command.dart' show ApplicationCommand, PartialApplicationCommand, ApplicationCommandType;
export 'src/models/commands/application_command_option.dart' show CommandOption, CommandOptionChoice, CommandOptionType, CommandOptionMentionable;
export 'src/models/commands/application_command_permissions.dart' show CommandPermission, CommandPermissions, CommandPermissionType;
export 'src/models/team.dart' show Team, TeamMember, TeamMembershipState;
export 'src/models/team.dart' show Team, TeamMember, TeamMembershipState, TeamMemberRole;
export 'src/models/interaction.dart'
show
ApplicationCommandInteractionData,
Expand All @@ -287,6 +294,8 @@ export 'src/models/interaction.dart'
MessageComponentInteraction,
ModalSubmitInteraction,
PingInteraction;
export 'src/models/entitlement.dart' show Entitlement, PartialEntitlement, EntitlementType;
export 'src/models/sku.dart' show Sku, SkuType;

export 'src/utils/flags.dart' show Flag, Flags;
export 'src/intents.dart' show GatewayIntents;
Expand Down
53 changes: 53 additions & 0 deletions lib/src/builders/application.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/builders/image.dart';
import 'package:nyxx/src/builders/sentinels.dart';
import 'package:nyxx/src/models/application.dart';
import 'package:nyxx/src/utils/flags.dart';

class ApplicationUpdateBuilder extends UpdateBuilder<Application> {
Uri? customInstallUrl;

String? description;

Uri? roleConnectionsVerificationUrl;

InstallationParameters? installationParameters;

Flags<ApplicationFlags>? flags;

ImageBuilder? icon;

ImageBuilder? coverImage;

Uri? interactionsEndpointUrl;

List<String>? tags;

ApplicationUpdateBuilder({
this.customInstallUrl,
this.description,
this.roleConnectionsVerificationUrl,
this.installationParameters,
this.flags,
this.icon = sentinelImageBuilder,
this.coverImage = sentinelImageBuilder,
this.interactionsEndpointUrl,
this.tags,
});

@override
Map<String, Object?> build() => {
if (customInstallUrl != null) 'custom_install_url': customInstallUrl!.toString(),
if (description != null) 'description': description,
if (roleConnectionsVerificationUrl != null) 'role_connections_verification_url': roleConnectionsVerificationUrl!.toString(),
if (installationParameters != null)
'install_params': {
'scopes': installationParameters!.scopes,
'permissions': installationParameters!.permissions.toString(),
},
if (flags != null) 'flags': flags!.value,
if (!identical(icon, sentinelImageBuilder)) 'icon': icon?.buildDataString(),
if (!identical(coverImage, sentinelImageBuilder)) 'cover_image': coverImage?.buildDataString(),
if (tags != null) 'tags': tags,
};
}
5 changes: 5 additions & 0 deletions lib/src/builders/channel/stage_instance.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/models/channel/stage_instance.dart';
import 'package:nyxx/src/models/snowflake.dart';

class StageInstanceBuilder extends CreateBuilder<StageInstance> {
String topic;
Expand All @@ -8,17 +9,21 @@ class StageInstanceBuilder extends CreateBuilder<StageInstance> {

bool? sendStartNotification;

Snowflake? guildScheduledEventId;

StageInstanceBuilder({
required this.topic,
this.privacyLevel,
this.sendStartNotification,
this.guildScheduledEventId,
});

@override
Map<String, Object?> build() => {
'topic': topic,
if (privacyLevel != null) 'privacy_level': privacyLevel!.value,
if (sendStartNotification != null) 'send_start_notification': sendStartNotification,
if (guildScheduledEventId != null) 'guild_scheduled_event_id': guildScheduledEventId!.toString(),
};
}

Expand Down
29 changes: 29 additions & 0 deletions lib/src/builders/entitlement.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/models/entitlement.dart';
import 'package:nyxx/src/models/snowflake.dart';

class TestEntitlementBuilder extends CreateBuilder<Entitlement> {
Snowflake skuId;

Snowflake ownerId;

TestEntitlementType ownerType;

TestEntitlementBuilder({required this.skuId, required this.ownerId, required this.ownerType});

@override
Map<String, Object?> build() => {
'sku_id': skuId.toString(),
'owner_id': ownerId.toString(),
'owner_type': ownerType.value,
};
}

enum TestEntitlementType {
guildSubscription._(1),
userSubscription._(2);

final int value;

const TestEntitlementType._(this.value);
}
5 changes: 4 additions & 1 deletion lib/src/builders/interaction_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class InteractionResponseBuilder extends CreateBuilder<InteractionResponseBuilde

factory InteractionResponseBuilder.modal(ModalBuilder modal) => InteractionResponseBuilder(type: InteractionCallbackType.modal, data: modal);

factory InteractionResponseBuilder.premiumRequired() => InteractionResponseBuilder(type: InteractionCallbackType.premiumRequired, data: null);

@override
Map<String, Object?> build() {
final builtData = switch (data) {
Expand Down Expand Up @@ -108,7 +110,8 @@ enum InteractionCallbackType {
deferredUpdateMessage._(6),
updateMessage._(7),
applicationCommandAutocompleteResult._(8),
modal._(9);
modal._(9),
premiumRequired._(10);

final int value;

Expand Down
35 changes: 35 additions & 0 deletions lib/src/builders/message/component.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:nyxx/src/builders/builder.dart';
import 'package:nyxx/src/models/channel/channel.dart';
import 'package:nyxx/src/models/commands/application_command_option.dart';
import 'package:nyxx/src/models/emoji.dart';
import 'package:nyxx/src/models/message/component.dart';
import 'package:nyxx/src/models/role.dart';
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/src/models/snowflake_entity/snowflake_entity.dart';
import 'package:nyxx/src/models/user/user.dart';

abstract class MessageComponentBuilder extends CreateBuilder<MessageComponent> {
MessageComponentType type;
Expand Down Expand Up @@ -111,6 +115,8 @@ class SelectMenuBuilder extends MessageComponentBuilder {

List<ChannelType>? channelTypes;

List<DefaultValue>? defaultValues;

String? placeholder;

int? minValues;
Expand All @@ -125,6 +131,7 @@ class SelectMenuBuilder extends MessageComponentBuilder {
this.options,
this.channelTypes,
this.placeholder,
this.defaultValues,
this.minValues,
this.maxValues,
this.isDisabled,
Expand All @@ -142,6 +149,7 @@ class SelectMenuBuilder extends MessageComponentBuilder {
SelectMenuBuilder.userSelect({
required this.customId,
this.placeholder,
List<DefaultValue<User>>? this.defaultValues,
this.minValues,
this.maxValues,
this.isDisabled,
Expand All @@ -150,6 +158,7 @@ class SelectMenuBuilder extends MessageComponentBuilder {
SelectMenuBuilder.roleSelect({
required this.customId,
this.placeholder,
List<DefaultValue<Role>>? this.defaultValues,
this.minValues,
this.maxValues,
this.isDisabled,
Expand All @@ -159,6 +168,7 @@ class SelectMenuBuilder extends MessageComponentBuilder {
required this.customId,
this.channelTypes,
this.placeholder,
List<DefaultValue<CommandOptionMentionable>>? this.defaultValues,
this.minValues,
this.maxValues,
this.isDisabled,
Expand All @@ -167,6 +177,7 @@ class SelectMenuBuilder extends MessageComponentBuilder {
SelectMenuBuilder.channelSelect({
required this.customId,
this.placeholder,
List<DefaultValue<Channel>>? this.defaultValues,
this.minValues,
this.maxValues,
this.isDisabled,
Expand All @@ -179,6 +190,7 @@ class SelectMenuBuilder extends MessageComponentBuilder {
if (options != null) 'options': options?.map((e) => e.build()).toList(),
if (channelTypes != null) 'channel_types': channelTypes?.map((e) => e.value).toList(),
if (placeholder != null) 'placeholder': placeholder,
if (defaultValues != null) 'default_values': defaultValues!.map((e) => e.build()).toList(),
if (minValues != null) 'min_values': minValues,
if (maxValues != null) 'max_values': maxValues,
if (isDisabled != null) 'disabled': isDisabled,
Expand Down Expand Up @@ -219,6 +231,29 @@ class SelectMenuOptionBuilder extends CreateBuilder<SelectMenuOption> {
};
}

class DefaultValue<T extends SnowflakeEntity<T>> extends CreateBuilder<DefaultValue<T>> {
Snowflake id;

String type;

DefaultValue({
required this.id,
required this.type,
});

static DefaultValue<User> user({required Snowflake id}) => DefaultValue(id: id, type: 'user');

static DefaultValue<Role> role({required Snowflake id}) => DefaultValue(id: id, type: 'role');

static DefaultValue<Channel> channel({required Snowflake id}) => DefaultValue(id: id, type: 'channel');

@override
Map<String, Object?> build() => {
'id': id.toString(),
'type': type,
};
}

class TextInputBuilder extends MessageComponentBuilder {
String customId;

Expand Down
7 changes: 7 additions & 0 deletions lib/src/client_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:nyxx/src/models/commands/application_command.dart';
import 'package:nyxx/src/models/commands/application_command_permissions.dart';
import 'package:nyxx/src/models/emoji.dart';
import 'package:nyxx/src/models/channel/stage_instance.dart';
import 'package:nyxx/src/models/entitlement.dart';
import 'package:nyxx/src/models/guild/audit_log.dart';
import 'package:nyxx/src/models/guild/auto_moderation.dart';
import 'package:nyxx/src/models/guild/guild.dart';
Expand Down Expand Up @@ -92,6 +93,9 @@ class RestClientOptions extends ClientOptions {
/// The [CacheConfig] to use for the [GuildApplicationCommandManager.permissionsCache] cache.
final CacheConfig<CommandPermissions> commandPermissionsConfig;

/// The [CacheConfig] to use for the [Application.entitlements] manager.
final CacheConfig<Entitlement> entitlementConfig;

/// Create a new [RestClientOptions].
const RestClientOptions({
super.plugins,
Expand All @@ -114,6 +118,7 @@ class RestClientOptions extends ClientOptions {
this.globalStickerCacheConfig = const CacheConfig(),
this.applicationCommandConfig = const CacheConfig(),
this.commandPermissionsConfig = const CacheConfig(),
this.entitlementConfig = const CacheConfig(),
});
}

Expand All @@ -126,6 +131,7 @@ class GatewayClientOptions extends RestClientOptions {
/// If the remaining number of session starts is below this number, an error will be thrown when connecting.
final int minimumSessionStarts;

/// Create a new [GatewayClientOptions].
const GatewayClientOptions({
this.minimumSessionStarts = 10,
super.plugins,
Expand All @@ -145,5 +151,6 @@ class GatewayClientOptions extends RestClientOptions {
super.voiceStateConfig,
super.applicationCommandConfig,
super.commandPermissionsConfig,
super.entitlementConfig,
});
}
12 changes: 12 additions & 0 deletions lib/src/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ class AuditLogEntryNotFoundException extends NyxxException {
AuditLogEntryNotFoundException(this.guildId, this.auditLogEntryId) : super('Audit log entry $auditLogEntryId not found in guild $guildId');
}

/// An exception thrown when an entitlement is not found for an application.
class EntitlementNotFoundException extends NyxxException {
/// The ID of the application.
final Snowflake applicationId;

/// The ID of the entitlement.
final Snowflake entitlementId;

/// Create a new [EntitlementNotFoundException].
EntitlementNotFoundException(this.applicationId, this.entitlementId) : super('Entitlement $entitlementId not found for application $applicationId');
}

/// An error thrown when a shard disconnects unexpectedly.
class ShardDisconnectedError extends Error {
/// The shard that was disconnected.
Expand Down
Loading

0 comments on commit 141e444

Please sign in to comment.