临时调整权限模块,备份

This commit is contained in:
liuwei
2025-06-09 14:12:31 +08:00
parent cedab1cefd
commit 9d15bf965b
30 changed files with 882 additions and 138 deletions

View File

@@ -13,11 +13,16 @@ from base.plugin_common.plugin_interface import PluginStatus
from utils.decorator.plugin_decorators import plugin_stats_decorator
from utils.decorator.points_decorator import plugin_points_cost
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
from base.wechat_api.wechat_api_client import WechatAPIClient
class VideoManPlugin(MessagePluginInterface):
"""猛男视频插件"""
# 功能权限常量
FEATURE_KEY = "VIDEO_MAN"
FEATURE_DESCRIPTION = "💪 猛男视频功能 [猛男视频, 猛男, 来个猛男, 搞个猛男]"
@property
def name(self) -> str:
return "猛男视频"
@@ -42,10 +47,20 @@ class VideoManPlugin(MessagePluginInterface):
def commands(self) -> List[str]:
return self._commands
@property
def feature_key(self) -> Optional[str]:
return self.FEATURE_KEY
@property
def feature_description(self) -> Optional[str]:
return self.FEATURE_DESCRIPTION
def __init__(self):
super().__init__()
# 使用插件目录下的down_load_dir文件夹
self.download_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "down_load_dir")
# 注册功能权限
self.feature = self.register_feature()
def initialize(self, context: Dict[str, Any]) -> bool:
"""初始化插件"""
@@ -90,7 +105,7 @@ class VideoManPlugin(MessagePluginInterface):
return command in self._commands
@plugin_stats_decorator(plugin_name="猛男视频")
@plugin_points_cost(2, "猛男视频消耗积分", Feature.VIDEO_MAN)
@plugin_points_cost(2, "猛男视频消耗积分", FEATURE_KEY)
async def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
"""处理消息"""
content = str(message.get("content", "")).strip()
@@ -98,9 +113,10 @@ class VideoManPlugin(MessagePluginInterface):
sender = message.get("sender")
roomid = message.get("roomid", "")
gbm: GroupBotManager = message.get("gbm")
bot: WechatAPIClient = message.get("bot")
# 检查权限
if roomid and gbm.get_group_permission(roomid, Feature.VIDEO_MAN) == PermissionStatus.DISABLED:
if roomid and gbm.get_group_permission(roomid, self.feature) == PermissionStatus.DISABLED:
return False, "没有权限"
try:
@@ -108,12 +124,12 @@ class VideoManPlugin(MessagePluginInterface):
file_abspath, first_frame = await self._download_video("https://api.52vmy.cn/api/video/boy?type=json")
# FIXME 需要换成web容器地址。否则无法获取。
if not file_abspath:
await self.bot.send_text_message((roomid if roomid else sender), f"\n❌视频下载失败,请稍后再试",
await bot.send_text_message((roomid if roomid else sender), f"\n❌视频下载失败,请稍后再试",
sender)
return False, "视频下载失败"
# 发送视频
result = await self.bot.send_video_message((roomid if roomid else sender), Path(file_abspath),
result = await bot.send_video_message((roomid if roomid else sender), Path(file_abspath),
Path(first_frame))
self.LOG.info(f"发送视频结果: {result}")
return True, "发送成功"