855 协议版本-调整完毕内容
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
import os
|
||||
import random
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
@@ -8,6 +10,7 @@ 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 XiurenImagePlugin(MessagePluginInterface):
|
||||
@@ -39,11 +42,12 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.image_folder = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "xiuren")
|
||||
self.image_folder = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||
"xiuren")
|
||||
|
||||
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} 插件...")
|
||||
|
||||
# 保存上下文对象
|
||||
@@ -86,13 +90,14 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
|
||||
@plugin_stats_decorator(plugin_name="秀人图片")
|
||||
@plugin_points_cost(2, "秀人图片消耗积分", Feature.PIC)
|
||||
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")
|
||||
bot: WechatAPIClient = message.get("bot")
|
||||
|
||||
# 检查权限
|
||||
if roomid and gbm.get_group_permission(roomid, Feature.PIC) == PermissionStatus.DISABLED:
|
||||
@@ -102,12 +107,13 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
# 获取随机图片
|
||||
pic_path = self._get_random_pic()
|
||||
if not pic_path:
|
||||
self.message_util.send_text(f"❌未找到图片资源",
|
||||
(roomid if roomid else sender), sender)
|
||||
await bot.send_text_message((roomid if roomid else sender), f"❌未找到图片资源",
|
||||
sender)
|
||||
return False, "未找到图片资源"
|
||||
|
||||
# 发送图片
|
||||
result = self.message_util.send_file(pic_path, (roomid if roomid else sender))
|
||||
|
||||
result = await bot.send_image_message((roomid if roomid else sender), Path(pic_path))
|
||||
self.LOG.info(f"发送图片结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user