From 77fea1c9e43f3f0c1f486380eee483e7259e3cbf Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 19 Mar 2025 15:08:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=80=E4=BA=BA=E5=9B=BE=E7=89=87=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=8C=96=E6=94=B9=E9=80=A0=E5=AE=8C=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/xiuren_image/main.py | 40 +++++++++++++++------- robot.py | 66 ------------------------------------ 2 files changed, 28 insertions(+), 78 deletions(-) diff --git a/plugins/xiuren_image/main.py b/plugins/xiuren_image/main.py index 1cb64e6..654782b 100644 --- a/plugins/xiuren_image/main.py +++ b/plugins/xiuren_image/main.py @@ -124,20 +124,36 @@ class XiurenImagePlugin(MessagePluginInterface): if not os.path.exists(self.image_folder): self.LOG.error(f"图片文件夹不存在: {self.image_folder}") return None - - image_files = [f for f in os.listdir(self.image_folder) - if f.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp'))] - - if not image_files: - self.LOG.error("图片文件夹中没有图片") + image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp'} + image_files = [] + if not os.path.exists(self.image_folder): + print(f"Error: Directory '{self.image_folder}' does not exist.") + return None + + if not os.access(self.image_folder, os.R_OK): + print(f"Error: No read access to directory '{self.image_folder}'.") + return None + + print(f"Scanning directory: {self.image_folder} (including subdirectories)") + + # 使用 os.walk() 递归遍历所有子目录 + for root, _, files in os.walk(self.image_folder): + 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 - # 随机选择一张图片 random_pic = random.choice(image_files) - pic_path = os.path.join(self.image_folder, random_pic) - - return pic_path - + if random_pic: + return os.path.abspath(random_pic) + else: + return None + except Exception as e: self.LOG.error(f"获取随机图片出错: {e}") - return None \ No newline at end of file + return None diff --git a/robot.py b/robot.py index 0f021d9..cbcc563 100644 --- a/robot.py +++ b/robot.py @@ -34,7 +34,6 @@ from group_video_man.bot_video_man import BotVideoMan from message_sign.main import SignInSystem from message_storage.message_to_db import MessageStorage from message_summary.message_summary_dify import message_summary_dify -from music.bot_music import BotMusic from plugin_common.event_system import EventType, EventSystem from plugin_common.message_plugin_interface import MessagePluginInterface from plugin_common.plugin_interface import PluginStatus @@ -49,7 +48,6 @@ from robot_cmd.robot_command import PermissionStatus __version__ = "39.2.4.0" from sehuatang.shehuatang import pdf_file_path -from xiuren.main import Xiuren from xiuren.meitu_dl import meitu_dowload_pub_pic from xiuren.random_pic import get_xiuren_heisi_pic from xiuren.xiuren_pdf import generate_pdf_from_images @@ -123,8 +121,6 @@ class Robot(Job): self.message_storage = MessageStorage() # 群成员变更模块加载 self.gmc = GroupMemberChange(wcf, self.redis_pool) - # # 点歌模块加载 - # self.music = BotMusic(wcf, self.gbm) # 签到模块加载 self.signin = SignInSystem(wcf, self.gbm, self.allContacts, self.db_pool, self.redis_pool, self.message_util) # 积分赠送功能加载 @@ -133,8 +129,6 @@ class Robot(Job): self.video = BotVideo(wcf, self.gbm) # 肌肉男视频 self.videoman = BotVideoMan(wcf, self.gbm) - # 秀人模块 - self.xiuren = Xiuren(wcf, self.gbm) # 美腿模块 self.beautyleg = BeautyLeg(wcf, self.gbm) # 加群测试 @@ -241,17 +235,6 @@ class Robot(Job): elif q == '#总结': self.message_summary_robot((msg.roomid if msg.from_group() else msg.sender)) return True - # 暂时只支持4K群要图 - elif q == "#黑丝": - if self.gbm.get_group_permission(msg.roomid, Feature.PIC) == PermissionStatus.DISABLED: - return True - else: - try: - file_path = get_xiuren_heisi_pic() - self.wcf.send_file(file_path, msg.roomid) - except Exception as e: - self.LOG.error(f"黑丝发图出错:{e}") - return True # 如果正则匹配到时加群指令,则从库中提取第一个群ID elif match: try: @@ -345,11 +328,6 @@ class Robot(Job): except Exception as e: self.LOG.error(f"group_member_change error: {e}") - # try: - # self.music.get_music(message=msg) - # except Exception as e: - # self.LOG.error(f"get_music error: {e}") - try: self.signin.member_sign_in(message=msg) except Exception as e: @@ -372,13 +350,6 @@ class Robot(Job): self.videoman.get_video(message=msg) except Exception as e: self.LOG.error(f"videoman get_video error: {e}") - - # 加入秀人图来功能 - try: - self.xiuren.handle_message(message=msg) - except Exception as e: - self.LOG.error(f"xiuren.handle_message error: {e}") - # 美腿功能 try: self.beautyleg.handle_message(message=msg) @@ -587,43 +558,6 @@ class Robot(Job): self.LOG.error(f"插件 {plugin.name} 处理消息失败: {e}") return False - # - # def _start_stats_dashboard(self) -> None: - # """启动统计看板服务器""" - # try: - # # 检查是否已加载统计看板插件 - # if 'stats_dashboard' in self.plugins: - # dashboard_plugin = self.plugins['stats_dashboard'] - # if hasattr(dashboard_plugin, 'start_server'): - # dashboard_plugin.start_server() - # self.LOG.info("统计看板服务器已启动") - # # 获取本地IP地址 - # import socket - # hostname = socket.gethostname() - # local_ip = socket.gethostbyname(hostname) - # - # # 获取配置信息 - # if hasattr(dashboard_plugin, 'config'): - # host = dashboard_plugin.config.get("host", "127.0.0.1") - # port = dashboard_plugin.config.get("port", 8080) - # username = dashboard_plugin.config.get("username", "admin") - # password = dashboard_plugin.config.get("password", "admin123") - # - # # 在控制台输出访问信息 - # print("\n" + "="*50) - # print("统计看板服务器已启动") - # print(f"本地访问地址: http://127.0.0.1:{port}") - # print(f"局域网访问地址: http://{local_ip}:{port}") - # print(f"用户名: {username}") - # print(f"密码: {password}") - # print("="*50 + "\n") - # else: - # self.LOG.warning("统计看板插件未实现start_server方法") - # else: - # self.LOG.warning("未找到统计看板插件,请确保插件已正确安装") - # except Exception as e: - # self.LOG.error(f"启动统计看板服务器出错: {e}") - # # ============================================== 业务内容========================================================== @scheduled_job(cron="0 0 8 * * *", name="每日新闻推送")