diff --git a/CHANGELOG.md b/CHANGELOG.md index a9b2582b3..175ec9842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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__ diff --git a/lib/src/core/guild/guild.dart b/lib/src/core/guild/guild.dart index d8ae99762..f1ff6709c 100644 --- a/lib/src/core/guild/guild.dart +++ b/lib/src/core/guild/guild.dart @@ -199,7 +199,7 @@ abstract class IGuild implements SnowflakeEntity { Future prune(int days, {Iterable? includeRoles, String? auditReason}); /// Get"s the guild's bans. - Stream getBans(); + Stream getBans({int limit = 1000, Snowflake? before, Snowflake? after}); /// Change self nickname in guild Future modifyCurrentMember({String? nick}); @@ -659,7 +659,8 @@ class Guild extends SnowflakeEntity implements IGuild { /// Get"s the guild's bans. @override - Stream getBans() => client.httpEndpoints.getGuildBans(id); + Stream getBans({int limit = 1000, Snowflake? before, Snowflake? after}) => + client.httpEndpoints.getGuildBans(id, limit: limit, before: before, after: after); /// Change self nickname in guild @override diff --git a/lib/src/core/user/user.dart b/lib/src/core/user/user.dart index 65bf59ea1..de0133016 100644 --- a/lib/src/core/user/user.dart +++ b/lib/src/core/user/user.dart @@ -50,6 +50,9 @@ abstract class IUser implements SnowflakeEntity, ISend, Mentionable, IMessageAut /// Gets the [DMChannel] for the user. FutureOr 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. @@ -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 sendMessage(MessageBuilder builder) async { diff --git a/lib/src/internal/constants.dart b/lib/src/internal/constants.dart index 0409b2345..e15f7f994 100644 --- a/lib/src/internal/constants.dart +++ b/lib/src/internal/constants.dart @@ -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"; diff --git a/lib/src/internal/http_endpoints.dart b/lib/src/internal/http_endpoints.dart index 367f20b9d..e2d7e485c 100644 --- a/lib/src/internal/http_endpoints.dart +++ b/lib/src/internal/http_endpoints.dart @@ -102,7 +102,7 @@ abstract class IHttpEndpoints { Future guildPrune(Snowflake guildId, int days, {Iterable? includeRoles, String? auditReason}); /// Get all guild bans. - Stream getGuildBans(Snowflake guildId); + Stream getGuildBans(Snowflake guildId, {int limit = 1000, Snowflake? before, Snowflake? after}); Future modifyCurrentMember(Snowflake guildId, {String? nick}); @@ -394,7 +394,7 @@ abstract class IHttpEndpoints { Future 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 fetchGuildEvents(Snowflake guildId, {bool withUserCount = false}); Future createGuildEvent(Snowflake guildId, GuildEventBuilder builder); @@ -606,8 +606,12 @@ class HttpEndpoints implements IHttpEndpoints { } @override - Stream getGuildBans(Snowflake guildId) async* { - final response = await httpHandler.execute(BasicRequest("/guilds/$guildId/bans")); + Stream 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); @@ -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"; diff --git a/pubspec.yaml b/pubspec.yaml index 9e792790b..ef7637e09 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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