diff --git a/lib/nyxx_extensions.dart b/lib/nyxx_extensions.dart index 761868a..d55e4fd 100644 --- a/lib/nyxx_extensions.dart +++ b/lib/nyxx_extensions.dart @@ -1,21 +1,16 @@ /// Extensions and additional utilities for working with [nyxx](https://pub.dev/packages/nyxx). library nyxx_extensions; -export 'src/utils/emoji.dart'; -export 'src/utils/endpoint_paginator.dart' hide streamPaginatedEndpoint; -export 'src/utils/formatters.dart'; -export 'src/utils/guild_joins.dart'; -export 'src/utils/pagination.dart'; -export 'src/utils/permissions.dart'; -export 'src/utils/sanitizer.dart'; - +export 'src/extensions/application.dart'; export 'src/extensions/cdn_asset.dart' hide getRequest; export 'src/extensions/channel.dart'; export 'src/extensions/client.dart'; export 'src/extensions/date_time.dart'; export 'src/extensions/embed.dart'; export 'src/extensions/emoji.dart'; +export 'src/extensions/events/guild.dart'; export 'src/extensions/guild.dart'; +export 'src/extensions/list.dart'; export 'src/extensions/managers/audit_log_manager.dart'; export 'src/extensions/managers/channel_manager.dart'; export 'src/extensions/managers/entitlement_manager.dart'; @@ -30,5 +25,11 @@ export 'src/extensions/role.dart'; export 'src/extensions/scheduled_event.dart'; export 'src/extensions/snowflake_entity.dart'; export 'src/extensions/user.dart'; -export 'src/extensions/list.dart'; -export 'src/extensions/application.dart'; + +export 'src/utils/emoji.dart'; +export 'src/utils/endpoint_paginator.dart' hide streamPaginatedEndpoint; +export 'src/utils/formatters.dart'; +export 'src/utils/guild_joins.dart'; +export 'src/utils/pagination.dart'; +export 'src/utils/permissions.dart'; +export 'src/utils/sanitizer.dart'; diff --git a/lib/src/extensions/application.dart b/lib/src/extensions/application.dart index 8256e78..bfd4ea6 100644 --- a/lib/src/extensions/application.dart +++ b/lib/src/extensions/application.dart @@ -1,7 +1,7 @@ import 'package:nyxx/nyxx.dart'; /// Extensions on [PartialApplication]s. -extension ApplicationExtensions on PartialApplication { +extension PartialApplicationExtensions on PartialApplication { /// Get a URL users can visit to add this bot to a guild. Uri getInviteUri({ List scopes = const ['bot', 'applications.commands'], diff --git a/lib/src/extensions/cdn_asset.dart b/lib/src/extensions/cdn_asset.dart index 6c2ddae..de6e0a0 100644 --- a/lib/src/extensions/cdn_asset.dart +++ b/lib/src/extensions/cdn_asset.dart @@ -1,6 +1,7 @@ import 'package:nyxx/nyxx.dart'; extension CdnAssetExtensions on CdnAsset { + /// Get the URL for this asset whth the given [format] and [size]. Uri get({CdnFormat? format, int? size}) => getRequest(this, format ?? defaultFormat, size).prepare(client).url; } diff --git a/lib/src/extensions/events/guild.dart b/lib/src/extensions/events/guild.dart new file mode 100644 index 0000000..d5e6cc0 --- /dev/null +++ b/lib/src/extensions/events/guild.dart @@ -0,0 +1,6 @@ +import 'package:nyxx/nyxx.dart'; + +extension GuildDeleteEventExtensions on GuildDeleteEvent { + /// Whether the client was removed from the guild, due to a ban or kick. + bool get wasRemoved => isUnavailable == false; +} diff --git a/lib/src/extensions/guild.dart b/lib/src/extensions/guild.dart index 8dd668a..84b816b 100644 --- a/lib/src/extensions/guild.dart +++ b/lib/src/extensions/guild.dart @@ -18,7 +18,5 @@ extension PartialGuildExtensions on PartialGuild { /// Extensions on [Guild]s. extension GuildExtensions on Guild { /// The acronym of the guild if no icon is chosen. - String get acronym { - return name.replaceAll(r"'s ", ' ').replaceAllMapped(RegExp(r'\w+'), (match) => match[0]![0]).replaceAll(RegExp(r'\s'), ''); - } + String get acronym => name.replaceAll(r"'s ", ' ').replaceAllMapped(RegExp(r'\w+'), (match) => match[0]![0]).replaceAll(RegExp(r'\s'), ''); } diff --git a/lib/src/extensions/member.dart b/lib/src/extensions/member.dart index 8c08dd0..c691e8a 100644 --- a/lib/src/extensions/member.dart +++ b/lib/src/extensions/member.dart @@ -1,5 +1,6 @@ import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/src/utils/permissions.dart'; +import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; /// Extensions on [PartialMember]s. extension PartialMemberExtensions on PartialMember { @@ -7,4 +8,18 @@ extension PartialMemberExtensions on PartialMember { /// /// {@macro compute_permissions_detail} Future computePermissionsIn(GuildChannel channel) async => await computePermissions(channel, await get()); + + /// Kick this member from the guild. + /// + /// External references: + /// + /// - [MemberManager.delete] + /// - Discord API Reference: https://discord.com/developers/docs/resources/guild#remove-guild-member + Future kick({String? auditLogReason}) => delete(auditLogReason: auditLogReason); +} + +extension MemberExtensions on Member { + /// The URL of this member's avatar decoration. + // Same as in UserExtensions. + Uri? get avatarDecorationUrl => avatarDecoration?.get(format: CdnFormat.png); } diff --git a/lib/src/extensions/message.dart b/lib/src/extensions/message.dart index 8a95371..1ed9a34 100644 --- a/lib/src/extensions/message.dart +++ b/lib/src/extensions/message.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use + import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/nyxx_extensions.dart'; @@ -21,6 +23,9 @@ extension MessageExtensions on Message { suppressEmbeds: builder.suppressEmbeds, suppressNotifications: builder.suppressNotifications, tts: builder.tts, + enforceNonce: builder.enforceNonce, + poll: builder.poll, + referencedMessage: builder.referencedMessage, ); return channel.sendMessage(copiedBuilder); diff --git a/lib/src/extensions/snowflake_entity.dart b/lib/src/extensions/snowflake_entity.dart index 111f405..0c897d5 100644 --- a/lib/src/extensions/snowflake_entity.dart +++ b/lib/src/extensions/snowflake_entity.dart @@ -11,6 +11,9 @@ extension SnowflakeEntityExtensions> on SnowflakeEn return null; } } + + /// The date and time this entity was created. + DateTime get createdAt => id.timestamp; } /// Extensions on [ManagedSnowflakeEntity]s. diff --git a/lib/src/extensions/user.dart b/lib/src/extensions/user.dart index d9f340b..53d53f4 100644 --- a/lib/src/extensions/user.dart +++ b/lib/src/extensions/user.dart @@ -1,4 +1,5 @@ import 'package:nyxx/nyxx.dart'; +import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; import 'package:nyxx_extensions/src/utils/formatters.dart'; /// Extensions on [PartialUser]. @@ -28,3 +29,12 @@ extension PartialUserExtensions on PartialUser { /// A mention of this user. String get mention => userMention(id); } + +extension UserExtensions on User { + /// The user's unique username, if migrated, else a combination of their username and discriminator. + String get tag => discriminator == '0' ? username : '$username#$discriminator'; + + /// The URL of this user's avatar decoration. + // Forcefully add the `.png` extension, otherwise it's converted as a GIF if the hash starts with `a_`, and GIFs are not supported. + Uri? get avatarDecorationUrl => avatarDecoration?.get(format: CdnFormat.png); +} diff --git a/lib/src/utils/emoji.dart b/lib/src/utils/emoji.dart index a52e6ce..864834e 100644 --- a/lib/src/utils/emoji.dart +++ b/lib/src/utils/emoji.dart @@ -1,3 +1,5 @@ +// ignore_for_file: implementation_imports + import 'dart:convert'; import 'package:http/http.dart' as http; diff --git a/pubspec.yaml b/pubspec.yaml index 158e401..25bae1b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: http: ^1.1.0 - nyxx: ^6.3.1 + nyxx: ^6.5.2 dev_dependencies: coverage: ^1.0.3