forked from Hay1tsme/artemis
add mai2 UserIntimateApi
This commit is contained in:
43
core/data/alembic/versions/54a84103b84e_mai2_intimacy.py
Normal file
43
core/data/alembic/versions/54a84103b84e_mai2_intimacy.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
"""mai2_intimacy
|
||||||
|
|
||||||
|
Revision ID: 54a84103b84e
|
||||||
|
Revises: bc91c1206dca
|
||||||
|
Create Date: 2024-09-16 17:47:49.164546
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import Column, Integer, UniqueConstraint
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '54a84103b84e'
|
||||||
|
down_revision = 'bc91c1206dca'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
"mai2_user_intimate",
|
||||||
|
Column("id", Integer, primary_key=True, nullable=False),
|
||||||
|
Column("user", Integer, nullable=False),
|
||||||
|
Column("partnerId", Integer, nullable=False),
|
||||||
|
Column("intimateLevel", Integer, nullable=False),
|
||||||
|
Column("intimateCountRewarded", Integer, nullable=False),
|
||||||
|
UniqueConstraint("user", "partnerId", name="mai2_user_intimate_uk"),
|
||||||
|
mysql_charset="utf8mb4",
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_foreign_key(
|
||||||
|
None,
|
||||||
|
"mai2_user_intimate",
|
||||||
|
"aime_user",
|
||||||
|
["user"],
|
||||||
|
["id"],
|
||||||
|
ondelete="cascade",
|
||||||
|
onupdate="cascade",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table("mai2_user_intimate")
|
@ -264,6 +264,11 @@ class Mai2DX(Mai2Base):
|
|||||||
if "user2pPlaylog" in upsert:
|
if "user2pPlaylog" in upsert:
|
||||||
await self.data.score.put_playlog_2p(user_id, upsert["user2pPlaylog"])
|
await self.data.score.put_playlog_2p(user_id, upsert["user2pPlaylog"])
|
||||||
|
|
||||||
|
# added in BUDDiES+
|
||||||
|
if "userIntimateList" in upsert and len(upsert["userIntimateList"]) > 0:
|
||||||
|
for intimate in upsert["userIntimateList"]:
|
||||||
|
await self.data.profile.put_intimacy(user_id, intimate["partnerId"], intimate["intimateLevel"], intimate["intimateCountRewarded"])
|
||||||
|
|
||||||
return {"returnCode": 1, "apiName": "UpsertUserAllApi"}
|
return {"returnCode": 1, "apiName": "UpsertUserAllApi"}
|
||||||
|
|
||||||
async def handle_get_user_data_api_request(self, data: Dict) -> Dict:
|
async def handle_get_user_data_api_request(self, data: Dict) -> Dict:
|
||||||
@ -713,6 +718,24 @@ class Mai2DX(Mai2Base):
|
|||||||
ret['loginId'] = ret.get('loginCount', 0)
|
ret['loginId'] = ret.get('loginCount', 0)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
# Intimate api added in BUDDiES+
|
||||||
|
async def handle_get_user_intimate_api_request(self, data: Dict) -> Dict:
|
||||||
|
intimate = await self.data.profile.get_intimacy(data["userId"])
|
||||||
|
if intimate is None:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
partner_list = [{
|
||||||
|
"partnerId": i["partnerId"],
|
||||||
|
"intimateLevel": i["intimateLevel"],
|
||||||
|
"intimateCountRewarded": i["intimateCountRewarded"]
|
||||||
|
} for i in intimate]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"userId": data["userId"],
|
||||||
|
"length": len(partner_list),
|
||||||
|
"userIntimateList": partner_list
|
||||||
|
}
|
||||||
|
|
||||||
# CardMaker support added in Universe
|
# CardMaker support added in Universe
|
||||||
async def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict:
|
async def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict:
|
||||||
p = await self.data.profile.get_profile_detail(data["userId"], self.version)
|
p = await self.data.profile.get_profile_detail(data["userId"], self.version)
|
||||||
|
@ -513,6 +513,22 @@ rival = Table(
|
|||||||
mysql_charset="utf8mb4",
|
mysql_charset="utf8mb4",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
intimacy = Table(
|
||||||
|
"mai2_user_intimate",
|
||||||
|
metadata,
|
||||||
|
Column("id", Integer, primary_key=True, nullable=False),
|
||||||
|
Column(
|
||||||
|
"user",
|
||||||
|
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||||
|
nullable=False,
|
||||||
|
),
|
||||||
|
Column("partnerId", Integer, nullable=False),
|
||||||
|
Column("intimateLevel", Integer, nullable=False),
|
||||||
|
Column("intimateCountRewarded", Integer, nullable=False),
|
||||||
|
UniqueConstraint("user", "partnerId", name="mai2_user_intimate_uk"),
|
||||||
|
mysql_charset="utf8mb4",
|
||||||
|
)
|
||||||
|
|
||||||
class Mai2ProfileData(BaseData):
|
class Mai2ProfileData(BaseData):
|
||||||
async def get_all_profile_versions(self, user_id: int) -> Optional[List[Row]]:
|
async def get_all_profile_versions(self, user_id: int) -> Optional[List[Row]]:
|
||||||
result = await self.execute(detail.select(detail.c.user == user_id))
|
result = await self.execute(detail.select(detail.c.user == user_id))
|
||||||
@ -908,6 +924,27 @@ class Mai2ProfileData(BaseData):
|
|||||||
if not result:
|
if not result:
|
||||||
self.logger.error(f"Failed to remove rival {rival_id} for user {user_id}!")
|
self.logger.error(f"Failed to remove rival {rival_id} for user {user_id}!")
|
||||||
|
|
||||||
|
async def get_intimacy(self, user_id: int) -> Optional[List[Row]]:
|
||||||
|
result = await self.execute(intimacy.select(intimacy.c.user == user_id))
|
||||||
|
if result:
|
||||||
|
return result.fetchall()
|
||||||
|
|
||||||
|
async def put_intimacy(self, user_id: int, partner_id: int, level: int, count_rewarded: int) -> Optional[int]:
|
||||||
|
sql = insert(intimacy).values(
|
||||||
|
user = user_id,
|
||||||
|
partnerId = partner_id,
|
||||||
|
intimateLevel = level,
|
||||||
|
intimateCountRewarded = count_rewarded
|
||||||
|
)
|
||||||
|
|
||||||
|
conflict = sql.on_duplicate_key_update(intimateLevel = level, intimateCountRewarded = count_rewarded)
|
||||||
|
|
||||||
|
result = await self.execute(conflict)
|
||||||
|
if result:
|
||||||
|
return result.lastrowid
|
||||||
|
|
||||||
|
self.logger.error(f"Failed to update intimacy for user {user_id} and partner {partner_id}!")
|
||||||
|
|
||||||
async def update_name(self, user_id: int, new_name: str) -> bool:
|
async def update_name(self, user_id: int, new_name: str) -> bool:
|
||||||
sql = detail.update(detail.c.user == user_id).values(
|
sql = detail.update(detail.c.user == user_id).values(
|
||||||
userName=new_name
|
userName=new_name
|
||||||
|
Reference in New Issue
Block a user