forked from Hay1tsme/artemis
mai2: fix presents
This commit is contained in:
parent
e9afaaf56c
commit
af8bd1d1c0
@ -474,6 +474,7 @@ class Mai2Base:
|
|||||||
items: List[Dict[str, Any]] = []
|
items: List[Dict[str, Any]] = []
|
||||||
user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"])
|
user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"])
|
||||||
if user_pres_list:
|
if user_pres_list:
|
||||||
|
self.logger.debug(f"Found {len(user_pres_list)} possible presents")
|
||||||
for present in user_pres_list:
|
for present in user_pres_list:
|
||||||
if (present['startDate'] and present['startDate'].timestamp() > datetime.now().timestamp()):
|
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']})")
|
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'])
|
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
|
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")
|
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)
|
await self.data.item.put_item(data["userId"], present['itemKind'], present['itemId'], present['stock'], True)
|
||||||
|
|
||||||
|
@ -332,6 +332,7 @@ class Mai2DX(Mai2Base):
|
|||||||
if kind == 4: # presents
|
if kind == 4: # presents
|
||||||
user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"])
|
user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"])
|
||||||
if user_pres_list:
|
if user_pres_list:
|
||||||
|
self.logger.debug(f"Found {len(user_pres_list)} possible presents")
|
||||||
for present in user_pres_list:
|
for present in user_pres_list:
|
||||||
if (present['startDate'] and present['startDate'].timestamp() > datetime.now().timestamp()):
|
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']})")
|
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'])
|
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
|
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")
|
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)
|
await self.data.item.put_item(data["userId"], present['itemKind'], present['itemId'], present['stock'], True)
|
||||||
|
|
||||||
|
@ -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]]:
|
async def get_presents_by_version_user(self, ver: int = None, user_id: int = None) -> Optional[List[Row]]:
|
||||||
result = await self.execute(present.select(
|
result = await self.execute(present.select(
|
||||||
and_(
|
and_(
|
||||||
or_(present.c.user == user_id, present.c.user is None)),
|
or_(present.c.user == user_id, present.c.user == None),
|
||||||
or_(present.c.version == ver, present.c.version is None)
|
or_(present.c.version == ver, present.c.version == None)
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
if result:
|
if result:
|
||||||
return result.fetchall()
|
return result.fetchall()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user