美腿功能

This commit is contained in:
liuwei
2025-03-10 09:39:59 +08:00
parent 93d0982ba3
commit 5505319918
4 changed files with 95 additions and 0 deletions

82
beautyleg/beauty_leg.py Normal file
View File

@@ -0,0 +1,82 @@
import logging
import os
import random
import tomllib
import requests
from wcferry import WxMsg, Wcf
from robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
import lz4.block as lb
class BeautyLeg:
def __init__(self, wcf: Wcf, gbm: GroupBotManager):
self.LOG = logging.getLogger(__name__)
self.wcf = wcf # 假设 wcf 对象在此类中初始化
self.gbm = gbm # 权限功能
with open("beautyleg/config.toml", "rb") as f:
plugin_config = tomllib.load(f)
config = plugin_config["Beautyleg"]
self.enable = config["enable"]
self.command = config["command"]
self.LOG.info(f"[美腿] 组件初始化完成,指令: {self.command}")
import requests
def get_random_file_from_dir(self, directory):
image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp'}
image_files = []
if not os.path.exists(directory):
print(f"Error: Directory '{directory}' does not exist.")
return None
if not os.access(directory, os.R_OK):
print(f"Error: No read access to directory '{directory}'.")
return None
print(f"Scanning directory: {directory} (including subdirectories)")
# 使用 os.walk() 递归遍历所有子目录
for root, _, files in os.walk(directory):
for file in files:
_, ext = os.path.splitext(file)
if ext.lower() in image_extensions:
full_path = os.path.join(root, file)
image_files.append(full_path)
if not image_files:
print("No image files found in the directory (including subdirectories).")
return None
return random.choice(image_files)
def handle_message(self, message: WxMsg):
if not self.enable:
return
content = str(message.content).strip()
command = content.split(" ")
if command[0] not in self.command:
return
if len(command) == 1:
self.wcf.send_text(f"-----Bot-----\n❌命令格式错误!{self.command}",
(message.roomid if message.from_group() else message.sender), message.sender)
return
# 如果触发了指令,但是没有权限,则返回权限不足
if self.gbm.get_group_permission(message.roomid, Feature.BEAUTY_LEG) == PermissionStatus.DISABLED:
return
# 使用示例
directory = 'beautyleg/download_dir' # 替换为你的目录路径
random_file_path = self.get_random_file_from_dir(directory)
if random_file_path:
return self.wcf.send_file(os.path.abspath(random_file_path), message.roomid)
else:
return None

3
beautyleg/config.toml Normal file
View File

@@ -0,0 +1,3 @@
[Beautyleg]
enable = true
command = ["美腿", "腿来"]

View File

@@ -24,6 +24,7 @@ from base.func_news import News
from base.func_tigerbot import TigerBot
from base.func_xinghuo_web import XinghuoWeb
from base.func_claude import Claude
from beautyleg.beauty_leg import BeautyLeg
from configuration import Config
from constants import ChatType
from game_task.game_task_encyclopedia import game_process_message, setup_schedule, get_group_ids, \
@@ -90,6 +91,8 @@ class Robot(Job):
self.video = BotVideo(wcf, self.gbm)
# 秀人模块
self.xiuren = Xiuren(wcf, self.gbm)
# 美腿模块
self.beautyleg = BeautyLeg(wcf, self.gbm)
if ChatType.is_in_chat_types(chat_type):
if chat_type == ChatType.TIGER_BOT.value and TigerBot.value_check(self.config.TIGERBOT):
@@ -351,6 +354,12 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"xiuren.handle_message error: {e}")
# 美腿功能
try:
self.beautyleg.handle_message(message=msg)
except Exception as e:
self.LOG.error(f"beautyleg.handle_text error: {e}")
if msg.is_at(self.wxid): # 被@
self.toAt(msg)
return # 处理完群聊信息,后面就不需要处理了

View File

@@ -34,6 +34,7 @@ class Feature(Enum):
MUSIC = 10, "点歌功能"
SIGNIN = 11, "签到功能"
POINT_TRADE = 12, "积分赠送功能"
BEAUTY_LEG = 13, "腿来能力"
VIDEO = 14, "视频点播功能"
def __new__(cls, value, description):