From 517f4f13971073c337fee37b047ef43da24c8504 Mon Sep 17 00:00:00 2001 From: SlyAimer <2289782085@qq.com> Date: Mon, 10 Mar 2025 11:19:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(src):=20=E6=B7=BB=E5=8A=A0=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E5=9B=BE=E5=8A=9F=E8=83=BD=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 menu 和 send_menu 列表中添加 "/随机图" --- src/plugins/check.py | 4 ++-- src/plugins/image.py | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/plugins/check.py b/src/plugins/check.py index 646b16d..8eb99f5 100644 --- a/src/plugins/check.py +++ b/src/plugins/check.py @@ -8,11 +8,11 @@ from src.clover_openai import ai_chat from src.clover_sqlite.models.chat import GroupChatRole from src.clover_sqlite.models.user import UserList -menu = ["/重启","/今日运势","/今日塔罗","/图","/日报","/点歌","/摸摸头","/群老婆","/今日老婆", "/开启ai","/关闭ai","/角色列表","/添加人设", "/更新人设", "/删除人设", "/切换人设", "/管理员注册", +menu = ["/重启","/今日运势","/今日塔罗","/图","/随机图","/日报","/点歌","/摸摸头","/群老婆","/今日老婆", "/开启ai","/关闭ai","/角色列表","/添加人设", "/更新人设", "/删除人设", "/切换人设", "/管理员注册", "/待办", "/test","/天气","我喜欢你", "❤", "/待办查询", "/新建待办", "/删除待办" ,"/cf","/B站搜索", "/BV搜索", "/喜报", "/悲报", "/luxun","/鲁迅说", "/奶龙", "/repo", "/info", "/menu", "/轻小说","/本季新番","/新番观察","/绝对色感"] -send_menu = ["/menu","/今日运势","/今日塔罗","/图","/日报","/点歌","/摸摸头","/群老婆","/待办","/天气", +send_menu = ["/menu","/今日运势","/今日塔罗","/图","/随机图","/日报","/点歌","/摸摸头","/群老婆","/待办","/天气", "/待办查询", "/新建待办", "/删除待办" ,"/cf","/B站搜索", "/BV搜索", "/喜报", "/悲报","/鲁迅说", "/轻小说","/本季新番","/新番观察","/绝对色感"] diff --git a/src/plugins/image.py b/src/plugins/image.py index 1b78a67..0a138bd 100644 --- a/src/plugins/image.py +++ b/src/plugins/image.py @@ -5,6 +5,7 @@ from nonebot.plugin import on_command from nonebot.adapters.qq import MessageSegment,MessageEvent from src.clover_image.get_image import get_image_names from src.clover_image.download_image import download_image +from src.clover_image.delete_file import delete_file from src.configs.path_config import temp_path @@ -15,13 +16,37 @@ async def handle_function(): local_image_path = await get_image_names() await image.finish(MessageSegment.file_image(Path(local_image_path))) +random_keyword_image = on_command("随机图", rule=to_me(), priority=10, block=False) +@random_keyword_image.handle() +async def handle_function(message: MessageEvent) -> None: + value = message.get_plaintext().split(" ") + keyword = "" + if len(value) == 2: + keyword = value[1] + if len(value) > 2: + await random_keyword_image.finish("格式不对捏,请试一下 /随机图+关键字") -image = on_command("/搜图", rule=to_me(), priority=10, block=True) -@image.handle() -async def handle_function(message: MessageEvent): + filename = f"{message.get_user_id()}{random.randint(0, 10000)}.jpg" + image_path = temp_path + filename - filename = str(message.get_user_id()) + str(random.randint(0, 10000)) + ".jpg" - image_ptah = temp_path + filename + await download_image(f"https://image.anosu.top/pixiv/direct?keyword={keyword}", image_path) + + try: + await random_keyword_image.send(MessageSegment.file_image(Path(image_path))) + except Exception as e: + print(e) + await random_keyword_image.finish("图被外星人抢走啦,请重试") + + await delete_file(image_path) + + +# search_image = on_command("/搜图", rule=to_me(), priority=10, block=True) +# @image.handle() +# async def handle_function(message: MessageEvent): +# +# filename = str(message.get_user_id()) + str(random.randint(0, 10000)) + ".jpg" +# image_ptah = temp_path + filename +# +# await download_image(message.attachments[0].url, image_ptah) +# await image.finish(MessageSegment.file_image(Path(image_ptah))) - await download_image(message.attachments[0].url, image_ptah) - await image.finish(MessageSegment.file_image(Path(image_ptah))) \ No newline at end of file