diff --git a/lib/nyxx_extensions.dart b/lib/nyxx_extensions.dart index e242919..23dead7 100644 --- a/lib/nyxx_extensions.dart +++ b/lib/nyxx_extensions.dart @@ -5,3 +5,5 @@ export 'src/user.dart'; export 'src/sanitizer.dart'; export 'src/guild.dart'; export 'src/pagination.dart'; +export 'src/channel.dart'; +export 'src/message.dart'; diff --git a/lib/src/channel.dart b/lib/src/channel.dart new file mode 100644 index 0000000..534d04d --- /dev/null +++ b/lib/src/channel.dart @@ -0,0 +1,6 @@ +import 'package:nyxx/nyxx.dart'; + +extension ChannelUtils on Channel { + /// A URL clients can visit to navigate to this channel. + Uri get url => Uri.https(manager.client.apiOptions.host, '/channels/${this is GuildChannel ? '${(this as GuildChannel).guildId}' : '@me'}/$id'); +} diff --git a/lib/src/guild.dart b/lib/src/guild.dart index 893d62a..e421c88 100644 --- a/lib/src/guild.dart +++ b/lib/src/guild.dart @@ -5,4 +5,7 @@ extension GuildExtension on Guild { String get acronym { return name.replaceAll(r"'s ", ' ').replaceAllMapped(RegExp(r'\w+'), (match) => match[0]![0]).replaceAll(RegExp(r'\s'), ''); } + + /// A URL clients can visit to navigate to this guild. + Uri get url => Uri.https(manager.client.apiOptions.host, '/channels/$id'); } diff --git a/lib/src/message.dart b/lib/src/message.dart new file mode 100644 index 0000000..352469d --- /dev/null +++ b/lib/src/message.dart @@ -0,0 +1,7 @@ +import 'package:nyxx/nyxx.dart'; +import 'package:nyxx_extensions/src/channel.dart'; + +extension MessageUtils on Message { + /// A URL clients can visit to navigate to this message. + Future get url async => Uri.https(manager.client.apiOptions.host, '${(await channel.get()).url.path}/$id'); +}