Skip to content

Commit fb5d6bd

Browse files
authored
Deploy 4.2.0 (#44)
2 parents b49b661 + 0305498 commit fb5d6bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1031
-164
lines changed

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
env:
6262
TEST_TOKEN: ${{ secrets.TEST_TOKEN }}
6363
TEST_GUILD: ${{ secrets.TEST_GUILD }}
64+
TEST_TEXT_CHANNEL: ${{ secrets.TEST_TEXT_CHANNEL }}
6465
steps:
6566
- name: Setup Dart Action
6667
uses: dart-lang/setup-dart@v1

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
1+
## 4.2.0
2+
__04.10.2024__
3+
4+
- feat: Add an alternative method for formatting dates (#27)
5+
- feat: Add methods to stream entities from paginated endpoints (#28)
6+
- feat: Add methods for computing permissions in a channel. (#29)
7+
- bug: Update README.md (#32)
8+
- feat: Restructure nyxx_extensions (#31)
9+
- feat: Add a plugin for detecting when the client joins or leaves a guild (#33)
10+
- feat: Add a method for fetching the children of a `CategoryChannel` (#34)
11+
- feat: Add endpoint pagination for reactions (#35)
12+
- feat: Add getter for everyone role in a guild (#36)
13+
- feat: Add .toBuilder() method to GuildChannel (#39)
14+
- feat: Add extension getter for cdn assets (#37)
15+
- feat: Add support for sanitizing slash commands mentions (#40)
16+
- feat: Add getInviteUrl extension for PartialApplications (#41)
17+
- feat: Add utilities for fetching lists of entities (#42)
18+
- feat: Add extension to get a member's highest role (#43)
19+
120
## 4.1.0
221
__15.11.2023__
22+
323
- Added a helper to reply to a message.
424
- Fixed an issue with paginating back to a page that had already been seen.
525

626
## 4.0.0
727
__20.10.2023__
28+
829
- Fixed an issue with link formatting.
930

1031
## 4.0.0-dev.1
1132
__17.09.2023__
33+
1234
- Bump nyxx to `6.0.0`. See the changelog at https://pub.dev/packages/nyxx for more information.
1335
- Removed helpers now in the nyxx package.
1436
- Added pagination support.
1537

1638
## 3.2.0
39+
__10.09.2023__
1740

1841
- Bump nyxx to `4.2.0`
1942
- Correctly export `acronym` property on guild

README.md

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,40 @@
11
# nyxx_extensions
22

3-
[![Discord Shield](https://discordapp.com/api/guilds/846136758470443069/widget.png?style=shield)](https://discord.gg/nyxx)
4-
[![pub](https://img.shields.io/pub/v/nyxx.svg)](https://pub.dartlang.org/packages/nyxx_extensions)
5-
[![documentation](https://img.shields.io/badge/Documentation-nyxx_interactions-yellow.svg)](https://www.dartdocs.org/documentation/nyxx_extensions/latest/)
3+
[![Discord](https://discordapp.com/api/guilds/846136758470443069/widget.png?style=shield)](https://discord.gg/nyxx)
4+
[![pub](https://img.shields.io/pub/v/nyxx_extensions.svg)](https://pub.dev/packages/nyxx_extensions)
5+
[![documentation](https://img.shields.io/badge/Documentation-nyxx__extensions-yellow.svg)](https://pub.dev/documentation/nyxx_extensions/latest/)
66

7-
Simple, robust framework for creating discord bots for Dart language.
7+
Additional utilities and helpers for working with [nyxx](https://pub.dev/packages/nyxx).
88

9-
<hr />
9+
While the main [nyxx](https://pub.dev/packages/nyxx) package focuses on providing a wrapper only for the features described in [Discord's developer documentation](https://discord.com/developers/docs/intro), this package contains a collection of commonly used functions and plugins when making Discord bots, such as [pagination](https://pub.dev/documentation/nyxx_extensions/latest/nyxx_extensions/Pagination-class.html), [sanitization](https://pub.dev/documentation/nyxx_extensions/latest/nyxx_extensions/sanitizeContent.html) or [endpoint pagination](https://pub.dev/documentation/nyxx_extensions/latest/search.html?q=stream).
1010

11-
### Features
12-
13-
Additional extensions and subpackages to ease out developing bots in nyxx framework.
11+
This package is very open to contributions as it is built upon the needs of developers using [nyxx](https://pub.dev/packages/nyxx). If you find yourself implementing a feature that isn't specific to your bot, please consider [opening a pull request](https://github.com/nyxx-discord/nyxx_extensions/pulls) and add your code to this package. Read our [contribution document](https://github.com/nyxx-discord/nyxx_extensions/blob/dev/CONTRIBUTING.md) for more information.
1412

1513
## Other nyxx packages
1614

17-
- [nyxx](https://github.com/nyxx-discord/nyxx)
18-
- [nyxx_interactions](https://github.com/nyxx-discord/nyxx_interactions)
19-
- [nyxx_commander](https://github.com/nyxx-discord/nyxx_commander)
20-
- [nyxx_lavalink](https://github.com/nyxx-discord/nyxx_lavalink)
21-
- [nyxx_pagination](https://github.com/nyxx-discord/nyxx_pagination)
22-
23-
## More examples
24-
25-
Nyxx examples can be found [here](https://github.com/nyxx-discord/nyxx_extensions/tree/dev/example).
15+
- [nyxx](https://pub.dev/packages/nyxx): The main package wrapping Discord's developer API.
16+
- [nyxx_commands](https://pub.dev/packages/nyxx_commands): A command framework for handling both simple & complex commands.
17+
- [nyxx_lavalink](https://pub.dev/packages/nyxx_lavalink): Lavalink support for playing audio in voice channels.
2618

27-
### Example bots
28-
- [Running on Dart](https://github.com/l7ssha/running_on_dart)
19+
## Additional documentation & help
2920

30-
## Documentation, help and examples
21+
The API documentation for the latest stable version can be found on [pub](https://pub.dev/documentation/nyxx).
3122

32-
**Dartdoc documentation for latest stable version is hosted on [pub](https://www.dartdocs.org/documentation/nyxx_extensions/latest/)**
23+
### [Docs and wiki](https://nyxx.l7ssha.xyz)
24+
Tutorials and wiki articles are hosted here, as well as API documentation for development versions from GitHub.
3325

34-
#### [Docs and wiki](https://nyxx.l7ssha.xyz)
35-
You can read docs and wiki articles for latest stable version on my website. This website also hosts docs for latest
36-
dev changes to framework (`dev` branch)
26+
### [Official nyxx Discord server](https://discord.gg/nyxx)
27+
Our Discord server is where you can get help for any nyxx packages, as well as release announcements and discussions about the library.
3728

38-
#### [Official nyxx discord server](https://discord.gg/nyxx)
39-
If you need assistance in developing bot using nyxx you can join official nyxx discord guild.
29+
### [Discord API docs](https://discord.dev/)
30+
Discord's API documentation details what nyxx implements & provides more detailed explanations of certain topics.
4031

41-
#### [Discord API docs](https://discordapp.com/developers/docs/intro)
42-
Discord API documentation features rich descriptions about all topics that nyxx covers.
43-
44-
#### [Discord API Guild](https://discord.gg/discord-api)
32+
### [Discord API Server](https://discord.gg/discord-api)
4533
The unofficial guild for Discord Bot developers. To get help with nyxx check `#dart_nyxx` channel.
4634

47-
#### [Dartdocs](https://www.dartdocs.org/documentation/nyxx_extensions/latest/)
35+
### [Pub.dev docs](https://pub.dev/documentation/nyxx)
4836
The dartdocs page will always have the documentation for the latest release.
4937

5038
## Contributing to Nyxx
5139

52-
Read [contributing document](https://github.com/nyxx-discord/nyxx_extensions/blob/dev/CONTRIBUTING.md)
53-
54-
## Credits
55-
56-
* [Hackzzila's](https://github.com/Hackzzila) for [nyx](https://github.com/Hackzzila/nyx).
40+
Read the [contributing document](https://github.com/nyxx-discord/nyxx/blob/dev/CONTRIBUTING.md)

example/example.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void main() async {
2424
// Sanitizing content makes it safe to send to Discord without triggering any mentions
2525
client.onMessageCreate.listen((event) async {
2626
if (event.message.content.startsWith('!sanitize')) {
27-
event.message.channel.sendMessage(MessageBuilder(
27+
await event.message.channel.sendMessage(MessageBuilder(
2828
content: 'Sanitized content: ${await sanitizeContent(event.message.content, channel: event.message.channel)}',
2929
));
3030
}
@@ -67,5 +67,15 @@ ullamcorper morbi tincidunt ornare.
6767
}
6868
});
6969

70+
client.onMessageCreate.listen((event) async {
71+
if (event.message.content.startsWith('!avatar') && event.message.mentions.isNotEmpty) {
72+
// Display the first mentioned user's avatar with the specified size.
73+
final user = event.message.mentions.first;
74+
await event.message.channel.sendMessage(MessageBuilder(
75+
content: 'Avatar URL: ${user.avatar.get(format: CdnFormat.jpeg, size: 3072)}',
76+
));
77+
}
78+
});
79+
7080
// ...and more!
7181
}

lib/nyxx_extensions.dart

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
1+
/// Extensions and additional utilities for working with [nyxx](https://pub.dev/packages/nyxx).
12
library nyxx_extensions;
23

3-
export 'src/channel.dart';
4-
export 'src/date_time.dart';
5-
export 'src/embed_builder.dart';
6-
export 'src/emoji.dart';
7-
export 'src/guild.dart';
8-
export 'src/message.dart';
9-
export 'src/pagination.dart';
10-
export 'src/role.dart';
11-
export 'src/sanitizer.dart';
12-
export 'src/user.dart';
4+
export 'src/utils/emoji.dart';
5+
export 'src/utils/endpoint_paginator.dart' hide streamPaginatedEndpoint;
136
export 'src/utils/formatters.dart';
7+
export 'src/utils/guild_joins.dart';
8+
export 'src/utils/pagination.dart';
9+
export 'src/utils/permissions.dart';
10+
export 'src/utils/sanitizer.dart';
11+
12+
export 'src/extensions/cdn_asset.dart' hide getRequest;
13+
export 'src/extensions/channel.dart';
14+
export 'src/extensions/client.dart';
15+
export 'src/extensions/date_time.dart';
16+
export 'src/extensions/embed.dart';
17+
export 'src/extensions/emoji.dart';
18+
export 'src/extensions/guild.dart';
19+
export 'src/extensions/managers/audit_log_manager.dart';
20+
export 'src/extensions/managers/channel_manager.dart';
21+
export 'src/extensions/managers/entitlement_manager.dart';
22+
export 'src/extensions/managers/guild_manager.dart';
23+
export 'src/extensions/managers/member_manager.dart';
24+
export 'src/extensions/managers/message_manager.dart';
25+
export 'src/extensions/managers/scheduled_event_manager.dart';
26+
export 'src/extensions/managers/user_manager.dart';
27+
export 'src/extensions/member.dart';
28+
export 'src/extensions/message.dart';
29+
export 'src/extensions/role.dart';
30+
export 'src/extensions/scheduled_event.dart';
31+
export 'src/extensions/snowflake_entity.dart';
32+
export 'src/extensions/user.dart';
33+
export 'src/extensions/list.dart';
34+
export 'src/extensions/application.dart';

lib/src/channel.dart

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'package:nyxx/nyxx.dart';
2+
3+
/// Extensions on [PartialApplication]s.
4+
extension ApplicationExtensions on PartialApplication {
5+
/// Get a URL users can visit to add this bot to a guild.
6+
Uri getInviteUri({
7+
List<String> scopes = const ['bot', 'application.commands'],
8+
Flags<Permissions>? permissions,
9+
Snowflake? guildId,
10+
bool? disableGuildSelect,
11+
}) =>
12+
Uri.https(
13+
'discord.com',
14+
'/oauth2/authorize',
15+
{
16+
'client_id': id.toString(),
17+
'scope': scopes.join(' '),
18+
if (permissions != null) 'permissions': permissions.value.toString(),
19+
if (guildId != null) 'guild_id': guildId.toString(),
20+
if (disableGuildSelect != null) 'disable_guild_select': disableGuildSelect,
21+
},
22+
);
23+
}

lib/src/extensions/cdn_asset.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:nyxx/nyxx.dart';
2+
3+
extension CdnAssetExtensions on CdnAsset {
4+
Uri get({CdnFormat? format, int? size}) => getRequest(this, format ?? defaultFormat, size).prepare(client).url;
5+
}
6+
7+
// Re-implementing the private method from CdnAsset
8+
CdnRequest getRequest(CdnAsset asset, CdnFormat format, int? size) {
9+
final route = HttpRoute();
10+
11+
for (final part in asset.base.parts) {
12+
route.add(part);
13+
}
14+
route.add(HttpRoutePart('${asset.hash}.${format.extension}'));
15+
16+
return CdnRequest(
17+
route,
18+
queryParameters: {
19+
if (size != null) 'size': size.toString(),
20+
},
21+
);
22+
}

lib/src/extensions/channel.dart

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import 'package:nyxx/nyxx.dart';
2+
import 'package:nyxx_extensions/src/extensions/guild.dart';
3+
import 'package:nyxx_extensions/src/extensions/managers/channel_manager.dart';
4+
import 'package:nyxx_extensions/src/utils/formatters.dart';
5+
import 'package:nyxx_extensions/src/utils/permissions.dart';
6+
7+
/// Extensions on [PartialChannel]s.
8+
extension PartialChannelExtensions on PartialChannel {
9+
/// A mention of this channel.
10+
String get mention => channelMention(id);
11+
}
12+
13+
/// Extensions on [Channel]s.
14+
extension ChannelExtensions on Channel {
15+
/// A URL clients can visit to navigate to this channel.
16+
Uri get url => Uri.https(manager.client.apiOptions.host, '/channels/${this is GuildChannel ? '${(this as GuildChannel).guildId}' : '@me'}/$id');
17+
}
18+
19+
/// Extensions on [GuildChannel]s.
20+
extension GuildChannelExtensions on GuildChannel {
21+
/// Compute [member]'s permissions in this channel.
22+
///
23+
/// {@macro compute_permissions_detail}
24+
Future<Permissions> computePermissionsFor(PartialMember member) async => await computePermissions(this, await member.get());
25+
}
26+
27+
/// Extensions on all [GuildChannel] types
28+
extension GuildChannelsExtension<T extends GuildChannel> on T {
29+
/// Create a builder with the properties of this channel
30+
GuildChannelBuilder<T> toBuilder() => switch (this) {
31+
GuildTextChannel channel => GuildTextChannelBuilder(
32+
name: channel.name,
33+
defaultAutoArchiveDuration: channel.defaultAutoArchiveDuration,
34+
isNsfw: channel.isNsfw,
35+
parentId: channel.parentId,
36+
permissionOverwrites: channel.permissionOverwrites
37+
.map((e) => PermissionOverwriteBuilder(
38+
id: e.id,
39+
type: e.type,
40+
allow: e.allow,
41+
deny: e.deny,
42+
))
43+
.toList(),
44+
position: channel.position,
45+
rateLimitPerUser: channel.rateLimitPerUser,
46+
topic: channel.topic,
47+
) as GuildChannelBuilder<T>,
48+
GuildVoiceChannel channel => GuildVoiceChannelBuilder(
49+
name: channel.name,
50+
permissionOverwrites:
51+
channel.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(),
52+
position: channel.position,
53+
isNsfw: channel.isNsfw,
54+
parentId: channel.parentId,
55+
bitRate: channel.bitrate,
56+
rtcRegion: channel.rtcRegion,
57+
userLimit: channel.userLimit,
58+
videoQualityMode: channel.videoQualityMode,
59+
) as GuildChannelBuilder<T>,
60+
GuildStageChannel channel => GuildStageChannelBuilder(
61+
name: channel.name,
62+
bitRate: channel.bitrate,
63+
isNsfw: channel.isNsfw,
64+
parentId: channel.parentId,
65+
permissionOverwrites:
66+
channel.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(),
67+
position: channel.position,
68+
rtcRegion: channel.rtcRegion,
69+
userLimit: channel.userLimit,
70+
videoQualityMode: channel.videoQualityMode,
71+
) as GuildChannelBuilder<T>,
72+
PrivateThread thread => ThreadBuilder.privateThread(
73+
name: thread.name,
74+
autoArchiveDuration: thread.autoArchiveDuration,
75+
invitable: thread.isInvitable,
76+
rateLimitPerUser: thread.rateLimitPerUser,
77+
) as GuildChannelBuilder<T>,
78+
PublicThread thread => ThreadBuilder.publicThread(
79+
name: thread.name,
80+
autoArchiveDuration: thread.autoArchiveDuration,
81+
rateLimitPerUser: thread.rateLimitPerUser,
82+
) as GuildChannelBuilder<T>,
83+
GuildCategory category => GuildCategoryBuilder(
84+
name: category.name,
85+
permissionOverwrites:
86+
category.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(),
87+
position: category.position,
88+
) as GuildChannelBuilder<T>,
89+
GuildAnnouncementChannel channel => GuildAnnouncementChannelBuilder(
90+
name: channel.name,
91+
defaultAutoArchiveDuration: channel.defaultAutoArchiveDuration,
92+
isNsfw: channel.isNsfw,
93+
parentId: channel.parentId,
94+
permissionOverwrites:
95+
channel.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(),
96+
position: channel.position,
97+
topic: channel.topic,
98+
) as GuildChannelBuilder<T>,
99+
_ => GuildChannelBuilder(
100+
name: name,
101+
type: type,
102+
position: position,
103+
permissionOverwrites: permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(),
104+
),
105+
};
106+
}
107+
108+
/// Extensions on [Thread]s.
109+
extension ThreadExtensions on Thread {
110+
/// Same as [listThreadMembers], but has no limit on the number of members returned.
111+
///
112+
/// {@macro paginated_endpoint_streaming_parameters}
113+
Stream<ThreadMember> streamThreadMembers({bool? withMembers, Snowflake? after, Snowflake? before, int? pageSize}) =>
114+
manager.streamThreadMembers(id, withMembers: withMembers, after: after, before: before, pageSize: pageSize);
115+
}
116+
117+
/// Extensions on [GuildCategory]s.
118+
extension GuildCategoryExtensions on GuildCategory {
119+
/// Fetch the channels in this category.
120+
Future<List<GuildChannel>> fetchChannels() async {
121+
final guildChannels = await guild.fetchChannels();
122+
123+
return guildChannels.where((element) => element.parentId == id).toList();
124+
}
125+
126+
/// Return a list of channels in the client's cache that are in this category.
127+
List<GuildChannel> get cachedChannels => guild.cachedChannels.where((element) => element.parentId == id).toList();
128+
}

0 commit comments

Comments
 (0)