优化代码,删除无效代码
This commit is contained in:
@@ -2,12 +2,12 @@ import os
|
||||
import random
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from message_util import MessageUtil
|
||||
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 BeautyLegPlugin(MessagePluginInterface):
|
||||
@@ -41,7 +41,7 @@ class BeautyLegPlugin(MessagePluginInterface):
|
||||
super().__init__()
|
||||
# 修改图片目录路径指向 resource/beauty_leg
|
||||
self.image_folder = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
|
||||
"resource", "beauty_leg")
|
||||
"resource", "beauty_leg")
|
||||
|
||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||
"""初始化插件"""
|
||||
@@ -49,7 +49,6 @@ class BeautyLegPlugin(MessagePluginInterface):
|
||||
|
||||
# 保存上下文对象
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util: MessageUtil = context.get("message_util")
|
||||
self.gbm = context.get("gbm")
|
||||
|
||||
self._commands = self._config.get("Beautyleg", {}).get("command", ["美腿", "腿来"])
|
||||
@@ -88,13 +87,14 @@ class BeautyLegPlugin(MessagePluginInterface):
|
||||
|
||||
@plugin_stats_decorator(plugin_name="美腿图片")
|
||||
@plugin_points_cost(2, "美腿图片消耗积分", Feature.BEAUTY_LEG)
|
||||
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.debug(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.BEAUTY_LEG) == PermissionStatus.DISABLED:
|
||||
@@ -104,14 +104,13 @@ class BeautyLegPlugin(MessagePluginInterface):
|
||||
# 获取随机图片
|
||||
random_file_path = self._get_random_file_from_dir(self.image_folder)
|
||||
if not random_file_path:
|
||||
self.message_util.send_text(f"\n❌未找到美腿图片资源",
|
||||
(roomid if roomid else sender), sender)
|
||||
await bot.send_text_message((roomid if roomid else sender), f"\n❌未找到美腿图片资源")
|
||||
return True, "未找到图片资源"
|
||||
|
||||
# 发送图片
|
||||
random_file_path = os.path.abspath(random_file_path)
|
||||
self.LOG.info(f"BeautyLeg.random_file_path: {random_file_path}")
|
||||
result = self.message_util.send_file(random_file_path, (roomid if roomid else sender))
|
||||
result = await bot.send_image_message((roomid if roomid else sender), random_file_path)
|
||||
self.LOG.info(f"发送图片结果: {result}")
|
||||
return True, "发送成功"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user