From ac25dd2cbb3ec84b26deecd93c1be8f066bb93b6 Mon Sep 17 00:00:00 2001 From: Lexedia Date: Thu, 28 Nov 2024 00:27:52 +0100 Subject: [PATCH] What the sigma? --- lib/src/extensions/activity.dart | 29 ------------------------ lib/src/extensions/application.dart | 9 -------- lib/src/extensions/guild.dart | 20 +--------------- lib/src/extensions/member.dart | 6 ----- lib/src/extensions/message.dart | 8 +++---- lib/src/extensions/role.dart | 9 -------- lib/src/extensions/scheduled_event.dart | 6 ----- lib/src/extensions/snowflake_entity.dart | 3 +++ lib/src/extensions/team.dart | 7 ------ lib/src/extensions/user.dart | 12 ---------- 10 files changed, 7 insertions(+), 102 deletions(-) delete mode 100644 lib/src/extensions/activity.dart delete mode 100644 lib/src/extensions/team.dart diff --git a/lib/src/extensions/activity.dart b/lib/src/extensions/activity.dart deleted file mode 100644 index 3b182f3..0000000 --- a/lib/src/extensions/activity.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:nyxx/nyxx.dart'; - -const mediaProxyUrl = 'https://media.discordapp.net'; - -extension ActivityAssetsExtension on Activity { - Uri? assetsLargeImageUrl({CdnFormat? format}) { - if (assets?.largeImage == null || applicationId == null) { - return null; - } - - return parseAssetUrl(assets!.largeImage!, applicationId!, format ?? CdnFormat.png); - } - - Uri? assetsSmallImageUrl({CdnFormat? format}) { - if (assets?.smallImage == null || applicationId == null) { - return null; - } - - return parseAssetUrl(assets!.smallImage!, applicationId!, format ?? CdnFormat.png); - } -} - -Uri parseAssetUrl(String assetUrl, Snowflake applicationId, CdnFormat format) { - var isMediaProxy = assetUrl.startsWith('mp:'); - - return isMediaProxy - ? Uri.parse('$mediaProxyUrl/${assetUrl.substring(3)}') - : Uri.https('cdn.discordapp.com', '/app-assets/$applicationId/$assetUrl.${format.extension}'); -} diff --git a/lib/src/extensions/application.dart b/lib/src/extensions/application.dart index ded65b8..bfd4ea6 100644 --- a/lib/src/extensions/application.dart +++ b/lib/src/extensions/application.dart @@ -1,5 +1,4 @@ import 'package:nyxx/nyxx.dart'; -import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; /// Extensions on [PartialApplication]s. extension PartialApplicationExtensions on PartialApplication { @@ -22,11 +21,3 @@ extension PartialApplicationExtensions on PartialApplication { }, ); } - -extension ApplicationExtensions on Application { - /// The URL of this application's icon image. - Uri? iconUrl({CdnFormat? format, int? size}) => icon?.get(format: format, size: size); - - /// The URL of this application's cover image. - Uri? coverUrl({CdnFormat? format, int? size}) => coverImage?.get(format: format, size: size); -} diff --git a/lib/src/extensions/guild.dart b/lib/src/extensions/guild.dart index 93bf850..84b816b 100644 --- a/lib/src/extensions/guild.dart +++ b/lib/src/extensions/guild.dart @@ -1,6 +1,5 @@ import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/src/extensions/managers/guild_manager.dart'; -import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; /// Extensions on [PartialGuild]s. extension PartialGuildExtensions on PartialGuild { @@ -14,27 +13,10 @@ extension PartialGuildExtensions on PartialGuild { /// Return a list of channels in the client's cache that are in this guild. List get cachedChannels => manager.client.channels.cache.values.whereType().where((element) => element.guildId == id).toList(); - - /// The date this guild was created at. - DateTime get createdAt => id.timestamp; } /// 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'), ''); - } - - /// The URL of this guild's icon image. - Uri? iconUrl({CdnFormat? format, int? size}) => icon?.get(format: format, size: size); - - /// The URL of this guild's banner image. - Uri? bannerUrl({CdnFormat? format, int? size}) => banner?.get(format: format, size: size); - - /// The URL of this guild's splash image. - Uri? splashUrl({CdnFormat? format, int? size}) => splash?.get(format: format, size: size); - - /// The URL of this guild's discovery splash image. - Uri? discoverySplashUrl({CdnFormat? format, int? size}) => discoverySplash?.get(format: format, size: size); + 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 4feec8d..c691e8a 100644 --- a/lib/src/extensions/member.dart +++ b/lib/src/extensions/member.dart @@ -19,12 +19,6 @@ extension PartialMemberExtensions on PartialMember { } extension MemberExtensions on Member { - /// The URL of this member's avatar image. - Uri? avatarUrl({CdnFormat? format, int? size}) => avatar?.get(format: format, size: size); - - /// The URL of this member's banner image. - Uri? bannerUrl({CdnFormat? format, int? size}) => banner?.get(format: format, size: size); - /// 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 60013f8..26f90ea 100644 --- a/lib/src/extensions/message.dart +++ b/lib/src/extensions/message.dart @@ -1,11 +1,6 @@ import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/nyxx_extensions.dart'; -extension PartialMessageExtensions on PartialMessage { - /// The time this message was sent at. - DateTime get createdAt => id.timestamp; -} - /// Extensions on [Message]s. extension MessageExtensions on Message { /// A URL clients can visit to navigate to this message. @@ -26,6 +21,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/role.dart b/lib/src/extensions/role.dart index ae07ce2..4111e39 100644 --- a/lib/src/extensions/role.dart +++ b/lib/src/extensions/role.dart @@ -1,6 +1,5 @@ import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/src/utils/formatters.dart'; -import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; /// Extensions on [PartialRole]s. extension PartialRoleExtensions on PartialRole { @@ -12,9 +11,6 @@ extension PartialRoleExtensions on PartialRole { return roleMention(id); } - - /// The date this role was created at. - DateTime get createdAt => id.timestamp; } /// Extensions on [List]s of [Role]s. @@ -33,8 +29,3 @@ extension RoleList on List { /// The roles in this list, sorted from lowest to highest. List get sorted => List.of(this)..sort(compare); } - -extension RoleExtensions on Role { - /// The URL of this role's icon image. - Uri? iconUrl({CdnFormat? format, int? size}) => icon?.get(format: format, size: size); -} diff --git a/lib/src/extensions/scheduled_event.dart b/lib/src/extensions/scheduled_event.dart index 19e13ee..c865074 100644 --- a/lib/src/extensions/scheduled_event.dart +++ b/lib/src/extensions/scheduled_event.dart @@ -1,7 +1,6 @@ import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/src/extensions/managers/scheduled_event_manager.dart'; import 'package:nyxx_extensions/src/utils/endpoint_paginator.dart'; -import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; /// Extensions on [PartialScheduledEvent]. extension PartialScheduledEventExtensions on PartialScheduledEvent { @@ -26,8 +25,3 @@ extension PartialScheduledEventExtensions on PartialScheduledEvent { withMembers: withMembers, ); } - -extension ScheduledEventExtensions on ScheduledEvent { - /// The URL of this event's icon image. - Uri? coverUrl({CdnFormat? format, int? size}) => coverImage?.get(format: format, size: size); -} 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/team.dart b/lib/src/extensions/team.dart deleted file mode 100644 index 58ea863..0000000 --- a/lib/src/extensions/team.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:nyxx/nyxx.dart'; -import 'package:nyxx_extensions/src/extensions/cdn_asset.dart'; - -extension TeamExtensions on Team { - /// Returns the URL of the team's icon. - Uri? iconUrl({CdnFormat? format, int? size}) => icon?.get(format: format, size: size); -} diff --git a/lib/src/extensions/user.dart b/lib/src/extensions/user.dart index f5d542c..53d53f4 100644 --- a/lib/src/extensions/user.dart +++ b/lib/src/extensions/user.dart @@ -28,24 +28,12 @@ extension PartialUserExtensions on PartialUser { /// A mention of this user. String get mention => userMention(id); - - /// Returns when the user was created. - DateTime get createdAt => id.timestamp; } 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 image. - Uri avatarUrl({CdnFormat? format, int? size}) => avatar.get(format: format, size: size); - - /// The URL of this user's banner image. - Uri? bannerUrl({CdnFormat? format, int? size}) => banner?.get(format: format, size: size); - - /// The URL of this user's default avatar image. - Uri get defaultAvatarUrl => defaultAvatar.url; - /// 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);