diff --git a/melisa/__init__.py b/melisa/__init__.py index 2636d32..5b8bf85 100644 --- a/melisa/__init__.py +++ b/melisa/__init__.py @@ -4,7 +4,7 @@ from .client import Client, Bot from .models import * from .exceptions import * -from .rest import RESTApp +from .rest import RESTApp, CDNBuilder from .cache import CacheManager, ChannelsCachingPolicy __package__ = "melisa" diff --git a/melisa/rest.py b/melisa/rest.py index b171010..936fe77 100644 --- a/melisa/rest.py +++ b/melisa/rest.py @@ -681,7 +681,7 @@ class CDNBuilder: def avatar_url( self, user_id: str, _hash: str, *, size: int = 1024, image_format: str = None ): - return "/{}/avatars/{}/{}.{}?size={}".format( + return "{}/avatars/{}/{}.{}?size={}".format( self.BASE_URL, user_id, _hash, @@ -692,7 +692,7 @@ class CDNBuilder: def guild_icon_url( self, guild_id: str, _hash: str, *, size: int = 1024, image_format: str = None ): - return "/icons/{}/{}.{}?size={}".format( + return "{}/icons/{}/{}.{}?size={}".format( self.BASE_URL, guild_id, _hash, @@ -703,7 +703,7 @@ class CDNBuilder: def default_avatar_url( self, discriminator: str ): - return "/embed/avatars/{}.png".format( + return "{}/embed/avatars/{}.png".format( self.BASE_URL, - discriminator + int(discriminator) % 5 ) diff --git a/tests/test_cdn.py b/tests/test_cdn.py new file mode 100644 index 0000000..8993480 --- /dev/null +++ b/tests/test_cdn.py @@ -0,0 +1,27 @@ +from melisa import CDNBuilder + +cdn = CDNBuilder("png") + + +class TestCDN: + def test_avatar_url(self): + assert ( + cdn.avatar_url("585766846268047370", "52320b1f9ddb1d7546da7b973bc23d6d") + == "https://cdn.discordapp.com/avatars/585766846268047370/52320b1f9ddb1d7546da7b973bc23d6d.png?size=1024" + ) + + def test_default_avatar_url(self): + assert ( + cdn.default_avatar_url("0575") + == "https://cdn.discordapp.com/embed/avatars/0.png" + ) + + def test_guild_icon_url(self): + assert ( + cdn.guild_icon_url( + "951867868188934216", + "5ef33b1f6c4b35f19b605c51c5a64469", + image_format="webp", + ) + == "https://cdn.discordapp.com/icons/951867868188934216/5ef33b1f6c4b35f19b605c51c5a64469.webp?size=1024" + )