From 99be4cbab2c881481fbce0f6ee85714cc89b07cd Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 18 Feb 2025 22:11:35 +0100 Subject: [PATCH] Fix --- .../stream_notifications/messages_proc.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/modules/stream_notifications/messages_proc.py b/src/modules/stream_notifications/messages_proc.py index 682b4c0..fa90553 100644 --- a/src/modules/stream_notifications/messages_proc.py +++ b/src/modules/stream_notifications/messages_proc.py @@ -93,7 +93,7 @@ class MessageEvent(BaseModel): -async def get_completion(message: str): +async def get_completion(message: str) -> str: async with AsyncClient() as client: response = await client.post( "https://openrouter.ai/api/v1/chat/completions", @@ -143,15 +143,16 @@ class MessagesProc: try: completion = await get_completion(event.message.text) - if not completion: - completion = "Пошел нахуй!" + max_length = 255 + completion_parts = [completion[i:i + max_length] for i in range(0, len(completion), max_length)] - await twitch.send_chat_message( - event.broadcaster_user_id, - config.TWITCH_ADMIN_USER_ID, - completion, - reply_parent_message_id=event.message_id - ) + for part in completion_parts: + await twitch.send_chat_message( + event.broadcaster_user_id, + config.TWITCH_ADMIN_USER_ID, + part, + reply_parent_message_id=event.message_id + ) except Exception as e: logger.error(f"Failed to get completion: {e}")