Skip to content

Commit

Permalink
novelai 0.3.2更新
Browse files Browse the repository at this point in the history
  • Loading branch information
sena-nana committed Oct 14, 2022
1 parent ccb015f commit 17b0809
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion nonebot-plugin-novelai/nonebot-plugin-novelai/txt2pix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={"文本生图", "咏唱"})
Expand Down Expand Up @@ -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())

Expand Down
11 changes: 8 additions & 3 deletions nonebot-plugin-novelai/nonebot-plugin-novelai/utils.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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"]
return result["translateResult"][0][0]["tgt"]
def file_name_check(input:str):
errorcode=["?","<",">","\\","/","*","|",":"]
for i in errorcode:
input.replace(i,"")
return input

0 comments on commit 17b0809

Please sign in to comment.