Skip to content

Commit

Permalink
0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sena-nana committed Nov 22, 2022
1 parent 0853bd3 commit e63be42
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 30 deletions.
18 changes: 12 additions & 6 deletions nonebot-plugin-novelai/aidraw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from collections import deque
import aiohttp
from aiohttp.client_exceptions import ClientConnectorError
from aiohttp.client_exceptions import ClientConnectorError, ClientOSError
from argparse import Namespace
from asyncio import get_running_loop
from nonebot import get_bot, on_shell_command
Expand All @@ -14,7 +14,7 @@

from .config import config, nickname
from .utils.data import lowQuality, basetag
from .mode import post, FIFO
from .backend import post, FIFO
from .extension.anlas import anlas_check, anlas_set
from .extension.daylimit import DayLimit
from .utils.save import save_img
Expand All @@ -29,8 +29,10 @@
aidraw_parser = ArgumentParser()
aidraw_parser.add_argument("tags", nargs="*", help="标签")
aidraw_parser.add_argument("-p", "--shape", "-形状", help="画布形状", dest="shape")
aidraw_parser.add_argument("-w", "--width", "-宽", help="画布宽", dest="width")
aidraw_parser.add_argument("-h", "--height", "-高", help="画布高", dest="height")
aidraw_parser.add_argument("-w", "--width", "-宽",
type=int, help="画布宽", dest="width")
aidraw_parser.add_argument("-e", "--height", "-高",
type=int, help="画布高", dest="height")
aidraw_parser.add_argument("-c", "--scale", "-规模",
type=float, help="规模", dest="scale")
aidraw_parser.add_argument(
Expand Down Expand Up @@ -71,7 +73,7 @@ async def aidraw_get(bot: Bot,
message = message+f",批量生成数量过多,自动修改为{config.novelai_max}"
args.count = config.novelai_max
# 判断次数限制
if config.novelai_daylimit and not await SUPERUSER(bot,event):
if config.novelai_daylimit and not await SUPERUSER(bot, event):
left = DayLimit.count(user_id, args.count)
if left == -1:
aidraw.finish(f"今天你的次数不够了哦")
Expand Down Expand Up @@ -225,14 +227,18 @@ async def _run_gennerate(fifo: FIFO):
except ClientConnectorError:
await sendtosuperuser(f"远程服务器拒绝连接,请检查配置是否正确,服务器是否已经启动")
raise RuntimeError(f"远程服务器拒绝连接,请检查配置是否正确,服务器是否已经启动")
except ClientOSError:
await sendtosuperuser(f"远程服务器崩掉了欸……")
raise RuntimeError(f"服务器崩掉了欸……请等待主人修复吧")
# 若启用ai检定,取消注释下行代码,并将构造消息体部分注释
# message = await check_safe_method(fifo, img_bytes, message)
# 构造消息体并保存图片
message = f"{config.novelai_mode}绘画完成~"
for i in img_bytes:
await save_img(fifo, i, fifo.group_id)
message += MessageSegment.image(i)
for i in fifo.format():
message = MessageSegment.text(i)
message += MessageSegment.text(i)
# 扣除点数
if fifo.cost > 0:
await anlas_set(fifo.user_id, -fifo.cost)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .config import config
from ..config import config

if config.novelai_mode=="novelai":
from .novelai.post import post,FIFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import time
from PIL import Image
from nonebot import get_driver
from ..utils.data import shapemap
from ..config import config
from ...utils.data import shapemap
from ...config import config
import random


Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(self,
self.img2img: bool = False
self.image: str = None
if width and height:
self.shape_set(width,height)
self.shape_set(width, height)
else:
self.width, self.height = shapemap.get(shape or "p")
# 数值合法检查
Expand Down Expand Up @@ -84,11 +84,20 @@ def add_image(self, image):
self.img2img = True
self.update_cost()

def shape_set(self, width, height):
base = round(min(width,height)/64)
if base>16:
base=16
if width >= height:
def shape_set(self, width:int, height:int):
if width*height > pow(config.novelai_size, 2):
if width<=height:
ratio=height/width
width:float=config.novelai_size/pow(ratio,0.5)
height:float=width*ratio
else:
ratio=width/height
height:float=config.novelai_size/pow(ratio,0.5)
width:float=height*ratio
base = round(max(width, height)/64)
if base > 16:
base = 16
if width <= height:
self.width = round(width / height * base) * 64
self.height = 64*base
else:
Expand All @@ -100,21 +109,22 @@ def body(self):

def keys(self):
return (
"seed","scale", "strength", "noise", "sampler", "model", "steps", "width", "height", "img2img")
"seed", "scale", "strength", "noise", "sampler", "model", "steps", "width", "height", "img2img")

def __getitem__(self, item):
return getattr(self, item)

def format(self):
dict_self = dict(self)
list=[]
list = []
str = ""
for i, v in dict_self.items():
str += f"{i}={v}\n"
list.append(str)
list.append(f"tags={dict_self['tags']}\n")
list.append(f"ntags={dict_self['ntags']}")
list.append(f"tags={self.tags}\n")
list.append(f"ntags={self.ntags}")
return list

def __repr__(self):
return f"time={self.time}\nuser_id={self.user_id}\ngroup_id={self.group_id}\ncost={self.cost}\ncount={self.count}\n"+"".join(self.format())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import aiohttp
from nonebot.log import logger
from .fifo import FIFO_BASE
from ..utils import png2jpg
from ...utils import png2jpg

async def post_base(fifo: FIFO_BASE, header, post_api):
# 请求交互
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..config import config
from ...config import config
from .fifo import FIFO
from ..base.post import post_base

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..config import config
from ...config import config
from ..base.fifo import FIFO_BASE

class FIFO(FIFO_BASE):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..config import config
from ...config import config
from .fifo import FIFO
from ..base.post import post_base

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions nonebot-plugin-novelai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Config(BaseSettings):
novelai_daylimit: int = 0 # 每日次数限制,0为禁用
novelai_h: bool = False # 是否允许H
novelai_max: int = 3 # 每次能够生成的最大数量
novelai_size: int = 1024 # 允许生成的图片最大分辨率,对应(值)^2.默认为1024(即1024*1024)。如果服务器比较寄,建议改成640(640*640)或者根据能够承受的情况修改。naifu和novelai会分别限制最大长宽为1024
# 可运行更改的设置
novelai_tags: str = "" # 内置的tag
novelai_ntags: str = "" # 内置的反tag
Expand Down
6 changes: 0 additions & 6 deletions nonebot-plugin-novelai/mode.py

This file was deleted.

2 changes: 1 addition & 1 deletion nonebot-plugin-novelai/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
try:
self.version = version(self.package)
except:
self.version = "0.5.1"
self.version = "0.5.2"

async def check_update(self):
"""检查更新,并推送"""
Expand Down

0 comments on commit e63be42

Please sign in to comment.