diff --git a/src/twitchclient/api.py b/src/twitchclient/api.py index 7447e18..9852396 100644 --- a/src/twitchclient/api.py +++ b/src/twitchclient/api.py @@ -880,3 +880,36 @@ class TwitchAPIClient(AioHTTPXClient): case _: raise s.Error(req.status_code, 'Internal Server Error') + + async def get_chat_settings( + self, + access_token: str, + broadcaster_id: int | str, + moderator_id: int | str | None = None, + cache_time: int | None = None, + ): + req = await self.get( + '/chat/settings', + headers=self.clean_dict( + { + 'Authorization': f'Bearer {access_token}', + 'X-Cache-TTL': cache_time, + } + ), + params=self.clean_dict( + { + 'broadcaster_id': broadcaster_id, + 'moderator_id': moderator_id, + } + ), + ) + + match req.status_code: + case st.OK: + return s.ChatSettings.model_validate(req.json()).data + + case st.BAD_REQUEST | 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 a4bf559..a72aa20 100644 --- a/src/twitchclient/schema.py +++ b/src/twitchclient/schema.py @@ -541,3 +541,25 @@ class ChannelChatBadges(BaseModel): class GlobalChatBadges(ChannelChatBadges): pass + + +class ChatSettingsData(BaseModel): + model_config = ConfigDict(extra='forbid') + + broadcaster_id: int + emote_mode: bool + follower_mode: bool + follower_mode_duration: int | None + moderator_id: int | None = None + non_moderator_chat_delay: bool | None = None + non_moderator_chat_delay_duration: int | None = None + slow_mode: bool + slow_mode_wait_time: int | None + subscriber_mode: bool + unique_chat_mode: bool + + +class ChatSettings(BaseModel): + model_config = ConfigDict(extra='forbid') + + data: list[ChatSettingsData]