forked from Hay1tsme/artemis
chuni: initial verse support
This commit is contained in:
@ -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