Добавлены update_user_chat_color, create_clip, get_clips
This commit is contained in:
@ -1145,3 +1145,94 @@ class TwitchAPIClient(AioHTTPXClient):
|
||||
|
||||
case _:
|
||||
raise s.Error(req.status_code, 'Internal Server Error')
|
||||
|
||||
async def update_user_chat_color(
|
||||
self,
|
||||
access_token: str,
|
||||
user_id: int | str,
|
||||
color: str,
|
||||
):
|
||||
req = await self.put(
|
||||
'/chat/color',
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
params={'user_id': user_id, 'color': color},
|
||||
)
|
||||
|
||||
match req.status_code:
|
||||
case st.NO_CONTENT:
|
||||
return True
|
||||
|
||||
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')
|
||||
|
||||
async def create_clip(
|
||||
self,
|
||||
access_token: str,
|
||||
broadcaster_id: int | str,
|
||||
*,
|
||||
has_delay: bool | None = None,
|
||||
):
|
||||
req = await self.post(
|
||||
'/clips',
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
params=self.clean_dict(
|
||||
{'broadcaster_id': broadcaster_id, 'has_delay': has_delay}
|
||||
),
|
||||
)
|
||||
|
||||
match req.status_code:
|
||||
case st.ACCEPTED:
|
||||
return True
|
||||
|
||||
case (
|
||||
st.BAD_REQUEST | st.UNAUTHORIZED | st.FORBIDDEN | st.NOT_FOUND
|
||||
):
|
||||
raise s.Error(req.status_code, req.json()['message'])
|
||||
|
||||
case _:
|
||||
raise s.Error(req.status_code, 'Internal Server Error')
|
||||
|
||||
async def get_clips(
|
||||
self,
|
||||
access_token: str,
|
||||
broadcaster_id: int | str | None = None,
|
||||
game_id: int | str | None = None,
|
||||
clip_id: str | list[str] | None = None,
|
||||
started_at: datetime | None = None,
|
||||
ended_at: datetime | None = None,
|
||||
first: int = 20,
|
||||
before: str | None = None,
|
||||
after: str | None = None,
|
||||
*,
|
||||
is_featured: bool | None = None,
|
||||
):
|
||||
req = await self.get(
|
||||
'/clips',
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
params=self.clean_dict(
|
||||
{
|
||||
'broadcaster_id': broadcaster_id,
|
||||
'game_id': game_id,
|
||||
'clip_id': clip_id,
|
||||
'started_at': started_at,
|
||||
'ended_at': ended_at,
|
||||
'first': first,
|
||||
'before': before,
|
||||
'after': after,
|
||||
'is_featured': is_featured,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
match req.status_code:
|
||||
case st.OK:
|
||||
return s.Clips.model_validate(req.json()).data
|
||||
|
||||
case st.BAD_REQUEST | st.UNAUTHORIZED | st.NOT_FOUND:
|
||||
raise s.Error(req.status_code, req.json()['message'])
|
||||
|
||||
case _:
|
||||
raise s.Error(req.status_code, 'Internal Server Error')
|
||||
|
||||
@ -640,3 +640,32 @@ class UserChatColor(BaseModel):
|
||||
model_config = ConfigDict(extra='forbid')
|
||||
|
||||
data: list[UserChatColorData]
|
||||
|
||||
|
||||
class Clip(BaseModel):
|
||||
model_config = ConfigDict(extra='forbid')
|
||||
|
||||
id: str
|
||||
url: str
|
||||
embed_url: str
|
||||
broadcaster_id: int
|
||||
broadcaster_name: str
|
||||
creator_id: int
|
||||
creator_name: str
|
||||
video_id: str
|
||||
game_id: int
|
||||
language: str
|
||||
title: str
|
||||
view_count: int
|
||||
created_at: datetime
|
||||
thumbnail_url: str
|
||||
duration: float
|
||||
vod_offset: int | None
|
||||
is_featured: bool
|
||||
|
||||
|
||||
class Clips(BaseModel):
|
||||
model_config = ConfigDict(extra='forbid')
|
||||
|
||||
data: list[Clip]
|
||||
pagination: Pagination | dict[Any, Any] | None = None
|
||||
|
||||
Reference in New Issue
Block a user