Skip to content

Commit

Permalink
fix typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Sep 23, 2024
1 parent e4e27c0 commit fc05d78
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions disnake/interactions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from ..poll import Poll
from ..state import ConnectionState
from ..types.components import Modal as ModalPayload
from ..types.guild import PartialGuild as PartialGuildPayload
from ..types.interactions import (
ApplicationCommandOptionChoice as ApplicationCommandOptionChoicePayload,
Interaction as InteractionPayload,
Expand Down Expand Up @@ -204,7 +205,7 @@ def __init__(self, *, data: InteractionPayload, state: ConnectionState) -> None:
self.version: int = data["version"]
self.application_id: int = int(data["application_id"])
self.guild_id: Optional[int] = utils._get_as_snowflake(data, "guild_id")
self._guild: Optional[Mapping[str, Any]] = data.get("guild")
self._guild: Optional[PartialGuildPayload] = data.get("guild")

self.locale: Locale = try_enum(Locale, data["locale"])
guild_locale = data.get("guild_locale")
Expand Down Expand Up @@ -275,12 +276,20 @@ def guild(self) -> Optional[Guild]:
guild = self._state._get_guild(self.guild_id)
if guild:
return guild
if self._guild is None:
return None

# create a guild mash
# honestly we should cache this for the duration of the interaction
# but not if we fetch it from the cache, just the result of this creation
guild = Guild(data=self._guild, state=self._state)
guild._add_role(Role(state=self._state, guild=guild, data={"id": 1, "name": "@everyone"}))
guild._add_role(
Role(
state=self._state,
guild=guild,
data={"id": 1, "name": "@everyone"}, # type: ignore
)
)
return guild

@utils.cached_slot_property("_cs_me")
Expand Down
4 changes: 4 additions & 0 deletions disnake/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class Guild(_BaseGuildPreview):
guild_scheduled_events: NotRequired[List[GuildScheduledEvent]]


class PartialGuild(Guild, total=False):
pass


class InviteGuild(Guild, total=False):
welcome_screen: WelcomeScreen

Expand Down
2 changes: 2 additions & 0 deletions disnake/types/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .components import Component, Modal
from .embed import Embed
from .entitlement import Entitlement
from .guild import PartialGuild
from .i18n import LocalizationDict
from .member import Member, MemberWithUser
from .role import Role
Expand Down Expand Up @@ -265,6 +266,7 @@ class _BaseUserInteraction(_BaseInteraction):
locale: str
app_permissions: NotRequired[str]
guild_id: NotRequired[Snowflake]
guild: NotRequired[PartialGuild]
guild_locale: NotRequired[str]
entitlements: NotRequired[List[Entitlement]]
# one of these two will always exist, according to docs
Expand Down

0 comments on commit fc05d78

Please sign in to comment.