feat: gate media downloads by group and retry douyu checks
This commit is contained in:
@@ -532,16 +532,21 @@ class MessageStorageDB(BaseDBOperator):
|
||||
|
||||
return self.execute_query(sql, tuple(params)) or []
|
||||
|
||||
def get_pending_media_messages(self, minutes_ago: int = 10, limit: int = 50) -> List[Dict]:
|
||||
def get_pending_media_messages(self, minutes_ago: int = 10, limit: int = 50,
|
||||
group_ids: Optional[List[str]] = None) -> List[Dict]:
|
||||
"""获取最近N分钟内未处理图片/表情消息(image_path IS NULL)
|
||||
|
||||
Args:
|
||||
minutes_ago: 查询最近多少分钟的消息,默认10分钟
|
||||
limit: 每次最多处理多少条,默认50条
|
||||
group_ids: 限制只查询指定群组,传空列表则直接返回空
|
||||
|
||||
Returns:
|
||||
包含消息ID、群ID、消息XML等信息的列表
|
||||
"""
|
||||
if group_ids is not None and not group_ids:
|
||||
return []
|
||||
|
||||
sql = """
|
||||
SELECT message_id, group_id, sender, message_type, message_xml, timestamp, attachment_url
|
||||
FROM messages
|
||||
@@ -553,7 +558,12 @@ class MessageStorageDB(BaseDBOperator):
|
||||
ORDER BY timestamp ASC
|
||||
LIMIT %s
|
||||
"""
|
||||
params = (minutes_ago, limit)
|
||||
params: List = [minutes_ago]
|
||||
if group_ids is not None:
|
||||
placeholders = ", ".join(["%s"] * len(group_ids))
|
||||
sql = sql.replace("ORDER BY timestamp ASC", f"AND group_id IN ({placeholders})\n ORDER BY timestamp ASC")
|
||||
params.extend(group_ids)
|
||||
params.append(limit)
|
||||
return self.execute_query(sql, params) or []
|
||||
|
||||
def get_pending_image_messages(self, minutes_ago: int = 10, limit: int = 50) -> List[Dict]:
|
||||
|
||||
Reference in New Issue
Block a user