855 协议版本-调整完毕内容
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import logging
|
||||
from loguru import logger
|
||||
import os
|
||||
import requests
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
||||
from utils.decorator.points_decorator import plugin_points_cost
|
||||
from wechat_ipad import WechatAPIClient
|
||||
|
||||
|
||||
class VideoPlugin(MessagePluginInterface):
|
||||
@@ -40,12 +40,13 @@ class VideoPlugin(MessagePluginInterface):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.bot: WechatAPIClient = None
|
||||
# 修改为使用插件目录下的down_load_dir文件夹
|
||||
self.download_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "down_load_dir")
|
||||
|
||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||
"""初始化插件"""
|
||||
self.LOG = logging.getLogger(f"Plugin.{self.name}")
|
||||
self.LOG = logger
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
@@ -56,7 +57,7 @@ class VideoPlugin(MessagePluginInterface):
|
||||
self._commands = self._config.get("Video", {}).get("command", ["黑丝视频", "黑丝", "来个黑丝", "搞个黑丝"])
|
||||
self.command_format = self._config.get("Video", {}).get("command-format", "黑丝")
|
||||
self.enable = self._config.get("Video", {}).get("enable", True)
|
||||
|
||||
|
||||
# 确保下载目录存在
|
||||
if not os.path.exists(self.download_dir):
|
||||
os.makedirs(self.download_dir, exist_ok=True)
|
||||
@@ -88,13 +89,14 @@ class VideoPlugin(MessagePluginInterface):
|
||||
|
||||
@plugin_stats_decorator(plugin_name="视频插件")
|
||||
@plugin_points_cost(2, "视频插件消耗积分", Feature.VIDEO)
|
||||
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
async def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
self.LOG.info(f"插件执行: {self.name}:{content}")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
self.bot: WechatAPIClient = message.get("bot")
|
||||
|
||||
# 检查权限
|
||||
if roomid and gbm.get_group_permission(roomid, Feature.VIDEO) == PermissionStatus.DISABLED:
|
||||
@@ -104,21 +106,21 @@ class VideoPlugin(MessagePluginInterface):
|
||||
# 下载视频
|
||||
save_path = os.path.join(self.download_dir, "video.mp4")
|
||||
file_abspath = self._download_stream("https://api.guiguiya.com/api/hook/heisis", save_path)
|
||||
|
||||
|
||||
if not file_abspath or not file_abspath.endswith("mp4"):
|
||||
self.message_util.send_text(f"\n❌视频下载失败,请稍后再试",
|
||||
(roomid if roomid else sender), sender)
|
||||
await self.bot.send_text_message((roomid if roomid else sender), f"\n❌视频下载失败,请稍后再试",
|
||||
sender)
|
||||
return False, "视频下载失败"
|
||||
|
||||
# 发送视频
|
||||
result = self.message_util.send_file(file_abspath, (roomid if roomid else sender))
|
||||
result = await self.bot.send_video_message((roomid if roomid else sender), file_abspath)
|
||||
self.LOG.info(f"发送视频结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理视频请求出错: {e}")
|
||||
self.message_util.send_text(f"\n❌请求出错:{e}",
|
||||
(roomid if roomid else sender), sender)
|
||||
await self.bot.send_text_message((roomid if roomid else sender), f"\n❌请求出错:{e}",
|
||||
sender)
|
||||
return False, f"处理出错: {e}"
|
||||
|
||||
def _download_stream(self, url, save_path):
|
||||
@@ -157,4 +159,4 @@ class VideoPlugin(MessagePluginInterface):
|
||||
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