From 17b0809e758e67511c43a4d9065dfcebd89fc1e7 Mon Sep 17 00:00:00 2001 From: sena-nana <851183156@qq.com> Date: Fri, 14 Oct 2022 11:34:54 +0800 Subject: [PATCH] =?UTF-8?q?novelai=200.3.2=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nonebot-plugin-novelai/txt2pix.py | 7 ++++++- .../nonebot-plugin-novelai/utils.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nonebot-plugin-novelai/nonebot-plugin-novelai/txt2pix.py b/nonebot-plugin-novelai/nonebot-plugin-novelai/txt2pix.py index 78bb912..163f2ea 100644 --- a/nonebot-plugin-novelai/nonebot-plugin-novelai/txt2pix.py +++ b/nonebot-plugin-novelai/nonebot-plugin-novelai/txt2pix.py @@ -8,10 +8,11 @@ from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message, MessageSegment from nonebot.log import logger from nonebot.params import CommandArg +import re from .config import config from .data import txt2pix_body,header,htags -from .utils import is_contain_chinese,translate_ZH2EN +from .utils import is_contain_chinese,translate_ZH2EN,file_name_check path = Path("data/novelai").resolve() txt2pix = on_command(".aidraw", aliases={"文本生图", "咏唱"}) @@ -76,6 +77,10 @@ async def txt2pix_handle(event: GroupMessageEvent, args: Message = CommandArg()) if i in input.lower(): await txt2pix.finish("H是不行的!") + # 处理奇奇怪怪的输入 + input=re.sub("\W","",input) + input=file_name_check(input) + #生成种子 seed = seed_raw or int(time.time()) diff --git a/nonebot-plugin-novelai/nonebot-plugin-novelai/utils.py b/nonebot-plugin-novelai/nonebot-plugin-novelai/utils.py index 4a84cf3..5cb084b 100644 --- a/nonebot-plugin-novelai/nonebot-plugin-novelai/utils.py +++ b/nonebot-plugin-novelai/nonebot-plugin-novelai/utils.py @@ -1,11 +1,11 @@ -def is_contain_chinese(check_str): +def is_contain_chinese(check_str:str): for ch in check_str: if u'\u4e00' <= ch <= u'\u9fff': return True return False import aiohttp -async def translate_ZH2EN(input): +async def translate_ZH2EN(input:str): async with aiohttp.ClientSession() as session: data = { 'doctype': 'json', @@ -14,4 +14,9 @@ async def translate_ZH2EN(input): } async with session.post("http://fanyi.youdao.com/translate",data=data) as requests: result = await requests.json() - return result["translateResult"][0][0]["tgt"] \ No newline at end of file + return result["translateResult"][0][0]["tgt"] +def file_name_check(input:str): + errorcode=["?","<",">","\\","/","*","|",":"] + for i in errorcode: + input.replace(i,"") + return input \ No newline at end of file