From 9d80ad7d694717a0fd53e39c2805a27562e70036 Mon Sep 17 00:00:00 2001 From: Miwory Date: Thu, 11 Dec 2025 17:14:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20get=5Fuser=5Femotes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/twitchclient/api.py | 35 +++++++++++++++++++++++++++++++++++ src/twitchclient/schema.py | 21 ++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/twitchclient/api.py b/src/twitchclient/api.py index 05f9dff..941e7f8 100644 --- a/src/twitchclient/api.py +++ b/src/twitchclient/api.py @@ -940,3 +940,38 @@ class TwitchAPIClient(AioHTTPXClient): case _: raise s.Error(req.status_code, 'Internal Server Error') + + async def get_user_emotes( + self, + access_token: str, + user_id: int | str, + after: str | None = None, + broadcaster_id: int | str | None = None, + cache_time: int | None = None, + ): + req = await self.get( + '/chat/emotes/global', + headers=self.clean_dict( + { + 'Authorization': f'Bearer {access_token}', + 'X-Cache-TTL': cache_time, + } + ), + params=self.clean_dict( + { + 'user_id': user_id, + 'after': after, + 'broadcaster_id': broadcaster_id, + } + ), + ) + + match req.status_code: + case st.OK: + return s.UserEmotes.model_validate(req.json()) + + case st.UNAUTHORIZED: + raise s.Error(req.status_code, req.json()['message']) + + case _: + raise s.Error(req.status_code, 'Internal Server Error') diff --git a/src/twitchclient/schema.py b/src/twitchclient/schema.py index fc05553..3b533b6 100644 --- a/src/twitchclient/schema.py +++ b/src/twitchclient/schema.py @@ -492,7 +492,22 @@ class ChannelEmote(BaseModel): name: str images: ChannelEmoteImages tier: int - emote_type: Literal['bitstier', 'follower', 'subscriptions'] + emote_type: Literal[ + 'none', + 'bitstier', + 'follower', + 'subscriptions', + 'channelpoints', + 'rewards', + 'hypetrain', + 'prime', + 'turbo', + 'smilies', + 'globals', + 'owl2019', + 'twofactor', + 'limitedtime' + ] format: list[Literal['animated', 'static']] scale: list[Literal['1.0', '2.0', '3.0']] theme_mode: list[Literal['dark', 'light']] @@ -585,3 +600,7 @@ class SharedChatSession(BaseModel): model_config = ConfigDict(extra='forbid') data: list[SharedChatSessionData] + + +class UserEmotes(ChannelEmotes): + pagination: Pagination | dict[Any, Any] | None = None