Skip to content
Draft
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
6 changes: 3 additions & 3 deletions discord/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
if TYPE_CHECKING:
from .guild import Guild
from .state import ConnectionState
from .types.appinfo import AppInfo as AppInfoPayload
from .types.appinfo import AppInstallParams as AppInstallParamsPayload
from .types.appinfo import PartialAppInfo as PartialAppInfoPayload
from .types.appinfo import ApplicationInfo as AppInfoPayload
from .types.appinfo import ApplicationInstallParams as AppInstallParamsPayload
from .types.appinfo import PartialApplicationInfo as PartialAppInfoPayload
from .types.appinfo import Team as TeamPayload
from .user import User

Expand Down
6 changes: 3 additions & 3 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3267,17 +3267,17 @@ def get_answer_voters(

# Misc

def application_info(self) -> Response[appinfo.AppInfo]:
def application_info(self) -> Response[appinfo.ApplicationInfo]:
return self.request(Route("GET", "/oauth2/applications/@me"))

def edit_current_application_info(
self, payload: dict[str, Any]
) -> Response[appinfo.AppInfo]:
) -> Response[appinfo.ApplicationInfo]:
return self.request(Route("PATCH", "/applications/@me"), json=payload)

def get_application(
self, application_id: Snowflake, /
) -> Response[appinfo.PartialAppInfo]:
) -> Response[appinfo.PartialApplicationInfo]:
return self.request(
Route(
"GET",
Expand Down
4 changes: 2 additions & 2 deletions discord/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
from .message import Message
from .role import Role
from .state import ConnectionState
from .types.activity import PartialPresenceUpdate
from .types.activity import PresenceUpdate
from .types.member import Member as MemberPayload
from .types.member import MemberUpdateEvent as MemberUpdateEventPayload
from .types.member import MemberWithUser as MemberWithUserPayload
Expand Down Expand Up @@ -472,7 +472,7 @@ def _update(self, data: MemberPayload | MemberUpdateEventPayload) -> None:
self._avatar_decoration = data.get("avatar_decoration_data")

def _presence_update(
self, data: PartialPresenceUpdate, user: UserPayload
self, data: PresenceUpdate, user: UserPayload
) -> tuple[User, User] | None:
self.activities = tuple(map(create_activity, data["activities"]))
self._client_status = {
Expand Down
103 changes: 64 additions & 39 deletions discord/types/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,78 +35,103 @@
StatusType = Literal["idle", "dnd", "online", "offline"]


class PartialPresenceUpdate(TypedDict):
class PresenceUpdate(TypedDict):
"""The presence update *can* always be partial in that it contains a user with at least the id"""

user: PartialUser
guild_id: Snowflake
status: StatusType
activities: list[Activity]
client_status: ClientStatus


class ClientStatus(TypedDict, total=False):
desktop: str
mobile: str
web: str
vr: str
class ClientStatus(TypedDict):
"""Received from the gateway"""

desktop: NotRequired[str]
mobile: NotRequired[str]
web: NotRequired[str]
vr: NotRequired[str]


class ActivityTimestamps(TypedDict):
"""Received from the gateway as part of an :class:`Activity` object"""

start: NotRequired[int]
end: NotRequired[int]

class ActivityTimestamps(TypedDict, total=False):
start: int
end: int

class ActivityParty(TypedDict):
"""Received from the gateway as part of an :class:`Activity` object"""

class ActivityParty(TypedDict, total=False):
id: str
size: list[int]
id: NotRequired[str]
size: NotRequired[list[int]]


class ActivityAssets(TypedDict, total=False):
large_image: str
large_text: str
small_image: str
small_text: str
class ActivityAssets(TypedDict):
"""Received from the gateway as part of an :class:`Activity` object"""

large_image: NotRequired[str]
large_text: NotRequired[str]
large_url: NotRequired[str]
small_image: NotRequired[str]
small_text: NotRequired[str]
small_url: NotRequired[str]
invite_cover_image: NotRequired[str]

class ActivitySecrets(TypedDict, total=False):
join: str
spectate: str
match: str

class ActivitySecrets(TypedDict):
"""Received from the gateway as part of an :class:`Activity` object"""

join: NotRequired[str]
spectate: NotRequired[str]
match: NotRequired[str]


class ActivityEmoji(TypedDict):
"""Received from the gateway as part of an :class:`Activity` object"""

id: NotRequired[Snowflake]
animated: NotRequired[bool]
name: str


class ActivityButton(TypedDict):
"""Received from the gateway as part of an :class:`Activity` object"""

label: str
url: str


ActivityType = Literal[0, 1, 2, 4, 5]
ActivityType = Literal[0, 1, 2, 3, 4, 5]


class SendableActivity(TypedDict):
url: NotRequired[str | None]
"""Partial :class:`Activity` object that can be sent to the gateway, bot users can only set these fields"""

name: str
type: ActivityType
url: NotRequired[str | None]
state: NotRequired[str | None]


class _BaseActivity(SendableActivity):
created_at: int

class Activity(SendableActivity):
"""The full :class:`Activity` object received from the gateway"""

class Activity(_BaseActivity, total=False):
state: str | None
details: str | None
timestamps: ActivityTimestamps
assets: ActivityAssets
party: ActivityParty
application_id: Snowflake
flags: int
emoji: ActivityEmoji | None
secrets: ActivitySecrets
session_id: str | None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discord.activity:L590 and discord.activity:L859 still tend to you the session_id, should be dropped.

instance: bool
buttons: list[str]
created_at: int
timestamps: NotRequired[ActivityTimestamps]
application_id: NotRequired[Snowflake]
status_display_type: NotRequired[int | None]
details: NotRequired[str | None]
details_url: NotRequired[str | None]
state: NotRequired[str | None]
state_url: NotRequired[str | None]
emoji: NotRequired[ActivityEmoji | None]
party: NotRequired[ActivityParty]
assets: NotRequired[ActivityAssets]
secrets: NotRequired[ActivitySecrets]
instance: NotRequired[bool]
flags: NotRequired[int]
buttons: NotRequired[
list[str]
] # Technically an :class:`ActivityButton` object. Over the gateway, these are sent as strings
68 changes: 35 additions & 33 deletions discord/types/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,58 +38,60 @@
ApplicationEventWebhookStatus = Literal[1, 2, 3]


class AppInstallParams(TypedDict):
class ApplicationInstallParams(TypedDict):
scopes: list[str]
permissions: str


class ApplicationIntegrationTypeConfiguration(TypedDict, total=False):
oauth2_install_params: AppInstallParams
class ApplicationIntegrationTypeConfiguration(TypedDict):
oauth2_install_params: ApplicationInstallParams

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs lists the ouath2_install_params field as optional (and it was that when using total=False).
image



class BaseAppInfo(TypedDict):
class ApplicationInfo(TypedDict):
id: Snowflake
name: str
icon: str | None
description: str
verify_key: str

icon: NotRequired[str | None]
cover_image: NotRequired[str]
guild_id: NotRequired[Snowflake]
guild: NotRequired[Guild]
rpc_origins: NotRequired[list[str]]
bot_public: bool
bot_require_code_grant: bool
bot: NotRequired[PartialUser]
terms_of_service_url: NotRequired[str]
privacy_policy_url: NotRequired[str]
owner: NotRequired[PartialUser]
team: NotRequired[Team | None]
rpc_origins: NotRequired[list[str]]
bot_public: NotRequired[bool]
bot_require_code_grant: NotRequired[bool]
terms_of_service_url: NotRequired[str | None]
privacy_policy_url: NotRequired[str | None]
verify_key: str
team: Team | None
guild_id: NotRequired[Snowflake]
guild: NotRequired[Guild]
primary_sku_id: NotRequired[Snowflake]
slug: NotRequired[str]
cover_image: NotRequired[str]
flags: NotRequired[int]
flags_new: NotRequired[str]
approximate_guild_count: NotRequired[int]
approximate_user_install_count: NotRequired[int]
approximate_user_authorization_count: NotRequired[int]
redirect_uris: NotRequired[list[str]]
interactions_endpoint_url: NotRequired[str | None]
role_connections_verification_url: NotRequired[str | None]
event_webhooks_url: NotRequired[str | None]
event_webhooks_status: NotRequired[ApplicationEventWebhookStatus]
event_webhooks_types: NotRequired[list[str]]
tags: NotRequired[list[str]]
install_params: NotRequired[AppInstallParams]
custom_install_url: NotRequired[str]
install_params: NotRequired[ApplicationInstallParams]
integration_types_config: NotRequired[
dict[
ApplicationIntegrationType,
ApplicationIntegrationTypeConfiguration | None,
]
]
custom_install_url: NotRequired[str]


class PartialApplicationInfo(TypedDict):
"""Received from the gateway during the READY event."""

class AppInfo(BaseAppInfo, total=False):
primary_sku_id: Snowflake
slug: str
id: Snowflake
flags: int
approximate_guild_count: int
approximate_user_install_count: int
approximate_user_authorization_count: int
redirect_uris: list[str]
interactions_endpoint_url: str | None
role_connections_verification_url: str | None
event_webhooks_url: str | None
event_webhooks_status: ApplicationEventWebhookStatus
event_webhooks_types: list[str]


class PartialAppInfo(BaseAppInfo, total=False):
pass
flags_new: str
4 changes: 2 additions & 2 deletions discord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing_extensions import NotRequired, Required, TypedDict

from .activity import PartialPresenceUpdate
from .activity import PresenceUpdate
from .channel import GuildChannel
from .emoji import Emoji
from .member import Member
Expand Down Expand Up @@ -142,7 +142,7 @@ class Guild(_BaseGuildPreview):
voice_states: NotRequired[list[GuildVoiceState]]
members: NotRequired[list[Member]]
channels: NotRequired[list[GuildChannel]]
presences: NotRequired[list[PartialPresenceUpdate]]
presences: NotRequired[list[PresenceUpdate]]
threads: NotRequired[list[Thread]]
max_presences: NotRequired[int | None]
max_members: NotRequired[int]
Expand Down
6 changes: 3 additions & 3 deletions discord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing_extensions import NotRequired, TypedDict

from .appinfo import PartialAppInfo
from .appinfo import PartialApplicationInfo
from .channel import PartialChannel
from .guild import InviteGuild, _GuildPreviewUnique
from .role import Role
Expand Down Expand Up @@ -62,7 +62,7 @@ class Invite(IncompleteInvite):
scheduled_event: NotRequired[ScheduledEvent]
target_user: NotRequired[PartialUser]
target_type: NotRequired[InviteTargetType]
target_application: NotRequired[PartialAppInfo]
target_application: NotRequired[PartialApplicationInfo]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get it correctly, the docs state that target_application is not limited to those three fields (see link 2).

roles: NotRequired[list[Role]]


Expand All @@ -75,7 +75,7 @@ class GatewayInviteCreate(TypedDict):
inviter: NotRequired[PartialUser]
target_type: NotRequired[InviteTargetType]
target_user: NotRequired[PartialUser]
target_application: NotRequired[PartialAppInfo]
target_application: NotRequired[PartialApplicationInfo]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. It's clearly not only limited to id, flags and flags_new

channel_id: Snowflake
code: str
created_at: str
Expand Down
Loading