From 6519ed7101d4d51bf75b897362dfe8ea6bb241ad Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Mon, 21 Aug 2023 00:31:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20=E4=BF=AE=E5=A4=8D=E5=BC=80?= =?UTF-8?q?=E7=AE=B1=E6=97=B6=E6=9C=80=E5=90=8E=E5=BC=80=E7=AE=B1=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=95=B0=E6=8D=AE=E6=9C=AA=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + plugins/open_cases/models/open_cases_user.py | 4 ++- plugins/open_cases/open_cases_c.py | 28 ++++++++++++++------ services/db_context.py | 4 ++- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5206db95..e6383f66 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,7 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能 ### 2022/8/20 * 修复词条回答包含at时使用模糊|正则等问时无法正确匹配问题 +* 修复开箱时最后开箱日期数据未更新 ### 2023/8/7 diff --git a/plugins/open_cases/models/open_cases_user.py b/plugins/open_cases/models/open_cases_user.py index 6f3482a1..3b488717 100755 --- a/plugins/open_cases/models/open_cases_user.py +++ b/plugins/open_cases/models/open_cases_user.py @@ -1,3 +1,5 @@ +from datetime import datetime + from tortoise import fields from services.db_context import Model @@ -39,7 +41,7 @@ class OpenCasesUser(Model): """赚取金币""" today_open_total: int = fields.IntField(default=0) """今日开箱数量""" - open_cases_time_last = fields.DatetimeField() + open_cases_time_last: datetime = fields.DatetimeField() """最后开箱日期""" knifes_name: str = fields.TextField(default="") """已获取金色""" diff --git a/plugins/open_cases/open_cases_c.py b/plugins/open_cases/open_cases_c.py index be2d9596..3bbea16d 100755 --- a/plugins/open_cases/open_cases_c.py +++ b/plugins/open_cases/open_cases_c.py @@ -122,7 +122,10 @@ async def open_case(user_id: str, group_id: int, case_name: str) -> Union[str, M case_price = case_skin.sell_min_price user.today_open_total += 1 user.total_count += 1 - await user.save(update_fields=["today_open_total", "total_count"]) + user.open_cases_time_last = datetime.now() + await user.save( + update_fields=["today_open_total", "total_count", "open_cases_time_last"] + ) add_count(user, skin, case_price) ridicule_result = random.choice(RESULT_MESSAGE[skin.color]) price_result = skin.sell_min_price @@ -203,7 +206,10 @@ async def open_multiple_case( now = datetime.now() user.today_open_total += num user.total_count += num - await user.save(update_fields=["today_open_total", "total_count"]) + user.open_cases_time_last = datetime.now() + await user.save( + update_fields=["today_open_total", "total_count", "open_cases_time_last"] + ) case_price = 0 if case_skin := await BuffSkin.get_or_none(case_name=case_name, color="CASE"): case_price = case_skin.sell_min_price @@ -275,8 +281,12 @@ def _handle_is_MAX_COUNT() -> str: return f"今天已达开箱上限了喔,明天再来吧\n(提升好感度可以增加每日开箱数 #疯狂暗示)" -async def total_open_statistics(user_id: str, group: str) -> str: - user, _ = await OpenCasesUser.get_or_create(user_id=user_id, group_id=group) +async def total_open_statistics( + user_id: Union[str, int], group_id: Union[str, int] +) -> str: + user, _ = await OpenCasesUser.get_or_create( + user_id=str(user_id), group_id=str(group_id) + ) return ( f"开箱总数:{user.total_count}\n" f"今日开箱:{user.today_open_total}\n" @@ -296,8 +306,8 @@ async def total_open_statistics(user_id: str, group: str) -> str: ) -async def group_statistics(group: str): - user_list = await OpenCasesUser.filter(group_id=group).all() +async def group_statistics(group_id: Union[int, str]): + user_list = await OpenCasesUser.filter(group_id=str(group_id)).all() # lan zi fen hong jin pricei uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0, 0] for user in user_list: @@ -332,7 +342,9 @@ async def group_statistics(group: str): ) -async def get_my_knifes(user_id: str, group_id: str) -> Union[str, MessageSegment]: +async def get_my_knifes( + user_id: Union[str, int], group_id: Union[str, int] +) -> Union[str, MessageSegment]: """获取我的金色 Args: @@ -342,7 +354,7 @@ async def get_my_knifes(user_id: str, group_id: str) -> Union[str, MessageSegmen Returns: Union[str, MessageSegment]: 回复消息或图片 """ - data_list = await get_old_knife(user_id, group_id) + data_list = await get_old_knife(str(user_id), str(group_id)) data_list += await OpenCasesLog.filter( user_id=user_id, group_id=group_id, color="KNIFE" ).all() diff --git a/services/db_context.py b/services/db_context.py index 7d6aec07..738705fa 100755 --- a/services/db_context.py +++ b/services/db_context.py @@ -48,7 +48,9 @@ async def init(): if not i_bind: i_bind = f"{sql_name}://{user}:{password}@{address}:{port}/{database}" try: - await Tortoise.init(db_url=i_bind, modules={"models": MODELS}) + await Tortoise.init( + db_url=i_bind, modules={"models": MODELS}, timezone="Asia/Shanghai" + ) await Tortoise.generate_schemas() logger.info(f"Database loaded successfully!") except Exception as e: