Skip to content

Commit

Permalink
Merge pull request #327 from nyxx-discord/dev
Browse files Browse the repository at this point in the history
Release 3.4.0
  • Loading branch information
l7ssha authored Apr 9, 2022
2 parents 26b1da1 + 02577de commit c4884ca
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.4.0
__09.04.2022__

- feature: Add `@bannerUrl()` method (#318)
- feature: Implement paginated bans (#326)

## 3.3.1
__30.03.2022__

Expand Down
5 changes: 3 additions & 2 deletions lib/src/core/guild/guild.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ abstract class IGuild implements SnowflakeEntity {
Future<int> prune(int days, {Iterable<Snowflake>? includeRoles, String? auditReason});

/// Get"s the guild's bans.
Stream<IBan> getBans();
Stream<IBan> getBans({int limit = 1000, Snowflake? before, Snowflake? after});

/// Change self nickname in guild
Future<void> modifyCurrentMember({String? nick});
Expand Down Expand Up @@ -659,7 +659,8 @@ class Guild extends SnowflakeEntity implements IGuild {

/// Get"s the guild's bans.
@override
Stream<IBan> getBans() => client.httpEndpoints.getGuildBans(id);
Stream<IBan> getBans({int limit = 1000, Snowflake? before, Snowflake? after}) =>
client.httpEndpoints.getGuildBans(id, limit: limit, before: before, after: after);

/// Change self nickname in guild
@override
Expand Down
7 changes: 7 additions & 0 deletions lib/src/core/user/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ abstract class IUser implements SnowflakeEntity, ISend, Mentionable, IMessageAut

/// Gets the [DMChannel] for the user.
FutureOr<IDMChannel> get dmChannel;

/// The user's banner url.
String? bannerUrl({String? format, int? size});
}

/// Represents a single user of Discord, either a human or a bot, outside of any specific guild's context.
Expand Down Expand Up @@ -158,6 +161,10 @@ class User extends SnowflakeEntity implements IUser {
@override
String avatarURL({String format = "webp", int size = 128}) => client.httpEndpoints.userAvatarURL(id, avatar, discriminator, format: format, size: size);

/// The user's banner url.
@override
String? bannerUrl({String? format, int? size}) => client.httpEndpoints.userBannerURL(id, bannerHash, format: format, size: size);

/// Sends a message to user.
@override
Future<IMessage> sendMessage(MessageBuilder builder) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Constants {
static const int apiVersion = 9;

/// Version of Nyxx
static const String version = "3.3.1";
static const String version = "3.4.0";

/// Url to Nyxx repo
static const String repoUrl = "https://github.com/nyxx-discord/nyxx";
Expand Down
36 changes: 31 additions & 5 deletions lib/src/internal/http_endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ abstract class IHttpEndpoints {
Future<int> guildPrune(Snowflake guildId, int days, {Iterable<Snowflake>? includeRoles, String? auditReason});

/// Get all guild bans.
Stream<IBan> getGuildBans(Snowflake guildId);
Stream<IBan> getGuildBans(Snowflake guildId, {int limit = 1000, Snowflake? before, Snowflake? after});

Future<void> modifyCurrentMember(Snowflake guildId, {String? nick});

Expand Down Expand Up @@ -394,7 +394,7 @@ abstract class IHttpEndpoints {
Future<void> deleteGuildSticker(Snowflake guildId, Snowflake stickerId);

/// Returns url of user banner
String getUserBannerURL(Snowflake userId, String hash, {String format = "png"});
String? userBannerURL(Snowflake userId, String? hash, {String? format, int? size});

Stream<GuildEvent> fetchGuildEvents(Snowflake guildId, {bool withUserCount = false});
Future<GuildEvent> createGuildEvent(Snowflake guildId, GuildEventBuilder builder);
Expand Down Expand Up @@ -606,8 +606,12 @@ class HttpEndpoints implements IHttpEndpoints {
}

@override
Stream<IBan> getGuildBans(Snowflake guildId) async* {
final response = await httpHandler.execute(BasicRequest("/guilds/$guildId/bans"));
Stream<IBan> getGuildBans(Snowflake guildId, {int limit = 1000, Snowflake? before, Snowflake? after}) async* {
final response = await httpHandler.execute(BasicRequest("/guilds/$guildId/bans", queryParams: {
"limit": limit,
if (before != null) "before": before,
if (after != null) "after": after,
}));

if (response is HttpResponseError) {
yield* Stream.error(response);
Expand Down Expand Up @@ -1583,7 +1587,29 @@ class HttpEndpoints implements IHttpEndpoints {
"${Constants.cdnUrl}/guilds/$guildId/users/$memberId/avatars/$avatarHash.$format";

@override
String getUserBannerURL(Snowflake userId, String hash, {String format = "png"}) => "${Constants.cdnUrl}/banners/$userId/$hash.$format";
@override
String? userBannerURL(Snowflake userId, String? hash, {String? format, int? size}) {
if (hash == null) {
return null;
}
var url = "${Constants.cdnUrl}/banners/$userId/$hash.";

if (format == null) {
if (hash.startsWith("a_")) {
url += "gif";
} else {
url += "webp";
}
} else {
url += format;
}

if (size != null) {
url += "?size=$size";
}

return url;
}

@override
String getRoleIconUrl(Snowflake roleId, String iconHash, String format, int size) => "${Constants.cdnUrl}/role-icons/$roleId/$iconHash.$format?size=$size";
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: nyxx
version: 3.3.1
version: 3.4.0
description: A Discord library for Dart. Simple, robust framework for creating discord bots for Dart language.
homepage: https://github.com/nyxx-discord/nyxx
repository: https://github.com/nyxx-discord/nyxx
Expand Down

0 comments on commit c4884ca

Please sign in to comment.