feature:1.加群功能插件化;2.成员变更不监听消息,使用定时检查策略;
This commit is contained in:
+15
-16
@@ -5,6 +5,7 @@ from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from wcferry import Wcf
|
||||
|
||||
from message_util import MessageUtil
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from plugins.stats_collector.decorators import plugin_stats_decorator
|
||||
@@ -51,13 +52,13 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
# 保存上下文对象
|
||||
self.wcf = context.get("wcf")
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
|
||||
self._commands = self._config.get("VideoMan", {}).get("command", ["猛男", "肌肉", "帅哥"])
|
||||
self.command_format = self._config.get("VideoMan", {}).get("command-format", "猛男")
|
||||
self.enable = self._config.get("VideoMan", {}).get("enable", True)
|
||||
|
||||
|
||||
# 确保下载目录存在
|
||||
if not os.path.exists(self.download_dir):
|
||||
os.makedirs(self.download_dir, exist_ok=True)
|
||||
@@ -104,10 +105,10 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
try:
|
||||
# 下载视频
|
||||
file_abspath = self._download_video("https://api.guiguiya.com/api/video/fuji?type=json")
|
||||
|
||||
|
||||
if not file_abspath:
|
||||
wcf.send_text(f"\n❌视频下载失败,请稍后再试",
|
||||
(roomid if roomid else sender), sender)
|
||||
self.message_util.send_text_msg(f"\n❌视频下载失败,请稍后再试",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, "视频下载失败"
|
||||
|
||||
# 发送视频
|
||||
@@ -117,8 +118,6 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理视频请求出错: {e}")
|
||||
wcf.send_text(f"\n❌请求出错:{e}",
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"处理出错: {e}"
|
||||
|
||||
def _download_video(self, api_url):
|
||||
@@ -130,43 +129,43 @@ class VideoManPlugin(MessagePluginInterface):
|
||||
# 确保下载目录存在
|
||||
if not os.path.exists(self.download_dir):
|
||||
os.makedirs(self.download_dir, exist_ok=True)
|
||||
|
||||
|
||||
save_path = os.path.join(self.download_dir, "video.mp4")
|
||||
|
||||
|
||||
try:
|
||||
# 获取视频URL
|
||||
response = requests.get(api_url)
|
||||
if response.status_code != 200:
|
||||
self.LOG.error(f"API请求失败,HTTP状态码: {response.status_code}")
|
||||
return None
|
||||
|
||||
|
||||
data = response.json()
|
||||
video_url = data.get("url")
|
||||
if not video_url:
|
||||
self.LOG.error("API响应中没有找到视频URL")
|
||||
return None
|
||||
|
||||
|
||||
# 下载视频
|
||||
video_response = requests.get(video_url, stream=True)
|
||||
if video_response.status_code != 200:
|
||||
self.LOG.error(f"无法下载视频,HTTP状态码: {video_response.status_code}")
|
||||
return None
|
||||
|
||||
|
||||
# 保存视频
|
||||
with open(save_path, "wb") as file:
|
||||
for chunk in video_response.iter_content(chunk_size=1024):
|
||||
if chunk: # 过滤空块
|
||||
file.write(chunk)
|
||||
|
||||
|
||||
abs_path = os.path.abspath(save_path)
|
||||
self.LOG.info(f"视频已下载至: {abs_path}")
|
||||
return abs_path
|
||||
|
||||
|
||||
except requests.RequestException as e:
|
||||
self.LOG.error(f"请求失败: {e}")
|
||||
except IOError as e:
|
||||
self.LOG.error(f"文件写入失败: {e}")
|
||||
except Exception as e:
|
||||
self.LOG.error(f"发生未知错误: {e}")
|
||||
|
||||
return None
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user