Skip to content

Commit

Permalink
Add methods for fetching channels in a category
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything committed Feb 19, 2024
1 parent b0f5b69 commit 0f8f5fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/src/extensions/channel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:nyxx/nyxx.dart';
import 'package:nyxx_extensions/src/extensions/guild.dart';
import 'package:nyxx_extensions/src/extensions/managers/channel_manager.dart';
import 'package:nyxx_extensions/src/utils/formatters.dart';
import 'package:nyxx_extensions/src/utils/permissions.dart';
Expand Down Expand Up @@ -31,3 +32,16 @@ extension ThreadExtensions on Thread {
Stream<ThreadMember> streamThreadMembers({bool? withMembers, Snowflake? after, Snowflake? before, int? pageSize}) =>
manager.streamThreadMembers(id, withMembers: withMembers, after: after, before: before, pageSize: pageSize);
}

/// Extensions on [GuildCategory]s.
extension GuildCategoryExtensions on GuildCategory {
/// Fetch the channels in this category.
Future<List<GuildChannel>> fetchChannels() async {
final guildChannels = await guild.fetchChannels();

return guildChannels.where((element) => element.parentId == id).toList();
}

/// Return a list of channels in the client's cache that are in this category.
List<GuildChannel> get cachedChannels => guild.cachedChannels.where((element) => element.parentId == id).toList();
}
3 changes: 3 additions & 0 deletions lib/src/extensions/guild.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extension PartialGuildExtensions on PartialGuild {
///
/// {@macro paginated_endpoint_streaming_parameters}
Stream<Ban> streamBans({Snowflake? after, Snowflake? before, int? pageSize}) => manager.streamBans(id, after: after, before: before, pageSize: pageSize);

/// Return a list of channels in the client's cache that are in this guild.
List<GuildChannel> get cachedChannels => manager.client.channels.cache.values.whereType<GuildChannel>().where((element) => element.guildId == id).toList();
}

/// Extensions on [Guild]s.
Expand Down

0 comments on commit 0f8f5fa

Please sign in to comment.