Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tests #50

Merged
1 commit merged into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions hikari/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ def icon_url(self) -> typing.Optional[files.URL]:
"""
return self.format_icon()

def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the icon for this team if set.

Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`. Can be any power
Expand All @@ -360,7 +360,7 @@ def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Option
return None

return routes.CDN_TEAM_ICON.compile_to_file(
constants.CDN_URL, team_id=self.id, hash=self.icon_hash, size=size, file_format=format,
constants.CDN_URL, team_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)


Expand Down Expand Up @@ -453,13 +453,13 @@ def icon_url(self) -> typing.Optional[files.URL]:
"""
return self.format_icon()

def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the icon for this application.

Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -480,7 +480,7 @@ def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Option
return None

return routes.CDN_APPLICATION_ICON.compile_to_file(
constants.CDN_URL, application_id=self.id, hash=self.icon_hash, size=size, file_format=format,
constants.CDN_URL, application_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)

@property
Expand All @@ -494,13 +494,13 @@ def cover_image_url(self) -> typing.Optional[files.URL]:
"""
return self.format_cover_image()

def format_cover_image(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_cover_image(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the cover image used in the store, if set.

Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
This conversation was marked as resolved.
Show resolved Hide resolved
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -521,5 +521,5 @@ def format_cover_image(self, *, format: str = "png", size: int = 4096) -> typing
return None

return routes.CDN_APPLICATION_COVER.compile_to_file(
constants.CDN_URL, application_id=self.id, hash=self.cover_image_hash, size=size, file_format=format,
constants.CDN_URL, application_id=self.id, hash=self.cover_image_hash, size=size, file_format=ext,
)
8 changes: 4 additions & 4 deletions hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ def icon_url(self) -> typing.Optional[files.URL]:
"""Icon for this DM channel, if set."""
return self.format_icon()

def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the icon for this DM, if set.

Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -480,7 +480,7 @@ def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Option
return None

return routes.CDN_CHANNEL_ICON.compile_to_file(
constants.CDN_URL, channel_id=self.id, hash=self.icon_hash, size=size, file_format=format,
constants.CDN_URL, channel_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)


Expand Down
72 changes: 36 additions & 36 deletions hikari/guilds.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ def flags(self) -> users.UserFlag:
return self.user.flags

@property
def avatar(self) -> files.URL:
return self.user.avatar
def avatar_url(self) -> files.URL:
return self.user.avatar_url

def format_avatar(self, *, format: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
return self.user.format_avatar(format=format, size=size)
def format_avatar(self, *, ext: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
return self.user.format_avatar(ext=ext, size=size)

@property
def default_avatar(self) -> files.URL:
Expand Down Expand Up @@ -644,18 +644,18 @@ def icon_url(self) -> typing.Optional[files.URL]:
"""Icon for the guild, if set; otherwise `builtins.None`."""
return self.format_icon()

def format_icon(self, *, format_: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's icon, if set.

Parameters
----------
format_ : typing.Optional[builtins.str]
The format to use for this URL, defaults to `png` or `gif`.
ext : typing.Optional[builtins.str]
The extension to use for this URL, defaults to `png` or `gif`.
Supports `png`, `jpeg`, `jpg`, `webp` and `gif` (when
animated).

If `builtins.None`, then the correct default format is determined
based on whether the icon is animated or not.
If `builtins.None`, then the correct default extension is
determined based on whether the icon is animated or not.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Can be any power of two between 16 and 4096.
Expand All @@ -673,14 +673,14 @@ def format_icon(self, *, format_: typing.Optional[str] = None, size: int = 4096)
if self.icon_hash is None:
return None

if format_ is None:
if ext is None:
if self.icon_hash.startswith("a_"):
format_ = "gif"
ext = "gif"
else:
format_ = "png"
ext = "png"

return routes.CDN_GUILD_ICON.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.icon_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)


Expand Down Expand Up @@ -711,13 +711,13 @@ def splash_url(self) -> typing.Optional[files.URL]:
"""Splash for the guild, if set."""
return self.format_splash()

def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's splash image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -737,21 +737,21 @@ def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=ext,
)

@property
def discovery_splash(self) -> typing.Optional[files.URL]:
def discovery_splash_url(self) -> typing.Optional[files.URL]:
"""Discovery splash for the guild, if set."""
return self.format_discovery_splash()

def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_discovery_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's discovery splash image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -771,7 +771,7 @@ def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) ->
return None

return routes.CDN_GUILD_DISCOVERY_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=ext,
)


Expand Down Expand Up @@ -951,13 +951,13 @@ def splash_url(self) -> typing.Optional[files.URL]:
"""Splash for the guild, if set."""
return self.format_splash()

def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's splash image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -977,21 +977,21 @@ def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=ext,
)

@property
def discovery_splash(self) -> typing.Optional[files.URL]:
def discovery_splash_url(self) -> typing.Optional[files.URL]:
"""Discovery splash for the guild, if set."""
return self.format_discovery_splash()

def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_discovery_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's discovery splash image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -1011,21 +1011,21 @@ def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) ->
return None

return routes.CDN_GUILD_DISCOVERY_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=ext,
)

@property
def banner(self) -> typing.Optional[files.URL]:
def banner_url(self) -> typing.Optional[files.URL]:
"""Banner for the guild, if set."""
return self.format_banner()

def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_banner(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's banner image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -1045,7 +1045,7 @@ def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_BANNER.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=ext,
)


Expand Down
16 changes: 8 additions & 8 deletions hikari/invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ def splash_url(self) -> typing.Optional[files.URL]:
"""Splash for the guild, if set."""
return self.format_splash()

def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's splash image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -162,21 +162,21 @@ def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=ext,
)

@property
def banner(self) -> typing.Optional[files.URL]:
"""Banner for the guild, if set."""
return self.format_banner()

def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_banner(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's banner image, if set.

Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -196,7 +196,7 @@ def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_BANNER.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=ext,
)


Expand Down
22 changes: 10 additions & 12 deletions hikari/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ def mention(self) -> str:
"""

@property
def avatar(self) -> files.URL:
def avatar_url(self) -> files.URL:
"""Avatar for the user, or the default avatar if not set."""
return self.format_avatar() or self.default_avatar

def format_avatar(self, *, format: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
def format_avatar(self, *, ext: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the avatar for this user, if set.

If no custom avatar is set, this returns `builtins.None`. You can then
Expand All @@ -252,14 +252,14 @@ def format_avatar(self, *, format: typing.Optional[str] = None, size: int = 4096

Parameters
----------
format : typing.Optional[builtins.str]
The format to use for this URL, defaults to `png` or `gif`.
ext : typing.Optional[builtins.str]
The ext to use for this URL, defaults to `png` or `gif`.
Supports `png`, `jpeg`, `jpg`, `webp` and `gif` (when
animated). Will be ignored for default avatars which can only be
`png`.

If `builtins.None`, then the correct default format is determined
based on whether the icon is animated or not.
If `builtins.None`, then the correct default extension is
determined based on whether the icon is animated or not.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Can be any power of two between 16 and 4096.
Expand All @@ -278,16 +278,14 @@ def format_avatar(self, *, format: typing.Optional[str] = None, size: int = 4096
if self.avatar_hash is None:
return None

if format is None:
if ext is None:
if self.avatar_hash.startswith("a_"):
# Ignore the fact this shadows `format`, as it is the parameter
# name, which shadows it anyway.
format = "gif" # noqa: A001 shadowing builtin
ext = "gif"
else:
format = "png" # noqa: A001 shadowing builtin
ext = "png"

return routes.CDN_USER_AVATAR.compile_to_file(
constants.CDN_URL, user_id=self.id, hash=self.avatar_hash, size=size, file_format=format,
constants.CDN_URL, user_id=self.id, hash=self.avatar_hash, size=size, file_format=ext,
)

@property
Expand Down
Loading