2023-02-18 21:01:31 +01:00
|
|
|
from typing import Optional, Dict, List
|
|
|
|
from sqlalchemy import Table, Column, UniqueConstraint, and_
|
|
|
|
from sqlalchemy.types import Integer
|
|
|
|
from sqlalchemy.schema import ForeignKey
|
|
|
|
from sqlalchemy.dialects.mysql import insert
|
|
|
|
|
|
|
|
from core.data.schema import BaseData, metadata
|
|
|
|
|
|
|
|
customize = Table(
|
|
|
|
"diva_profile_customize_item",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
2023-03-09 17:38:58 +01:00
|
|
|
Column(
|
|
|
|
"user",
|
|
|
|
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
|
|
|
nullable=False,
|
|
|
|
),
|
2023-02-18 21:01:31 +01:00
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("item_id", Integer, nullable=False),
|
2023-03-09 17:38:58 +01:00
|
|
|
UniqueConstraint(
|
|
|
|
"user", "version", "item_id", name="diva_profile_customize_item_uk"
|
|
|
|
),
|
|
|
|
mysql_charset="utf8mb4",
|
2023-02-18 21:01:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class DivaCustomizeItemData(BaseData):
|
|
|
|
def put_customize_item(self, aime_id: int, version: int, item_id: int) -> None:
|
2023-03-09 17:38:58 +01:00
|
|
|
sql = insert(customize).values(version=version, user=aime_id, item_id=item_id)
|
2023-02-18 21:01:31 +01:00
|
|
|
|
|
|
|
result = self.execute(sql)
|
|
|
|
if result is None:
|
2023-03-09 17:38:58 +01:00
|
|
|
self.logger.error(
|
|
|
|
f"{__name__} Failed to insert diva profile customize item! aime id: {aime_id} item: {item_id}"
|
|
|
|
)
|
2023-02-18 21:01:31 +01:00
|
|
|
return None
|
|
|
|
return result.lastrowid
|
|
|
|
|
|
|
|
def get_customize_items(self, aime_id: int, version: int) -> Optional[List[Dict]]:
|
|
|
|
"""
|
|
|
|
Given a game version and an aime id, return all the customize items, not used directly
|
|
|
|
"""
|
2023-03-09 17:38:58 +01:00
|
|
|
sql = customize.select(
|
|
|
|
and_(customize.c.version == version, customize.c.user == aime_id)
|
|
|
|
)
|
2023-02-18 21:01:31 +01:00
|
|
|
|
|
|
|
result = self.execute(sql)
|
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchall()
|
|
|
|
|
|
|
|
def get_customize_items_have_string(self, aime_id: int, version: int) -> str:
|
|
|
|
"""
|
|
|
|
Given a game version and an aime id, return the cstmz_itm_have hex string
|
|
|
|
required for diva directly
|
|
|
|
"""
|
|
|
|
items_list = self.get_customize_items(aime_id, version)
|
|
|
|
if items_list is None:
|
|
|
|
items_list = []
|
|
|
|
item_have = 0
|
|
|
|
|
|
|
|
for item in items_list:
|
|
|
|
item_have |= 1 << item["item_id"]
|
|
|
|
|
|
|
|
# convert the int to a 250 digit long hex string
|
|
|
|
return "{0:0>250}".format(hex(item_have).upper()[2:])
|