Skip to content

Commit

Permalink
fix:优化ai绘画流程
Browse files Browse the repository at this point in the history
  • Loading branch information
zmdyy0318 committed Oct 27, 2022
1 parent b527907 commit 5d29026
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/plugins/novelai/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ async def handle_event(self, event: GroupMessageEvent):
logger.error(f"Image::handle_event get_value failed:{self.__db.get_last_error_msg()}")
return self.__fail_message % "数据库错误"

# 验证token
point = 0
need_login = False
if token is not None:
ret, message, point = await self.__get_point(token)
if ret is False:
need_login = True
else:
need_login = True

if need_login:
ret, message, token = await self.__login(self.__config.nai_username, self.__config.nai_password)
if ret is False:
return self.__fail_message % f"登录失败:{message}"
self.__db.update_value(group_id, "token", token)

ret, message, point = await self.__get_point(token)
if ret is False:
return self.__fail_message % f"获取积分失败:{message}"

image = None
for seg in event.get_message():
if seg.type == "image":
Expand All @@ -128,13 +108,31 @@ async def handle_event(self, event: GroupMessageEvent):
info += f'\n使用图片{image.width}x{image.height}'
if keyword_en.find(",") <= 0 and keyword.find(" ") >= 0:
info += f'\n关键词之间记得用逗号分开哦'
if point < 50:
info += f'\n我要被榨干了'
await bot.send_group_msg(group_id=group_id, message=info)
except Exception as e:
logger.error(f"Image::handle_event send info failed:{e}")
return self.__fail_message % "发送信息失败"

# 验证token
point = 0
need_login = False
if token is not None:
ret, message, point = await self.__get_point(token)
if ret is False:
need_login = True
else:
need_login = True

if need_login:
ret, message, token = await self.__login(self.__config.nai_username, self.__config.nai_password)
if ret is False:
return self.__fail_message % f"登录失败:{message}"
self.__db.update_value(group_id, "token", token)

ret, message, point = await self.__get_point(token)
if ret is False:
return self.__fail_message % f"获取积分失败:{message}"

ret, message, buffer = await self.__generate_image(token, model_name, keyword_en, explict_keyword_en, image)
if ret is False:
return self.__fail_message % f"生成图片失败:{message}"
Expand Down Expand Up @@ -234,8 +232,8 @@ async def __generate_image(self, token: str, model: str, keyword_en: str, explic
"input": keyword_en,
"model": model,
"parameters": {
"height": 384,
"width": 384,
"height": 512,
"width": 512,
"n_samples": 1,
"sampler": "k_euler_ancestral",
"scale": 11,
Expand Down Expand Up @@ -264,8 +262,8 @@ async def __generate_image(self, token: str, model: str, keyword_en: str, explic
"input": keyword_en,
"model": model,
"parameters": {
"height": 384,
"width": 384,
"height": 512,
"width": 512,
"n_samples": 1,
"noise": 0.2,
"sampler": "k_euler_ancestral",
Expand Down

0 comments on commit 5d29026

Please sign in to comment.