From af8bd1d1c08be6f9e2fc50987cf0934b29091c65 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Fri, 28 Jun 2024 23:29:31 -0400 Subject: [PATCH] mai2: fix presents --- titles/mai2/base.py | 5 ++++- titles/mai2/dx.py | 5 ++++- titles/mai2/schema/item.py | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/titles/mai2/base.py b/titles/mai2/base.py index 79905ff..16b2039 100644 --- a/titles/mai2/base.py +++ b/titles/mai2/base.py @@ -474,6 +474,7 @@ class Mai2Base: items: List[Dict[str, Any]] = [] user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"]) if user_pres_list: + self.logger.debug(f"Found {len(user_pres_list)} possible presents") for present in user_pres_list: if (present['startDate'] and present['startDate'].timestamp() > datetime.now().timestamp()): self.logger.debug(f"Present {present['id']} distribution hasn't started yet (begins {present['startDate']})") @@ -485,7 +486,9 @@ class Mai2Base: test = await self.data.item.get_item(data["userId"], present['itemKind'], present['itemId']) if not test: # Don't send presents for items the user already has - items.append({"itemId": present['itemId'], "itemKind": present['itemKind'], "stock": present['stock'], "isValid": True}) + pres_id = present['itemKind'] * 1000000 + pres_id += present['itemId'] + items.append({"itemId": pres_id, "itemKind": 4, "stock": present['stock'], "isValid": True}) self.logger.info(f"Give user {data['userId']} {present['stock']}x item {present['itemId']} (kind {present['itemKind']}) as present") await self.data.item.put_item(data["userId"], present['itemKind'], present['itemId'], present['stock'], True) diff --git a/titles/mai2/dx.py b/titles/mai2/dx.py index 5ca03f7..3b28f30 100644 --- a/titles/mai2/dx.py +++ b/titles/mai2/dx.py @@ -332,6 +332,7 @@ class Mai2DX(Mai2Base): if kind == 4: # presents user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"]) if user_pres_list: + self.logger.debug(f"Found {len(user_pres_list)} possible presents") for present in user_pres_list: if (present['startDate'] and present['startDate'].timestamp() > datetime.now().timestamp()): self.logger.debug(f"Present {present['id']} distribution hasn't started yet (begins {present['startDate']})") @@ -343,7 +344,9 @@ class Mai2DX(Mai2Base): test = await self.data.item.get_item(data["userId"], present['itemKind'], present['itemId']) if not test: # Don't send presents for items the user already has - items.append({"itemId": present['itemId'], "itemKind": present['itemKind'], "stock": present['stock'], "isValid": True}) + pres_id = present['itemKind'] * 1000000 + pres_id += present['itemId'] + items.append({"itemId": pres_id, "itemKind": 4, "stock": present['stock'], "isValid": True}) self.logger.info(f"Give user {data['userId']} {present['stock']}x item {present['itemId']} (kind {present['itemKind']}) as present") await self.data.item.put_item(data["userId"], present['itemKind'], present['itemId'], present['stock'], True) diff --git a/titles/mai2/schema/item.py b/titles/mai2/schema/item.py index 65e129f..d53ebbc 100644 --- a/titles/mai2/schema/item.py +++ b/titles/mai2/schema/item.py @@ -635,10 +635,10 @@ class Mai2ItemData(BaseData): async def get_presents_by_version_user(self, ver: int = None, user_id: int = None) -> Optional[List[Row]]: result = await self.execute(present.select( and_( - or_(present.c.user == user_id, present.c.user is None)), - or_(present.c.version == ver, present.c.version is None) + or_(present.c.user == user_id, present.c.user == None), + or_(present.c.version == ver, present.c.version == None) ) - ) + )) if result: return result.fetchall()