mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-02-14 11:47:28 +08:00
mai2: add present support
This commit is contained in:
@@ -327,16 +327,35 @@ class Mai2DX(Mai2Base):
|
||||
async def handle_get_user_item_api_request(self, data: Dict) -> Dict:
|
||||
kind = int(data["nextIndex"] / 10000000000)
|
||||
next_idx = int(data["nextIndex"] % 10000000000)
|
||||
user_item_list = await self.data.item.get_items(data["userId"], kind)
|
||||
|
||||
items: List[Dict[str, Any]] = []
|
||||
for i in range(next_idx, len(user_item_list)):
|
||||
tmp = user_item_list[i]._asdict()
|
||||
tmp.pop("user")
|
||||
tmp.pop("id")
|
||||
items.append(tmp)
|
||||
if len(items) >= int(data["maxCount"]):
|
||||
break
|
||||
|
||||
if kind == 4: # presents
|
||||
user_pres_list = await self.data.item.get_presents_by_version_user(self.version, data["userId"])
|
||||
if user_pres_list:
|
||||
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']})")
|
||||
continue # present period hasn't started yet, move onto the next one
|
||||
|
||||
if (present['endDate'] and present['endDate'].timestamp() < datetime.now().timestamp()):
|
||||
self.logger.warn(f"Present {present['id']} ended on {present['endDate']} and should be removed")
|
||||
continue # present period ended, move onto the next one
|
||||
|
||||
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})
|
||||
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)
|
||||
|
||||
else:
|
||||
user_item_list = await self.data.item.get_items(data["userId"], kind)
|
||||
for i in range(next_idx, len(user_item_list)):
|
||||
tmp = user_item_list[i]._asdict()
|
||||
tmp.pop("user")
|
||||
tmp.pop("id")
|
||||
items.append(tmp)
|
||||
if len(items) >= int(data["maxCount"]):
|
||||
break
|
||||
|
||||
xout = kind * 10000000000 + next_idx + len(items)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user