mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
fix: qqbot wechatbot 模块循环依赖问题
This commit is contained in:
+40
-38
@@ -12,6 +12,7 @@ from typing import Optional, List, Tuple
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from app.core.cache import FileCache
|
from app.core.cache import FileCache
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo, Context
|
from app.core.context import MediaInfo, Context
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
@@ -33,13 +34,13 @@ class QQBot:
|
|||||||
"""QQ Bot 通知客户端"""
|
"""QQ Bot 通知客户端"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
QQ_APP_ID: Optional[str] = None,
|
QQ_APP_ID: Optional[str] = None,
|
||||||
QQ_APP_SECRET: Optional[str] = None,
|
QQ_APP_SECRET: Optional[str] = None,
|
||||||
QQ_OPENID: Optional[str] = None,
|
QQ_OPENID: Optional[str] = None,
|
||||||
QQ_GROUP_OPENID: Optional[str] = None,
|
QQ_GROUP_OPENID: Optional[str] = None,
|
||||||
name: Optional[str] = None,
|
name: Optional[str] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
初始化 QQ Bot
|
初始化 QQ Bot
|
||||||
@@ -98,14 +99,14 @@ class QQBot:
|
|||||||
|
|
||||||
def _forward_to_message_chain(self, payload: dict) -> None:
|
def _forward_to_message_chain(self, payload: dict) -> None:
|
||||||
"""直接调用消息链处理,避免 HTTP 开销"""
|
"""直接调用消息链处理,避免 HTTP 开销"""
|
||||||
|
|
||||||
def _run():
|
def _run():
|
||||||
try:
|
try:
|
||||||
# FIXME
|
# 回调
|
||||||
"""MessageChain().process(
|
RequestUtils(timeout=15).post_res(
|
||||||
body=payload,
|
f"http://127.0.0.1:{settings.PORT}/api/v1/message?token={settings.API_TOKEN}&source={self._config_name}",
|
||||||
form={},
|
json=payload
|
||||||
args={"source": self._config_name},
|
)
|
||||||
)"""
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"QQ Bot 转发消息失败: {e}")
|
logger.error(f"QQ Bot 转发消息失败: {e}")
|
||||||
|
|
||||||
@@ -234,10 +235,10 @@ class QQBot:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _format_message_markdown(
|
def _format_message_markdown(
|
||||||
title: Optional[str] = None,
|
title: Optional[str] = None,
|
||||||
text: Optional[str] = None,
|
text: Optional[str] = None,
|
||||||
image: Optional[str] = None,
|
image: Optional[str] = None,
|
||||||
link: Optional[str] = None,
|
link: Optional[str] = None,
|
||||||
) -> tuple:
|
) -> tuple:
|
||||||
"""
|
"""
|
||||||
将消息格式化为 QQ Markdown,类似 Telegram 处理方式
|
将消息格式化为 QQ Markdown,类似 Telegram 处理方式
|
||||||
@@ -271,14 +272,14 @@ class QQBot:
|
|||||||
return content, bool(content)
|
return content, bool(content)
|
||||||
|
|
||||||
def send_msg(
|
def send_msg(
|
||||||
self,
|
self,
|
||||||
title: str,
|
title: str,
|
||||||
text: Optional[str] = None,
|
text: Optional[str] = None,
|
||||||
image: Optional[str] = None,
|
image: Optional[str] = None,
|
||||||
link: Optional[str] = None,
|
link: Optional[str] = None,
|
||||||
userid: Optional[str] = None,
|
userid: Optional[str] = None,
|
||||||
targets: Optional[dict] = None,
|
targets: Optional[dict] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
发送 QQ 消息
|
发送 QQ 消息
|
||||||
@@ -303,7 +304,8 @@ class QQBot:
|
|||||||
targets_to_send = broadcast
|
targets_to_send = broadcast
|
||||||
logger.debug(f"QQ Bot: 广播模式,共 {len(targets_to_send)} 个目标")
|
logger.debug(f"QQ Bot: 广播模式,共 {len(targets_to_send)} 个目标")
|
||||||
else:
|
else:
|
||||||
logger.warn("QQ Bot: 未指定接收者且无互动用户,请在配置中设置 QQ_OPENID/QQ_GROUP_OPENID 或先让用户发消息")
|
logger.warn(
|
||||||
|
"QQ Bot: 未指定接收者且无互动用户,请在配置中设置 QQ_OPENID/QQ_GROUP_OPENID 或先让用户发消息")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 使用 Markdown 格式发送(类似 Telegram)
|
# 使用 Markdown 格式发送(类似 Telegram)
|
||||||
@@ -349,12 +351,12 @@ class QQBot:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def send_medias_msg(
|
def send_medias_msg(
|
||||||
self,
|
self,
|
||||||
medias: List[MediaInfo],
|
medias: List[MediaInfo],
|
||||||
userid: Optional[str] = None,
|
userid: Optional[str] = None,
|
||||||
title: Optional[str] = None,
|
title: Optional[str] = None,
|
||||||
link: Optional[str] = None,
|
link: Optional[str] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""发送媒体列表(转为文本)"""
|
"""发送媒体列表(转为文本)"""
|
||||||
if not medias:
|
if not medias:
|
||||||
@@ -370,12 +372,12 @@ class QQBot:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def send_torrents_msg(
|
def send_torrents_msg(
|
||||||
self,
|
self,
|
||||||
torrents: List[Context],
|
torrents: List[Context],
|
||||||
userid: Optional[str] = None,
|
userid: Optional[str] = None,
|
||||||
title: Optional[str] = None,
|
title: Optional[str] = None,
|
||||||
link: Optional[str] = None,
|
link: Optional[str] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""发送种子列表(转为文本)"""
|
"""发送种子列表(转为文本)"""
|
||||||
if not torrents:
|
if not torrents:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from app.core.config import settings
|
|||||||
from app.core.context import MediaInfo, Context
|
from app.core.context import MediaInfo, Context
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
|
|
||||||
@@ -356,19 +357,16 @@ class WeChatBot:
|
|||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f"收到来自 {self._config_name} 的企业微信智能机器人消息:userid={sender}, text={text}")
|
logger.info(f"收到来自 {self._config_name} 的企业微信智能机器人消息:userid={sender}, text={text}")
|
||||||
self._forward_to_message_chain(userid=sender, text=text)
|
self._forward_to_message_chain(payload)
|
||||||
|
|
||||||
def _forward_to_message_chain(self, userid: str, text: str) -> None:
|
def _forward_to_message_chain(self, payload: dict) -> None:
|
||||||
def _run():
|
def _run():
|
||||||
try:
|
try:
|
||||||
# FIXME
|
# 回调
|
||||||
"""MessageChain().handle_message(
|
RequestUtils(timeout=15).post_res(
|
||||||
channel=MessageChannel.Wechat,
|
f"http://127.0.0.1:{settings.PORT}/api/v1/message?token={settings.API_TOKEN}&source={self._config_name}",
|
||||||
source=self._config_name,
|
json=payload
|
||||||
userid=userid,
|
)
|
||||||
username=userid,
|
|
||||||
text=text,
|
|
||||||
)"""
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"企业微信智能机器人转发消息失败:{err}")
|
logger.error(f"企业微信智能机器人转发消息失败:{err}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user