mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-02-12 10:47:28 +08:00
chuni: initial verse support
This commit is contained in:
@@ -262,7 +262,11 @@ cmission_progress = Table(
|
||||
"chuni_item_cmission_progress",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("missionId", Integer, nullable=False),
|
||||
Column("order", Integer),
|
||||
Column("stage", Integer),
|
||||
@@ -273,14 +277,34 @@ cmission_progress = Table(
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
unlock_challenge = Table(
|
||||
"chuni_item_unlock_challenge",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("unlockChallengeId", Integer, nullable=False),
|
||||
Column("status", Integer),
|
||||
Column("clearCourseId", Integer),
|
||||
Column("conditionType", Integer),
|
||||
Column("score", Integer),
|
||||
Column("life", Integer),
|
||||
Column("clearDate", TIMESTAMP),
|
||||
UniqueConstraint(
|
||||
"version", "user", "unlockChallengeId", name="chuni_item_unlock_challenge_uk"
|
||||
),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class ChuniItemData(BaseData):
|
||||
async def get_oldest_free_matching(self, version: int) -> Optional[Row]:
|
||||
sql = matching.select(
|
||||
and_(
|
||||
matching.c.version == version,
|
||||
matching.c.isFull == False
|
||||
)
|
||||
and_(matching.c.version == version, matching.c.isFull == False)
|
||||
).order_by(matching.c.roomId.asc())
|
||||
|
||||
result = await self.execute(sql)
|
||||
@@ -289,11 +313,9 @@ class ChuniItemData(BaseData):
|
||||
return result.fetchone()
|
||||
|
||||
async def get_newest_matching(self, version: int) -> Optional[Row]:
|
||||
sql = matching.select(
|
||||
and_(
|
||||
matching.c.version == version
|
||||
)
|
||||
).order_by(matching.c.roomId.desc())
|
||||
sql = matching.select(and_(matching.c.version == version)).order_by(
|
||||
matching.c.roomId.desc()
|
||||
)
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
@@ -301,11 +323,7 @@ class ChuniItemData(BaseData):
|
||||
return result.fetchone()
|
||||
|
||||
async def get_all_matchings(self, version: int) -> Optional[List[Row]]:
|
||||
sql = matching.select(
|
||||
and_(
|
||||
matching.c.version == version
|
||||
)
|
||||
)
|
||||
sql = matching.select(and_(matching.c.version == version))
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
@@ -329,7 +347,7 @@ class ChuniItemData(BaseData):
|
||||
matching_member_info_list: List,
|
||||
user_id: int = None,
|
||||
rest_sec: int = 60,
|
||||
is_full: bool = False
|
||||
is_full: bool = False,
|
||||
) -> Optional[int]:
|
||||
sql = insert(matching).values(
|
||||
roomId=room_id,
|
||||
@@ -452,23 +470,31 @@ class ChuniItemData(BaseData):
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
async def put_favorite_music(self, user_id: int, version: int, music_id: int) -> Optional[int]:
|
||||
sql = insert(favorite).values(user=user_id, version=version, favId=music_id, favKind=1)
|
||||
async def put_favorite_music(
|
||||
self, user_id: int, version: int, music_id: int
|
||||
) -> Optional[int]:
|
||||
sql = insert(favorite).values(
|
||||
user=user_id, version=version, favId=music_id, favKind=1
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(user=user_id, version=version, favId=music_id, favKind=1)
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
user=user_id, version=version, favId=music_id, favKind=1
|
||||
)
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def delete_favorite_music(self, user_id: int, version: int, music_id: int) -> Optional[int]:
|
||||
async def delete_favorite_music(
|
||||
self, user_id: int, version: int, music_id: int
|
||||
) -> Optional[int]:
|
||||
sql = delete(favorite).where(
|
||||
and_(
|
||||
favorite.c.user==user_id,
|
||||
favorite.c.version==version,
|
||||
favorite.c.favId==music_id,
|
||||
favorite.c.favKind==1
|
||||
favorite.c.user == user_id,
|
||||
favorite.c.version == version,
|
||||
favorite.c.favId == music_id,
|
||||
favorite.c.favKind == 1,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -611,8 +637,12 @@ class ChuniItemData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_map_areas(self, user_id: int, map_area_ids: List[int]) -> Optional[List[Row]]:
|
||||
sql = select(map_area).where(map_area.c.user == user_id, map_area.c.mapAreaId.in_(map_area_ids))
|
||||
async def get_map_areas(
|
||||
self, user_id: int, map_area_ids: List[int]
|
||||
) -> Optional[List[Row]]:
|
||||
sql = select(map_area).where(
|
||||
map_area.c.user == user_id, map_area.c.mapAreaId.in_(map_area_ids)
|
||||
)
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
@@ -713,7 +743,7 @@ class ChuniItemData(BaseData):
|
||||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
|
||||
async def put_cmission_progress(
|
||||
self, user_id: int, mission_id: int, progress_data: Dict
|
||||
) -> Optional[int]:
|
||||
@@ -723,10 +753,10 @@ class ChuniItemData(BaseData):
|
||||
sql = insert(cmission_progress).values(**progress_data)
|
||||
conflict = sql.on_duplicate_key_update(**progress_data)
|
||||
result = await self.execute(conflict)
|
||||
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
async def get_cmission_progress(
|
||||
@@ -739,21 +769,21 @@ class ChuniItemData(BaseData):
|
||||
)
|
||||
).order_by(cmission_progress.c.order.asc())
|
||||
result = await self.execute(sql)
|
||||
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
|
||||
return result.fetchall()
|
||||
|
||||
|
||||
async def get_cmission(self, user_id: int, mission_id: int) -> Optional[Row]:
|
||||
sql = cmission.select(
|
||||
and_(cmission.c.user == user_id, cmission.c.missionId == mission_id)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
|
||||
return result.fetchone()
|
||||
|
||||
async def put_cmission(self, user_id: int, mission_data: Dict) -> Optional[int]:
|
||||
@@ -762,17 +792,46 @@ class ChuniItemData(BaseData):
|
||||
sql = insert(cmission).values(**mission_data)
|
||||
conflict = sql.on_duplicate_key_update(**mission_data)
|
||||
result = await self.execute(conflict)
|
||||
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
async def get_cmissions(self, user_id: int) -> Optional[List[Row]]:
|
||||
sql = cmission.select(cmission.c.user == user_id)
|
||||
result = await self.execute(sql)
|
||||
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
return result.fetchall()
|
||||
|
||||
async def put_unlock_challenge(
|
||||
self, user_id: int, version: int, unlock_challenge_data: Dict
|
||||
) -> Optional[int]:
|
||||
unlock_challenge_data["user"] = user_id
|
||||
unlock_challenge_data["version"] = version
|
||||
|
||||
sql = insert(unlock_challenge).values(**unlock_challenge_data)
|
||||
conflict = sql.on_duplicate_key_update(**unlock_challenge_data)
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_unlock_challenges(
|
||||
self, user_id: int, version: int
|
||||
) -> Optional[List[Row]]:
|
||||
sql = unlock_challenge.select(
|
||||
and_(
|
||||
unlock_challenge.c.user == user_id,
|
||||
unlock_challenge.c.version == version,
|
||||
)
|
||||
)
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
return result.fetchall()
|
||||
|
||||
@@ -25,6 +25,8 @@ profile = Table(
|
||||
Column("frameId", Integer),
|
||||
Column("isMaimai", Boolean),
|
||||
Column("trophyId", Integer),
|
||||
Column("trophyIdSub1", Integer),
|
||||
Column("trophyIdSub2", Integer),
|
||||
Column("userName", String(25)),
|
||||
Column("isWebJoin", Boolean),
|
||||
Column("playCount", Integer),
|
||||
@@ -465,6 +467,8 @@ class ChuniProfileData(BaseData):
|
||||
sql = profile.update((profile.c.user == user_id) & (profile.c.version == version)).values(
|
||||
nameplateId=new_nameplate,
|
||||
trophyId=new_trophy,
|
||||
trophyIdSub1=new_trophySub1,
|
||||
trophyIdSub2=new_trophySub2,
|
||||
charaIllustId=new_character
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
@@ -899,4 +903,4 @@ class ChuniProfileData(BaseData):
|
||||
async def get_net_battle(self, aime_id: int) -> Optional[Row]:
|
||||
result = await self.execute(net_battle.select(net_battle.c.user == aime_id))
|
||||
if result:
|
||||
return result.fetchone()
|
||||
return result.fetchone()
|
||||
@@ -139,6 +139,8 @@ playlog = Table(
|
||||
Column("regionId", Integer),
|
||||
Column("machineType", Integer),
|
||||
Column("ticketId", Integer),
|
||||
Column("monthPoint", Integer),
|
||||
Column("eventPoint", Integer),
|
||||
mysql_charset="utf8mb4"
|
||||
)
|
||||
|
||||
@@ -420,4 +422,4 @@ class ChuniScoreData(BaseData):
|
||||
return None
|
||||
|
||||
rows = result.fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
return [dict(row) for row in rows]
|
||||
@@ -289,6 +289,27 @@ login_bonus = Table(
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
unlock_challenge = Table(
|
||||
"chuni_static_unlock_challenge",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("unlockChallengeId", Integer, nullable=False),
|
||||
Column("name", String(255)),
|
||||
Column("isEnabled", Boolean, server_default="1"),
|
||||
Column("startDate", TIMESTAMP, server_default=func.now()),
|
||||
Column("courseId1", Integer),
|
||||
Column("courseId2", Integer),
|
||||
Column("courseId3", Integer),
|
||||
Column("courseId4", Integer),
|
||||
Column("courseId5", Integer),
|
||||
UniqueConstraint(
|
||||
"version", "unlockChallengeId", name="chuni_static_unlock_challenge_pk"
|
||||
),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class ChuniStaticData(BaseData):
|
||||
async def put_login_bonus(
|
||||
self,
|
||||
@@ -556,7 +577,7 @@ class ChuniStaticData(BaseData):
|
||||
return result.fetchall()
|
||||
|
||||
async def get_music(self, version: int) -> Optional[List[Row]]:
|
||||
sql = music.select(music.c.version <= version)
|
||||
sql = music.select(music.c.version == version)
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
@@ -586,6 +607,28 @@ class ChuniStaticData(BaseData):
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
async def get_music_by_metadata(
|
||||
self, title: Optional[str] = None, artist: Optional[str] = None, genre: Optional[str] = None
|
||||
) -> Optional[List[Row]]:
|
||||
# all conditions should use like for partial matches
|
||||
conditions = []
|
||||
if title:
|
||||
conditions.append(music.c.title.like(f"%{title}%"))
|
||||
if artist:
|
||||
conditions.append(music.c.artist.like(f"%{artist}%"))
|
||||
if genre:
|
||||
conditions.append(music.c.genre.like(f"%{genre}%"))
|
||||
|
||||
if not conditions:
|
||||
return None
|
||||
|
||||
sql = select(music).where(and_(*conditions))
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
async def put_avatar(
|
||||
self,
|
||||
@@ -629,11 +672,25 @@ class ChuniStaticData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_avatar_items(self, version: int, category: int, enabled_only: bool = True) -> Optional[List[Dict]]:
|
||||
async def get_avatar_items(
|
||||
self, version: int, category: int, enabled_only: bool = True
|
||||
) -> Optional[List[Dict]]:
|
||||
if enabled_only:
|
||||
sql = select(avatar).where((avatar.c.version == version) & (avatar.c.category == category) & (avatar.c.isEnabled)).order_by(avatar.c.sortName)
|
||||
sql = (
|
||||
select(avatar)
|
||||
.where(
|
||||
(avatar.c.version == version)
|
||||
& (avatar.c.category == category)
|
||||
& (avatar.c.isEnabled)
|
||||
)
|
||||
.order_by(avatar.c.sortName)
|
||||
)
|
||||
else:
|
||||
sql = select(avatar).where((avatar.c.version == version) & (avatar.c.category == category)).order_by(avatar.c.sortName)
|
||||
sql = (
|
||||
select(avatar)
|
||||
.where((avatar.c.version == version) & (avatar.c.category == category))
|
||||
.order_by(avatar.c.sortName)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
@@ -676,11 +733,21 @@ class ChuniStaticData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_nameplates(self, version: int, enabled_only: bool = True) -> Optional[List[Dict]]:
|
||||
async def get_nameplates(
|
||||
self, version: int, enabled_only: bool = True
|
||||
) -> Optional[List[Dict]]:
|
||||
if enabled_only:
|
||||
sql = select(nameplate).where((nameplate.c.version == version) & (nameplate.c.isEnabled)).order_by(nameplate.c.sortName)
|
||||
sql = (
|
||||
select(nameplate)
|
||||
.where((nameplate.c.version == version) & (nameplate.c.isEnabled))
|
||||
.order_by(nameplate.c.sortName)
|
||||
)
|
||||
else:
|
||||
sql = select(nameplate).where(nameplate.c.version == version).order_by(nameplate.c.sortName)
|
||||
sql = (
|
||||
select(nameplate)
|
||||
.where(nameplate.c.version == version)
|
||||
.order_by(nameplate.c.sortName)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
@@ -720,11 +787,21 @@ class ChuniStaticData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_trophies(self, version: int, enabled_only: bool = True) -> Optional[List[Dict]]:
|
||||
async def get_trophies(
|
||||
self, version: int, enabled_only: bool = True
|
||||
) -> Optional[List[Dict]]:
|
||||
if enabled_only:
|
||||
sql = select(trophy).where((trophy.c.version == version) & (trophy.c.isEnabled)).order_by(trophy.c.name)
|
||||
sql = (
|
||||
select(trophy)
|
||||
.where((trophy.c.version == version) & (trophy.c.isEnabled))
|
||||
.order_by(trophy.c.name)
|
||||
)
|
||||
else:
|
||||
sql = select(trophy).where(trophy.c.version == version).order_by(trophy.c.name)
|
||||
sql = (
|
||||
select(trophy)
|
||||
.where(trophy.c.version == version)
|
||||
.order_by(trophy.c.name)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
@@ -767,11 +844,21 @@ class ChuniStaticData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_map_icons(self, version: int, enabled_only: bool = True) -> Optional[List[Dict]]:
|
||||
async def get_map_icons(
|
||||
self, version: int, enabled_only: bool = True
|
||||
) -> Optional[List[Dict]]:
|
||||
if enabled_only:
|
||||
sql = select(map_icon).where((map_icon.c.version == version) & (map_icon.c.isEnabled)).order_by(map_icon.c.sortName)
|
||||
sql = (
|
||||
select(map_icon)
|
||||
.where((map_icon.c.version == version) & (map_icon.c.isEnabled))
|
||||
.order_by(map_icon.c.sortName)
|
||||
)
|
||||
else:
|
||||
sql = select(map_icon).where(map_icon.c.version == version).order_by(map_icon.c.sortName)
|
||||
sql = (
|
||||
select(map_icon)
|
||||
.where(map_icon.c.version == version)
|
||||
.order_by(map_icon.c.sortName)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
@@ -814,11 +901,21 @@ class ChuniStaticData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_system_voices(self, version: int, enabled_only: bool = True) -> Optional[List[Dict]]:
|
||||
async def get_system_voices(
|
||||
self, version: int, enabled_only: bool = True
|
||||
) -> Optional[List[Dict]]:
|
||||
if enabled_only:
|
||||
sql = select(system_voice).where((system_voice.c.version == version) & (system_voice.c.isEnabled)).order_by(system_voice.c.sortName)
|
||||
sql = (
|
||||
select(system_voice)
|
||||
.where((system_voice.c.version == version) & (system_voice.c.isEnabled))
|
||||
.order_by(system_voice.c.sortName)
|
||||
)
|
||||
else:
|
||||
sql = select(system_voice).where(system_voice.c.version == version).order_by(system_voice.c.sortName)
|
||||
sql = (
|
||||
select(system_voice)
|
||||
.where(system_voice.c.version == version)
|
||||
.order_by(system_voice.c.sortName)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
@@ -873,11 +970,21 @@ class ChuniStaticData(BaseData):
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_characters(self, version: int, enabled_only: bool = True) -> Optional[List[Dict]]:
|
||||
async def get_characters(
|
||||
self, version: int, enabled_only: bool = True
|
||||
) -> Optional[List[Dict]]:
|
||||
if enabled_only:
|
||||
sql = select(character).where((character.c.version == version) & (character.c.isEnabled)).order_by(character.c.sortName)
|
||||
sql = (
|
||||
select(character)
|
||||
.where((character.c.version == version) & (character.c.isEnabled))
|
||||
.order_by(character.c.sortName)
|
||||
)
|
||||
else:
|
||||
sql = select(character).where(character.c.version == version).order_by(character.c.sortName)
|
||||
sql = (
|
||||
select(character)
|
||||
.where(character.c.version == version)
|
||||
.order_by(character.c.sortName)
|
||||
)
|
||||
result = await self.execute(sql)
|
||||
|
||||
if result is None:
|
||||
@@ -1074,3 +1181,54 @@ class ChuniStaticData(BaseData):
|
||||
self.logger.error(f"Failed to set opt enabled status to {enabled} for opt {opt_id}")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def put_unlock_challenge(
|
||||
self,
|
||||
version: int,
|
||||
unlock_challenge_id: int,
|
||||
name: str,
|
||||
course_id1: Optional[int] = None,
|
||||
course_id2: Optional[int] = None,
|
||||
course_id3: Optional[int] = None,
|
||||
course_id4: Optional[int] = None,
|
||||
course_id5: Optional[int] = None,
|
||||
) -> Optional[int]:
|
||||
|
||||
sql = insert(unlock_challenge).values(
|
||||
version=version,
|
||||
unlockChallengeId=unlock_challenge_id,
|
||||
name=name,
|
||||
courseId1=course_id1,
|
||||
courseId2=course_id2,
|
||||
courseId3=course_id3,
|
||||
courseId4=course_id4,
|
||||
courseId5=course_id5,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
name=name,
|
||||
courseId1=course_id1,
|
||||
courseId2=course_id2,
|
||||
courseId3=course_id3,
|
||||
courseId4=course_id4,
|
||||
courseId5=course_id5,
|
||||
)
|
||||
|
||||
result = await self.execute(conflict)
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def get_unlock_challenges(self, version: int) -> Optional[List[Dict]]:
|
||||
sql = unlock_challenge.select(
|
||||
and_(
|
||||
unlock_challenge.c.version == version,
|
||||
unlock_challenge.c.isEnabled == True,
|
||||
)
|
||||
).order_by(unlock_challenge.c.startDate.asc())
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
Reference in New Issue
Block a user