mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
Address code review feedback
- Add validation to ensure only one context parameter is provided in get_message_by_id - Simplify logger check in error handling Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com>
This commit is contained in:
@@ -291,6 +291,15 @@ class QQOfficialClient:
|
||||
"""
|
||||
if not await self.check_access_token():
|
||||
await self.get_access_token()
|
||||
|
||||
# Validate that exactly one context parameter is provided
|
||||
provided_contexts = sum([bool(channel_id), bool(group_openid), bool(user_openid)])
|
||||
if provided_contexts == 0:
|
||||
await self.logger.warning(f'Cannot fetch message {message_id}: no context provided')
|
||||
return {}
|
||||
if provided_contexts > 1:
|
||||
await self.logger.warning(f'Cannot fetch message {message_id}: multiple contexts provided')
|
||||
return {}
|
||||
|
||||
# Determine which API endpoint to use based on provided parameters
|
||||
if channel_id:
|
||||
@@ -302,9 +311,6 @@ class QQOfficialClient:
|
||||
elif user_openid:
|
||||
# Private message
|
||||
url = f'{self.base_url}/v2/users/{user_openid}/messages/{message_id}'
|
||||
else:
|
||||
await self.logger.warning(f'Cannot fetch message {message_id}: no valid context provided')
|
||||
return {}
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
headers = {
|
||||
|
||||
@@ -70,7 +70,7 @@ class QQOfficialMessageConverter(abstract_platform_adapter.AbstractMessageConver
|
||||
content_type=attachment.get('content_type', '')
|
||||
)
|
||||
quoted_chain.append(platform_message.Image(base64=img_base64))
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
# If image fetch fails, just skip it
|
||||
pass
|
||||
|
||||
@@ -89,8 +89,7 @@ class QQOfficialMessageConverter(abstract_platform_adapter.AbstractMessageConver
|
||||
)
|
||||
except Exception as e:
|
||||
# If fetching quoted message fails, log and continue
|
||||
if self.bot and hasattr(self.bot, 'logger'):
|
||||
await self.bot.logger.warning(f'Failed to fetch quoted message {referenced_msg_id}: {e}')
|
||||
await self.bot.logger.warning(f'Failed to fetch quoted message {referenced_msg_id}: {e}')
|
||||
|
||||
if pic_url is not None:
|
||||
base64_url = await image.get_qq_official_image_base64(pic_url=pic_url, content_type=content_type)
|
||||
|
||||
Reference in New Issue
Block a user