-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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}'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
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 { | ||
/// Compute this member's permissions in [channel]. | ||
/// | ||
/// {@macro compute_permissions_detail} | ||
Future<Permissions> 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<void> kick({String? auditLogReason}) => delete(auditLogReason: auditLogReason); | ||
} | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters