mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
fix query_resource_points and sign_in
This commit is contained in:
parent
92e60ba141
commit
d2fe95cc05
@ -243,6 +243,8 @@ __Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__
|
|||||||
* 使用action自动更新poetry.lock [@pull/515](https://github.com/HibiKier/zhenxun_bot/pull/515)
|
* 使用action自动更新poetry.lock [@pull/515](https://github.com/HibiKier/zhenxun_bot/pull/515)
|
||||||
* fix(bilibili_sub): card is None and timeout [@pull/516](https://github.com/HibiKier/zhenxun_bot/pull/516)
|
* fix(bilibili_sub): card is None and timeout [@pull/516](https://github.com/HibiKier/zhenxun_bot/pull/516)
|
||||||
* 修复了epic有时获取新免费游戏消息时获取不到图片
|
* 修复了epic有时获取新免费游戏消息时获取不到图片
|
||||||
|
* 修复好感度满时签到出错(虽然是不可能满的
|
||||||
|
* 修复原神资源图标下载路径错误
|
||||||
|
|
||||||
### 2022/5/21
|
### 2022/5/21
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,7 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
|||||||
level = 0
|
level = 0
|
||||||
if not msg:
|
if not msg:
|
||||||
await add_group_level.finish("用法:修改群权限 [group] [level]")
|
await add_group_level.finish("用法:修改群权限 [group] [level]")
|
||||||
msg = msg.split(" ")
|
msg = msg.split()
|
||||||
if len(msg) < 2:
|
if len(msg) < 2:
|
||||||
await add_group_level.finish("参数不完全..[group] [level]")
|
await add_group_level.finish("参数不完全..[group] [level]")
|
||||||
if is_number(msg[0]) and is_number(msg[1]):
|
if is_number(msg[0]) and is_number(msg[1]):
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
from pathlib import Path
|
||||||
from typing import Tuple, Optional, List
|
from typing import Tuple, Optional, List
|
||||||
from configs.path_config import IMAGE_PATH, TEXT_PATH
|
from configs.path_config import IMAGE_PATH, TEXT_PATH
|
||||||
from utils.message_builder import image
|
from utils.message_builder import image
|
||||||
@ -136,7 +137,7 @@ async def download_resource_data(semaphore: Semaphore):
|
|||||||
asyncio.ensure_future(
|
asyncio.ensure_future(
|
||||||
download_image(
|
download_image(
|
||||||
img_url,
|
img_url,
|
||||||
f"{icon_path}/{id_}.png",
|
icon_path / f"{id_}.png",
|
||||||
semaphore,
|
semaphore,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
@ -178,7 +179,7 @@ async def download_map_init(semaphore: Semaphore, flag: bool = False):
|
|||||||
map_url = _map_data["url"]
|
map_url = _map_data["url"]
|
||||||
await download_image(
|
await download_image(
|
||||||
map_url,
|
map_url,
|
||||||
f"{map_path}/{idx}.png",
|
map_path / f"{idx}.png",
|
||||||
semaphore,
|
semaphore,
|
||||||
force_flag=flag,
|
force_flag=flag,
|
||||||
)
|
)
|
||||||
@ -227,15 +228,14 @@ async def download_resource_type():
|
|||||||
except (TimeoutError, ConnectTimeout):
|
except (TimeoutError, ConnectTimeout):
|
||||||
logger.warning("下载原神资源类型数据超时....")
|
logger.warning("下载原神资源类型数据超时....")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"载原神资源类型数据超时 {type(e)}:{e}")
|
logger.error(f"载原神资源类型数据错误 {type(e)}:{e}")
|
||||||
|
|
||||||
|
|
||||||
# 初始化资源图标
|
# 初始化资源图标
|
||||||
def gen_icon(icon: str):
|
def gen_icon(icon: Path):
|
||||||
A = BuildImage(0, 0, background=f"{icon_path}/box.png")
|
A = BuildImage(0, 0, background=f"{icon_path}/box.png")
|
||||||
B = BuildImage(0, 0, background=f"{icon_path}/box_alpha.png")
|
B = BuildImage(0, 0, background=f"{icon_path}/box_alpha.png")
|
||||||
icon_ = icon_path / f"{icon}"
|
icon_img = BuildImage(115, 115, background=icon)
|
||||||
icon_img = BuildImage(115, 115, background=icon_)
|
|
||||||
icon_img.circle()
|
icon_img.circle()
|
||||||
B.paste(icon_img, (17, 10), True)
|
B.paste(icon_img, (17, 10), True)
|
||||||
B.paste(A, alpha=True)
|
B.paste(A, alpha=True)
|
||||||
@ -246,14 +246,14 @@ def gen_icon(icon: str):
|
|||||||
# 下载图片
|
# 下载图片
|
||||||
async def download_image(
|
async def download_image(
|
||||||
img_url: str,
|
img_url: str,
|
||||||
path: str,
|
path: Path,
|
||||||
semaphore: Semaphore,
|
semaphore: Semaphore,
|
||||||
gen_flag: bool = False,
|
gen_flag: bool = False,
|
||||||
force_flag: bool = False,
|
force_flag: bool = False,
|
||||||
):
|
):
|
||||||
async with semaphore:
|
async with semaphore:
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(path) or not is_valid or force_flag:
|
if not path.exists() or not is_valid(path) or force_flag:
|
||||||
if await AsyncHttpx.download_file(img_url, path, timeout=10):
|
if await AsyncHttpx.download_file(img_url, path, timeout=10):
|
||||||
logger.info(f"下载原神资源图标:{img_url}")
|
logger.info(f"下载原神资源图标:{img_url}")
|
||||||
if gen_flag:
|
if gen_flag:
|
||||||
|
|||||||
@ -55,13 +55,10 @@ async def get_card(
|
|||||||
date = datetime.now().date()
|
date = datetime.now().date()
|
||||||
_type = "view" if is_card_view else "sign"
|
_type = "view" if is_card_view else "sign"
|
||||||
card_file = (
|
card_file = (
|
||||||
Path(SIGN_TODAY_CARD_PATH)
|
Path(SIGN_TODAY_CARD_PATH) / f"{user_id}_{user.group_id}_{_type}_{date}.png"
|
||||||
/ f"{user_id}_{user.group_id}_{_type}_{date}.png"
|
|
||||||
)
|
)
|
||||||
if card_file.exists():
|
if card_file.exists():
|
||||||
return image(
|
return image(f"{user_id}_{user.group_id}_{_type}_{date}.png", "sign/today_card")
|
||||||
f"{user_id}_{user.group_id}_{_type}_{date}.png", "sign/today_card"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
if add_impression == -1:
|
if add_impression == -1:
|
||||||
card_file = (
|
card_file = (
|
||||||
@ -75,9 +72,7 @@ async def get_card(
|
|||||||
)
|
)
|
||||||
is_card_view = True
|
is_card_view = True
|
||||||
ava = BytesIO(await get_user_avatar(user_id))
|
ava = BytesIO(await get_user_avatar(user_id))
|
||||||
uid = await GroupInfoUser.get_group_member_uid(
|
uid = await GroupInfoUser.get_group_member_uid(user.user_qq, user.group_id)
|
||||||
user.user_qq, user.group_id
|
|
||||||
)
|
|
||||||
impression_list = None
|
impression_list = None
|
||||||
if is_card_view:
|
if is_card_view:
|
||||||
_, impression_list, _ = await SignGroupUser.get_all_impression(
|
_, impression_list, _ = await SignGroupUser.get_all_impression(
|
||||||
@ -128,9 +123,13 @@ def _generate_card(
|
|||||||
level, next_impression, previous_impression = get_level_and_next_impression(
|
level, next_impression, previous_impression = get_level_and_next_impression(
|
||||||
user.impression
|
user.impression
|
||||||
)
|
)
|
||||||
|
interpolation = next_impression - user.impression
|
||||||
|
if level == "9":
|
||||||
|
level = "8"
|
||||||
|
interpolation = 0
|
||||||
info_img.text((0, 0), f"· 好感度等级:{level} [{lik2relation[level]}]")
|
info_img.text((0, 0), f"· 好感度等级:{level} [{lik2relation[level]}]")
|
||||||
info_img.text((0, 20), f"· {NICKNAME}对你的态度:{level2attitude[level]}")
|
info_img.text((0, 20), f"· {NICKNAME}对你的态度:{level2attitude[level]}")
|
||||||
info_img.text((0, 40), f"· 距离升级还差 {next_impression - user.impression:.2f} 好感度")
|
info_img.text((0, 40), f"· 距离升级还差 {interpolation:.2f} 好感度")
|
||||||
|
|
||||||
bar_bk = BuildImage(220, 20, background=SIGN_RESOURCE_PATH / "bar_white.png")
|
bar_bk = BuildImage(220, 20, background=SIGN_RESOURCE_PATH / "bar_white.png")
|
||||||
bar = BuildImage(220, 20, background=SIGN_RESOURCE_PATH / "bar.png")
|
bar = BuildImage(220, 20, background=SIGN_RESOURCE_PATH / "bar.png")
|
||||||
@ -240,7 +239,9 @@ def _generate_card(
|
|||||||
f"上次签到日期:{'从未' if user.checkin_time_last == datetime.min else user.checkin_time_last.date()}",
|
f"上次签到日期:{'从未' if user.checkin_time_last == datetime.min else user.checkin_time_last.date()}",
|
||||||
)
|
)
|
||||||
today_data.text((0, 25), f"总金币:{gold}")
|
today_data.text((0, 25), f"总金币:{gold}")
|
||||||
default_setu_prob = Config.get_config("send_setu", "INITIAL_SETU_PROBABILITY") * 100
|
default_setu_prob = (
|
||||||
|
Config.get_config("send_setu", "INITIAL_SETU_PROBABILITY") * 100
|
||||||
|
)
|
||||||
today_data.text(
|
today_data.text(
|
||||||
(0, 50),
|
(0, 50),
|
||||||
f"色图概率:{(default_setu_prob + user.impression if user.impression < 100 else 100):.2f}%",
|
f"色图概率:{(default_setu_prob + user.impression if user.impression < 100 else 100):.2f}%",
|
||||||
@ -286,12 +287,8 @@ def _generate_card(
|
|||||||
bk.paste(today_sign_text_img, (550, 180), True)
|
bk.paste(today_sign_text_img, (550, 180), True)
|
||||||
bk.paste(today_data, (580, 220), True)
|
bk.paste(today_data, (580, 220), True)
|
||||||
bk.paste(watermark, (15, 400), True)
|
bk.paste(watermark, (15, 400), True)
|
||||||
bk.save(
|
bk.save(SIGN_TODAY_CARD_PATH / f"{user_id}_{user.group_id}_{_type}_{data}.png")
|
||||||
SIGN_TODAY_CARD_PATH / f"{user_id}_{user.group_id}_{_type}_{data}.png"
|
return image(f"{user_id}_{user.group_id}_{_type}_{data}.png", "sign/today_card")
|
||||||
)
|
|
||||||
return image(
|
|
||||||
f"{user_id}_{user.group_id}_{_type}_{data}.png", "sign/today_card"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_progress_bar_pic():
|
def generate_progress_bar_pic():
|
||||||
|
|||||||
@ -121,7 +121,7 @@ def fig2b64(plt_: plt) -> str:
|
|||||||
return "base64://" + base64_str
|
return "base64://" + base64_str
|
||||||
|
|
||||||
|
|
||||||
def is_valid(file: str) -> bool:
|
def is_valid(file: Union[str, Path]) -> bool:
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
判断图片是否损坏
|
判断图片是否损坏
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user