2023-02-17 07:02:21 +01:00
|
|
|
from typing import Dict, List, Optional
|
2023-05-10 21:32:35 +02:00
|
|
|
from sqlalchemy import (
|
|
|
|
ForeignKeyConstraint,
|
|
|
|
Table,
|
|
|
|
Column,
|
|
|
|
UniqueConstraint,
|
|
|
|
PrimaryKeyConstraint,
|
|
|
|
and_,
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, Float
|
|
|
|
from sqlalchemy.engine.base import Connection
|
|
|
|
from sqlalchemy.engine import Row
|
|
|
|
from sqlalchemy.schema import ForeignKey
|
|
|
|
from sqlalchemy.sql import func, select
|
|
|
|
from sqlalchemy.dialects.mysql import insert
|
2023-05-10 21:32:35 +02:00
|
|
|
from datetime import datetime
|
2023-02-17 07:02:21 +01:00
|
|
|
|
|
|
|
from core.data.schema import BaseData, metadata
|
|
|
|
|
|
|
|
events = Table(
|
|
|
|
"chuni_static_events",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("eventId", Integer),
|
|
|
|
Column("type", Integer),
|
|
|
|
Column("name", String(255)),
|
2023-05-10 21:32:35 +02:00
|
|
|
Column("startDate", TIMESTAMP, server_default=func.now()),
|
2023-02-17 07:02:21 +01:00
|
|
|
Column("enabled", Boolean, server_default="1"),
|
|
|
|
UniqueConstraint("version", "eventId", name="chuni_static_events_uk"),
|
2023-03-09 17:38:58 +01:00
|
|
|
mysql_charset="utf8mb4",
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
music = Table(
|
|
|
|
"chuni_static_music",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("songId", Integer),
|
|
|
|
Column("chartId", Integer),
|
|
|
|
Column("title", String(255)),
|
2023-03-09 17:38:58 +01:00
|
|
|
Column("artist", String(255)),
|
2023-02-17 07:02:21 +01:00
|
|
|
Column("level", Float),
|
|
|
|
Column("genre", String(255)),
|
|
|
|
Column("jacketPath", String(255)),
|
2023-03-01 21:09:06 +01:00
|
|
|
Column("worldsEndTag", String(7)),
|
2023-02-17 07:02:21 +01:00
|
|
|
UniqueConstraint("version", "songId", "chartId", name="chuni_static_music_uk"),
|
2023-03-09 17:38:58 +01:00
|
|
|
mysql_charset="utf8mb4",
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
charge = Table(
|
|
|
|
"chuni_static_charge",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("chargeId", Integer),
|
|
|
|
Column("name", String(255)),
|
|
|
|
Column("expirationDays", Integer),
|
|
|
|
Column("consumeType", Integer),
|
|
|
|
Column("sellingAppeal", Boolean),
|
|
|
|
Column("enabled", Boolean, server_default="1"),
|
|
|
|
UniqueConstraint("version", "chargeId", name="chuni_static_charge_uk"),
|
2023-03-09 17:38:58 +01:00
|
|
|
mysql_charset="utf8mb4",
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
avatar = Table(
|
|
|
|
"chuni_static_avatar",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("avatarAccessoryId", Integer),
|
|
|
|
Column("name", String(255)),
|
|
|
|
Column("category", Integer),
|
|
|
|
Column("iconPath", String(255)),
|
|
|
|
Column("texturePath", String(255)),
|
|
|
|
UniqueConstraint("version", "avatarAccessoryId", name="chuni_static_avatar_uk"),
|
2023-03-09 17:38:58 +01:00
|
|
|
mysql_charset="utf8mb4",
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
2023-03-15 21:03:22 +01:00
|
|
|
gachas = Table(
|
|
|
|
"chuni_static_gachas",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("gachaId", Integer, nullable=False),
|
|
|
|
Column("gachaName", String(255), nullable=False),
|
|
|
|
Column("type", Integer, nullable=False, server_default="0"),
|
|
|
|
Column("kind", Integer, nullable=False, server_default="0"),
|
|
|
|
Column("isCeiling", Boolean, server_default="0"),
|
|
|
|
Column("ceilingCnt", Integer, server_default="10"),
|
|
|
|
Column("changeRateCnt1", Integer, server_default="0"),
|
|
|
|
Column("changeRateCnt2", Integer, server_default="0"),
|
|
|
|
Column("startDate", TIMESTAMP, server_default="2018-01-01 00:00:00.0"),
|
|
|
|
Column("endDate", TIMESTAMP, server_default="2038-01-01 00:00:00.0"),
|
|
|
|
Column("noticeStartDate", TIMESTAMP, server_default="2018-01-01 00:00:00.0"),
|
|
|
|
Column("noticeEndDate", TIMESTAMP, server_default="2038-01-01 00:00:00.0"),
|
|
|
|
UniqueConstraint("version", "gachaId", "gachaName", name="chuni_static_gachas_uk"),
|
|
|
|
mysql_charset="utf8mb4",
|
|
|
|
)
|
|
|
|
|
|
|
|
cards = Table(
|
|
|
|
"chuni_static_cards",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("cardId", Integer, nullable=False),
|
|
|
|
Column("charaName", String(255), nullable=False),
|
|
|
|
Column("charaId", Integer, nullable=False),
|
|
|
|
Column("presentName", String(255), nullable=False),
|
|
|
|
Column("rarity", Integer, server_default="2"),
|
|
|
|
Column("labelType", Integer, nullable=False),
|
|
|
|
Column("difType", Integer, nullable=False),
|
|
|
|
Column("miss", Integer, nullable=False),
|
|
|
|
Column("combo", Integer, nullable=False),
|
|
|
|
Column("chain", Integer, nullable=False),
|
|
|
|
Column("skillName", String(255), nullable=False),
|
|
|
|
UniqueConstraint("version", "cardId", name="chuni_static_cards_uk"),
|
|
|
|
mysql_charset="utf8mb4",
|
|
|
|
)
|
|
|
|
|
|
|
|
gacha_cards = Table(
|
|
|
|
"chuni_static_gacha_cards",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("gachaId", Integer, nullable=False),
|
|
|
|
Column("cardId", Integer, nullable=False),
|
|
|
|
Column("rarity", Integer, nullable=False),
|
|
|
|
Column("weight", Integer, server_default="1"),
|
|
|
|
Column("isPickup", Boolean, server_default="0"),
|
|
|
|
UniqueConstraint("gachaId", "cardId", name="chuni_static_gacha_cards_uk"),
|
|
|
|
mysql_charset="utf8mb4",
|
|
|
|
)
|
|
|
|
|
2023-03-28 18:28:57 +02:00
|
|
|
login_bonus_preset = Table(
|
|
|
|
"chuni_static_login_bonus_preset",
|
|
|
|
metadata,
|
2023-05-10 21:32:35 +02:00
|
|
|
Column("presetId", Integer, nullable=False),
|
2023-03-28 18:28:57 +02:00
|
|
|
Column("version", Integer, nullable=False),
|
|
|
|
Column("presetName", String(255), nullable=False),
|
|
|
|
Column("isEnabled", Boolean, server_default="1"),
|
2023-05-10 21:32:35 +02:00
|
|
|
PrimaryKeyConstraint(
|
|
|
|
"presetId", "version", name="chuni_static_login_bonus_preset_pk"
|
|
|
|
),
|
2023-03-28 18:28:57 +02:00
|
|
|
mysql_charset="utf8mb4",
|
|
|
|
)
|
|
|
|
|
|
|
|
login_bonus = Table(
|
|
|
|
"chuni_static_login_bonus",
|
|
|
|
metadata,
|
|
|
|
Column("id", Integer, primary_key=True, nullable=False),
|
|
|
|
Column("version", Integer, nullable=False),
|
2023-05-10 21:32:35 +02:00
|
|
|
Column("presetId", Integer, nullable=False),
|
2023-03-28 18:28:57 +02:00
|
|
|
Column("loginBonusId", Integer, nullable=False),
|
|
|
|
Column("loginBonusName", String(255), nullable=False),
|
|
|
|
Column("presentId", Integer, nullable=False),
|
|
|
|
Column("presentName", String(255), nullable=False),
|
|
|
|
Column("itemNum", Integer, nullable=False),
|
|
|
|
Column("needLoginDayCount", Integer, nullable=False),
|
|
|
|
Column("loginBonusCategoryType", Integer, nullable=False),
|
|
|
|
UniqueConstraint(
|
|
|
|
"version", "presetId", "loginBonusId", name="chuni_static_login_bonus_uk"
|
|
|
|
),
|
2023-05-10 21:32:35 +02:00
|
|
|
ForeignKeyConstraint(
|
|
|
|
["presetId", "version"],
|
|
|
|
[
|
|
|
|
"chuni_static_login_bonus_preset.presetId",
|
|
|
|
"chuni_static_login_bonus_preset.version",
|
|
|
|
],
|
|
|
|
onupdate="CASCADE",
|
|
|
|
ondelete="CASCADE",
|
|
|
|
name="chuni_static_login_bonus_ibfk_1",
|
|
|
|
),
|
2023-03-28 18:28:57 +02:00
|
|
|
mysql_charset="utf8mb4",
|
|
|
|
)
|
|
|
|
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2023-02-17 07:02:21 +01:00
|
|
|
class ChuniStaticData(BaseData):
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_login_bonus(
|
2023-03-28 18:28:57 +02:00
|
|
|
self,
|
|
|
|
version: int,
|
|
|
|
preset_id: int,
|
|
|
|
login_bonus_id: int,
|
|
|
|
login_bonus_name: str,
|
|
|
|
present_id: int,
|
|
|
|
present_ame: str,
|
|
|
|
item_num: int,
|
|
|
|
need_login_day_count: int,
|
|
|
|
login_bonus_category_type: int,
|
|
|
|
) -> Optional[int]:
|
|
|
|
sql = insert(login_bonus).values(
|
|
|
|
version=version,
|
|
|
|
presetId=preset_id,
|
|
|
|
loginBonusId=login_bonus_id,
|
|
|
|
loginBonusName=login_bonus_name,
|
|
|
|
presentId=present_id,
|
|
|
|
presentName=present_ame,
|
|
|
|
itemNum=item_num,
|
|
|
|
needLoginDayCount=need_login_day_count,
|
|
|
|
loginBonusCategoryType=login_bonus_category_type,
|
|
|
|
)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
|
|
|
loginBonusName=login_bonus_name,
|
|
|
|
presentName=present_ame,
|
|
|
|
itemNum=item_num,
|
|
|
|
needLoginDayCount=need_login_day_count,
|
|
|
|
loginBonusCategoryType=login_bonus_category_type,
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-28 18:28:57 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.lastrowid
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_login_bonus(
|
2023-04-24 03:04:52 +02:00
|
|
|
self,
|
|
|
|
version: int,
|
|
|
|
preset_id: int,
|
2023-03-28 18:28:57 +02:00
|
|
|
) -> Optional[List[Row]]:
|
|
|
|
sql = login_bonus.select(
|
|
|
|
and_(
|
|
|
|
login_bonus.c.version == version,
|
|
|
|
login_bonus.c.presetId == preset_id,
|
|
|
|
)
|
|
|
|
).order_by(login_bonus.c.needLoginDayCount.desc())
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-28 18:28:57 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_login_bonus_by_required_days(
|
2023-03-28 18:28:57 +02:00
|
|
|
self, version: int, preset_id: int, need_login_day_count: int
|
|
|
|
) -> Optional[Row]:
|
|
|
|
sql = login_bonus.select(
|
|
|
|
and_(
|
|
|
|
login_bonus.c.version == version,
|
|
|
|
login_bonus.c.presetId == preset_id,
|
|
|
|
login_bonus.c.needLoginDayCount == need_login_day_count,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-28 18:28:57 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchone()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_login_bonus_preset(
|
2023-03-28 18:28:57 +02:00
|
|
|
self, version: int, preset_id: int, preset_name: str, is_enabled: bool
|
|
|
|
) -> Optional[int]:
|
|
|
|
sql = insert(login_bonus_preset).values(
|
2023-05-10 21:32:35 +02:00
|
|
|
presetId=preset_id,
|
2023-03-28 18:28:57 +02:00
|
|
|
version=version,
|
|
|
|
presetName=preset_name,
|
|
|
|
isEnabled=is_enabled,
|
|
|
|
)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
|
|
|
presetName=preset_name, isEnabled=is_enabled
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-28 18:28:57 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.lastrowid
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_login_bonus_presets(
|
2023-03-28 18:28:57 +02:00
|
|
|
self, version: int, is_enabled: bool = True
|
|
|
|
) -> Optional[List[Row]]:
|
|
|
|
sql = login_bonus_preset.select(
|
|
|
|
and_(
|
|
|
|
login_bonus_preset.c.version == version,
|
|
|
|
login_bonus_preset.c.isEnabled == is_enabled,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-28 18:28:57 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_event(
|
2023-03-09 17:38:58 +01:00
|
|
|
self, version: int, event_id: int, type: int, name: str
|
|
|
|
) -> Optional[int]:
|
2023-02-17 07:02:21 +01:00
|
|
|
sql = insert(events).values(
|
2023-03-09 17:38:58 +01:00
|
|
|
version=version, eventId=event_id, type=type, name=name
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
2023-03-09 17:38:58 +01:00
|
|
|
conflict = sql.on_duplicate_key_update(name=name)
|
2023-02-17 07:02:21 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.lastrowid
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def update_event(
|
2023-03-09 17:38:58 +01:00
|
|
|
self, version: int, event_id: int, enabled: bool
|
|
|
|
) -> Optional[bool]:
|
|
|
|
sql = events.update(
|
|
|
|
and_(events.c.version == version, events.c.eventId == event_id)
|
|
|
|
).values(enabled=enabled)
|
2023-02-17 07:02:21 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
2023-08-08 16:17:56 +02:00
|
|
|
self.logger.warning(
|
2023-03-09 17:38:58 +01:00
|
|
|
f"update_event: failed to update event! version: {version}, event_id: {event_id}, enabled: {enabled}"
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
event = self.get_event(version, event_id)
|
|
|
|
if event is None:
|
2023-08-08 16:17:56 +02:00
|
|
|
self.logger.warning(
|
2023-03-09 17:38:58 +01:00
|
|
|
f"update_event: failed to fetch event {event_id} after updating"
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
return None
|
|
|
|
return event["enabled"]
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_event(self, version: int, event_id: int) -> Optional[Row]:
|
2023-03-09 17:38:58 +01:00
|
|
|
sql = select(events).where(
|
|
|
|
and_(events.c.version == version, events.c.eventId == event_id)
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.fetchone()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_enabled_events(self, version: int) -> Optional[List[Row]]:
|
2023-03-09 17:38:58 +01:00
|
|
|
sql = select(events).where(
|
|
|
|
and_(events.c.version == version, events.c.enabled == True)
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_events(self, version: int) -> Optional[List[Row]]:
|
2023-02-17 07:02:21 +01:00
|
|
|
sql = select(events).where(events.c.version == version)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_music(
|
2023-03-09 17:38:58 +01:00
|
|
|
self,
|
|
|
|
version: int,
|
|
|
|
song_id: int,
|
|
|
|
chart_id: int,
|
|
|
|
title: int,
|
|
|
|
artist: str,
|
|
|
|
level: float,
|
|
|
|
genre: str,
|
|
|
|
jacketPath: str,
|
|
|
|
we_tag: str,
|
|
|
|
) -> Optional[int]:
|
2023-02-17 07:02:21 +01:00
|
|
|
sql = insert(music).values(
|
2023-03-09 17:38:58 +01:00
|
|
|
version=version,
|
|
|
|
songId=song_id,
|
|
|
|
chartId=chart_id,
|
|
|
|
title=title,
|
|
|
|
artist=artist,
|
|
|
|
level=level,
|
|
|
|
genre=genre,
|
|
|
|
jacketPath=jacketPath,
|
|
|
|
worldsEndTag=we_tag,
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
2023-03-09 17:38:58 +01:00
|
|
|
title=title,
|
|
|
|
artist=artist,
|
|
|
|
level=level,
|
|
|
|
genre=genre,
|
|
|
|
jacketPath=jacketPath,
|
|
|
|
worldsEndTag=we_tag,
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.lastrowid
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_charge(
|
2023-03-09 17:38:58 +01:00
|
|
|
self,
|
|
|
|
version: int,
|
|
|
|
charge_id: int,
|
|
|
|
name: str,
|
|
|
|
expiration_days: int,
|
|
|
|
consume_type: int,
|
|
|
|
selling_appeal: bool,
|
|
|
|
) -> Optional[int]:
|
2023-02-17 07:02:21 +01:00
|
|
|
sql = insert(charge).values(
|
2023-03-09 17:38:58 +01:00
|
|
|
version=version,
|
|
|
|
chargeId=charge_id,
|
|
|
|
name=name,
|
|
|
|
expirationDays=expiration_days,
|
|
|
|
consumeType=consume_type,
|
|
|
|
sellingAppeal=selling_appeal,
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
2023-03-09 17:38:58 +01:00
|
|
|
name=name,
|
|
|
|
expirationDays=expiration_days,
|
|
|
|
consumeType=consume_type,
|
|
|
|
sellingAppeal=selling_appeal,
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.lastrowid
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_enabled_charges(self, version: int) -> Optional[List[Row]]:
|
2023-03-09 17:38:58 +01:00
|
|
|
sql = select(charge).where(
|
|
|
|
and_(charge.c.version == version, charge.c.enabled == True)
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.fetchall()
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_charges(self, version: int) -> Optional[List[Row]]:
|
2023-02-17 07:02:21 +01:00
|
|
|
sql = select(charge).where(charge.c.version == version)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_music(self, version: int) -> Optional[List[Row]]:
|
2023-05-10 21:32:35 +02:00
|
|
|
sql = music.select(music.c.version <= version)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-05-10 21:32:35 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_music_chart(
|
2023-03-09 17:38:58 +01:00
|
|
|
self, version: int, song_id: int, chart_id: int
|
|
|
|
) -> Optional[List[Row]]:
|
|
|
|
sql = select(music).where(
|
|
|
|
and_(
|
|
|
|
music.c.version == version,
|
|
|
|
music.c.songId == song_id,
|
|
|
|
music.c.chartId == chart_id,
|
|
|
|
)
|
|
|
|
)
|
2023-02-17 07:02:21 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.fetchone()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_song(self, music_id: int) -> Optional[Row]:
|
2023-07-11 11:16:11 +02:00
|
|
|
sql = music.select(music.c.id == music_id)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-07-11 11:16:11 +02:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchone()
|
|
|
|
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_avatar(
|
2023-03-09 17:38:58 +01:00
|
|
|
self,
|
|
|
|
version: int,
|
|
|
|
avatarAccessoryId: int,
|
|
|
|
name: str,
|
|
|
|
category: int,
|
|
|
|
iconPath: str,
|
|
|
|
texturePath: str,
|
|
|
|
) -> Optional[int]:
|
2023-02-17 07:02:21 +01:00
|
|
|
sql = insert(avatar).values(
|
2023-03-09 17:38:58 +01:00
|
|
|
version=version,
|
|
|
|
avatarAccessoryId=avatarAccessoryId,
|
|
|
|
name=name,
|
|
|
|
category=category,
|
|
|
|
iconPath=iconPath,
|
|
|
|
texturePath=texturePath,
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
2023-03-09 17:38:58 +01:00
|
|
|
name=name,
|
|
|
|
category=category,
|
|
|
|
iconPath=iconPath,
|
|
|
|
texturePath=texturePath,
|
2023-02-17 07:02:21 +01:00
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-09 17:38:58 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-02-17 07:02:21 +01:00
|
|
|
return result.lastrowid
|
2023-03-15 21:03:22 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_gacha(
|
2023-03-15 21:03:22 +01:00
|
|
|
self,
|
|
|
|
version: int,
|
|
|
|
gacha_id: int,
|
|
|
|
gacha_name: int,
|
|
|
|
**gacha_data,
|
|
|
|
) -> Optional[int]:
|
|
|
|
sql = insert(gachas).values(
|
|
|
|
version=version,
|
|
|
|
gachaId=gacha_id,
|
|
|
|
gachaName=gacha_name,
|
|
|
|
**gacha_data,
|
|
|
|
)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
|
|
|
version=version,
|
|
|
|
gachaId=gacha_id,
|
|
|
|
gachaName=gacha_name,
|
|
|
|
**gacha_data,
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
2023-08-08 16:17:56 +02:00
|
|
|
self.logger.warning(f"Failed to insert gacha! gacha_id {gacha_id}")
|
2023-03-15 21:03:22 +01:00
|
|
|
return None
|
|
|
|
return result.lastrowid
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_gachas(self, version: int) -> Optional[List[Dict]]:
|
2023-03-15 21:03:22 +01:00
|
|
|
sql = gachas.select(gachas.c.version <= version).order_by(
|
|
|
|
gachas.c.gachaId.asc()
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_gacha(self, version: int, gacha_id: int) -> Optional[Dict]:
|
2023-03-15 21:03:22 +01:00
|
|
|
sql = gachas.select(
|
|
|
|
and_(gachas.c.version <= version, gachas.c.gachaId == gacha_id)
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchone()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_gacha_card(
|
2023-03-15 21:03:22 +01:00
|
|
|
self, gacha_id: int, card_id: int, **gacha_card
|
|
|
|
) -> Optional[int]:
|
|
|
|
sql = insert(gacha_cards).values(gachaId=gacha_id, cardId=card_id, **gacha_card)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(
|
|
|
|
gachaId=gacha_id, cardId=card_id, **gacha_card
|
|
|
|
)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
2023-08-08 16:17:56 +02:00
|
|
|
self.logger.warning(f"Failed to insert gacha card! gacha_id {gacha_id}")
|
2023-03-15 21:03:22 +01:00
|
|
|
return None
|
|
|
|
return result.lastrowid
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_gacha_cards(self, gacha_id: int) -> Optional[List[Dict]]:
|
2023-03-15 21:03:22 +01:00
|
|
|
sql = gacha_cards.select(gacha_cards.c.gachaId == gacha_id)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchall()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_gacha_card_by_character(
|
2023-03-24 18:10:10 +01:00
|
|
|
self, gacha_id: int, chara_id: int
|
|
|
|
) -> Optional[Dict]:
|
2023-03-15 21:03:22 +01:00
|
|
|
sql_sub = (
|
2023-03-24 18:10:10 +01:00
|
|
|
select(cards.c.cardId).filter(cards.c.charaId == chara_id).scalar_subquery()
|
2023-03-15 21:03:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Perform the main query, also rename the resulting column to ranking
|
2023-03-24 18:10:10 +01:00
|
|
|
sql = gacha_cards.select(
|
|
|
|
and_(gacha_cards.c.gachaId == gacha_id, gacha_cards.c.cardId == sql_sub)
|
|
|
|
)
|
2023-03-15 21:03:22 +01:00
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return result.fetchone()
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def put_card(self, version: int, card_id: int, **card_data) -> Optional[int]:
|
2023-03-15 21:03:22 +01:00
|
|
|
sql = insert(cards).values(version=version, cardId=card_id, **card_data)
|
|
|
|
|
|
|
|
conflict = sql.on_duplicate_key_update(**card_data)
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(conflict)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
2023-08-08 16:17:56 +02:00
|
|
|
self.logger.warning(f"Failed to insert card! card_id {card_id}")
|
2023-03-15 21:03:22 +01:00
|
|
|
return None
|
|
|
|
return result.lastrowid
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
async def get_card(self, version: int, card_id: int) -> Optional[Dict]:
|
2023-03-15 21:03:22 +01:00
|
|
|
sql = cards.select(and_(cards.c.version <= version, cards.c.cardId == card_id))
|
|
|
|
|
2024-01-09 20:42:17 +01:00
|
|
|
result = await self.execute(sql)
|
2023-03-15 21:03:22 +01:00
|
|
|
if result is None:
|
|
|
|
return None
|
2023-07-11 11:16:11 +02:00
|
|
|
return result.fetchone()
|