修复首次签到时使用道具后签到报错

This commit is contained in:
HibiKier 2023-03-20 21:23:04 +08:00
parent 99cf2b32b1
commit fac1d4bff9
3 changed files with 19 additions and 19 deletions

View File

@ -331,6 +331,12 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
## 更新
### 2023/3/20
* 修复BuildImage类text居中类型bug [@pull/1301](https://github.com/HibiKier/zhenxun_bot/pull/1317)
* 修复原神今日素材有时发不出图片的问题 [@pull/1301](https://github.com/HibiKier/zhenxun_bot/pull/1317)
* 修复首次签到时使用道具后签到报错
### 2023/3/19
* 优化代码

View File

@ -57,7 +57,7 @@ async def _(event: MessageEvent):
await update_image()
await material.send(
Message(
image(f"{file_name}.png", "genshin/material")
image(IMAGE_PATH / "genshin" / "material" / f"{file_name}.png")
+ "\n※ 每日素材数据来源于米游社"
)
)
@ -83,18 +83,20 @@ async def update_image():
os.mkdir(f"{IMAGE_PATH}/genshin/material")
for file in os.listdir(f"{IMAGE_PATH}/genshin/material"):
os.remove(f"{IMAGE_PATH}/genshin/material/{file}")
browser = await get_browser()
browser = get_browser()
if not browser:
logger.warning("获取 browser 失败,请部署至 linux 环境....")
return False
# url = "https://genshin.pub/daily"
url = "https://bbs.mihoyo.com/ys/obc/channel/map/193"
page = await browser.new_page(viewport={'width': 860, 'height': 3000})
page = await browser.new_page(viewport={"width": 860, "height": 3000})
await page.goto(url)
await page.wait_for_timeout(3000)
file_name = str((datetime.now() - timedelta(hours=4)).date())
# background_img.save(f"{IMAGE_PATH}/genshin/material/{file_name}.png")
await page.locator('//*[@id="__layout"]/div/div[2]/div[2]/div/div[1]/div[2]/div/div').screenshot(path=f"{IMAGE_PATH}/genshin/material/{file_name}.png")
await page.locator(
'//*[@id="__layout"]/div/div[2]/div[2]/div/div[1]/div[2]/div/div'
).screenshot(path=f"{IMAGE_PATH}/genshin/material/{file_name}.png")
await page.close()
return True
except Exception as e:
@ -102,16 +104,3 @@ async def update_image():
if page:
await page.close()
return False
# 获取背景高度以及修改最后一张图片的黑边
def get_background_height(weapons_img: List[str]) -> int:
height = 0
for weapons in weapons_img:
height += BuildImage(0, 0, background=weapons).size[1]
last_weapon = BuildImage(0, 0, background=weapons_img[-1])
w, h = last_weapon.size
last_weapon.crop((0, 0, w, h - 10))
last_weapon.save(weapons_img[-1])
return height

View File

@ -456,7 +456,7 @@ class BuildImage:
说明:
在图片上添加文字
参数:
:param pos: 文字位置
:param pos: 文字位置(使用center_type中的center后会失效,使用by_width后x失效,使用by_height后y失效)
:param text: 文字内容
:param fill: 文字颜色
:param center_type: 居中类型可能的值 center: 完全居中by_width: 水平居中by_height: 垂直居中
@ -469,7 +469,12 @@ class BuildImage:
"center_type must be 'center', 'by_width' or 'by_height'"
)
w, h = self.w, self.h
ttf_w, ttf_h = self.getsize(text)
longgest_text = ''
sentence = text.split("\n")
for x in sentence:
longgest_text = x if len(x) > len(longgest_text) else longgest_text
ttf_w, ttf_h = self.getsize(longgest_text)
ttf_h = ttf_h * len(sentence)
if center_type == "center":
w = int((w - ttf_w) / 2)
h = int((h - ttf_h) / 2)