Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa authored Jul 15, 2022
2 parents eb368e8 + 51a6206 commit dbbd8d1
Show file tree
Hide file tree
Showing 29 changed files with 1,156 additions and 56 deletions.
2 changes: 2 additions & 0 deletions changes/1126.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add `hikari.events.StickersUpdateEvent` and relevant cache internals.
Add sticker related public methods onto `hikari.impl.CacheImpl` and `hikari.guilds.Guild`.
1 change: 1 addition & 0 deletions changes/1195.deprecation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`RESTClient.edit_permission_overwrites` renamed to `RESTClient.edit_permission_overwrite`
1 change: 1 addition & 0 deletions changes/1207.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed case of `Member.mention` returning bang (`!`) mention, as it is deprecated by Discord.
1 change: 1 addition & 0 deletions changes/1212.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix how CommandBuilder handles `default_member_permissions` to match the behaviour on PartialCommand.
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pytest-cov==3.0.0
pytest-randomly==3.12.0

# Coverage testing.
coverage[toml]==6.4.1
coverage[toml]==6.4.2

# Other stuff
async-timeout==4.0.2 # Used for timeouts in some test cases.
Expand All @@ -29,7 +29,7 @@ sphobjinv==2.2.2
#################

mypy==0.961
pyright==1.1.259
pyright==1.1.260

#######################
# DEPENDENCY CHECKING #
Expand Down
112 changes: 112 additions & 0 deletions hikari/api/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from hikari import messages
from hikari import presences
from hikari import snowflakes
from hikari import stickers
from hikari import users
from hikari import voices
from hikari.api import config
Expand Down Expand Up @@ -168,6 +169,51 @@ def get_emojis_view_for_guild(
specified guild.
"""

@abc.abstractmethod
def get_sticker(
self, sticker: snowflakes.SnowflakeishOr[stickers.GuildSticker], /
) -> typing.Optional[stickers.GuildSticker]:
"""Get a sticker from the cache.
Parameters
----------
sticker : hikari.snowflakes.SnowflakeishOr[hikari.stickers.GuildSticker]
Object or ID of the sticker to get from the cache.
Returns
-------
typing.Optional[hikari.stickers.GuildSticker]
The object of the sticker that was found in the cache or `builtins.None`.
"""

@abc.abstractmethod
def get_stickers_view(self) -> CacheView[snowflakes.Snowflake, stickers.GuildSticker]:
"""Get a view of the sticker objects in the cache.
Returns
-------
CacheView[hikari.snowflakes.Snowflake, hikari.stickers.GuildSticker]
A view of sticker IDs to objects of the stickers found in the cache.
"""

@abc.abstractmethod
def get_stickers_view_for_guild(
self, guild: snowflakes.SnowflakeishOr[guilds.PartialGuild], /
) -> CacheView[snowflakes.Snowflake, stickers.GuildSticker]:
"""Get a view of the known custom emojis cached for a specific guild.
Parameters
----------
guild : hikari.snowflakes.SnowflakeishOr[hikari.guilds.PartialGuild]
Object or ID of the guild to get the cached sticker objects for.
Returns
-------
CacheView[hikari.snowflakes.Snowflake, hikari.guilds.stickers.GuildSticker]
A view of sticker IDs to objects of stickers found in the cache for the
specified guild.
"""

@abc.abstractmethod
def get_guild(
self, guild: snowflakes.SnowflakeishOr[guilds.PartialGuild], /
Expand Down Expand Up @@ -816,6 +862,72 @@ def update_emoji(
`builtins.None`).
"""

@abc.abstractmethod
def clear_stickers(self) -> CacheView[snowflakes.Snowflake, stickers.GuildSticker]:
"""Remove all the sticker objects from the cache.
!!! note
This will skip stickers that are being kept alive by a reference.
Returns
-------
CacheView[hikari.snowflakes.Snowflake, hikari.stickers.GuildSticker]
A cache view of sticker IDs to objects of the stickers that were
removed from the cache.
"""

@abc.abstractmethod
def clear_stickers_for_guild(
self, guild: snowflakes.SnowflakeishOr[guilds.PartialGuild], /
) -> CacheView[snowflakes.Snowflake, stickers.GuildSticker]:
"""Remove the known custom emoji objects cached for a specific guild.
Parameters
----------
guild : hikari.snowflakes.SnowflakeishOr[hikari.guilds.PartialGuild]
Object or ID of the guild to remove the cached sticker objects for.
!!! note
This will skip stickers that are being kept alive by a reference.
Returns
-------
CacheView[hikari.snowflakes.Snowflake, hikari.stickers.GuildSticker]
A view of sticker IDs to objects of the stickers that were removed
from the cache.
"""

@abc.abstractmethod
def delete_sticker(
self, sticker: snowflakes.SnowflakeishOr[stickers.GuildSticker], /
) -> typing.Optional[stickers.GuildSticker]:
"""Remove a sticker from the cache.
Parameters
----------
sticker : hikari.snowflakes.SnowflakeishOr[hikari.stickers.GuildSticker]
Object or ID of the sticker to remove from the cache.
!!! note
This will not delete stickers that are being kept alive by a reference.
Returns
-------
typing.Optional[hikari.stickers.GuildSticker]
The object of the sticker that was removed from the cache or
`builtins.None`.
"""

@abc.abstractmethod
def set_sticker(self, sticker: stickers.GuildSticker, /) -> None:
"""Add a sticker to the cache.
Parameters
----------
sticker : hikari.stickers.GuildSticker
The object of the sticker to add to the cache.
"""

@abc.abstractmethod
def clear_guilds(self) -> CacheView[snowflakes.Snowflake, guilds.GatewayGuild]:
"""Remove all the guild objects from the cache.
Expand Down
4 changes: 4 additions & 0 deletions hikari/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class CacheComponents(enums.Flag):
DM_CHANNEL_IDS = 1 << 10
"""Enables the DM channel IDs cache."""

GUILD_STICKERS = 1 << 11
"""Enables the guild stickers cache."""

ALL = (
GUILDS
| GUILD_CHANNELS
Expand All @@ -85,6 +88,7 @@ class CacheComponents(enums.Flag):
| MESSAGES
| ME
| DM_CHANNEL_IDS
| GUILD_STICKERS
)
"""Fully enables the cache."""

Expand Down
9 changes: 7 additions & 2 deletions hikari/api/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def channels(self) -> typing.Mapping[snowflakes.Snowflake, channel_models.GuildC
def emojis(self) -> typing.Mapping[snowflakes.Snowflake, emoji_models.KnownCustomEmoji]:
"""Get a mapping of emoji IDs to the emojis that belong to the guild."""

@abc.abstractmethod
def stickers(self) -> typing.Mapping[snowflakes.Snowflake, sticker_models.GuildSticker]:
"""Get a mapping of sticker IDs to the stickers that belong to the guild."""

@abc.abstractmethod
def guild(self) -> guild_models.GatewayGuild:
"""Get the object of the guild this definition is for."""
Expand Down Expand Up @@ -912,8 +916,9 @@ def deserialize_gateway_guild(self, payload: data_binding.JSONObject) -> Gateway
`hikari.channels.GuildChannel`,
`hikari.guilds.Member`,
`hikari.presences.MemberPresence`,
`hikari.guilds.Role`, and
`hikari.emojis.KnownCustomEmoji`. This is provided in
`hikari.guilds.Role`,
`hikari.emojis.KnownCustomEmoji`, and
`hikari.stickers.GuildSticker`. This is provided in
several components to allow separate caching and linking
between entities in various relational cache implementations
internally.
Expand Down
28 changes: 28 additions & 0 deletions hikari/api/event_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,34 @@ def deserialize_guild_emojis_update_event(
The parsed guild emojis update event object.
"""

@abc.abstractmethod
def deserialize_guild_stickers_update_event(
self,
shard: gateway_shard.GatewayShard,
payload: data_binding.JSONObject,
*,
old_stickers: typing.Optional[typing.Sequence[guild_models.stickers.GuildSticker]] = None,
) -> guild_events.StickersUpdateEvent:
"""Parse a raw payload from Discord into a guild stickers update event object.
Parameters
----------
shard : hikari.api.shard.GatewayShard
The shard that emitted this event.
payload : hikari.internal.data_binding.JSONObject
The dict payload to parse.
Other Parameters
----------------
typing.Optional[typing.Sequence[hikari.guilds.stickers.GuildSticker]]
The sequence of stickers or `builtins.None`.
Returns
-------
hikari.events.guild_events.StickersUpdateEvent
The parsed guild stickers update event object.
"""

@abc.abstractmethod
def deserialize_integration_create_event(
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
Expand Down
10 changes: 5 additions & 5 deletions hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ async def edit_voice_state(

@typing.overload
@abc.abstractmethod
async def edit_permission_overwrites(
async def edit_permission_overwrite(
self,
channel: snowflakes.SnowflakeishOr[channels_.GuildChannel],
target: typing.Union[channels_.PermissionOverwrite, users.PartialUser, guilds.PartialRole],
Expand All @@ -518,7 +518,7 @@ async def edit_permission_overwrites(

@typing.overload
@abc.abstractmethod
async def edit_permission_overwrites(
async def edit_permission_overwrite(
self,
channel: snowflakes.SnowflakeishOr[channels_.GuildChannel],
target: snowflakes.Snowflakeish,
Expand All @@ -531,7 +531,7 @@ async def edit_permission_overwrites(
"""Edit permissions for a given entity ID and type."""

@abc.abstractmethod
async def edit_permission_overwrites(
async def edit_permission_overwrite(
self,
channel: snowflakes.SnowflakeishOr[channels_.GuildChannel],
target: typing.Union[
Expand Down Expand Up @@ -560,9 +560,9 @@ async def edit_permission_overwrites(
If provided, the type of the target to update. If unset, will attempt to get
the type from `target`.
allow : hikari.undefined.UndefinedOr[hikari.permissions.Permissions]
If provided, the new vale of all allowed permissions.
If provided, the new value of all allowed permissions.
deny : hikari.undefined.UndefinedOr[hikari.permissions.Permissions]
If provided, the new vale of all disallowed permissions.
If provided, the new value of all disallowed permissions.
reason : hikari.undefined.UndefinedOr[builtins.str]
If provided, the reason that will be recorded in the audit logs.
Maximum of 512 characters.
Expand Down
10 changes: 4 additions & 6 deletions hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,9 @@ async def edit_overwrite(
If provided, the type of the target to update. If unset, will attempt to get
the type from `target`.
allow : hikari.undefined.UndefinedOr[hikari.permissions.Permissions]
If provided, the new vale of all allowed permissions.
If provided, the new value of all allowed permissions.
deny : hikari.undefined.UndefinedOr[hikari.permissions.Permissions]
If provided, the new vale of all disallowed permissions.
If provided, the new value of all disallowed permissions.
reason : hikari.undefined.UndefinedOr[builtins.str]
If provided, the reason that will be recorded in the audit logs.
Maximum of 512 characters.
Expand Down Expand Up @@ -1074,11 +1074,9 @@ async def edit_overwrite(
assert not isinstance(
target, int
), "Cannot determine the type of the target to update. Try specifying 'target_type' manually."
return await self.app.rest.edit_permission_overwrites(
self.id, target, allow=allow, deny=deny, reason=reason
)
return await self.app.rest.edit_permission_overwrite(self.id, target, allow=allow, deny=deny, reason=reason)

return await self.app.rest.edit_permission_overwrites(
return await self.app.rest.edit_permission_overwrite(
self.id, typing.cast(int, target), target_type=target_type, allow=allow, deny=deny, reason=reason
)

Expand Down
46 changes: 46 additions & 0 deletions hikari/events/guild_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"BanCreateEvent",
"BanDeleteEvent",
"EmojisUpdateEvent",
"StickersUpdateEvent",
"IntegrationEvent",
"IntegrationCreateEvent",
"IntegrationDeleteEvent",
Expand All @@ -60,6 +61,7 @@
from hikari import guilds
from hikari import presences as presences_
from hikari import snowflakes
from hikari import stickers as stickers_
from hikari import users
from hikari import voices
from hikari.api import shard as gateway_shard
Expand Down Expand Up @@ -168,6 +170,9 @@ class GuildAvailableEvent(GuildVisibilityEvent):
The emojis in the guild.
"""

stickers: typing.Mapping[snowflakes.Snowflake, stickers_.GuildSticker] = attr.field(repr=False)
"""Mapping of sticker IDs to the stickers in the guild."""

roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
"""Mapping of role IDs to the roles in the guild.
Expand Down Expand Up @@ -259,6 +264,9 @@ class GuildJoinEvent(GuildVisibilityEvent):
emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
"""Mapping of emoji IDs to the emojis in the guild."""

stickers: typing.Mapping[snowflakes.Snowflake, stickers_.GuildSticker] = attr.field(repr=False)
"""Mapping of sticker IDs to the stickers in the guild."""

roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
"""Mapping of role IDs to the roles in the guild."""

Expand Down Expand Up @@ -373,6 +381,9 @@ class GuildUpdateEvent(GuildEvent):
The emojis in the guild.
"""

stickers: typing.Mapping[snowflakes.Snowflake, stickers_.GuildSticker] = attr.field(repr=False)
"""Mapping of sticker IDs to the stickers in the guild."""

roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
"""Mapping of role IDs to the roles in the guild.
Expand Down Expand Up @@ -523,6 +534,41 @@ async def fetch_emojis(self) -> typing.Sequence[emojis_.KnownCustomEmoji]:
return await self.app.rest.fetch_guild_emojis(self.guild_id)


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_EMOJIS)
class StickersUpdateEvent(GuildEvent):
"""Event that is fired when the emojis in a guild are updated."""

app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
# <<inherited docstring from Event>>.

shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
# <<inherited docstring from ShardEvent>>.

guild_id: snowflakes.Snowflake = attr.field()
# <<inherited docstring from GuildEvent>>.

old_stickers: typing.Optional[typing.Sequence[guilds.stickers.GuildSticker]] = attr.field()
"""Sequence of all old stickers in this guild.
This will be `builtins.None` if it's missing from the cache.
"""

stickers: typing.Sequence[guilds.stickers.GuildSticker] = attr.field()
"""Sequence of all stickers in this guild."""

async def fetch_stickers(self) -> typing.Sequence[guilds.stickers.GuildSticker]:
"""Perform an API call to retrieve an up-to-date view of the emojis.
Returns
-------
typing.Sequence[guilds.stickers.GuildSticker]
All emojis in the guild.
"""
return await self.app.rest.fetch_guild_stickers(self.guild_id)


@base_events.requires_intents(intents.Intents.GUILD_INTEGRATIONS)
class IntegrationEvent(GuildEvent, abc.ABC):
"""Event base for any integration related events."""
Expand Down
Loading

0 comments on commit dbbd8d1

Please sign in to comment.