diff --git a/core/aimedb.py b/core/aimedb.py index c5c1837..727a310 100644 --- a/core/aimedb.py +++ b/core/aimedb.py @@ -177,9 +177,9 @@ class AimedbServlette(): async def handle_lookup(self, data: bytes, resp_code: int) -> ADBBaseResponse: req = ADBLookupRequest(data) - user_id = self.data.card.get_user_id_from_card(req.access_code) - is_banned = self.data.card.get_card_banned(req.access_code) - is_locked = self.data.card.get_card_locked(req.access_code) + user_id = await self.data.card.get_user_id_from_card(req.access_code) + is_banned = await self.data.card.get_card_banned(req.access_code) + is_locked = await self.data.card.get_card_locked(req.access_code) ret = ADBLookupResponse.from_req(req.head, user_id) if is_banned and is_locked: @@ -196,10 +196,10 @@ class AimedbServlette(): async def handle_lookup_ex(self, data: bytes, resp_code: int) -> ADBBaseResponse: req = ADBLookupRequest(data) - user_id = self.data.card.get_user_id_from_card(req.access_code) + user_id = await self.data.card.get_user_id_from_card(req.access_code) - is_banned = self.data.card.get_card_banned(req.access_code) - is_locked = self.data.card.get_card_locked(req.access_code) + is_banned = await self.data.card.get_card_banned(req.access_code) + is_locked = await self.data.card.get_card_locked(req.access_code) ret = ADBLookupExResponse.from_req(req.head, user_id) if is_banned and is_locked: @@ -233,7 +233,7 @@ class AimedbServlette(): be fine. """ req = ADBFelicaLookupRequest(data) - ac = self.data.card.to_access_code(req.idm) + ac = await self.data.card.to_access_code(req.idm) self.logger.info( f"idm {req.idm} ipm {req.pmm} -> access_code {ac}" ) @@ -244,17 +244,17 @@ class AimedbServlette(): I've never seen this used. """ req = ADBFelicaLookupRequest(data) - ac = self.data.card.to_access_code(req.idm) + ac = await self.data.card.to_access_code(req.idm) if self.config.server.allow_user_registration: - user_id = self.data.user.create_user() + user_id = await self.data.user.create_user() if user_id is None: self.logger.error("Failed to register user!") user_id = -1 else: - card_id = self.data.card.create_card(user_id, ac) + card_id = await self.data.card.create_card(user_id, ac) if card_id is None: self.logger.error("Failed to register card!") @@ -273,8 +273,8 @@ class AimedbServlette(): async def handle_felica_lookup_ex(self, data: bytes, resp_code: int) -> bytes: req = ADBFelicaLookup2Request(data) - access_code = self.data.card.to_access_code(req.idm) - user_id = self.data.card.get_user_id_from_card(access_code=access_code) + access_code = await self.data.card.to_access_code(req.idm) + user_id = await self.data.card.get_user_id_from_card(access_code=access_code) if user_id is None: user_id = -1 @@ -308,14 +308,14 @@ class AimedbServlette(): user_id = -1 if self.config.server.allow_user_registration: - user_id = self.data.user.create_user() + user_id = await self.data.user.create_user() if user_id is None: self.logger.error("Failed to register user!") user_id = -1 else: - card_id = self.data.card.create_card(user_id, req.access_code) + card_id = await self.data.card.create_card(user_id, req.access_code) if card_id is None: self.logger.error("Failed to register card!") diff --git a/core/allnet.py b/core/allnet.py index 712b945..219f331 100644 --- a/core/allnet.py +++ b/core/allnet.py @@ -170,10 +170,10 @@ class AllnetServlet: self.logger.debug(f"Allnet request: {vars(req)}") - machine = self.data.arcade.get_machine(req.serial) + machine = await self.data.arcade.get_machine(req.serial) if machine is None and not self.config.server.allow_unregistered_serials: msg = f"Unrecognised serial {req.serial} attempted allnet auth from {request_ip}." - self.data.base.log_event( + await self.data.base.log_event( "allnet", "ALLNET_AUTH_UNKNOWN_SERIAL", logging.WARN, msg ) self.logger.warning(msg) @@ -183,11 +183,11 @@ class AllnetServlet: return PlainTextResponse(urllib.parse.unquote(urllib.parse.urlencode(resp_dict)) + "\n") if machine is not None: - arcade = self.data.arcade.get_arcade(machine["arcade"]) + arcade = await self.data.arcade.get_arcade(machine["arcade"]) if self.config.server.check_arcade_ip: if arcade["ip"] and arcade["ip"] is not None and arcade["ip"] != req.ip: msg = f"Serial {req.serial} attempted allnet auth from bad IP {req.ip} (expected {arcade['ip']})." - self.data.base.log_event( + await self.data.base.log_event( "allnet", "ALLNET_AUTH_BAD_IP", logging.ERROR, msg ) self.logger.warning(msg) @@ -198,7 +198,7 @@ class AllnetServlet: elif (not arcade["ip"] or arcade["ip"] is None) and self.config.server.strict_ip_checking: msg = f"Serial {req.serial} attempted allnet auth from bad IP {req.ip}, but arcade {arcade['id']} has no IP set! (strict checking enabled)." - self.data.base.log_event( + await self.data.base.log_event( "allnet", "ALLNET_AUTH_NO_SHOP_IP", logging.ERROR, msg ) self.logger.warning(msg) @@ -242,7 +242,7 @@ class AllnetServlet: if req.game_id not in TitleServlet.title_registry: if not self.config.server.is_develop: msg = f"Unrecognised game {req.game_id} attempted allnet auth from {request_ip}." - self.data.base.log_event( + await self.data.base.log_event( "allnet", "ALLNET_AUTH_UNKNOWN_GAME", logging.WARN, msg ) self.logger.warning(msg) @@ -269,7 +269,7 @@ class AllnetServlet: resp.uri, resp.host = TitleServlet.title_registry[req.game_id].get_allnet_info(req.game_id, int(int_ver), req.serial) msg = f"{req.serial} authenticated from {request_ip}: {req.game_id} v{req.ver}" - self.data.base.log_event("allnet", "ALLNET_AUTH_SUCCESS", logging.INFO, msg) + await self.data.base.log_event("allnet", "ALLNET_AUTH_SUCCESS", logging.INFO, msg) self.logger.info(msg) resp_dict = {k: v for k, v in vars(resp).items() if v is not None} @@ -335,7 +335,7 @@ class AllnetServlet: resp.uri += f"|http://{self.config.server.hostname}:{self.config.server.port}/dl/ini/{req.game_id}-{req.ver.replace('.', '')}-opt.ini" self.logger.debug(f"Sending download uri {resp.uri}") - self.data.base.log_event("allnet", "DLORDER_REQ_SUCCESS", logging.INFO, f"{Utils.get_ip_addr(request)} requested DL Order for {req.serial} {req.game_id} v{req.ver}") + await self.data.base.log_event("allnet", "DLORDER_REQ_SUCCESS", logging.INFO, f"{Utils.get_ip_addr(request)} requested DL Order for {req.serial} {req.game_id} v{req.ver}") res_str = urllib.parse.unquote(urllib.parse.urlencode(vars(resp))) + "\n" """if is_dfi: @@ -352,7 +352,7 @@ class AllnetServlet: if path.exists(f"{self.config.allnet.update_cfg_folder}/{req_file}"): self.logger.info(f"Request for DL INI file {req_file} from {Utils.get_ip_addr(request)} successful") - self.data.base.log_event("allnet", "DLORDER_INI_SENT", logging.INFO, f"{Utils.get_ip_addr(request)} successfully recieved {req_file}") + await self.data.base.log_event("allnet", "DLORDER_INI_SENT", logging.INFO, f"{Utils.get_ip_addr(request)} successfully recieved {req_file}") return PlainTextResponse(open( f"{self.config.allnet.update_cfg_folder}/{req_file}", "r" @@ -390,7 +390,7 @@ class AllnetServlet: msg = f"{rep.serial} @ {client_ip} reported {rep.rep_type.name} download state {rep.rf_state.name} for {rep.gd} v{rep.dav}:"\ f" {rep.tdsc}/{rep.tsc} segments downloaded for working files {rep.wfl} with {rep.dfl if rep.dfl else 'none'} complete." - self.data.base.log_event("allnet", "DL_REPORT", logging.INFO, msg, dl_data) + await self.data.base.log_event("allnet", "DL_REPORT", logging.INFO, msg, dl_data) self.logger.info(msg) return PlainTextResponse("OK") @@ -540,10 +540,10 @@ class BillingServlet: kc_serial_bytes = req.keychipid.encode() - machine = self.data.arcade.get_machine(req.keychipid) + machine = await self.data.arcade.get_machine(req.keychipid) if machine is None and not self.config.server.allow_unregistered_serials: msg = f"Unrecognised serial {req.keychipid} attempted billing checkin from {request_ip} for {req.gameid} v{req.gamever}." - self.data.base.log_event( + await self.data.base.log_event( "allnet", "BILLING_CHECKIN_NG_SERIAL", logging.WARN, msg ) self.logger.warning(msg) @@ -555,7 +555,7 @@ class BillingServlet: f"{req.playcnt} billing_type {req.billingtype.name} nearfull {req.nearfull} playlimit {req.playlimit}" ) self.logger.info(msg) - self.data.base.log_event("billing", "BILLING_CHECKIN_OK", logging.INFO, msg) + await self.data.base.log_event("billing", "BILLING_CHECKIN_OK", logging.INFO, msg) if req.traceleft > 0: self.logger.warn(f"{req.traceleft} unsent tracelogs") kc_playlimit = req.playlimit @@ -699,7 +699,7 @@ class BillingInfo: self.boardid = str(data.get("boardid", None)) self.tenpoip = str(data.get("tenpoip", None)) self.libalibver = float(data.get("libalibver", None)) - self.datamax = int(data.get("datamax", None)) + self.data.max = int(data.get("datamax", None)) self.billingtype = BillingType(int(data.get("billingtype", None))) self.protocolver = float(data.get("protocolver", None)) self.operatingfix = bool(data.get("operatingfix", None)) diff --git a/core/data/schema/arcade.py b/core/data/schema/arcade.py index 2fb8e43..03d0915 100644 --- a/core/data/schema/arcade.py +++ b/core/data/schema/arcade.py @@ -69,7 +69,7 @@ arcade_owner = Table( class ArcadeData(BaseData): - def get_machine(self, serial: str = None, id: int = None) -> Optional[Row]: + async def get_machine(self, serial: str = None, id: int = None) -> Optional[Row]: if serial is not None: serial = serial.replace("-", "") if len(serial) == 11: @@ -89,12 +89,12 @@ class ArcadeData(BaseData): self.logger.error(f"{__name__ }: Need either serial or ID to look up!") return None - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_machine( + async def put_machine( self, arcade_id: int, serial: str = "", @@ -110,13 +110,13 @@ class ArcadeData(BaseData): arcade=arcade_id, keychip=serial, board=board, game=game, is_cab=is_cab ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.lastrowid - def set_machine_serial(self, machine_id: int, serial: str) -> None: - result = self.execute( + async def set_machine_serial(self, machine_id: int, serial: str) -> None: + result = await self.execute( machine.update(machine.c.id == machine_id).values(keychip=serial) ) if result is None: @@ -125,8 +125,8 @@ class ArcadeData(BaseData): ) return result.lastrowid - def set_machine_boardid(self, machine_id: int, boardid: str) -> None: - result = self.execute( + async def set_machine_boardid(self, machine_id: int, boardid: str) -> None: + result = await self.execute( machine.update(machine.c.id == machine_id).values(board=boardid) ) if result is None: @@ -134,21 +134,21 @@ class ArcadeData(BaseData): f"Failed to update board id for machine {machine_id} -> {boardid}" ) - def get_arcade(self, id: int) -> Optional[Row]: + async def get_arcade(self, id: int) -> Optional[Row]: sql = arcade.select(arcade.c.id == id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_arcade_machines(self, id: int) -> Optional[List[Row]]: + async def get_arcade_machines(self, id: int) -> Optional[List[Row]]: sql = machine.select(machine.c.arcade == id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_arcade( + async def put_arcade( self, name: str, nickname: str = None, @@ -171,42 +171,42 @@ class ArcadeData(BaseData): regional_id=regional_id, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.lastrowid - def get_arcades_managed_by_user(self, user_id: int) -> Optional[List[Row]]: + async def get_arcades_managed_by_user(self, user_id: int) -> Optional[List[Row]]: sql = select(arcade).join(arcade_owner, arcade_owner.c.arcade == arcade.c.id).where(arcade_owner.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return False return result.fetchall() - def get_manager_permissions(self, user_id: int, arcade_id: int) -> Optional[int]: + async def get_manager_permissions(self, user_id: int, arcade_id: int) -> Optional[int]: sql = select(arcade_owner.c.permissions).where(and_(arcade_owner.c.user == user_id, arcade_owner.c.arcade == arcade_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return False return result.fetchone() - def get_arcade_owners(self, arcade_id: int) -> Optional[Row]: + async def get_arcade_owners(self, arcade_id: int) -> Optional[Row]: sql = select(arcade_owner).where(arcade_owner.c.arcade == arcade_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def add_arcade_owner(self, arcade_id: int, user_id: int) -> None: + async def add_arcade_owner(self, arcade_id: int, user_id: int) -> None: sql = insert(arcade_owner).values(arcade=arcade_id, user=user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.lastrowid - def format_serial( + async def format_serial( self, platform_code: str, platform_rev: int, serial_num: int, append: int = 4152 ) -> str: return f"{platform_code}{platform_rev:02d}A{serial_num:04d}{append:04d}" # 0x41 = A, 0x52 = R @@ -217,16 +217,16 @@ class ArcadeData(BaseData): return True - def get_arcade_by_name(self, name: str) -> Optional[List[Row]]: + async def get_arcade_by_name(self, name: str) -> Optional[List[Row]]: sql = arcade.select(or_(arcade.c.name.like(f"%{name}%"), arcade.c.nickname.like(f"%{name}%"))) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_arcades_by_ip(self, ip: str) -> Optional[List[Row]]: + async def get_arcades_by_ip(self, ip: str) -> Optional[List[Row]]: sql = arcade.select().where(arcade.c.ip == ip) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/core/data/schema/base.py b/core/data/schema/base.py index 1ad65e5..5549ab2 100644 --- a/core/data/schema/base.py +++ b/core/data/schema/base.py @@ -92,7 +92,7 @@ class BaseData: message=message, details=json.dumps(details), ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( @@ -104,7 +104,7 @@ class BaseData: async def get_event_log(self, entries: int = 100) -> Optional[List[Dict]]: sql = event_log.select().limit(entries).all() - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None diff --git a/core/data/schema/card.py b/core/data/schema/card.py index a95684e..6953b26 100644 --- a/core/data/schema/card.py +++ b/core/data/schema/card.py @@ -27,34 +27,34 @@ aime_card = Table( class CardData(BaseData): - def get_card_by_access_code(self, access_code: str) -> Optional[Row]: + async def get_card_by_access_code(self, access_code: str) -> Optional[Row]: sql = aime_card.select(aime_card.c.access_code == access_code) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_card_by_id(self, card_id: int) -> Optional[Row]: + async def get_card_by_id(self, card_id: int) -> Optional[Row]: sql = aime_card.select(aime_card.c.id == card_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def update_access_code(self, old_ac: str, new_ac: str) -> None: + async def update_access_code(self, old_ac: str, new_ac: str) -> None: sql = aime_card.update(aime_card.c.access_code == old_ac).values( access_code=new_ac ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"Failed to change card access code from {old_ac} to {new_ac}" ) - def get_user_id_from_card(self, access_code: str) -> Optional[int]: + async def get_user_id_from_card(self, access_code: str) -> Optional[int]: """ Given a 20 digit access code as a string, get the user id associated with that card """ @@ -64,7 +64,7 @@ class CardData(BaseData): return int(card["user"]) - def get_card_banned(self, access_code: str) -> Optional[bool]: + async def get_card_banned(self, access_code: str) -> Optional[bool]: """ Given a 20 digit access code as a string, check if the card is banned """ @@ -74,7 +74,7 @@ class CardData(BaseData): if card["is_banned"]: return True return False - def get_card_locked(self, access_code: str) -> Optional[bool]: + async def get_card_locked(self, access_code: str) -> Optional[bool]: """ Given a 20 digit access code as a string, check if the card is locked """ @@ -85,29 +85,29 @@ class CardData(BaseData): return True return False - def delete_card(self, card_id: int) -> None: + async def delete_card(self, card_id: int) -> None: sql = aime_card.delete(aime_card.c.id == card_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error(f"Failed to delete card with id {card_id}") - def get_user_cards(self, aime_id: int) -> Optional[List[Row]]: + async def get_user_cards(self, aime_id: int) -> Optional[List[Row]]: """ Returns all cards owned by a user """ sql = aime_card.select(aime_card.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def create_card(self, user_id: int, access_code: str) -> Optional[int]: + async def create_card(self, user_id: int, access_code: str) -> Optional[int]: """ Given a aime_user id and a 20 digit access code as a string, create a card and return the ID if successful """ sql = aime_card.insert().values(user=user_id, access_code=access_code) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.lastrowid diff --git a/core/data/schema/user.py b/core/data/schema/user.py index 221ba81..6b733e2 100644 --- a/core/data/schema/user.py +++ b/core/data/schema/user.py @@ -1,4 +1,3 @@ -from enum import Enum from typing import Optional, List from sqlalchemy import Table, Column from sqlalchemy.types import Integer, String, TIMESTAMP @@ -24,15 +23,8 @@ aime_user = Table( mysql_charset="utf8mb4", ) - -class PermissionBits(Enum): - PermUser = 1 - PermMod = 2 - PermSysAdmin = 4 - - class UserData(BaseData): - def create_user( + async def create_user( self, id: int = None, username: str = None, @@ -60,14 +52,14 @@ class UserData(BaseData): username=username, email=email, password=password, permissions=permission ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_user(self, user_id: int) -> Optional[Row]: + async def get_user(self, user_id: int) -> Optional[Row]: sql = select(aime_user).where(aime_user.c.id == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return False return result.fetchone() @@ -85,39 +77,34 @@ class UserData(BaseData): return bcrypt.checkpw(passwd, usr["password"].encode()) - def reset_autoincrement(self, ai_value: int) -> None: - # ALTER TABLE isn't in sqlalchemy so we do this the ugly way - sql = f"ALTER TABLE aime_user AUTO_INCREMENT={ai_value}" - self.execute(sql) - - def delete_user(self, user_id: int) -> None: + async def delete_user(self, user_id: int) -> None: sql = aime_user.delete(aime_user.c.id == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error(f"Failed to delete user with id {user_id}") - def get_unregistered_users(self) -> List[Row]: + async def get_unregistered_users(self) -> List[Row]: """ Returns a list of users who have not registered with the webui. They may or may not have cards. """ sql = select(aime_user).where(aime_user.c.password == None) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def find_user_by_email(self, email: str) -> Row: + async def find_user_by_email(self, email: str) -> Row: sql = select(aime_user).where(aime_user.c.email == email) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return False return result.fetchone() - def find_user_by_username(self, username: str) -> List[Row]: + async def find_user_by_username(self, username: str) -> List[Row]: sql = aime_user.select(aime_user.c.username.like(f"%{username}%")) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return False return result.fetchall() diff --git a/core/frontend.py b/core/frontend.py index 054092c..26796d3 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -110,7 +110,7 @@ class FrontendServlet(resource.Resource): async def robots(cls, request: Request) -> PlainTextResponse: return PlainTextResponse("User-agent: *\nDisallow: /\n\nUser-agent: AdsBot-Google\nDisallow: /") - def render_GET(self, request): + async def render_GET(self, request): self.logger.debug(f"{Utils.get_ip_addr(request)} -> {request.uri.decode()}") template = self.environment.get_template("core/frontend/index.jinja") return template.render( @@ -167,7 +167,7 @@ class FE_Gate(FE_Base): sesh=vars(usr_sesh), ).encode("utf-16") - def render_POST(self, request: Request): + async def render_POST(self, request: Request): uri = request.uri.decode() ip = Utils.get_ip_addr(request) @@ -177,13 +177,13 @@ class FE_Gate(FE_Base): if passwd == b"": passwd = None - uid = self.data.card.get_user_id_from_card(access_code) - user = self.data.user.get_user(uid) + uid = await self.data.card.get_user_id_from_card(access_code) + user = await self.data.user.get_user(uid) if uid is None: return redirectTo(b"/gate?e=1", request) if passwd is None: - sesh = self.data.user.check_password(uid) + sesh = await self.data.user.check_password(uid) if sesh is not None: return redirectTo( @@ -210,14 +210,14 @@ class FE_Gate(FE_Base): email: str = request.args[b"email"][0].decode() passwd: bytes = request.args[b"passwd"][0] - uid = self.data.card.get_user_id_from_card(access_code) + uid = await self.data.card.get_user_id_from_card(access_code) if uid is None: return redirectTo(b"/gate?e=1", request) salt = bcrypt.gensalt() hashed = bcrypt.hashpw(passwd, salt) - result = self.data.user.create_user( + result = await self.data.user.create_user( uid, username, email.lower(), hashed.decode(), 1 ) if result is None: @@ -231,16 +231,16 @@ class FE_Gate(FE_Base): else: return b"" - def create_user(self, request: Request): + async def create_user(self, request: Request): if b"ac" not in request.args or len(request.args[b"ac"][0].decode()) != 20: return redirectTo(b"/gate?e=2", request) ac = request.args[b"ac"][0].decode() - card = self.data.card.get_card_by_access_code(ac) + card = await self.data.card.get_card_by_access_code(ac) if card is None: return redirectTo(b"/gate?e=1", request) - user = self.data.user.get_user(card['user']) + user = await self.data.user.get_user(card['user']) if user is None: self.logger.warning(f"Card {ac} exists with no/invalid associated user ID {card['user']}") return redirectTo(b"/gate?e=0", request) @@ -257,7 +257,7 @@ class FE_Gate(FE_Base): class FE_User(FE_Base): - def render_GET(self, request: Request): + async def render_GET(self, request: Request): uri = request.uri.decode() template = self.environment.get_template("core/frontend/user/index.jinja") @@ -276,12 +276,12 @@ class FE_User(FE_Base): else: usrid = usr_sesh.userId - user = self.data.user.get_user(usrid) + user = await self.data.user.get_user(usrid) if user is None: return redirectTo(b"/user", request) - cards = self.data.card.get_user_cards(usrid) - arcades = self.data.arcade.get_arcades_managed_by_user(usrid) + cards = await self.data.card.get_user_cards(usrid) + arcades = await self.data.arcade.get_arcades_managed_by_user(usrid) card_data = [] arcade_data = [] @@ -307,12 +307,12 @@ class FE_User(FE_Base): arcades=arcade_data ).encode("utf-16") - def render_POST(self, request: Request): + async def render_POST(self, request: Request): pass class FE_System(FE_Base): - def render_GET(self, request: Request): + async def render_GET(self, request: Request): uri = request.uri.decode() template = self.environment.get_template("core/frontend/sys/index.jinja") usrlist: List[Dict] = [] @@ -331,17 +331,17 @@ class FE_System(FE_Base): uname_search = uri_parse.get("usrName") if uid_search is not None: - u = self.data.user.get_user(uid_search[0]) + u = await self.data.user.get_user(uid_search[0]) if u is not None: usrlist.append(u._asdict()) elif email_search is not None: - u = self.data.user.find_user_by_email(email_search[0]) + u = await self.data.user.find_user_by_email(email_search[0]) if u is not None: usrlist.append(u._asdict()) elif uname_search is not None: - ul = self.data.user.find_user_by_username(uname_search[0]) + ul = await self.data.user.find_user_by_username(uname_search[0]) for u in ul: usrlist.append(u._asdict()) @@ -353,24 +353,24 @@ class FE_System(FE_Base): ac_ip_search = uri_parse.get("arcadeIp") if ac_id_search is not None: - u = self.data.arcade.get_arcade(ac_id_search[0]) + u = await self.data.arcade.get_arcade(ac_id_search[0]) if u is not None: aclist.append(u._asdict()) elif ac_name_search is not None: - ul = self.data.arcade.get_arcade_by_name(ac_name_search[0]) + ul = await self.data.arcade.get_arcade_by_name(ac_name_search[0]) if ul is not None: for u in ul: aclist.append(u._asdict()) elif ac_user_search is not None: - ul = self.data.arcade.get_arcades_managed_by_user(ac_user_search[0]) + ul = await self.data.arcade.get_arcades_managed_by_user(ac_user_search[0]) if ul is not None: for u in ul: aclist.append(u._asdict()) elif ac_ip_search is not None: - ul = self.data.arcade.get_arcades_by_ip(ac_ip_search[0]) + ul = await self.data.arcade.get_arcades_by_ip(ac_ip_search[0]) if ul is not None: for u in ul: aclist.append(u._asdict()) @@ -382,17 +382,17 @@ class FE_System(FE_Base): cab_acid_search = uri_parse.get("cabAcId") if cab_id_search is not None: - u = self.data.arcade.get_machine(id=cab_id_search[0]) + u = await self.data.arcade.get_machine(id=cab_id_search[0]) if u is not None: cablist.append(u._asdict()) elif cab_serial_search is not None: - u = self.data.arcade.get_machine(serial=cab_serial_search[0]) + u = await self.data.arcade.get_machine(serial=cab_serial_search[0]) if u is not None: cablist.append(u._asdict()) elif cab_acid_search is not None: - ul = self.data.arcade.get_arcade_machines(cab_acid_search[0]) + ul = await self.data.arcade.get_arcade_machines(cab_acid_search[0]) for u in ul: cablist.append(u._asdict()) @@ -414,12 +414,12 @@ class FE_Game(FE_Base): return self return resource.Resource.getChild(self, name, request) - def render_GET(self, request: Request) -> bytes: + async def render_GET(self, request: Request) -> bytes: return redirectTo(b"/user", request) class FE_Arcade(FE_Base): - def render_GET(self, request: Request): + async def render_GET(self, request: Request): uri = request.uri.decode() template = self.environment.get_template("core/frontend/arcade/index.jinja") managed = [] @@ -433,8 +433,8 @@ class FE_Arcade(FE_Base): if m is not None: arcadeid = m.group(1) - perms = self.data.arcade.get_manager_permissions(usr_sesh.userId, arcadeid) - arcade = self.data.arcade.get_arcade(arcadeid) + perms = await self.data.arcade.get_manager_permissions(usr_sesh.userId, arcadeid) + arcade = await self.data.arcade.get_arcade(arcadeid) if perms is None: perms = 0 @@ -452,7 +452,7 @@ class FE_Arcade(FE_Base): class FE_Machine(FE_Base): - def render_GET(self, request: Request): + async def render_GET(self, request: Request): uri = request.uri.decode() template = self.environment.get_template("core/frontend/machine/index.jinja") diff --git a/example_config/core.yaml b/example_config/core.yaml index 600c66b..ac3a69e 100644 --- a/example_config/core.yaml +++ b/example_config/core.yaml @@ -18,7 +18,6 @@ title: loglevel: "info" reboot_start_time: "04:00" reboot_end_time: "05:00" - ssl_key: "cert/title.key" database: host: "localhost" diff --git a/read.py b/read.py index 05bbd1d..8a0ae72 100644 --- a/read.py +++ b/read.py @@ -6,6 +6,7 @@ import yaml from os import path import logging import coloredlogs +import asyncio from logging.handlers import TimedRotatingFileHandler from typing import List, Optional @@ -38,6 +39,9 @@ class BaseReader: ret.append(f"{root}/{dir}") return ret + + async def read(self) -> None: + pass if __name__ == "__main__": @@ -136,6 +140,8 @@ if __name__ == "__main__": for dir, mod in titles.items(): if args.game in mod.game_codes: handler = mod.reader(config, args.version, bin_arg, opt_arg, args.extra) - handler.read() + loop = asyncio.get_event_loop() + loop.run_until_complete(handler.read()) + logger.info("Done") diff --git a/titles/chuni/base.py b/titles/chuni/base.py index cffcb75..72d665e 100644 --- a/titles/chuni/base.py +++ b/titles/chuni/base.py @@ -38,20 +38,20 @@ class ChuniBase: return {"returnCode": 1} user_id = data["userId"] - login_bonus_presets = self.data.static.get_login_bonus_presets(self.version) + login_bonus_presets = await self.data.static.get_login_bonus_presets(self.version) for preset in login_bonus_presets: # check if a user already has some pogress and if not add the # login bonus entry - user_login_bonus = self.data.item.get_login_bonus( + user_login_bonus = await self.data.item.get_login_bonus( user_id, self.version, preset["presetId"] ) if user_login_bonus is None: - self.data.item.put_login_bonus( + await self.data.item.put_login_bonus( user_id, self.version, preset["presetId"] ) # yeah i'm lazy - user_login_bonus = self.data.item.get_login_bonus( + user_login_bonus = await self.data.item.get_login_bonus( user_id, self.version, preset["presetId"] ) @@ -67,7 +67,7 @@ class ChuniBase: bonus_count = user_login_bonus["bonusCount"] + 1 last_update_date = datetime.now() - all_login_boni = self.data.static.get_login_bonus( + all_login_boni = await self.data.static.get_login_bonus( self.version, preset["presetId"] ) @@ -91,13 +91,13 @@ class ChuniBase: is_finished = True # grab the item for the corresponding day - login_item = self.data.static.get_login_bonus_by_required_days( + login_item = await self.data.static.get_login_bonus_by_required_days( self.version, preset["presetId"], bonus_count ) if login_item is not None: # now add the present to the database so the # handle_get_user_item_api_request can grab them - self.data.item.put_item( + await self.data.item.put_item( user_id, { "itemId": login_item["presentId"], @@ -107,7 +107,7 @@ class ChuniBase: }, ) - self.data.item.put_login_bonus( + await self.data.item.put_login_bonus( user_id, self.version, preset["presetId"], @@ -124,7 +124,7 @@ class ChuniBase: return {"returnCode": 1} async def handle_get_game_charge_api_request(self, data: Dict) -> Dict: - game_charge_list = self.data.static.get_enabled_charges(self.version) + game_charge_list = await self.data.static.get_enabled_charges(self.version) if game_charge_list is None or len(game_charge_list) == 0: return {"length": 0, "gameChargeList": []} @@ -146,7 +146,7 @@ class ChuniBase: return {"length": len(charges), "gameChargeList": charges} async def handle_get_game_event_api_request(self, data: Dict) -> Dict: - game_events = self.data.static.get_enabled_events(self.version) + game_events = await self.data.static.get_enabled_events(self.version) if game_events is None or len(game_events) == 0: self.logger.warning("No enabled events, did you run the reader?") @@ -194,7 +194,7 @@ class ChuniBase: } async def handle_get_game_ranking_api_request(self, data: Dict) -> Dict: - rankings = self.data.score.get_rankings(self.version) + rankings = await self.data.score.get_rankings(self.version) return {"type": data["type"], "gameRankingList": rankings} async def handle_get_game_sale_api_request(self, data: Dict) -> Dict: @@ -241,7 +241,7 @@ class ChuniBase: "isAou": "false", } async def handle_get_user_activity_api_request(self, data: Dict) -> Dict: - user_activity_list = self.data.profile.get_profile_activity( + user_activity_list = await self.data.profile.get_profile_activity( data["userId"], data["kind"] ) @@ -262,7 +262,7 @@ class ChuniBase: } async def handle_get_user_character_api_request(self, data: Dict) -> Dict: - characters = self.data.item.get_characters(data["userId"]) + characters = await self.data.item.get_characters(data["userId"]) if characters is None: return { "userId": data["userId"], @@ -297,7 +297,7 @@ class ChuniBase: } async def handle_get_user_charge_api_request(self, data: Dict) -> Dict: - user_charge_list = self.data.profile.get_profile_charge(data["userId"]) + user_charge_list = await self.data.profile.get_profile_charge(data["userId"]) charge_list = [] for charge in user_charge_list: @@ -320,7 +320,7 @@ class ChuniBase: } async def handle_get_user_course_api_request(self, data: Dict) -> Dict: - user_course_list = self.data.score.get_courses(data["userId"]) + user_course_list = await self.data.score.get_courses(data["userId"]) if user_course_list is None: return { "userId": data["userId"], @@ -355,7 +355,7 @@ class ChuniBase: } async def handle_get_user_data_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is None: return {} @@ -367,7 +367,7 @@ class ChuniBase: return {"userId": data["userId"], "userData": profile} async def handle_get_user_data_ex_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_data_ex(data["userId"], self.version) + p = await self.data.profile.get_profile_data_ex(data["userId"], self.version) if p is None: return {} @@ -379,7 +379,7 @@ class ChuniBase: return {"userId": data["userId"], "userDataEx": profile} async def handle_get_user_duel_api_request(self, data: Dict) -> Dict: - user_duel_list = self.data.item.get_duels(data["userId"]) + user_duel_list = await self.data.item.get_duels(data["userId"]) if user_duel_list is None: return {} @@ -397,7 +397,7 @@ class ChuniBase: } async def handle_get_user_rival_data_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_rival(data["rivalId"]) + p = await self.data.profile.get_rival(data["rivalId"]) if p is None: return {} userRivalData = { @@ -416,7 +416,7 @@ class ChuniBase: user_rival_music_list = [] # Fetch all the rival music entries for the user - all_entries = self.data.score.get_rival_music(rival_id) + all_entries = await self.data.score.get_rival_music(rival_id) # Process the entries based on max_count and nextIndex for music in all_entries: @@ -467,7 +467,7 @@ class ChuniBase: # still needs to be implemented on WebUI # 1: Music, 2: User, 3: Character - fav_list = self.data.item.get_all_favorites( + fav_list = await self.data.item.get_all_favorites( data["userId"], self.version, fav_kind=int(data["kind"]) ) if fav_list is not None: @@ -492,7 +492,7 @@ class ChuniBase: async def handle_get_user_item_api_request(self, data: Dict) -> Dict: kind = int(int(data["nextIndex"]) / 10000000000) next_idx = int(int(data["nextIndex"]) % 10000000000) - user_item_list = self.data.item.get_items(data["userId"], kind) + user_item_list = await self.data.item.get_items(data["userId"], kind) if user_item_list is None or len(user_item_list) == 0: return { @@ -528,7 +528,7 @@ class ChuniBase: async def handle_get_user_login_bonus_api_request(self, data: Dict) -> Dict: user_id = data["userId"] - user_login_bonus = self.data.item.get_all_login_bonus(user_id, self.version) + user_login_bonus = await self.data.item.get_all_login_bonus(user_id, self.version) # ignore the loginBonus request if its disabled in config if user_login_bonus is None or not self.game_cfg.mods.use_login_bonus: return {"userId": user_id, "length": 0, "userLoginBonusList": []} @@ -553,7 +553,7 @@ class ChuniBase: } async def handle_get_user_map_api_request(self, data: Dict) -> Dict: - user_map_list = self.data.item.get_maps(data["userId"]) + user_map_list = await self.data.item.get_maps(data["userId"]) if user_map_list is None: return {} @@ -571,7 +571,7 @@ class ChuniBase: } async def handle_get_user_music_api_request(self, data: Dict) -> Dict: - music_detail = self.data.score.get_scores(data["userId"]) + music_detail = await self.data.score.get_scores(data["userId"]) if music_detail is None: return { "userId": data["userId"], @@ -630,7 +630,7 @@ class ChuniBase: } async def handle_get_user_option_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_option(data["userId"]) + p = await self.data.profile.get_profile_option(data["userId"]) option = p._asdict() option.pop("id") @@ -639,7 +639,7 @@ class ChuniBase: return {"userId": data["userId"], "userGameOption": option} async def handle_get_user_option_ex_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_option_ex(data["userId"]) + p = await self.data.profile.get_profile_option_ex(data["userId"]) option = p._asdict() option.pop("id") @@ -651,10 +651,10 @@ class ChuniBase: return bytes([ord(c) for c in src]).decode("utf-8") async def handle_get_user_preview_api_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_preview(data["userId"], self.version) + profile = await self.data.profile.get_profile_preview(data["userId"], self.version) if profile is None: return None - profile_character = self.data.item.get_character( + profile_character = await self.data.item.get_character( data["userId"], profile["characterId"] ) @@ -693,7 +693,7 @@ class ChuniBase: } async def handle_get_user_recent_rating_api_request(self, data: Dict) -> Dict: - recent_rating_list = self.data.profile.get_profile_recent_rating(data["userId"]) + recent_rating_list = await self.data.profile.get_profile_recent_rating(data["userId"]) if recent_rating_list is None: return { "userId": data["userId"], @@ -722,15 +722,15 @@ class ChuniBase: team_rank = 0 # Get user profile - profile = self.data.profile.get_profile_data(data["userId"], self.version) + profile = await self.data.profile.get_profile_data(data["userId"], self.version) if profile and profile["teamId"]: # Get team by id - team = self.data.profile.get_team_by_id(profile["teamId"]) + team = await self.data.profile.get_team_by_id(profile["teamId"]) if team: team_id = team["id"] team_name = team["teamName"] - team_rank = self.data.profile.get_team_rank(team["id"]) + team_rank = await self.data.profile.get_team_rank(team["id"]) # Don't return anything if no team name has been defined for defaults and there is no team set for the player if not profile["teamId"] and team_name == "": @@ -819,58 +819,58 @@ class ChuniBase: except Exception: pass - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) if "userDataEx" in upsert: - self.data.profile.put_profile_data_ex( + await self.data.profile.put_profile_data_ex( user_id, self.version, upsert["userDataEx"][0] ) if "userGameOption" in upsert: - self.data.profile.put_profile_option(user_id, upsert["userGameOption"][0]) + await self.data.profile.put_profile_option(user_id, upsert["userGameOption"][0]) if "userGameOptionEx" in upsert: - self.data.profile.put_profile_option_ex( + await self.data.profile.put_profile_option_ex( user_id, upsert["userGameOptionEx"][0] ) if "userRecentRatingList" in upsert: - self.data.profile.put_profile_recent_rating( + await self.data.profile.put_profile_recent_rating( user_id, upsert["userRecentRatingList"] ) if "userCharacterList" in upsert: for character in upsert["userCharacterList"]: - self.data.item.put_character(user_id, character) + await self.data.item.put_character(user_id, character) if "userMapList" in upsert: for map in upsert["userMapList"]: - self.data.item.put_map(user_id, map) + await self.data.item.put_map(user_id, map) if "userCourseList" in upsert: for course in upsert["userCourseList"]: - self.data.score.put_course(user_id, course) + await self.data.score.put_course(user_id, course) if "userDuelList" in upsert: for duel in upsert["userDuelList"]: - self.data.item.put_duel(user_id, duel) + await self.data.item.put_duel(user_id, duel) if "userItemList" in upsert: for item in upsert["userItemList"]: - self.data.item.put_item(user_id, item) + await self.data.item.put_item(user_id, item) if "userActivityList" in upsert: for activity in upsert["userActivityList"]: - self.data.profile.put_profile_activity(user_id, activity) + await self.data.profile.put_profile_activity(user_id, activity) if "userChargeList" in upsert: for charge in upsert["userChargeList"]: - self.data.profile.put_profile_charge(user_id, charge) + await self.data.profile.put_profile_charge(user_id, charge) if "userMusicDetailList" in upsert: for song in upsert["userMusicDetailList"]: - self.data.score.put_score(user_id, song) + await self.data.score.put_score(user_id, song) if "userPlaylogList" in upsert: for playlog in upsert["userPlaylogList"]: @@ -881,7 +881,7 @@ class ChuniBase: playlog["playedUserName2"] = self.read_wtf8(playlog["playedUserName2"]) if playlog["playedUserName3"] is not None: playlog["playedUserName3"] = self.read_wtf8(playlog["playedUserName3"]) - self.data.score.put_playlog(user_id, playlog, self.version) + await self.data.score.put_playlog(user_id, playlog, self.version) if "userTeamPoint" in upsert: team_points = upsert["userTeamPoint"] @@ -889,7 +889,7 @@ class ChuniBase: for tp in team_points: if tp["teamId"] != '65535': # Fetch the current team data - current_team = self.data.profile.get_team_by_id(tp["teamId"]) + current_team = await self.data.profile.get_team_by_id(tp["teamId"]) # Calculate the new teamPoint new_team_point = int(tp["teamPoint"]) + current_team["teamPoint"] @@ -900,24 +900,24 @@ class ChuniBase: } # Update the team data - self.data.profile.update_team(tp["teamId"], team_data) + await self.data.profile.update_team(tp["teamId"], team_data) except: pass # Probably a better way to catch if the team is not set yet (new profiles), but let's just pass if "userMapAreaList" in upsert: for map_area in upsert["userMapAreaList"]: - self.data.item.put_map_area(user_id, map_area) + await self.data.item.put_map_area(user_id, map_area) if "userOverPowerList" in upsert: for overpower in upsert["userOverPowerList"]: - self.data.profile.put_profile_overpower(user_id, overpower) + await self.data.profile.put_profile_overpower(user_id, overpower) if "userEmoneyList" in upsert: for emoney in upsert["userEmoneyList"]: - self.data.profile.put_profile_emoney(user_id, emoney) + await self.data.profile.put_profile_emoney(user_id, emoney) if "userLoginBonusList" in upsert: for login in upsert["userLoginBonusList"]: - self.data.item.put_login_bonus( + await self.data.item.put_login_bonus( user_id, self.version, login["presetId"], isWatched=True ) @@ -930,7 +930,7 @@ class ChuniBase: async def handle_upsert_user_chargelog_api_request(self, data: Dict) -> Dict: # add tickets after they got bought, this makes sure the tickets are # still valid after an unsuccessful logout - self.data.profile.put_profile_charge(data["userId"], data["userCharge"]) + await self.data.profile.put_profile_charge(data["userId"], data["userCharge"]) return {"returnCode": "1"} async def handle_upsert_client_bookkeeping_api_request(self, data: Dict) -> Dict: diff --git a/titles/chuni/new.py b/titles/chuni/new.py index 9902906..405c25b 100644 --- a/titles/chuni/new.py +++ b/titles/chuni/new.py @@ -102,7 +102,7 @@ class ChuniNew(ChuniBase): return {"returnCode": "1"} async def handle_get_user_map_area_api_request(self, data: Dict) -> Dict: - user_map_areas = self.data.item.get_map_areas(data["userId"]) + user_map_areas = await self.data.item.get_map_areas(data["userId"]) map_areas = [] for map_area in user_map_areas: @@ -117,10 +117,10 @@ class ChuniNew(ChuniBase): return {"userId": data["userId"], "symbolCharInfoList": []} async def handle_get_user_preview_api_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_preview(data["userId"], self.version) + profile = await self.data.profile.get_profile_preview(data["userId"], self.version) if profile is None: return None - profile_character = self.data.item.get_character( + profile_character = await self.data.item.get_character( data["userId"], profile["characterId"] ) @@ -165,7 +165,7 @@ class ChuniNew(ChuniBase): return data1 async def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is None: return {} @@ -187,7 +187,7 @@ class ChuniNew(ChuniBase): """ returns all current active banners (gachas) """ - game_gachas = self.data.static.get_gachas(self.version) + game_gachas = await self.data.static.get_gachas(self.version) # clean the database rows game_gacha_list = [] @@ -217,7 +217,7 @@ class ChuniNew(ChuniBase): """ returns all valid cards for a given gachaId """ - game_gacha_cards = self.data.static.get_gacha_cards(data["gachaId"]) + game_gacha_cards = await self.data.static.get_gacha_cards(data["gachaId"]) game_gacha_card_list = [] for gacha_card in game_gacha_cards: @@ -238,7 +238,7 @@ class ChuniNew(ChuniBase): } async def handle_cm_get_user_data_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is None: return {} @@ -263,7 +263,7 @@ class ChuniNew(ChuniBase): } async def handle_get_user_gacha_api_request(self, data: Dict) -> Dict: - user_gachas = self.data.item.get_user_gachas(data["userId"]) + user_gachas = await self.data.item.get_user_gachas(data["userId"]) if user_gachas is None: return {"userId": data["userId"], "length": 0, "userGachaList": []} @@ -282,7 +282,7 @@ class ChuniNew(ChuniBase): } async def handle_get_user_printed_card_api_request(self, data: Dict) -> Dict: - user_print_list = self.data.item.get_user_print_states( + user_print_list = await self.data.item.get_user_print_states( data["userId"], has_completed=True ) if user_print_list is None: @@ -319,7 +319,7 @@ class ChuniNew(ChuniBase): async def handle_get_user_card_print_error_api_request(self, data: Dict) -> Dict: user_id = data["userId"] - user_print_states = self.data.item.get_user_print_states( + user_print_states = await self.data.item.get_user_print_states( user_id, has_completed=False ) @@ -362,14 +362,14 @@ class ChuniNew(ChuniBase): # characterId should be returned if chara_id != -1: # get the - card = self.data.static.get_gacha_card_by_character(gacha_id, chara_id) + card = await self.data.static.get_gacha_card_by_character(gacha_id, chara_id) tmp = card._asdict() tmp.pop("id") rolled_cards.append(tmp) else: - gacha_cards = self.data.static.get_gacha_cards(gacha_id) + gacha_cards = await self.data.static.get_gacha_cards(gacha_id) # get the card id for each roll for _ in range(num_rolls): @@ -396,7 +396,7 @@ class ChuniNew(ChuniBase): user_data.pop("rankUpChallengeResults") user_data.pop("userEmoney") - self.data.profile.put_profile_data(user_id, self.version, user_data) + await self.data.profile.put_profile_data(user_id, self.version, user_data) # save the user gacha user_gacha = upsert["userGacha"] @@ -404,16 +404,16 @@ class ChuniNew(ChuniBase): user_gacha.pop("gachaId") user_gacha.pop("dailyGachaDate") - self.data.item.put_user_gacha(user_id, gacha_id, user_gacha) + await self.data.item.put_user_gacha(user_id, gacha_id, user_gacha) # save all user items if "userItemList" in upsert: for item in upsert["userItemList"]: - self.data.item.put_item(user_id, item) + await self.data.item.put_item(user_id, item) # add every gamegachaCard to database for card in upsert["gameGachaCardList"]: - self.data.item.put_user_print_state( + await self.data.item.put_user_print_state( user_id, hasCompleted=False, placeId=place_id, @@ -423,7 +423,7 @@ class ChuniNew(ChuniBase): # retrieve every game gacha card which has been added in order to get # the orderId for the next request - user_print_states = self.data.item.get_user_print_states_by_gacha( + user_print_states = await self.data.item.get_user_print_states_by_gacha( user_id, gacha_id, has_completed=False ) card_print_state_list = [] @@ -465,7 +465,7 @@ class ChuniNew(ChuniBase): ) # add the entry to the user print table with the random serialId - self.data.item.put_user_print_detail(user_id, serial_id, user_print_detail) + await self.data.item.put_user_print_detail(user_id, serial_id, user_print_detail) return { "returnCode": 1, @@ -482,10 +482,10 @@ class ChuniNew(ChuniBase): # save all user items if "userItemList" in data: for item in data["userItemList"]: - self.data.item.put_item(user_id, item) + await self.data.item.put_item(user_id, item) # set the card print state to success and use the orderId as the key - self.data.item.put_user_print_state( + await self.data.item.put_user_print_state( user_id, id=upsert["orderId"], hasCompleted=True ) @@ -497,7 +497,7 @@ class ChuniNew(ChuniBase): # set the card print state to success and use the orderId as the key for order_id in order_ids: - self.data.item.put_user_print_state(user_id, id=order_id, hasCompleted=True) + await self.data.item.put_user_print_state(user_id, id=order_id, hasCompleted=True) return {"returnCode": "1", "apiName": "CMUpsertUserPrintCancelApi"} @@ -508,11 +508,11 @@ class ChuniNew(ChuniBase): async def handle_begin_matching_api_request(self, data: Dict) -> Dict: room_id = 1 # check if there is a free matching room - matching_room = self.data.item.get_oldest_free_matching(self.version) + matching_room = await self.data.item.get_oldest_free_matching(self.version) if matching_room is None: # grab the latest roomId and add 1 for the new room - newest_matching = self.data.item.get_newest_matching(self.version) + newest_matching = await self.data.item.get_newest_matching(self.version) if newest_matching is not None: room_id = newest_matching["roomId"] + 1 @@ -522,12 +522,12 @@ class ChuniNew(ChuniBase): # create the new room with room_id and the current user id (host) # user id is required for the countdown later on - self.data.item.put_matching( + await self.data.item.put_matching( self.version, room_id, [new_member], user_id=new_member["userId"] ) # get the newly created matching room - matching_room = self.data.item.get_matching(self.version, room_id) + matching_room = await self.data.item.get_matching(self.version, room_id) else: # a room already exists, so just add the new member to it matching_member_list = matching_room["matchingMemberInfoList"] @@ -537,7 +537,7 @@ class ChuniNew(ChuniBase): matching_member_list.append(new_member) # add the updated room to the database, make sure to set isFull correctly! - self.data.item.put_matching( + await self.data.item.put_matching( self.version, matching_room["roomId"], matching_member_list, @@ -555,7 +555,7 @@ class ChuniNew(ChuniBase): return {"roomId": 1, "matchingWaitState": matching_wait} async def handle_end_matching_api_request(self, data: Dict) -> Dict: - matching_room = self.data.item.get_matching(self.version, data["roomId"]) + matching_room = await self.data.item.get_matching(self.version, data["roomId"]) members = matching_room["matchingMemberInfoList"] # only set the host user to role 1 every other to 0? @@ -564,7 +564,7 @@ class ChuniNew(ChuniBase): for m in members ] - self.data.item.put_matching( + await self.data.item.put_matching( self.version, matching_room["roomId"], members, @@ -585,7 +585,7 @@ class ChuniNew(ChuniBase): async def handle_remove_matching_member_api_request(self, data: Dict) -> Dict: # get all matching rooms, because Chuni only returns the userId # not the actual roomId - matching_rooms = self.data.item.get_all_matchings(self.version) + matching_rooms = await self.data.item.get_all_matchings(self.version) if matching_rooms is None: return {"returnCode": "1"} @@ -599,10 +599,10 @@ class ChuniNew(ChuniBase): # if the last user got removed, delete the matching room if len(new_members) <= 0: - self.data.item.delete_matching(self.version, room["roomId"]) + await self.data.item.delete_matching(self.version, room["roomId"]) else: # remove the user from the room - self.data.item.put_matching( + await self.data.item.put_matching( self.version, room["roomId"], new_members, @@ -615,7 +615,7 @@ class ChuniNew(ChuniBase): async def handle_get_matching_state_api_request(self, data: Dict) -> Dict: polling_interval = 1 # get the current active room - matching_room = self.data.item.get_matching(self.version, data["roomId"]) + matching_room = await self.data.item.get_matching(self.version, data["roomId"]) members = matching_room["matchingMemberInfoList"] rest_sec = matching_room["restMSec"] @@ -638,7 +638,7 @@ class ChuniNew(ChuniBase): current_member["userName"] = self.read_wtf8(current_member["userName"]) members[i] = current_member - self.data.item.put_matching( + await self.data.item.put_matching( self.version, data["roomId"], members, diff --git a/titles/chuni/read.py b/titles/chuni/read.py index 7100ae6..5082f7a 100644 --- a/titles/chuni/read.py +++ b/titles/chuni/read.py @@ -28,7 +28,7 @@ class ChuniReader(BaseReader): self.logger.error(f"Invalid chunithm version {version}") exit(1) - def read(self) -> None: + async def read(self) -> None: data_dirs = [] if self.bin_dir is not None: data_dirs += self.get_data_directories(self.bin_dir) @@ -38,13 +38,13 @@ class ChuniReader(BaseReader): for dir in data_dirs: self.logger.info(f"Read from {dir}") - self.read_events(f"{dir}/event") - self.read_music(f"{dir}/music") - self.read_charges(f"{dir}/chargeItem") - self.read_avatar(f"{dir}/avatarAccessory") - self.read_login_bonus(f"{dir}/") + await self.read_events(f"{dir}/event") + await self.read_music(f"{dir}/music") + await self.read_charges(f"{dir}/chargeItem") + await self.read_avatar(f"{dir}/avatarAccessory") + await self.read_login_bonus(f"{dir}/") - def read_login_bonus(self, root_dir: str) -> None: + async def read_login_bonus(self, root_dir: str) -> None: for root, dirs, files in walk(f"{root_dir}loginBonusPreset"): for dir in dirs: if path.exists(f"{root}/{dir}/LoginBonusPreset.xml"): @@ -60,7 +60,7 @@ class ChuniReader(BaseReader): True if xml_root.find("disableFlag").text == "false" else False ) - result = self.data.static.put_login_bonus_preset( + result = await self.data.static.put_login_bonus_preset( self.version, id, name, is_enabled ) @@ -98,7 +98,7 @@ class ChuniReader(BaseReader): bonus_root.find("loginBonusCategoryType").text ) - result = self.data.static.put_login_bonus( + result = await self.data.static.put_login_bonus( self.version, id, bonus_id, @@ -117,7 +117,7 @@ class ChuniReader(BaseReader): f"Failed to insert login bonus {bonus_id}" ) - def read_events(self, evt_dir: str) -> None: + async def read_events(self, evt_dir: str) -> None: for root, dirs, files in walk(evt_dir): for dir in dirs: if path.exists(f"{root}/{dir}/Event.xml"): @@ -132,7 +132,7 @@ class ChuniReader(BaseReader): for substances in xml_root.findall("substances"): event_type = substances.find("type").text - result = self.data.static.put_event( + result = await self.data.static.put_event( self.version, id, event_type, name ) if result is not None: @@ -140,7 +140,7 @@ class ChuniReader(BaseReader): else: self.logger.warning(f"Failed to insert event {id}") - def read_music(self, music_dir: str) -> None: + async def read_music(self, music_dir: str) -> None: for root, dirs, files in walk(music_dir): for dir in dirs: if path.exists(f"{root}/{dir}/Music.xml"): @@ -185,7 +185,7 @@ class ChuniReader(BaseReader): ) we_chara = None - result = self.data.static.put_music( + result = await self.data.static.put_music( self.version, song_id, chart_id, @@ -206,7 +206,7 @@ class ChuniReader(BaseReader): f"Failed to insert music {song_id} chart {chart_id}" ) - def read_charges(self, charge_dir: str) -> None: + async def read_charges(self, charge_dir: str) -> None: for root, dirs, files in walk(charge_dir): for dir in dirs: if path.exists(f"{root}/{dir}/ChargeItem.xml"): @@ -222,7 +222,7 @@ class ChuniReader(BaseReader): consumeType = xml_root.find("consumeType").text sellingAppeal = bool(xml_root.find("sellingAppeal").text) - result = self.data.static.put_charge( + result = await self.data.static.put_charge( self.version, id, name, @@ -236,7 +236,7 @@ class ChuniReader(BaseReader): else: self.logger.warning(f"Failed to insert charge {id}") - def read_avatar(self, avatar_dir: str) -> None: + async def read_avatar(self, avatar_dir: str) -> None: for root, dirs, files in walk(avatar_dir): for dir in dirs: if path.exists(f"{root}/{dir}/AvatarAccessory.xml"): @@ -254,7 +254,7 @@ class ChuniReader(BaseReader): for texture in xml_root.findall("texture"): texturePath = texture.find("path").text - result = self.data.static.put_avatar( + result = await self.data.static.put_avatar( self.version, id, name, category, iconPath, texturePath ) diff --git a/titles/chuni/schema/item.py b/titles/chuni/schema/item.py index dc2751d..5077e14 100644 --- a/titles/chuni/schema/item.py +++ b/titles/chuni/schema/item.py @@ -245,7 +245,7 @@ matching = Table( class ChuniItemData(BaseData): - def get_oldest_free_matching(self, version: int) -> Optional[Row]: + async def get_oldest_free_matching(self, version: int) -> Optional[Row]: sql = matching.select( and_( matching.c.version == version, @@ -253,46 +253,46 @@ class ChuniItemData(BaseData): ) ).order_by(matching.c.roomId.asc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_newest_matching(self, version: int) -> Optional[Row]: + async def get_newest_matching(self, version: int) -> Optional[Row]: sql = matching.select( and_( matching.c.version == version ) ).order_by(matching.c.roomId.desc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_all_matchings(self, version: int) -> Optional[List[Row]]: + async def get_all_matchings(self, version: int) -> Optional[List[Row]]: sql = matching.select( and_( matching.c.version == version ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_matching(self, version: int, room_id: int) -> Optional[Row]: + async def get_matching(self, version: int, room_id: int) -> Optional[Row]: sql = matching.select( and_(matching.c.version == version, matching.c.roomId == room_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_matching( + async def put_matching( self, version: int, room_id: int, @@ -314,22 +314,22 @@ class ChuniItemData(BaseData): restMSec=rest_sec, matchingMemberInfoList=matching_member_info_list ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def delete_matching(self, version: int, room_id: int): + async def delete_matching(self, version: int, room_id: int): sql = delete(matching).where( and_(matching.c.roomId == room_id, matching.c.version == version) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.lastrowid - def get_all_favorites( + async def get_all_favorites( self, user_id: int, version: int, fav_kind: int = 1 ) -> Optional[List[Row]]: sql = favorite.select( @@ -340,12 +340,12 @@ class ChuniItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_login_bonus( + async def put_login_bonus( self, user_id: int, version: int, preset_id: int, **login_bonus_data ) -> Optional[int]: sql = insert(login_bonus).values( @@ -354,12 +354,12 @@ class ChuniItemData(BaseData): conflict = sql.on_duplicate_key_update(presetId=preset_id, **login_bonus_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_all_login_bonus( + async def get_all_login_bonus( self, user_id: int, version: int, is_finished: bool = False ) -> Optional[List[Row]]: sql = login_bonus.select( @@ -370,12 +370,12 @@ class ChuniItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_login_bonus( + async def get_login_bonus( self, user_id: int, version: int, preset_id: int ) -> Optional[Row]: sql = login_bonus.select( @@ -386,12 +386,12 @@ class ChuniItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_character(self, user_id: int, character_data: Dict) -> Optional[int]: + async def put_character(self, user_id: int, character_data: Dict) -> Optional[int]: character_data["user"] = user_id character_data = self.fix_bools(character_data) @@ -399,30 +399,30 @@ class ChuniItemData(BaseData): sql = insert(character).values(**character_data) conflict = sql.on_duplicate_key_update(**character_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_character(self, user_id: int, character_id: int) -> Optional[Dict]: + async def get_character(self, user_id: int, character_id: int) -> Optional[Dict]: sql = select(character).where( and_(character.c.user == user_id, character.c.characterId == character_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_characters(self, user_id: int) -> Optional[List[Row]]: + async def get_characters(self, user_id: int) -> Optional[List[Row]]: sql = select(character).where(character.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_item(self, user_id: int, item_data: Dict) -> Optional[int]: + async def put_item(self, user_id: int, item_data: Dict) -> Optional[int]: item_data["user"] = user_id item_data = self.fix_bools(item_data) @@ -430,12 +430,12 @@ class ChuniItemData(BaseData): sql = insert(item).values(**item_data) conflict = sql.on_duplicate_key_update(**item_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_items(self, user_id: int, kind: int = None) -> Optional[List[Row]]: + async def get_items(self, user_id: int, kind: int = None) -> Optional[List[Row]]: if kind is None: sql = select(item).where(item.c.user == user_id) else: @@ -443,12 +443,12 @@ class ChuniItemData(BaseData): and_(item.c.user == user_id, item.c.itemKind == kind) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_duel(self, user_id: int, duel_data: Dict) -> Optional[int]: + async def put_duel(self, user_id: int, duel_data: Dict) -> Optional[int]: duel_data["user"] = user_id duel_data = self.fix_bools(duel_data) @@ -456,20 +456,20 @@ class ChuniItemData(BaseData): sql = insert(duel).values(**duel_data) conflict = sql.on_duplicate_key_update(**duel_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_duels(self, user_id: int) -> Optional[List[Row]]: + async def get_duels(self, user_id: int) -> Optional[List[Row]]: sql = select(duel).where(duel.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_map(self, user_id: int, map_data: Dict) -> Optional[int]: + async def put_map(self, user_id: int, map_data: Dict) -> Optional[int]: map_data["user"] = user_id map_data = self.fix_bools(map_data) @@ -477,20 +477,20 @@ class ChuniItemData(BaseData): sql = insert(map).values(**map_data) conflict = sql.on_duplicate_key_update(**map_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_maps(self, user_id: int) -> Optional[List[Row]]: + async def get_maps(self, user_id: int) -> Optional[List[Row]]: sql = select(map).where(map.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_map_area(self, user_id: int, map_area_data: Dict) -> Optional[int]: + async def put_map_area(self, user_id: int, map_area_data: Dict) -> Optional[int]: map_area_data["user"] = user_id map_area_data = self.fix_bools(map_area_data) @@ -498,28 +498,28 @@ class ChuniItemData(BaseData): sql = insert(map_area).values(**map_area_data) conflict = sql.on_duplicate_key_update(**map_area_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_map_areas(self, user_id: int) -> Optional[List[Row]]: + async def get_map_areas(self, user_id: int) -> Optional[List[Row]]: sql = select(map_area).where(map_area.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_user_gachas(self, aime_id: int) -> Optional[List[Row]]: + async def get_user_gachas(self, aime_id: int) -> Optional[List[Row]]: sql = gacha.select(gacha.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_user_gacha( + async def put_user_gacha( self, aime_id: int, gacha_id: int, gacha_data: Dict ) -> Optional[int]: sql = insert(gacha).values(user=aime_id, gachaId=gacha_id, **gacha_data) @@ -527,14 +527,14 @@ class ChuniItemData(BaseData): conflict = sql.on_duplicate_key_update( user=aime_id, gachaId=gacha_id, **gacha_data ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_user_gacha: Failed to insert! aime_id: {aime_id}") return None return result.lastrowid - def get_user_print_states( + async def get_user_print_states( self, aime_id: int, has_completed: bool = False ) -> Optional[List[Row]]: sql = print_state.select( @@ -544,12 +544,12 @@ class ChuniItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_user_print_states_by_gacha( + async def get_user_print_states_by_gacha( self, aime_id: int, gacha_id: int, has_completed: bool = False ) -> Optional[List[Row]]: sql = print_state.select( @@ -560,16 +560,16 @@ class ChuniItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_user_print_state(self, aime_id: int, **print_data) -> Optional[int]: + async def put_user_print_state(self, aime_id: int, **print_data) -> Optional[int]: sql = insert(print_state).values(user=aime_id, **print_data) conflict = sql.on_duplicate_key_update(user=aime_id, **print_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -578,7 +578,7 @@ class ChuniItemData(BaseData): return None return result.lastrowid - def put_user_print_detail( + async def put_user_print_detail( self, aime_id: int, serial_id: str, user_print_data: Dict ) -> Optional[int]: sql = insert(print_detail).values( @@ -586,7 +586,7 @@ class ChuniItemData(BaseData): ) conflict = sql.on_duplicate_key_update(user=aime_id, **user_print_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( diff --git a/titles/chuni/schema/profile.py b/titles/chuni/schema/profile.py index 43b5641..b5ac493 100644 --- a/titles/chuni/schema/profile.py +++ b/titles/chuni/schema/profile.py @@ -395,7 +395,7 @@ team = Table( class ChuniProfileData(BaseData): - def put_profile_data( + async def put_profile_data( self, aime_id: int, version: int, profile_data: Dict ) -> Optional[int]: profile_data["user"] = aime_id @@ -407,26 +407,26 @@ class ChuniProfileData(BaseData): sql = insert(profile).values(**profile_data) conflict = sql.on_duplicate_key_update(**profile_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_profile_data: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]: sql = ( select([profile, option]) .join(option, profile.c.user == option.c.user) .filter(and_(profile.c.user == aime_id, profile.c.version <= version)) ).order_by(profile.c.version.desc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_data(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_data(self, aime_id: int, version: int) -> Optional[Row]: sql = select(profile).where( and_( profile.c.user == aime_id, @@ -434,12 +434,12 @@ class ChuniProfileData(BaseData): ) ).order_by(profile.c.version.desc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_data_ex( + async def put_profile_data_ex( self, aime_id: int, version: int, profile_ex_data: Dict ) -> Optional[int]: profile_ex_data["user"] = aime_id @@ -449,7 +449,7 @@ class ChuniProfileData(BaseData): sql = insert(profile_ex).values(**profile_ex_data) conflict = sql.on_duplicate_key_update(**profile_ex_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -458,7 +458,7 @@ class ChuniProfileData(BaseData): return None return result.lastrowid - def get_profile_data_ex(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_data_ex(self, aime_id: int, version: int) -> Optional[Row]: sql = select(profile_ex).where( and_( profile_ex.c.user == aime_id, @@ -466,17 +466,17 @@ class ChuniProfileData(BaseData): ) ).order_by(profile_ex.c.version.desc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_option(self, aime_id: int, option_data: Dict) -> Optional[int]: + async def put_profile_option(self, aime_id: int, option_data: Dict) -> Optional[int]: option_data["user"] = aime_id sql = insert(option).values(**option_data) conflict = sql.on_duplicate_key_update(**option_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -485,22 +485,22 @@ class ChuniProfileData(BaseData): return None return result.lastrowid - def get_profile_option(self, aime_id: int) -> Optional[Row]: + async def get_profile_option(self, aime_id: int) -> Optional[Row]: sql = select(option).where(option.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_option_ex( + async def put_profile_option_ex( self, aime_id: int, option_ex_data: Dict ) -> Optional[int]: option_ex_data["user"] = aime_id sql = insert(option_ex).values(**option_ex_data) conflict = sql.on_duplicate_key_update(**option_ex_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -509,15 +509,15 @@ class ChuniProfileData(BaseData): return None return result.lastrowid - def get_profile_option_ex(self, aime_id: int) -> Optional[Row]: + async def get_profile_option_ex(self, aime_id: int) -> Optional[Row]: sql = select(option_ex).where(option_ex.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_recent_rating( + async def put_profile_recent_rating( self, aime_id: int, recent_rating_data: List[Dict] ) -> Optional[int]: sql = insert(recent_rating).values( @@ -525,7 +525,7 @@ class ChuniProfileData(BaseData): ) conflict = sql.on_duplicate_key_update(recentRating=recent_rating_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_recent_rating: Failed to update! aime_id: {aime_id}" @@ -533,15 +533,15 @@ class ChuniProfileData(BaseData): return None return result.lastrowid - def get_profile_recent_rating(self, aime_id: int) -> Optional[Row]: + async def get_profile_recent_rating(self, aime_id: int) -> Optional[Row]: sql = select(recent_rating).where(recent_rating.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_activity(self, aime_id: int, activity_data: Dict) -> Optional[int]: + async def put_profile_activity(self, aime_id: int, activity_data: Dict) -> Optional[int]: # The game just uses "id" but we need to distinguish that from the db column "id" activity_data["user"] = aime_id activity_data["activityId"] = activity_data["id"] @@ -549,7 +549,7 @@ class ChuniProfileData(BaseData): sql = insert(activity).values(**activity_data) conflict = sql.on_duplicate_key_update(**activity_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -558,24 +558,24 @@ class ChuniProfileData(BaseData): return None return result.lastrowid - def get_profile_activity(self, aime_id: int, kind: int) -> Optional[List[Row]]: + async def get_profile_activity(self, aime_id: int, kind: int) -> Optional[List[Row]]: sql = ( select(activity) .where(and_(activity.c.user == aime_id, activity.c.kind == kind)) .order_by(activity.c.sortNumber.desc()) # to get the last played track ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_profile_charge(self, aime_id: int, charge_data: Dict) -> Optional[int]: + async def put_profile_charge(self, aime_id: int, charge_data: Dict) -> Optional[int]: charge_data["user"] = aime_id sql = insert(charge).values(**charge_data) conflict = sql.on_duplicate_key_update(**charge_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -584,40 +584,40 @@ class ChuniProfileData(BaseData): return None return result.lastrowid - def get_profile_charge(self, aime_id: int) -> Optional[List[Row]]: + async def get_profile_charge(self, aime_id: int) -> Optional[List[Row]]: sql = select(charge).where(charge.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def add_profile_region(self, aime_id: int, region_id: int) -> Optional[int]: + async def add_profile_region(self, aime_id: int, region_id: int) -> Optional[int]: pass - def get_profile_regions(self, aime_id: int) -> Optional[List[Row]]: + async def get_profile_regions(self, aime_id: int) -> Optional[List[Row]]: pass - def put_profile_emoney(self, aime_id: int, emoney_data: Dict) -> Optional[int]: + async def put_profile_emoney(self, aime_id: int, emoney_data: Dict) -> Optional[int]: emoney_data["user"] = aime_id sql = insert(emoney).values(**emoney_data) conflict = sql.on_duplicate_key_update(**emoney_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_profile_emoney(self, aime_id: int) -> Optional[List[Row]]: + async def get_profile_emoney(self, aime_id: int) -> Optional[List[Row]]: sql = select(emoney).where(emoney.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_profile_overpower( + async def put_profile_overpower( self, aime_id: int, overpower_data: Dict ) -> Optional[int]: overpower_data["user"] = aime_id @@ -625,31 +625,31 @@ class ChuniProfileData(BaseData): sql = insert(overpower).values(**overpower_data) conflict = sql.on_duplicate_key_update(**overpower_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_profile_overpower(self, aime_id: int) -> Optional[List[Row]]: + async def get_profile_overpower(self, aime_id: int) -> Optional[List[Row]]: sql = select(overpower).where(overpower.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_team_by_id(self, team_id: int) -> Optional[Row]: + async def get_team_by_id(self, team_id: int) -> Optional[Row]: sql = select(team).where(team.c.id == team_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_team_rank(self, team_id: int) -> int: + async def get_team_rank(self, team_id: int) -> int: # Normal ranking system, likely the one used in the real servers # Query all teams sorted by 'teamPoint' - result = self.execute( + result = await self.execute( select(team.c.id).order_by(team.c.teamPoint.desc()) ) @@ -666,13 +666,13 @@ class ChuniProfileData(BaseData): # RIP scaled team ranking. Gone, but forgotten # def get_team_rank_scaled(self, team_id: int) -> int: - def update_team(self, team_id: int, team_data: Dict) -> bool: + async def update_team(self, team_id: int, team_data: Dict) -> bool: team_data["id"] = team_id sql = insert(team).values(**team_data) conflict = sql.on_duplicate_key_update(**team_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -680,16 +680,16 @@ class ChuniProfileData(BaseData): ) return False return True - def get_rival(self, rival_id: int) -> Optional[Row]: + async def get_rival(self, rival_id: int) -> Optional[Row]: sql = select(profile).where(profile.c.user == rival_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_overview(self) -> Dict: + async def get_overview(self) -> Dict: # Fetch and add up all the playcounts - playcount_sql = self.execute(select(profile.c.playCount)) + playcount_sql = await self.execute(select(profile.c.playCount)) if playcount_sql is None: self.logger.warn( diff --git a/titles/chuni/schema/score.py b/titles/chuni/schema/score.py index 7e41b8f..0a6424c 100644 --- a/titles/chuni/schema/score.py +++ b/titles/chuni/schema/score.py @@ -142,55 +142,55 @@ playlog = Table( class ChuniScoreData(BaseData): - def get_courses(self, aime_id: int) -> Optional[Row]: + async def get_courses(self, aime_id: int) -> Optional[Row]: sql = select(course).where(course.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_course(self, aime_id: int, course_data: Dict) -> Optional[int]: + async def put_course(self, aime_id: int, course_data: Dict) -> Optional[int]: course_data["user"] = aime_id course_data = self.fix_bools(course_data) sql = insert(course).values(**course_data) conflict = sql.on_duplicate_key_update(**course_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_scores(self, aime_id: int) -> Optional[Row]: + async def get_scores(self, aime_id: int) -> Optional[Row]: sql = select(best_score).where(best_score.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_score(self, aime_id: int, score_data: Dict) -> Optional[int]: + async def put_score(self, aime_id: int, score_data: Dict) -> Optional[int]: score_data["user"] = aime_id score_data = self.fix_bools(score_data) sql = insert(best_score).values(**score_data) conflict = sql.on_duplicate_key_update(**score_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_playlogs(self, aime_id: int) -> Optional[Row]: + async def get_playlogs(self, aime_id: int) -> Optional[Row]: sql = select(playlog).where(playlog.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_playlog(self, aime_id: int, playlog_data: Dict, version: int) -> Optional[int]: + async def put_playlog(self, aime_id: int, playlog_data: Dict, version: int) -> Optional[int]: # Calculate the ROM version that should be inserted into the DB, based on the version of the ggame being inserted # We only need from Version 10 (Plost) and back, as newer versions include romVersion in their upsert # This matters both for gameRankings, as well as a future DB update to keep version data separate @@ -216,12 +216,12 @@ class ChuniScoreData(BaseData): sql = insert(playlog).values(**playlog_data) conflict = sql.on_duplicate_key_update(**playlog_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_rankings(self, version: int) -> Optional[List[Dict]]: + async def get_rankings(self, version: int) -> Optional[List[Dict]]: # Calculates the ROM version that should be fetched for rankings, based on the game version being retrieved # This prevents tracks that are not accessible in your version from counting towards the 10 results romVer = { @@ -241,7 +241,7 @@ class ChuniScoreData(BaseData): 0: "1.00%" } sql = select([playlog.c.musicId.label('id'), func.count(playlog.c.musicId).label('point')]).where((playlog.c.level != 4) & (playlog.c.romVersion.like(romVer.get(version, "%")))).group_by(playlog.c.musicId).order_by(func.count(playlog.c.musicId).desc()).limit(10) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None @@ -249,10 +249,10 @@ class ChuniScoreData(BaseData): rows = result.fetchall() return [dict(row) for row in rows] - def get_rival_music(self, rival_id: int) -> Optional[List[Dict]]: + async def get_rival_music(self, rival_id: int) -> Optional[List[Dict]]: sql = select(best_score).where(best_score.c.user == rival_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/titles/chuni/schema/static.py b/titles/chuni/schema/static.py index fe32d41..ed67b5d 100644 --- a/titles/chuni/schema/static.py +++ b/titles/chuni/schema/static.py @@ -175,7 +175,7 @@ login_bonus = Table( class ChuniStaticData(BaseData): - def put_login_bonus( + async def put_login_bonus( self, version: int, preset_id: int, @@ -207,12 +207,12 @@ class ChuniStaticData(BaseData): loginBonusCategoryType=login_bonus_category_type, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_login_bonus( + async def get_login_bonus( self, version: int, preset_id: int, @@ -224,12 +224,12 @@ class ChuniStaticData(BaseData): ) ).order_by(login_bonus.c.needLoginDayCount.desc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_login_bonus_by_required_days( + async def get_login_bonus_by_required_days( self, version: int, preset_id: int, need_login_day_count: int ) -> Optional[Row]: sql = login_bonus.select( @@ -240,12 +240,12 @@ class ChuniStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_login_bonus_preset( + async def put_login_bonus_preset( self, version: int, preset_id: int, preset_name: str, is_enabled: bool ) -> Optional[int]: sql = insert(login_bonus_preset).values( @@ -259,12 +259,12 @@ class ChuniStaticData(BaseData): presetName=preset_name, isEnabled=is_enabled ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_login_bonus_presets( + async def get_login_bonus_presets( self, version: int, is_enabled: bool = True ) -> Optional[List[Row]]: sql = login_bonus_preset.select( @@ -274,12 +274,12 @@ class ChuniStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_event( + async def put_event( self, version: int, event_id: int, type: int, name: str ) -> Optional[int]: sql = insert(events).values( @@ -288,19 +288,19 @@ class ChuniStaticData(BaseData): conflict = sql.on_duplicate_key_update(name=name) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def update_event( + async def update_event( 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) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning( f"update_event: failed to update event! version: {version}, event_id: {event_id}, enabled: {enabled}" @@ -315,35 +315,35 @@ class ChuniStaticData(BaseData): return None return event["enabled"] - def get_event(self, version: int, event_id: int) -> Optional[Row]: + async def get_event(self, version: int, event_id: int) -> Optional[Row]: sql = select(events).where( and_(events.c.version == version, events.c.eventId == event_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_enabled_events(self, version: int) -> Optional[List[Row]]: + async def get_enabled_events(self, version: int) -> Optional[List[Row]]: sql = select(events).where( and_(events.c.version == version, events.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_events(self, version: int) -> Optional[List[Row]]: + async def get_events(self, version: int) -> Optional[List[Row]]: sql = select(events).where(events.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_music( + async def put_music( self, version: int, song_id: int, @@ -376,12 +376,12 @@ class ChuniStaticData(BaseData): worldsEndTag=we_tag, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_charge( + async def put_charge( self, version: int, charge_id: int, @@ -406,38 +406,38 @@ class ChuniStaticData(BaseData): sellingAppeal=selling_appeal, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_enabled_charges(self, version: int) -> Optional[List[Row]]: + async def get_enabled_charges(self, version: int) -> Optional[List[Row]]: sql = select(charge).where( and_(charge.c.version == version, charge.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_charges(self, version: int) -> Optional[List[Row]]: + async def get_charges(self, version: int) -> Optional[List[Row]]: sql = select(charge).where(charge.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_music(self, version: int) -> Optional[List[Row]]: + async def get_music(self, version: int) -> Optional[List[Row]]: sql = music.select(music.c.version <= version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_music_chart( + async def get_music_chart( self, version: int, song_id: int, chart_id: int ) -> Optional[List[Row]]: sql = select(music).where( @@ -448,21 +448,21 @@ class ChuniStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_song(self, music_id: int) -> Optional[Row]: + async def get_song(self, music_id: int) -> Optional[Row]: sql = music.select(music.c.id == music_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_avatar( + async def put_avatar( self, version: int, avatarAccessoryId: int, @@ -487,12 +487,12 @@ class ChuniStaticData(BaseData): texturePath=texturePath, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_gacha( + async def put_gacha( self, version: int, gacha_id: int, @@ -513,33 +513,33 @@ class ChuniStaticData(BaseData): **gacha_data, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert gacha! gacha_id {gacha_id}") return None return result.lastrowid - def get_gachas(self, version: int) -> Optional[List[Dict]]: + async def get_gachas(self, version: int) -> Optional[List[Dict]]: sql = gachas.select(gachas.c.version <= version).order_by( gachas.c.gachaId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_gacha(self, version: int, gacha_id: int) -> Optional[Dict]: + async def get_gacha(self, version: int, gacha_id: int) -> Optional[Dict]: sql = gachas.select( and_(gachas.c.version <= version, gachas.c.gachaId == gacha_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_gacha_card( + async def put_gacha_card( self, gacha_id: int, card_id: int, **gacha_card ) -> Optional[int]: sql = insert(gacha_cards).values(gachaId=gacha_id, cardId=card_id, **gacha_card) @@ -548,21 +548,21 @@ class ChuniStaticData(BaseData): gachaId=gacha_id, cardId=card_id, **gacha_card ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert gacha card! gacha_id {gacha_id}") return None return result.lastrowid - def get_gacha_cards(self, gacha_id: int) -> Optional[List[Dict]]: + async def get_gacha_cards(self, gacha_id: int) -> Optional[List[Dict]]: sql = gacha_cards.select(gacha_cards.c.gachaId == gacha_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_gacha_card_by_character( + async def get_gacha_card_by_character( self, gacha_id: int, chara_id: int ) -> Optional[Dict]: sql_sub = ( @@ -574,26 +574,26 @@ class ChuniStaticData(BaseData): and_(gacha_cards.c.gachaId == gacha_id, gacha_cards.c.cardId == sql_sub) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_card(self, version: int, card_id: int, **card_data) -> Optional[int]: + async def put_card(self, version: int, card_id: int, **card_data) -> Optional[int]: sql = insert(cards).values(version=version, cardId=card_id, **card_data) conflict = sql.on_duplicate_key_update(**card_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert card! card_id {card_id}") return None return result.lastrowid - def get_card(self, version: int, card_id: int) -> Optional[Dict]: + async def get_card(self, version: int, card_id: int) -> Optional[Dict]: sql = cards.select(and_(cards.c.version <= version, cards.c.cardId == card_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() \ No newline at end of file diff --git a/titles/cm/read.py b/titles/cm/read.py index 376789d..ae90b52 100644 --- a/titles/cm/read.py +++ b/titles/cm/read.py @@ -50,7 +50,7 @@ class CardMakerReader(BaseReader): ): return f"{root}/{dir}" - def read(self) -> None: + async def read(self) -> None: static_datas = { "static_gachas.csv": "read_ongeki_gacha_csv", "static_gacha_cards.csv": "read_ongeki_gacha_card_csv", @@ -66,7 +66,7 @@ class CardMakerReader(BaseReader): for file, func in static_datas.items(): if os.path.exists(f"{self.bin_dir}/MU3/{file}"): read_csv = getattr(CardMakerReader, func) - read_csv(self, f"{self.bin_dir}/MU3/{file}") + await read_csv(self, f"{self.bin_dir}/MU3/{file}") else: self.logger.warning( f"Couldn't find {file} file in {self.bin_dir}, skipping" @@ -78,12 +78,12 @@ class CardMakerReader(BaseReader): # ONGEKI (MU3) cnnot easily access the bin data(A000.pac) # so only opt_dir will work for now for dir in data_dirs: - self.read_chuni_card(f"{dir}/CHU/card") - self.read_chuni_gacha(f"{dir}/CHU/gacha") - self.read_mai2_card(f"{dir}/MAI/card") - self.read_ongeki_gacha(f"{dir}/MU3/gacha") + await self.read_chuni_card(f"{dir}/CHU/card") + await self.read_chuni_gacha(f"{dir}/CHU/gacha") + await self.read_mai2_card(f"{dir}/MAI/card") + await self.read_ongeki_gacha(f"{dir}/MU3/gacha") - def read_chuni_card(self, base_dir: str) -> None: + async def read_chuni_card(self, base_dir: str) -> None: self.logger.info(f"Reading cards from {base_dir}...") version_ids = { @@ -114,7 +114,7 @@ class CardMakerReader(BaseReader): chain = int(troot.find("chain").text) skill_name = troot.find("skillName").text - self.chuni_data.static.put_card( + await self.chuni_data.static.put_card( version, card_id, charaName=chara_name, @@ -131,7 +131,7 @@ class CardMakerReader(BaseReader): self.logger.info(f"Added chuni card {card_id}") - def read_chuni_gacha(self, base_dir: str) -> None: + async def read_chuni_gacha(self, base_dir: str) -> None: self.logger.info(f"Reading gachas from {base_dir}...") version_ids = { @@ -158,7 +158,7 @@ class CardMakerReader(BaseReader): True if troot.find("ceilingType").text == "1" else False ) - self.chuni_data.static.put_gacha( + await self.chuni_data.static.put_gacha( version, gacha_id, name, @@ -181,7 +181,7 @@ class CardMakerReader(BaseReader): True if gacha_card.find("pickup").text == "1" else False ) - self.chuni_data.static.put_gacha_card( + await self.chuni_data.static.put_gacha_card( gacha_id, card_id, weight=weight, @@ -193,7 +193,7 @@ class CardMakerReader(BaseReader): f"Added chuni card {card_id} to gacha {gacha_id}" ) - def read_mai2_card(self, base_dir: str) -> None: + async def read_mai2_card(self, base_dir: str) -> None: self.logger.info(f"Reading cards from {base_dir}...") version_ids = { @@ -231,18 +231,18 @@ class CardMakerReader(BaseReader): False if re.search(r"\d{2}/\d{2}/\d{2}", name) else enabled ) - self.mai2_data.static.put_card( + await self.mai2_data.static.put_card( version, card_id, name, enabled=enabled ) self.logger.info(f"Added mai2 card {card_id}") - def read_ongeki_gacha_csv(self, file_path: str) -> None: + async def read_ongeki_gacha_csv(self, file_path: str) -> None: self.logger.info(f"Reading gachas from {file_path}...") with open(file_path, encoding="utf-8") as f: reader = csv.DictReader(f) for row in reader: - self.ongeki_data.static.put_gacha( + await self.ongeki_data.static.put_gacha( row["version"], row["gachaId"], row["gachaName"], @@ -254,13 +254,13 @@ class CardMakerReader(BaseReader): self.logger.info(f"Added ongeki gacha {row['gachaId']}") - def read_ongeki_gacha_card_csv(self, file_path: str) -> None: + async def read_ongeki_gacha_card_csv(self, file_path: str) -> None: self.logger.info(f"Reading gacha cards from {file_path}...") with open(file_path, encoding="utf-8") as f: reader = csv.DictReader(f) for row in reader: - self.ongeki_data.static.put_gacha_card( + await self.ongeki_data.static.put_gacha_card( row["gachaId"], row["cardId"], rarity=row["rarity"], @@ -271,7 +271,7 @@ class CardMakerReader(BaseReader): self.logger.info(f"Added ongeki card {row['cardId']} to gacha") - def read_ongeki_gacha(self, base_dir: str) -> None: + async def read_ongeki_gacha(self, base_dir: str) -> None: self.logger.info(f"Reading gachas from {base_dir}...") # assuming some GachaKinds based on the GachaType @@ -294,7 +294,7 @@ class CardMakerReader(BaseReader): # skip already existing gachas if ( - self.ongeki_data.static.get_gacha( + await self.ongeki_data.static.get_gacha( OngekiConstants.VER_ONGEKI_BRIGHT_MEMORY, gacha_id ) is not None @@ -320,7 +320,7 @@ class CardMakerReader(BaseReader): is_ceiling = 1 max_select_point = 33 - self.ongeki_data.static.put_gacha( + await self.ongeki_data.static.put_gacha( version, gacha_id, name, diff --git a/titles/cxb/base.py b/titles/cxb/base.py index 691897d..cc4e50d 100644 --- a/titles/cxb/base.py +++ b/titles/cxb/base.py @@ -35,7 +35,7 @@ class CxbBase: return {"data": []} async def handle_auth_usercheck_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_index( + profile = await self.data.profile.get_profile_index( 0, data["usercheck"]["authid"], self.version ) if profile is not None: @@ -50,7 +50,7 @@ class CxbBase: return {"token": data["entry"]["authid"], "uid": data["entry"]["authid"]} async def handle_auth_login_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_index( + profile = await self.data.profile.get_profile_index( 0, data["login"]["authid"], self.version ) @@ -204,8 +204,8 @@ class CxbBase: uid = data["loadrange"]["uid"] self.logger.info(f"Load data for {uid}") - profile = self.data.profile.get_profile(uid, self.version) - songs = self.data.score.get_best_scores(uid) + profile = await self.data.profile.get_profile(uid, self.version) + songs = await self.data.score.get_best_scores(uid) data1 = [] index = [] @@ -271,7 +271,7 @@ class CxbBase: thread_ScoreData = Thread(target=CxbBase.task_generateScoreData(song, index, data1)) thread_ScoreData.start() - v_profile = self.data.profile.get_profile_index(0, uid, self.version) + v_profile = await self.data.profile.get_profile_index(0, uid, self.version) v_profile_data = v_profile["data"] for _, data in enumerate(profile): @@ -300,11 +300,11 @@ class CxbBase: for value in data["saveindex"]["data"]: if "playedUserId" in value[1]: - self.data.profile.put_profile( + await self.data.profile.put_profile( data["saveindex"]["uid"], self.version, value[0], value[1] ) if "mcode" not in value[1]: - self.data.profile.put_profile( + await self.data.profile.put_profile( data["saveindex"]["uid"], self.version, value[0], value[1] ) if "shopId" in value: @@ -335,7 +335,7 @@ class CxbBase: "index": value[0], } ) - self.data.score.put_best_score( + await self.data.score.put_best_score( data["saveindex"]["uid"], song_json["mcode"], self.version, @@ -360,32 +360,32 @@ class CxbBase: for index, value in enumerate(data["saveindex"]["data"]): if int(data["saveindex"]["index"][index]) == 101: - self.data.profile.put_profile( + await self.data.profile.put_profile( aimeId, self.version, data["saveindex"]["index"][index], value ) if ( int(data["saveindex"]["index"][index]) >= 700000 and int(data["saveindex"]["index"][index]) <= 701000 ): - self.data.profile.put_profile( + await self.data.profile.put_profile( aimeId, self.version, data["saveindex"]["index"][index], value ) if ( int(data["saveindex"]["index"][index]) >= 500 and int(data["saveindex"]["index"][index]) <= 510 ): - self.data.profile.put_profile( + await self.data.profile.put_profile( aimeId, self.version, data["saveindex"]["index"][index], value ) if "playedUserId" in value: - self.data.profile.put_profile( + await self.data.profile.put_profile( aimeId, self.version, data["saveindex"]["index"][index], json.loads(value), ) if "mcode" not in value and "normalCR" not in value: - self.data.profile.put_profile( + await self.data.profile.put_profile( aimeId, self.version, data["saveindex"]["index"][index], @@ -437,7 +437,7 @@ class CxbBase: } ) - self.data.score.put_best_score( + await self.data.score.put_best_score( aimeId, data1["mcode"], self.version, indexSongList[i], songCode[0] ) i += 1 @@ -446,7 +446,7 @@ class CxbBase: async def handle_action_sprankreq_request(self, data: Dict) -> Dict: uid = data["sprankreq"]["uid"] self.logger.info(f"Get best rankings for {uid}") - p = self.data.score.get_best_rankings(uid) + p = await self.data.score.get_best_rankings(uid) rankList: List[Dict[str, Any]] = [] @@ -492,7 +492,7 @@ class CxbBase: # REV S2 if "clear" in rid: try: - self.data.score.put_ranking( + await self.data.score.put_ranking( user_id=uid, rev_id=int(rid["rid"]), song_id=int(rid["sc"][1]), @@ -500,7 +500,7 @@ class CxbBase: clear=rid["clear"], ) except Exception: - self.data.score.put_ranking( + await self.data.score.put_ranking( user_id=uid, rev_id=int(rid["rid"]), song_id=0, @@ -510,7 +510,7 @@ class CxbBase: # REV else: try: - self.data.score.put_ranking( + await self.data.score.put_ranking( user_id=uid, rev_id=int(rid["rid"]), song_id=int(rid["sc"][1]), @@ -518,7 +518,7 @@ class CxbBase: clear=0, ) except Exception: - self.data.score.put_ranking( + await self.data.score.put_ranking( user_id=uid, rev_id=int(rid["rid"]), song_id=0, @@ -530,12 +530,12 @@ class CxbBase: async def handle_action_addenergy_request(self, data: Dict) -> Dict: uid = data["addenergy"]["uid"] self.logger.info(f"Add energy to user {uid}") - profile = self.data.profile.get_profile_index(0, uid, self.version) + profile = await self.data.profile.get_profile_index(0, uid, self.version) data1 = profile["data"] - p = self.data.item.get_energy(uid) + p = await self.data.item.get_energy(uid) if not p: - self.data.item.put_energy(uid, 5) + await self.data.item.put_energy(uid, 5) return { "class": data1["myClass"], @@ -548,7 +548,7 @@ class CxbBase: energy = p["energy"] newenergy = int(energy) + 5 - self.data.item.put_energy(uid, newenergy) + await self.data.item.put_energy(uid, newenergy) if int(energy) <= 995: array.append( diff --git a/titles/cxb/read.py b/titles/cxb/read.py index b71740d..9a2ae98 100644 --- a/titles/cxb/read.py +++ b/titles/cxb/read.py @@ -1,6 +1,5 @@ -from typing import Optional, Dict, List -from os import walk, path -import urllib +from typing import Optional +from os import path import csv from read import BaseReader @@ -8,7 +7,6 @@ from core.config import CoreConfig from titles.cxb.database import CxbData from titles.cxb.const import CxbConstants - class CxbReader(BaseReader): def __init__( self, @@ -29,17 +27,14 @@ class CxbReader(BaseReader): self.logger.error(f"Invalid project cxb version {version}") exit(1) - def read(self) -> None: - pull_bin_ram = True + async def read(self) -> None: + if path.exists(self.bin_dir): + await self.read_csv(self.bin_dir) + + else: + self.logger.warn(f"{self.bin_dir} does not exist, nothing to import") - if not path.exists(f"{self.bin_dir}"): - self.logger.warning(f"Couldn't find csv file in {self.bin_dir}, skipping") - pull_bin_ram = False - - if pull_bin_ram: - self.read_csv(f"{self.bin_dir}") - - def read_csv(self, bin_dir: str) -> None: + async def read_csv(self, bin_dir: str) -> None: self.logger.info(f"Read csv from {bin_dir}") try: @@ -55,7 +50,7 @@ class CxbReader(BaseReader): if not "N/A" in row["standard"]: self.logger.info(f"Added song {song_id} chart 0") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, index, @@ -71,7 +66,7 @@ class CxbReader(BaseReader): ) if not "N/A" in row["hard"]: self.logger.info(f"Added song {song_id} chart 1") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, index, @@ -83,7 +78,7 @@ class CxbReader(BaseReader): ) if not "N/A" in row["master"]: self.logger.info(f"Added song {song_id} chart 2") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, index, @@ -97,7 +92,7 @@ class CxbReader(BaseReader): ) if not "N/A" in row["unlimited"]: self.logger.info(f"Added song {song_id} chart 3") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, index, @@ -113,7 +108,7 @@ class CxbReader(BaseReader): ) if not "N/A" in row["easy"]: self.logger.info(f"Added song {song_id} chart 4") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, index, diff --git a/titles/cxb/rev.py b/titles/cxb/rev.py index 1a7c5ac..757b7e8 100644 --- a/titles/cxb/rev.py +++ b/titles/cxb/rev.py @@ -25,7 +25,7 @@ class CxbRev(CxbBase): score_data = json.loads(data["putlog"]["data"]) userid = score_data["usid"] - self.data.score.put_playlog( + await self.data.score.put_playlog( userid, score_data["mcode"], score_data["difficulty"], diff --git a/titles/cxb/schema/item.py b/titles/cxb/schema/item.py index 022a036..9e6a904 100644 --- a/titles/cxb/schema/item.py +++ b/titles/cxb/schema/item.py @@ -19,12 +19,12 @@ energy = Table( class CxbItemData(BaseData): - def put_energy(self, user_id: int, rev_energy: int) -> Optional[int]: + async def put_energy(self, user_id: int, rev_energy: int) -> Optional[int]: sql = insert(energy).values(user=user_id, energy=rev_energy) conflict = sql.on_duplicate_key_update(energy=rev_energy) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert item! user: {user_id}, energy: {rev_energy}" @@ -33,10 +33,10 @@ class CxbItemData(BaseData): return result.lastrowid - def get_energy(self, user_id: int) -> Optional[Dict]: + async def get_energy(self, user_id: int) -> Optional[Dict]: sql = energy.select(and_(energy.c.user == user_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/cxb/schema/profile.py b/titles/cxb/schema/profile.py index 5c62f76..a3e6039 100644 --- a/titles/cxb/schema/profile.py +++ b/titles/cxb/schema/profile.py @@ -21,7 +21,7 @@ profile = Table( class CxbProfileData(BaseData): - def put_profile( + async def put_profile( self, user_id: int, version: int, index: int, data: JSON ) -> Optional[int]: sql = insert(profile).values( @@ -30,7 +30,7 @@ class CxbProfileData(BaseData): conflict = sql.on_duplicate_key_update(index=index, data=data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to update! user: {user_id}, index: {index}, data: {data}" @@ -39,7 +39,7 @@ class CxbProfileData(BaseData): return result.lastrowid - def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]: + async def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]: """ Given a game version and either a profile or aime id, return the profile """ @@ -47,12 +47,12 @@ class CxbProfileData(BaseData): and_(profile.c.version == version, profile.c.user == aime_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_profile_index( + async def get_profile_index( self, index: int, aime_id: int = None, version: int = None ) -> Optional[Dict]: """ @@ -72,7 +72,7 @@ class CxbProfileData(BaseData): ) return None - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/cxb/schema/score.py b/titles/cxb/schema/score.py index b6f4f16..7be33d8 100644 --- a/titles/cxb/schema/score.py +++ b/titles/cxb/schema/score.py @@ -58,7 +58,7 @@ ranking = Table( class CxbScoreData(BaseData): - def put_best_score( + async def put_best_score( self, user_id: int, song_mcode: str, @@ -79,7 +79,7 @@ class CxbScoreData(BaseData): conflict = sql.on_duplicate_key_update(data=sql.inserted.data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert best score! profile: {user_id}, song: {song_mcode}, data: {data}" @@ -88,7 +88,7 @@ class CxbScoreData(BaseData): return result.lastrowid - def put_playlog( + async def put_playlog( self, user_id: int, song_mcode: str, @@ -125,7 +125,7 @@ class CxbScoreData(BaseData): combo=combo, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_mcode}, chart: {chart_id}" @@ -134,7 +134,7 @@ class CxbScoreData(BaseData): return result.lastrowid - def put_ranking( + async def put_ranking( self, user_id: int, rev_id: int, song_id: int, score: int, clear: int ) -> Optional[int]: """ @@ -151,7 +151,7 @@ class CxbScoreData(BaseData): conflict = sql.on_duplicate_key_update(score=score) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert ranking log! profile: {user_id}, score: {score}, clear: {clear}" @@ -160,28 +160,28 @@ class CxbScoreData(BaseData): return result.lastrowid - def get_best_score(self, user_id: int, song_mcode: int) -> Optional[Dict]: + async def get_best_score(self, user_id: int, song_mcode: int) -> Optional[Dict]: sql = score.select( and_(score.c.user == user_id, score.c.song_mcode == song_mcode) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_best_scores(self, user_id: int) -> Optional[Dict]: + async def get_best_scores(self, user_id: int) -> Optional[Dict]: sql = score.select(score.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_best_rankings(self, user_id: int) -> Optional[List[Dict]]: + async def get_best_rankings(self, user_id: int) -> Optional[List[Dict]]: sql = ranking.select(ranking.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/titles/cxb/schema/static.py b/titles/cxb/schema/static.py index 6459e99..b863ef9 100644 --- a/titles/cxb/schema/static.py +++ b/titles/cxb/schema/static.py @@ -29,7 +29,7 @@ music = Table( class CxbStaticData(BaseData): - def put_music( + async def put_music( self, version: int, mcode: str, @@ -55,12 +55,12 @@ class CxbStaticData(BaseData): title=title, artist=artist, category=category, level=level ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_music( + async def get_music( self, version: int, song_id: Optional[int] = None ) -> Optional[List[Row]]: if song_id is None: @@ -73,12 +73,12 @@ class CxbStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_music_chart( + async def get_music_chart( self, version: int, song_id: int, chart_id: int ) -> Optional[List[Row]]: sql = select(music).where( @@ -89,7 +89,7 @@ class CxbStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/diva/base.py b/titles/diva/base.py index eb7d11e..7fe3fb5 100644 --- a/titles/diva/base.py +++ b/titles/diva/base.py @@ -128,7 +128,7 @@ class DivaBase: async def handle_shop_catalog_request(self, data: Dict) -> Dict: catalog = "" - shopList = self.data.static.get_enabled_shops(self.version) + shopList = await self.data.static.get_enabled_shops(self.version) if not shopList: with open(r"titles/diva/data/ShopCatalog.dat", encoding="utf-8") as shop: lines = shop.readlines() @@ -164,8 +164,8 @@ class DivaBase: return response async def handle_buy_module_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile(data["pd_id"], self.version) - module = self.data.static.get_enabled_shop(self.version, int(data["mdl_id"])) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) + module = await self.data.static.get_enabled_shop(self.version, int(data["mdl_id"])) # make sure module is available to purchase if not module: @@ -177,11 +177,11 @@ class DivaBase: new_vcld_pts = profile["vcld_pts"] - int(data["mdl_price"]) - self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts) - self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"]) + await self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts) + await self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"]) # generate the mdl_have string - mdl_have = self.data.module.get_modules_have_string(data["pd_id"], self.version) + mdl_have = await self.data.module.get_modules_have_string(data["pd_id"], self.version) response = "&shp_rslt=1" response += f"&mdl_id={data['mdl_id']}" @@ -193,7 +193,7 @@ class DivaBase: async def handle_cstmz_itm_ctlg_request(self, data: Dict) -> Dict: catalog = "" - itemList = self.data.static.get_enabled_items(self.version) + itemList = await self.data.static.get_enabled_items(self.version) if not itemList: with open(r"titles/diva/data/ItemCatalog.dat", encoding="utf-8") as item: lines = item.readlines() @@ -229,8 +229,8 @@ class DivaBase: return response async def handle_buy_cstmz_itm_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile(data["pd_id"], self.version) - item = self.data.static.get_enabled_item( + profile = await self.data.profile.get_profile(data["pd_id"], self.version) + item = await self.data.static.get_enabled_item( self.version, int(data["cstmz_itm_id"]) ) @@ -245,14 +245,14 @@ class DivaBase: new_vcld_pts = profile["vcld_pts"] - int(data["cstmz_itm_price"]) # save new Vocaloid Points balance - self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts) + await self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts) - self.data.customize.put_customize_item( + await self.data.customize.put_customize_item( data["pd_id"], self.version, data["cstmz_itm_id"] ) # generate the cstmz_itm_have string - cstmz_itm_have = self.data.customize.get_customize_items_have_string( + cstmz_itm_have = await self.data.customize.get_customize_items_have_string( data["pd_id"], self.version ) @@ -297,7 +297,7 @@ class DivaBase: async def handle_qst_inf_request(self, data: Dict) -> Dict: quest = "" - questList = self.data.static.get_enabled_quests(self.version) + questList = await self.data.static.get_enabled_quests(self.version) if not questList: with open(r"titles/diva/data/QuestInfo.dat", encoding="utf-8") as shop: lines = shop.readlines() @@ -381,8 +381,8 @@ class DivaBase: return f"" async def handle_pre_start_request(self, data: Dict) -> str: - profile = self.data.profile.get_profile(data["aime_id"], self.version) - profile_shop = self.data.item.get_shop(data["aime_id"], self.version) + profile = await self.data.profile.get_profile(data["aime_id"], self.version) + profile_shop = await self.data.item.get_shop(data["aime_id"], self.version) if profile is None: return f"&ps_result=-3" @@ -422,28 +422,28 @@ class DivaBase: return response async def handle_registration_request(self, data: Dict) -> Dict: - self.data.profile.create_profile( + await self.data.profile.create_profile( self.version, data["aime_id"], data["player_name"] ) return f"&cd_adm_result=1&pd_id={data['aime_id']}" async def handle_start_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile(data["pd_id"], self.version) - profile_shop = self.data.item.get_shop(data["pd_id"], self.version) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) + profile_shop = await self.data.item.get_shop(data["pd_id"], self.version) if profile is None: return mdl_have = "F" * 250 # generate the mdl_have string if "unlock_all_modules" is disabled if not self.game_config.mods.unlock_all_modules: - mdl_have = self.data.module.get_modules_have_string( + mdl_have = await self.data.module.get_modules_have_string( data["pd_id"], self.version ) cstmz_itm_have = "F" * 250 # generate the cstmz_itm_have string if "unlock_all_items" is disabled if not self.game_config.mods.unlock_all_items: - cstmz_itm_have = self.data.customize.get_customize_items_have_string( + cstmz_itm_have = await self.data.customize.get_customize_items_have_string( data["pd_id"], self.version ) @@ -524,7 +524,7 @@ class DivaBase: } # get clear status from user scores - pv_records = self.data.score.get_best_scores(data["pd_id"]) + pv_records = await self.data.score.get_best_scores(data["pd_id"]) clear_status = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" if pv_records is not None: @@ -586,7 +586,7 @@ class DivaBase: return f"" async def handle_spend_credit_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile(data["pd_id"], self.version) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) if profile is None: return @@ -663,30 +663,30 @@ class DivaBase: return pv_result - def task_generateScoreData(self, data: Dict, pd_by_pv_id, song): + async def task_generateScoreData(self, data: Dict, pd_by_pv_id, song): if int(song) > 0: # the request do not send a edition so just perform a query best score and ranking for each edition. # 0=ORIGINAL, 1=EXTRA - pd_db_song_0 = self.data.score.get_best_user_score( + pd_db_song_0 = await self.data.score.get_best_user_score( data["pd_id"], int(song), data["difficulty"], edition=0 ) - pd_db_song_1 = self.data.score.get_best_user_score( + pd_db_song_1 = await self.data.score.get_best_user_score( data["pd_id"], int(song), data["difficulty"], edition=1 ) pd_db_ranking_0, pd_db_ranking_1 = None, None if pd_db_song_0: - pd_db_ranking_0 = self.data.score.get_global_ranking( + pd_db_ranking_0 = await self.data.score.get_global_ranking( data["pd_id"], int(song), data["difficulty"], edition=0 ) if pd_db_song_1: - pd_db_ranking_1 = self.data.score.get_global_ranking( + pd_db_ranking_1 = await self.data.score.get_global_ranking( data["pd_id"], int(song), data["difficulty"], edition=1 ) - pd_db_customize = self.data.pv_customize.get_pv_customize( + pd_db_customize = await self.data.pv_customize.get_pv_customize( data["pd_id"], int(song) ) @@ -712,7 +712,7 @@ class DivaBase: pd_by_pv_id = [] for song in song_id: - thread_ScoreData = Thread(target=self.task_generateScoreData(data, pd_by_pv_id, song)) + thread_ScoreData = Thread(target=await self.task_generateScoreData(data, pd_by_pv_id, song)) threads.append(thread_ScoreData) for x in threads: @@ -735,7 +735,7 @@ class DivaBase: return f"" async def handle_stage_result_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile(data["pd_id"], self.version) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) pd_song_list = data["stg_ply_pv_id"].split(",") pd_song_difficulty = data["stg_difficulty"].split(",") @@ -753,14 +753,14 @@ class DivaBase: for index, value in enumerate(pd_song_list): if "-1" not in pd_song_list[index]: - profile_pd_db_song = self.data.score.get_best_user_score( + profile_pd_db_song = await self.data.score.get_best_user_score( data["pd_id"], pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], ) if profile_pd_db_song is None: - self.data.score.put_best_score( + await self.data.score.put_best_score( data["pd_id"], self.version, pd_song_list[index], @@ -777,7 +777,7 @@ class DivaBase: pd_song_worst_cnt[index], pd_song_max_combo[index], ) - self.data.score.put_playlog( + await self.data.score.put_playlog( data["pd_id"], self.version, pd_song_list[index], @@ -795,7 +795,7 @@ class DivaBase: pd_song_max_combo[index], ) elif int(pd_song_max_score[index]) >= int(profile_pd_db_song["score"]): - self.data.score.put_best_score( + await self.data.score.put_best_score( data["pd_id"], self.version, pd_song_list[index], @@ -812,7 +812,7 @@ class DivaBase: pd_song_worst_cnt[index], pd_song_max_combo[index], ) - self.data.score.put_playlog( + await self.data.score.put_playlog( data["pd_id"], self.version, pd_song_list[index], @@ -830,7 +830,7 @@ class DivaBase: pd_song_max_combo[index], ) elif int(pd_song_max_score[index]) != int(profile_pd_db_song["score"]): - self.data.score.put_playlog( + await self.data.score.put_playlog( data["pd_id"], self.version, pd_song_list[index], @@ -851,7 +851,7 @@ class DivaBase: # Profile saving based on registration list # Calculate new level - best_scores = self.data.score.get_best_scores(data["pd_id"]) + best_scores = await self.data.score.get_best_scores(data["pd_id"]) total_atn_pnt = 0 for best_score in best_scores: @@ -865,7 +865,7 @@ class DivaBase: response += f"&lv_pnt_old={int(profile['lv_pnt'])}" # update the profile and commit changes to the db - self.data.profile.update_profile( + await self.data.profile.update_profile( profile["user"], lv_num=new_level, lv_pnt=new_level_pnt, @@ -914,15 +914,15 @@ class DivaBase: return response async def handle_end_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile(data["pd_id"], self.version) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) - self.data.profile.update_profile( + await self.data.profile.update_profile( profile["user"], my_qst_id=data["my_qst_id"], my_qst_sts=data["my_qst_sts"] ) return f"" async def handle_shop_exit_request(self, data: Dict) -> Dict: - self.data.item.put_shop( + await self.data.item.put_shop( data["pd_id"], self.version, data["mdl_eqp_cmn_ary"], @@ -930,7 +930,7 @@ class DivaBase: data["ms_itm_flg_cmn_ary"], ) if int(data["use_pv_mdl_eqp"]) == 1: - self.data.pv_customize.put_pv_customize( + await self.data.pv_customize.put_pv_customize( data["pd_id"], self.version, data["ply_pv_id"], @@ -939,7 +939,7 @@ class DivaBase: data["ms_itm_flg_pv_ary"], ) else: - self.data.pv_customize.put_pv_customize( + await self.data.pv_customize.put_pv_customize( data["pd_id"], self.version, data["ply_pv_id"], @@ -952,7 +952,7 @@ class DivaBase: return response async def handle_card_procedure_request(self, data: Dict) -> str: - profile = self.data.profile.get_profile(data["aime_id"], self.version) + profile = await self.data.profile.get_profile(data["aime_id"], self.version) if profile is None: return "&cd_adm_result=0" @@ -972,7 +972,7 @@ class DivaBase: return response async def handle_change_name_request(self, data: Dict) -> str: - profile = self.data.profile.get_profile(data["pd_id"], self.version) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) # make sure user has enough Vocaloid Points if profile["vcld_pts"] < int(data["chg_name_price"]): @@ -980,7 +980,7 @@ class DivaBase: # update the vocaloid points and player name new_vcld_pts = profile["vcld_pts"] - int(data["chg_name_price"]) - self.data.profile.update_profile( + await self.data.profile.update_profile( profile["user"], player_name=data["player_name"], vcld_pts=new_vcld_pts ) @@ -992,14 +992,14 @@ class DivaBase: return response async def handle_change_passwd_request(self, data: Dict) -> str: - profile = self.data.profile.get_profile(data["pd_id"], self.version) + profile = await self.data.profile.get_profile(data["pd_id"], self.version) # TODO: return correct error number instead of 0 if data["passwd"] != profile["passwd"]: return "&cd_adm_result=0" # set password to true and update the saved password - self.data.profile.update_profile( + await self.data.profile.update_profile( profile["user"], passwd_stat=1, passwd=data["new_passwd"] ) diff --git a/titles/diva/read.py b/titles/diva/read.py index f143bb6..97c9481 100644 --- a/titles/diva/read.py +++ b/titles/diva/read.py @@ -28,7 +28,7 @@ class DivaReader(BaseReader): self.logger.error(f"Invalid project diva version {version}") exit(1) - def read(self) -> None: + async def read(self) -> None: pull_bin_ram = True pull_bin_rom = True pull_opt_rom = True @@ -48,14 +48,14 @@ class DivaReader(BaseReader): self.logger.warning("No option directory specified, skipping") if pull_bin_ram: - self.read_ram(f"{self.bin_dir}/ram") + await self.read_ram(f"{self.bin_dir}/ram") if pull_bin_rom: - self.read_rom(f"{self.bin_dir}/rom") + await self.read_rom(f"{self.bin_dir}/rom") if pull_opt_rom: for dir in opt_dirs: - self.read_rom(f"{dir}/rom") + await self.read_rom(f"{dir}/rom") - def read_ram(self, ram_root_dir: str) -> None: + async def read_ram(self, ram_root_dir: str) -> None: self.logger.info(f"Read RAM from {ram_root_dir}") if path.exists(f"{ram_root_dir}/databank"): @@ -91,7 +91,7 @@ class DivaReader(BaseReader): f"Added shop item {split[x+0]}" ) - self.data.static.put_shop( + await self.data.static.put_shop( self.version, split[x + 0], split[x + 2], @@ -109,7 +109,7 @@ class DivaReader(BaseReader): for x in range(0, len(split), 7): self.logger.info(f"Added item {split[x+0]}") - self.data.static.put_items( + await self.data.static.put_items( self.version, split[x + 0], split[x + 2], @@ -123,7 +123,7 @@ class DivaReader(BaseReader): elif file.startswith("QuestInfo") and len(split) >= 9: self.logger.info(f"Added quest {split[0]}") - self.data.static.put_quests( + await self.data.static.put_quests( self.version, split[0], split[6], @@ -141,7 +141,7 @@ class DivaReader(BaseReader): else: self.logger.warning(f"Databank folder not found in {ram_root_dir}, skipping") - def read_rom(self, rom_root_dir: str) -> None: + async def read_rom(self, rom_root_dir: str) -> None: self.logger.info(f"Read ROM from {rom_root_dir}") pv_list: Dict[str, Dict] = {} @@ -199,7 +199,7 @@ class DivaReader(BaseReader): diff = pv_data["difficulty"]["easy"]["0"]["level"].split("_") self.logger.info(f"Added song {song_id} chart 0") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 0, @@ -220,7 +220,7 @@ class DivaReader(BaseReader): diff = pv_data["difficulty"]["normal"]["0"]["level"].split("_") self.logger.info(f"Added song {song_id} chart 1") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 1, @@ -238,7 +238,7 @@ class DivaReader(BaseReader): diff = pv_data["difficulty"]["hard"]["0"]["level"].split("_") self.logger.info(f"Added song {song_id} chart 2") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 2, @@ -257,7 +257,7 @@ class DivaReader(BaseReader): diff = pv_data["difficulty"]["extreme"]["0"]["level"].split("_") self.logger.info(f"Added song {song_id} chart 3") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 3, @@ -275,7 +275,7 @@ class DivaReader(BaseReader): diff = pv_data["difficulty"]["extreme"]["1"]["level"].split("_") self.logger.info(f"Added song {song_id} chart 4") - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 4, diff --git a/titles/diva/schema/customize.py b/titles/diva/schema/customize.py index 91480f5..838a7d2 100644 --- a/titles/diva/schema/customize.py +++ b/titles/diva/schema/customize.py @@ -25,10 +25,10 @@ customize = Table( class DivaCustomizeItemData(BaseData): - def put_customize_item(self, aime_id: int, version: int, item_id: int) -> None: + async def put_customize_item(self, aime_id: int, version: int, item_id: int) -> None: sql = insert(customize).values(version=version, user=aime_id, item_id=item_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} Failed to insert diva profile customize item! aime id: {aime_id} item: {item_id}" @@ -36,7 +36,7 @@ class DivaCustomizeItemData(BaseData): return None return result.lastrowid - def get_customize_items(self, aime_id: int, version: int) -> Optional[List[Dict]]: + async 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 """ @@ -44,12 +44,12 @@ class DivaCustomizeItemData(BaseData): and_(customize.c.version == version, customize.c.user == aime_id) ) - result = self.execute(sql) + result = await 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: + async 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 diff --git a/titles/diva/schema/item.py b/titles/diva/schema/item.py index 4d484ae..c09896b 100644 --- a/titles/diva/schema/item.py +++ b/titles/diva/schema/item.py @@ -26,7 +26,7 @@ shop = Table( class DivaItemData(BaseData): - def put_shop( + async def put_shop( self, aime_id: int, version: int, @@ -48,7 +48,7 @@ class DivaItemData(BaseData): ms_itm_flg_ary=ms_itm_flg_ary, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} Failed to insert diva profile! aime id: {aime_id} array: {mdl_eqp_ary}" @@ -56,13 +56,13 @@ class DivaItemData(BaseData): return None return result.lastrowid - def get_shop(self, aime_id: int, version: int) -> Optional[List[Dict]]: + async def get_shop(self, aime_id: int, version: int) -> Optional[List[Dict]]: """ Given a game version and either a profile or aime id, return the profile """ sql = shop.select(and_(shop.c.version == version, shop.c.user == aime_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/diva/schema/module.py b/titles/diva/schema/module.py index 5872d68..a6286ee 100644 --- a/titles/diva/schema/module.py +++ b/titles/diva/schema/module.py @@ -23,10 +23,10 @@ module = Table( class DivaModuleData(BaseData): - def put_module(self, aime_id: int, version: int, module_id: int) -> None: + async def put_module(self, aime_id: int, version: int, module_id: int) -> None: sql = insert(module).values(version=version, user=aime_id, module_id=module_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} Failed to insert diva profile module! aime id: {aime_id} module: {module_id}" @@ -34,18 +34,18 @@ class DivaModuleData(BaseData): return None return result.lastrowid - def get_modules(self, aime_id: int, version: int) -> Optional[List[Dict]]: + async def get_modules(self, aime_id: int, version: int) -> Optional[List[Dict]]: """ Given a game version and an aime id, return all the modules, not used directly """ sql = module.select(and_(module.c.version == version, module.c.user == aime_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_modules_have_string(self, aime_id: int, version: int) -> str: + async def get_modules_have_string(self, aime_id: int, version: int) -> str: """ Given a game version and an aime id, return the mdl_have hex string required for diva directly diff --git a/titles/diva/schema/profile.py b/titles/diva/schema/profile.py index 7bd6bf0..f3d00ae 100644 --- a/titles/diva/schema/profile.py +++ b/titles/diva/schema/profile.py @@ -70,7 +70,7 @@ profile = Table( class DivaProfileData(BaseData): - def create_profile( + async def create_profile( self, version: int, aime_id: int, player_name: str ) -> Optional[int]: """ @@ -82,7 +82,7 @@ class DivaProfileData(BaseData): conflict = sql.on_duplicate_key_update(player_name=sql.inserted.player_name) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} Failed to insert diva profile! aime id: {aime_id} username: {player_name}" @@ -90,21 +90,21 @@ class DivaProfileData(BaseData): return None return result.lastrowid - def update_profile(self, aime_id: int, **profile_args) -> None: + async def update_profile(self, aime_id: int, **profile_args) -> None: """ Given an aime_id update the profile corresponding to the arguments which are the diva_profile Columns """ sql = profile.update(profile.c.user == aime_id).values(**profile_args) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"update_profile: failed to update profile! profile: {aime_id}" ) return None - def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]: + async def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]: """ Given a game version and either a profile or aime id, return the profile """ @@ -112,7 +112,7 @@ class DivaProfileData(BaseData): and_(profile.c.version == version, profile.c.user == aime_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/diva/schema/pv_customize.py b/titles/diva/schema/pv_customize.py index 1ca8909..c56378d 100644 --- a/titles/diva/schema/pv_customize.py +++ b/titles/diva/schema/pv_customize.py @@ -39,7 +39,7 @@ pv_customize = Table( class DivaPvCustomizeData(BaseData): - def put_pv_customize( + async def put_pv_customize( self, aime_id: int, version: int, @@ -64,7 +64,7 @@ class DivaPvCustomizeData(BaseData): ms_itm_flg_ary=ms_itm_flg_ary, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} Failed to insert diva pv customize! aime id: {aime_id}" @@ -72,7 +72,7 @@ class DivaPvCustomizeData(BaseData): return None return result.lastrowid - def get_pv_customize(self, aime_id: int, pv_id: int) -> Optional[List[Dict]]: + async def get_pv_customize(self, aime_id: int, pv_id: int) -> Optional[List[Dict]]: """ Given either a profile or aime id, return a Pv Customize row """ @@ -80,7 +80,7 @@ class DivaPvCustomizeData(BaseData): and_(pv_customize.c.user == aime_id, pv_customize.c.pv_id == pv_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/diva/schema/score.py b/titles/diva/schema/score.py index 2171659..e802a41 100644 --- a/titles/diva/schema/score.py +++ b/titles/diva/schema/score.py @@ -57,7 +57,7 @@ playlog = Table( class DivaScoreData(BaseData): - def put_best_score( + async def put_best_score( self, user_id: int, game_version: int, @@ -109,7 +109,7 @@ class DivaScoreData(BaseData): max_combo=max_combo, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert best score! profile: {user_id}, song: {song_id}" @@ -118,7 +118,7 @@ class DivaScoreData(BaseData): return result.lastrowid - def put_playlog( + async def put_playlog( self, user_id: int, game_version: int, @@ -157,7 +157,7 @@ class DivaScoreData(BaseData): max_combo=max_combo, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {difficulty}" @@ -166,7 +166,7 @@ class DivaScoreData(BaseData): return result.lastrowid - def get_best_user_score( + async def get_best_user_score( self, user_id: int, pv_id: int, difficulty: int, edition: int ) -> Optional[Row]: sql = score.select( @@ -178,12 +178,12 @@ class DivaScoreData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_top3_scores( + async def get_top3_scores( self, pv_id: int, difficulty: int, edition: int ) -> Optional[List[Row]]: sql = ( @@ -198,12 +198,12 @@ class DivaScoreData(BaseData): .limit(3) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_global_ranking( + async def get_global_ranking( self, user_id: int, pv_id: int, difficulty: int, edition: int ) -> Optional[List[Row]]: # get the subquery max score of a user with pv_id, difficulty and @@ -227,15 +227,15 @@ class DivaScoreData(BaseData): score.c.edition == edition, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_best_scores(self, user_id: int) -> Optional[List[Row]]: + async def get_best_scores(self, user_id: int) -> Optional[List[Row]]: sql = score.select(score.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/titles/diva/schema/static.py b/titles/diva/schema/static.py index 02ee0ec..e6aa207 100644 --- a/titles/diva/schema/static.py +++ b/titles/diva/schema/static.py @@ -83,7 +83,7 @@ items = Table( class DivaStaticData(BaseData): - def put_quests( + async def put_quests( self, version: int, questId: int, @@ -111,22 +111,22 @@ class DivaStaticData(BaseData): conflict = sql.on_duplicate_key_update(name=name) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_enabled_quests(self, version: int) -> Optional[List[Row]]: + async def get_enabled_quests(self, version: int) -> Optional[List[Row]]: sql = select(quests).where( and_(quests.c.version == version, quests.c.quest_enable == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_shop( + async def put_shop( self, version: int, shopId: int, @@ -150,12 +150,12 @@ class DivaStaticData(BaseData): conflict = sql.on_duplicate_key_update(name=name) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_enabled_shop(self, version: int, shopId: int) -> Optional[Row]: + async def get_enabled_shop(self, version: int, shopId: int) -> Optional[Row]: sql = select(shop).where( and_( shop.c.version == version, @@ -164,22 +164,22 @@ class DivaStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_enabled_shops(self, version: int) -> Optional[List[Row]]: + async def get_enabled_shops(self, version: int) -> Optional[List[Row]]: sql = select(shop).where( and_(shop.c.version == version, shop.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_items( + async def put_items( self, version: int, itemId: int, @@ -203,12 +203,12 @@ class DivaStaticData(BaseData): conflict = sql.on_duplicate_key_update(name=name) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_enabled_item(self, version: int, itemId: int) -> Optional[Row]: + async def get_enabled_item(self, version: int, itemId: int) -> Optional[Row]: sql = select(items).where( and_( items.c.version == version, @@ -217,22 +217,22 @@ class DivaStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_enabled_items(self, version: int) -> Optional[List[Row]]: + async def get_enabled_items(self, version: int) -> Optional[List[Row]]: sql = select(items).where( and_(items.c.version == version, items.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_music( + async def put_music( self, version: int, song: int, @@ -271,12 +271,12 @@ class DivaStaticData(BaseData): date=date, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_music( + async def get_music( self, version: int, song_id: Optional[int] = None ) -> Optional[List[Row]]: if song_id is None: @@ -289,12 +289,12 @@ class DivaStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_music_chart( + async def get_music_chart( self, version: int, song_id: int, chart_id: int ) -> Optional[List[Row]]: sql = select(music).where( @@ -305,7 +305,7 @@ class DivaStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/idac/frontend.py b/titles/idac/frontend.py index 8845b35..b5ac3ad 100644 --- a/titles/idac/frontend.py +++ b/titles/idac/frontend.py @@ -37,7 +37,7 @@ class IDACFrontend(FE_Base): 34: "full_tune_fragments", } - def generate_all_tables_json(self, user_id: int): + async def generate_all_tables_json(self, user_id: int): json_export = {} idac_tables = { @@ -73,7 +73,7 @@ class IDACFrontend(FE_Base): sql = sql.where(table.c.version == self.version) # lol use the profile connection for items, dirty hack - result = self.data.profile.execute(sql) + result = await self.data.profile.execute(sql) data_list = result.fetchall() # add the list to the json export with the correct table name @@ -86,7 +86,7 @@ class IDACFrontend(FE_Base): return json.dumps(json_export, indent=4, default=str, ensure_ascii=False) - def render_GET(self, request: Request) -> bytes: + async def render_GET(self, request: Request) -> bytes: uri: str = request.uri.decode() template = self.environment.get_template( @@ -103,7 +103,7 @@ class IDACFrontend(FE_Base): return redirectTo(b"/game/idac", request) # set the file name, content type and size to download the json - content = self.generate_all_tables_json(user_id).encode("utf-8") + content = await self.generate_all_tables_json(user_id).encode("utf-8") request.responseHeaders.addRawHeader( b"content-type", b"application/octet-stream" ) @@ -119,9 +119,9 @@ class IDACFrontend(FE_Base): profile_data, tickets, rank = None, None, None if user_id > 0: - profile_data = self.data.profile.get_profile(user_id, self.version) - ticket_data = self.data.item.get_tickets(user_id) - rank = self.data.profile.get_profile_rank(user_id, self.version) + profile_data = await self.data.profile.get_profile(user_id, self.version) + ticket_data = await self.data.item.get_tickets(user_id) + rank = await self.data.profile.get_profile_rank(user_id, self.version) tickets = { self.ticket_names[ticket["ticket_id"]]: ticket["ticket_cnt"] @@ -137,6 +137,3 @@ class IDACFrontend(FE_Base): sesh=vars(usr_sesh), active_page="idac", ).encode("utf-16") - - def render_POST(self, request: Request) -> bytes: - pass diff --git a/titles/idac/index.py b/titles/idac/index.py index d6ac62a..d923946 100644 --- a/titles/idac/index.py +++ b/titles/idac/index.py @@ -124,7 +124,7 @@ class IDACServlet(BaseServlet): resp = None try: handler = getattr(self.versions[internal_ver], func_to_find) - resp = handler(req_data, header_application) + resp = await handler(req_data, header_application) except Exception as e: traceback.print_exc() diff --git a/titles/idac/read.py b/titles/idac/read.py index 8798e9b..3b7e034 100644 --- a/titles/idac/read.py +++ b/titles/idac/read.py @@ -33,7 +33,7 @@ class IDACReader(BaseReader): self.logger.error(f"Invalid Initial D THE ARCADE version {version}") exit(1) - def read(self) -> None: + async def read(self) -> None: if self.bin_dir is None and self.opt_dir is None: self.logger.error( ( @@ -59,9 +59,9 @@ class IDACReader(BaseReader): ) exit(1) - self.read_idac_profile(self.opt_dir) + await self.read_idac_profile(self.opt_dir) - def read_idac_profile(self, file_path: str) -> None: + async def read_idac_profile(self, file_path: str) -> None: self.logger.info(f"Reading profile from {file_path}...") # read it as binary to avoid encoding issues @@ -88,14 +88,14 @@ class IDACReader(BaseReader): self.logger.info("Exiting...") exit(0) - user_id = self.data.user.create_user() + user_id = await self.data.user.create_user() if user_id is None: self.logger.error("Failed to register user!") user_id = -1 else: - card_id = self.data.card.create_card(user_id, access_code) + card_id = await self.data.card.create_card(user_id, access_code) if card_id is None: self.logger.error("Failed to register card!") @@ -150,7 +150,7 @@ class IDACReader(BaseReader): # lol use the profile connection for items, dirty hack conflict = sql.on_duplicate_key_update(**data) - result = self.data.profile.execute(conflict) + result = await self.data.profile.execute(conflict) if result is None: self.logger.error(f"Failed to insert data into table {name}") diff --git a/titles/idac/schema/item.py b/titles/idac/schema/item.py index 80ee7ba..d617cd9 100644 --- a/titles/idac/schema/item.py +++ b/titles/idac/schema/item.py @@ -297,7 +297,7 @@ timetrial_event = Table( class IDACItemData(BaseData): - def get_random_user_car(self, aime_id: int, version: int) -> Optional[List[Row]]: + async def get_random_user_car(self, aime_id: int, version: int) -> Optional[List[Row]]: sql = ( select(car) .where(and_(car.c.user == aime_id, car.c.version == version)) @@ -305,20 +305,20 @@ class IDACItemData(BaseData): .limit(1) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_random_car(self, version: int) -> Optional[List[Row]]: + async def get_random_car(self, version: int) -> Optional[List[Row]]: sql = select(car).where(car.c.version == version).order_by(func.rand()).limit(1) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_car( + async def get_car( self, aime_id: int, version: int, style_car_id: int ) -> Optional[List[Row]]: sql = select(car).where( @@ -329,12 +329,12 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_cars( + async def get_cars( self, version: int, aime_id: int, only_pickup: bool = False ) -> Optional[List[Row]]: if only_pickup: @@ -350,106 +350,106 @@ class IDACItemData(BaseData): and_(car.c.user == aime_id, car.c.version == version) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_ticket(self, aime_id: int, ticket_id: int) -> Optional[Row]: + async def get_ticket(self, aime_id: int, ticket_id: int) -> Optional[Row]: sql = select(ticket).where( ticket.c.user == aime_id, ticket.c.ticket_id == ticket_id ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_tickets(self, aime_id: int) -> Optional[List[Row]]: + async def get_tickets(self, aime_id: int) -> Optional[List[Row]]: sql = select(ticket).where(ticket.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_story(self, aime_id: int, chapter_id: int) -> Optional[Row]: + async def get_story(self, aime_id: int, chapter_id: int) -> Optional[Row]: sql = select(story).where( and_(story.c.user == aime_id, story.c.chapter == chapter_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_stories(self, aime_id: int) -> Optional[List[Row]]: + async def get_stories(self, aime_id: int) -> Optional[List[Row]]: sql = select(story).where(story.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_story_episodes(self, aime_id: int, chapter_id: int) -> Optional[List[Row]]: + async def get_story_episodes(self, aime_id: int, chapter_id: int) -> Optional[List[Row]]: sql = select(episode).where( and_(episode.c.user == aime_id, episode.c.chapter == chapter_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_story_episode(self, aime_id: int, episode_id: int) -> Optional[Row]: + async def get_story_episode(self, aime_id: int, episode_id: int) -> Optional[Row]: sql = select(episode).where( and_(episode.c.user == aime_id, episode.c.episode == episode_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_story_episode_difficulties( + async def get_story_episode_difficulties( self, aime_id: int, episode_id: int ) -> Optional[List[Row]]: sql = select(difficulty).where( and_(difficulty.c.user == aime_id, difficulty.c.episode == episode_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_courses(self, aime_id: int) -> Optional[List[Row]]: + async def get_courses(self, aime_id: int) -> Optional[List[Row]]: sql = select(course).where(course.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_course(self, aime_id: int, course_id: int) -> Optional[Row]: + async def get_course(self, aime_id: int, course_id: int) -> Optional[Row]: sql = select(course).where( and_(course.c.user == aime_id, course.c.course_id == course_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_time_trial_courses(self, version: int) -> Optional[List[Row]]: + async def get_time_trial_courses(self, version: int) -> Optional[List[Row]]: sql = select(trial.c.course_id).where(trial.c.version == version).distinct() - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_time_trial_user_best_time_by_course_car( + async def get_time_trial_user_best_time_by_course_car( self, version: int, aime_id: int, course_id: int, style_car_id: int ) -> Optional[Row]: sql = select(trial).where( @@ -461,12 +461,12 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_time_trial_user_best_courses( + async def get_time_trial_user_best_courses( self, version: int, aime_id: int ) -> Optional[List[Row]]: # get for a given aime_id the best time for each course @@ -491,12 +491,12 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_time_trial_best_cars_by_course( + async def get_time_trial_best_cars_by_course( self, version: int, course_id: int, aime_id: Optional[int] = None ) -> Optional[List[Row]]: subquery = ( @@ -527,12 +527,12 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_time_trial_ranking_by_course( + async def get_time_trial_ranking_by_course( self, version: int, course_id: int, @@ -568,12 +568,12 @@ class IDACItemData(BaseData): if limit is not None: sql = sql.limit(limit) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_time_trial_best_ranking_by_course( + async def get_time_trial_best_ranking_by_course( self, version: int, aime_id: int, course_id: int ) -> Optional[Row]: sql = ( @@ -589,12 +589,12 @@ class IDACItemData(BaseData): .limit(1) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_challenge( + async def get_challenge( self, aime_id: int, vs_type: int, play_difficulty: int ) -> Optional[Row]: sql = select(challenge).where( @@ -605,20 +605,20 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_challenges(self, aime_id: int) -> Optional[List[Row]]: + async def get_challenges(self, aime_id: int) -> Optional[List[Row]]: sql = select(challenge).where(challenge.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_best_challenges_by_vs_type( + async def get_best_challenges_by_vs_type( self, aime_id: int, story_type: int = 4 ) -> Optional[List[Row]]: subquery = ( @@ -653,20 +653,20 @@ class IDACItemData(BaseData): .order_by(challenge.c.vs_type) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_theory_courses(self, aime_id: int) -> Optional[List[Row]]: + async def get_theory_courses(self, aime_id: int) -> Optional[List[Row]]: sql = select(theory_course).where(theory_course.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_theory_course_by_powerhouse_lv( + async def get_theory_course_by_powerhouse_lv( self, aime_id: int, course_id: int, powerhouse_lv: int, count: int = 3 ) -> Optional[List[Row]]: sql = ( @@ -682,40 +682,40 @@ class IDACItemData(BaseData): .limit(count) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_theory_course(self, aime_id: int, course_id: int) -> Optional[List[Row]]: + async def get_theory_course(self, aime_id: int, course_id: int) -> Optional[List[Row]]: sql = select(theory_course).where( and_( theory_course.c.user == aime_id, theory_course.c.course_id == course_id ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_theory_partners(self, aime_id: int) -> Optional[List[Row]]: + async def get_theory_partners(self, aime_id: int) -> Optional[List[Row]]: sql = select(theory_partner).where(theory_partner.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_theory_running(self, aime_id: int) -> Optional[List[Row]]: + async def get_theory_running(self, aime_id: int) -> Optional[List[Row]]: sql = select(theory_running).where(theory_running.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_theory_running_by_course( + async def get_theory_running_by_course( self, aime_id: int, course_id: int ) -> Optional[Row]: sql = select(theory_running).where( @@ -725,32 +725,32 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_vs_infos(self, aime_id: int) -> Optional[List[Row]]: + async def get_vs_infos(self, aime_id: int) -> Optional[List[Row]]: sql = select(vs_info).where(vs_info.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_stamps(self, aime_id: int) -> Optional[List[Row]]: + async def get_stamps(self, aime_id: int) -> Optional[List[Row]]: sql = select(stamp).where( and_( stamp.c.user == aime_id, ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_timetrial_event(self, aime_id: int, timetrial_event_id: int) -> Optional[Row]: + async def get_timetrial_event(self, aime_id: int, timetrial_event_id: int) -> Optional[Row]: sql = select(timetrial_event).where( and_( timetrial_event.c.user == aime_id, @@ -758,49 +758,49 @@ class IDACItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_car(self, aime_id: int, version: int, car_data: Dict) -> Optional[int]: + async def put_car(self, aime_id: int, version: int, car_data: Dict) -> Optional[int]: car_data["user"] = aime_id car_data["version"] = version sql = insert(car).values(**car_data) conflict = sql.on_duplicate_key_update(**car_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_car: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_ticket(self, aime_id: int, ticket_data: Dict) -> Optional[int]: + async def put_ticket(self, aime_id: int, ticket_data: Dict) -> Optional[int]: ticket_data["user"] = aime_id sql = insert(ticket).values(**ticket_data) conflict = sql.on_duplicate_key_update(**ticket_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_ticket: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_story(self, aime_id: int, story_data: Dict) -> Optional[int]: + async def put_story(self, aime_id: int, story_data: Dict) -> Optional[int]: story_data["user"] = aime_id sql = insert(story).values(**story_data) conflict = sql.on_duplicate_key_update(**story_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_story: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_story_episode_play_status( + async def put_story_episode_play_status( self, aime_id: int, chapter_id: int, play_status: int = 1 ) -> Optional[int]: sql = ( @@ -809,7 +809,7 @@ class IDACItemData(BaseData): .values(play_status=play_status) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warn( f"put_story_episode_play_status: Failed to update! aime_id: {aime_id}" @@ -817,7 +817,7 @@ class IDACItemData(BaseData): return None return result.lastrowid - def put_story_episode( + async def put_story_episode( self, aime_id: int, chapter_id: int, episode_data: Dict ) -> Optional[int]: episode_data["user"] = aime_id @@ -825,14 +825,14 @@ class IDACItemData(BaseData): sql = insert(episode).values(**episode_data) conflict = sql.on_duplicate_key_update(**episode_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_story_episode: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_story_episode_difficulty( + async def put_story_episode_difficulty( self, aime_id: int, episode_id: int, difficulty_data: Dict ) -> Optional[int]: difficulty_data["user"] = aime_id @@ -840,7 +840,7 @@ class IDACItemData(BaseData): sql = insert(difficulty).values(**difficulty_data) conflict = sql.on_duplicate_key_update(**difficulty_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -849,19 +849,19 @@ class IDACItemData(BaseData): return None return result.lastrowid - def put_course(self, aime_id: int, course_data: Dict) -> Optional[int]: + async def put_course(self, aime_id: int, course_data: Dict) -> Optional[int]: course_data["user"] = aime_id sql = insert(course).values(**course_data) conflict = sql.on_duplicate_key_update(**course_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_course: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_time_trial( + async def put_time_trial( self, version: int, aime_id: int, time_trial_data: Dict ) -> Optional[int]: time_trial_data["user"] = aime_id @@ -869,47 +869,47 @@ class IDACItemData(BaseData): sql = insert(trial).values(**time_trial_data) conflict = sql.on_duplicate_key_update(**time_trial_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_time_trial: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_challenge(self, aime_id: int, challenge_data: Dict) -> Optional[int]: + async def put_challenge(self, aime_id: int, challenge_data: Dict) -> Optional[int]: challenge_data["user"] = aime_id sql = insert(challenge).values(**challenge_data) conflict = sql.on_duplicate_key_update(**challenge_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_challenge: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_theory_course( + async def put_theory_course( self, aime_id: int, theory_course_data: Dict ) -> Optional[int]: theory_course_data["user"] = aime_id sql = insert(theory_course).values(**theory_course_data) conflict = sql.on_duplicate_key_update(**theory_course_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_theory_course: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_theory_partner( + async def put_theory_partner( self, aime_id: int, theory_partner_data: Dict ) -> Optional[int]: theory_partner_data["user"] = aime_id sql = insert(theory_partner).values(**theory_partner_data) conflict = sql.on_duplicate_key_update(**theory_partner_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -918,14 +918,14 @@ class IDACItemData(BaseData): return None return result.lastrowid - def put_theory_running( + async def put_theory_running( self, aime_id: int, theory_running_data: Dict ) -> Optional[int]: theory_running_data["user"] = aime_id sql = insert(theory_running).values(**theory_running_data) conflict = sql.on_duplicate_key_update(**theory_running_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -934,26 +934,26 @@ class IDACItemData(BaseData): return None return result.lastrowid - def put_vs_info(self, aime_id: int, vs_info_data: Dict) -> Optional[int]: + async def put_vs_info(self, aime_id: int, vs_info_data: Dict) -> Optional[int]: vs_info_data["user"] = aime_id sql = insert(vs_info).values(**vs_info_data) conflict = sql.on_duplicate_key_update(**vs_info_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_vs_info: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_stamp( + async def put_stamp( self, aime_id: int, stamp_data: Dict ) -> Optional[int]: stamp_data["user"] = aime_id sql = insert(stamp).values(**stamp_data) conflict = sql.on_duplicate_key_update(**stamp_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -962,7 +962,7 @@ class IDACItemData(BaseData): return None return result.lastrowid - def put_timetrial_event( + async def put_timetrial_event( self, aime_id: int, time_trial_event_id: int, point: int ) -> Optional[int]: timetrial_event_data = { @@ -973,7 +973,7 @@ class IDACItemData(BaseData): sql = insert(timetrial_event).values(**timetrial_event_data) conflict = sql.on_duplicate_key_update(**timetrial_event_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( diff --git a/titles/idac/schema/profile.py b/titles/idac/schema/profile.py index 5e363ca..bb6593b 100644 --- a/titles/idac/schema/profile.py +++ b/titles/idac/schema/profile.py @@ -253,7 +253,7 @@ class IDACProfileData(BaseData): ) self.date_time_format_short = "%Y-%m-%d" - def get_profile(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile(self, aime_id: int, version: int) -> Optional[Row]: sql = select(profile).where( and_( profile.c.user == aime_id, @@ -261,12 +261,12 @@ class IDACProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_different_random_profiles( + async def get_different_random_profiles( self, aime_id: int, version: int, count: int = 9 ) -> Optional[Row]: sql = ( @@ -281,36 +281,36 @@ class IDACProfileData(BaseData): .limit(count) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_profile_config(self, aime_id: int) -> Optional[Row]: + async def get_profile_config(self, aime_id: int) -> Optional[Row]: sql = select(config).where( and_( config.c.user == aime_id, ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_avatar(self, aime_id: int) -> Optional[Row]: + async def get_profile_avatar(self, aime_id: int) -> Optional[Row]: sql = select(avatar).where( and_( avatar.c.user == aime_id, ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_rank(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_rank(self, aime_id: int, version: int) -> Optional[Row]: sql = select(rank).where( and_( rank.c.user == aime_id, @@ -318,12 +318,12 @@ class IDACProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_stock(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_stock(self, aime_id: int, version: int) -> Optional[Row]: sql = select(stock).where( and_( stock.c.user == aime_id, @@ -331,12 +331,12 @@ class IDACProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_theory(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_theory(self, aime_id: int, version: int) -> Optional[Row]: sql = select(theory).where( and_( theory.c.user == aime_id, @@ -344,12 +344,12 @@ class IDACProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile( + async def put_profile( self, aime_id: int, version: int, profile_data: Dict ) -> Optional[int]: profile_data["user"] = aime_id @@ -357,19 +357,19 @@ class IDACProfileData(BaseData): sql = insert(profile).values(**profile_data) conflict = sql.on_duplicate_key_update(**profile_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_profile: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_profile_config(self, aime_id: int, config_data: Dict) -> Optional[int]: + async def put_profile_config(self, aime_id: int, config_data: Dict) -> Optional[int]: config_data["user"] = aime_id sql = insert(config).values(**config_data) conflict = sql.on_duplicate_key_update(**config_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -378,12 +378,12 @@ class IDACProfileData(BaseData): return None return result.lastrowid - def put_profile_avatar(self, aime_id: int, avatar_data: Dict) -> Optional[int]: + async def put_profile_avatar(self, aime_id: int, avatar_data: Dict) -> Optional[int]: avatar_data["user"] = aime_id sql = insert(avatar).values(**avatar_data) conflict = sql.on_duplicate_key_update(**avatar_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( @@ -392,7 +392,7 @@ class IDACProfileData(BaseData): return None return result.lastrowid - def put_profile_rank( + async def put_profile_rank( self, aime_id: int, version: int, rank_data: Dict ) -> Optional[int]: rank_data["user"] = aime_id @@ -400,14 +400,14 @@ class IDACProfileData(BaseData): sql = insert(rank).values(**rank_data) conflict = sql.on_duplicate_key_update(**rank_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_profile_rank: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_profile_stock( + async def put_profile_stock( self, aime_id: int, version: int, stock_data: Dict ) -> Optional[int]: stock_data["user"] = aime_id @@ -415,14 +415,14 @@ class IDACProfileData(BaseData): sql = insert(stock).values(**stock_data) conflict = sql.on_duplicate_key_update(**stock_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn(f"put_profile_stock: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_profile_theory( + async def put_profile_theory( self, aime_id: int, version: int, theory_data: Dict ) -> Optional[int]: theory_data["user"] = aime_id @@ -430,7 +430,7 @@ class IDACProfileData(BaseData): sql = insert(theory).values(**theory_data) conflict = sql.on_duplicate_key_update(**theory_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warn( diff --git a/titles/idac/season2.py b/titles/idac/season2.py index 6523177..f25296c 100644 --- a/titles/idac/season2.py +++ b/titles/idac/season2.py @@ -53,7 +53,7 @@ class IDACSeason2(IDACBase): "timetrial_event_id" ) - def handle_alive_get_request(self, data: Dict, headers: Dict): + async def handle_alive_get_request(self, data: Dict, headers: Dict): return { "status_code": "0", # 1 = success, 0 = failed @@ -76,7 +76,7 @@ class IDACSeason2(IDACBase): output[key] = value return output - def handle_boot_getconfigdata_request(self, data: Dict, headers: Dict): + async def handle_boot_getconfigdata_request(self, data: Dict, headers: Dict): """ category: 1 = D Coin @@ -297,10 +297,10 @@ class IDACSeason2(IDACBase): "timetrial_event_data": self.timetrial_event, } - def handle_boot_bookkeep_request(self, data: Dict, headers: Dict): + async def handle_boot_bookkeep_request(self, data: Dict, headers: Dict): pass - def handle_boot_getgachadata_request(self, data: Dict, headers: Dict): + async def handle_boot_getgachadata_request(self, data: Dict, headers: Dict): """ Reward category types: 9: Face @@ -350,7 +350,7 @@ class IDACSeason2(IDACBase): return avatar_gacha_data - def handle_boot_gettimereleasedata_request(self, data: Dict, headers: Dict): + async def handle_boot_gettimereleasedata_request(self, data: Dict, headers: Dict): """ timerelease chapter: 1 = Story: 1, 2, 3, 4, 5, 6, 7, 8, 9, 19 (Chapter 10), (29 Chapter 11 lol?) @@ -385,12 +385,12 @@ class IDACSeason2(IDACBase): return time_release_data - def handle_advertise_getrankingdata_request(self, data: Dict, headers: Dict): + async def handle_advertise_getrankingdata_request(self, data: Dict, headers: Dict): best_data = [] for last_update in data.get("last_update_date"): course_id = last_update.get("course_id") - ranking = self.data.item.get_time_trial_ranking_by_course( + ranking = await self.data.item.get_time_trial_ranking_by_course( self.version, course_id ) ranking_data = [] @@ -398,8 +398,8 @@ class IDACSeason2(IDACBase): user_id = rank["user"] # get the username, country and store from the profile - profile = self.data.profile.get_profile(user_id, self.version) - arcade = self.data.arcade.get_arcade(profile["store"]) + profile = await self.data.profile.get_profile(user_id, self.version) + arcade = await self.data.arcade.get_arcade(profile["store"]) if arcade is None: arcade = {} @@ -444,7 +444,7 @@ class IDACSeason2(IDACBase): "rank_management_flag": 0, } - def handle_login_checklock_request(self, data: Dict, headers: Dict): + async def handle_login_checklock_request(self, data: Dict, headers: Dict): user_id = data["id"] access_code = data["accesscode"] is_new_player = 0 @@ -454,7 +454,7 @@ class IDACSeason2(IDACBase): lock_result = 1 # check if an IDAC profile already exists - p = self.data.profile.get_profile(user_id, self.version) + p = await self.data.profile.get_profile(user_id, self.version) is_new_player = 1 if p is None else 0 else: lock_result = 0 @@ -474,35 +474,35 @@ class IDACSeason2(IDACBase): "server_status": 1, } - def handle_login_unlock_request(self, data: Dict, headers: Dict): + async def handle_login_unlock_request(self, data: Dict, headers: Dict): return { "status_code": "0", "lock_result": 1, } - def handle_login_relock_request(self, data: Dict, headers: Dict): + async def handle_login_relock_request(self, data: Dict, headers: Dict): return { "status_code": "0", "lock_result": 1, "lock_date": int(datetime.now().timestamp()), } - def handle_login_guestplay_request(self, data: Dict, headers: Dict): + async def handle_login_guestplay_request(self, data: Dict, headers: Dict): # TODO pass - def _generate_story_data(self, user_id: int) -> Dict: - stories = self.data.item.get_stories(user_id) + async def _generate_story_data(self, user_id: int) -> Dict: + stories = await self.data.item.get_stories(user_id) story_data = [] for s in stories: chapter_id = s["chapter"] - episodes = self.data.item.get_story_episodes(user_id, chapter_id) + episodes = await self.data.item.get_story_episodes(user_id, chapter_id) episode_data = [] for e in episodes: episode_id = e["episode"] - difficulties = self.data.item.get_story_episode_difficulties( + difficulties = await self.data.item.get_story_episode_difficulties( user_id, episode_id ) @@ -537,9 +537,9 @@ class IDACSeason2(IDACBase): return story_data - def _generate_special_data(self, user_id: int) -> Dict: + async def _generate_special_data(self, user_id: int) -> Dict: # 4 = special mode - specials = self.data.item.get_best_challenges_by_vs_type(user_id, story_type=4) + specials = await self.data.item.get_best_challenges_by_vs_type(user_id, story_type=4) special_data = [] for s in specials: @@ -556,9 +556,9 @@ class IDACSeason2(IDACBase): return special_data - def _generate_challenge_data(self, user_id: int) -> Dict: + async def _generate_challenge_data(self, user_id: int) -> Dict: # challenge mode (Bunta challenge only right now) - challenges = self.data.item.get_best_challenges_by_vs_type( + challenges = await self.data.item.get_best_challenges_by_vs_type( user_id, story_type=3 ) @@ -578,24 +578,24 @@ class IDACSeason2(IDACBase): return challenge_data - def _save_stock_data(self, user_id: int, stock_data: Dict): + async def _save_stock_data(self, user_id: int, stock_data: Dict): updated_stock_data = {} for k, v in stock_data.items(): if v != "": updated_stock_data[k] = v if updated_stock_data: - self.data.profile.put_profile_stock( + await self.data.profile.put_profile_stock( user_id, self.version, updated_stock_data ) - def handle_user_getdata_request(self, data: Dict, headers: Dict): + async def handle_user_getdata_request(self, data: Dict, headers: Dict): user_id = int(headers["session"]) # get the user's profile, can never be None - p = self.data.profile.get_profile(user_id, self.version) + p = await self.data.profile.get_profile(user_id, self.version) user_data = p._asdict() - arcade = self.data.arcade.get_arcade(user_data["store"]) + arcade = await self.data.arcade.get_arcade(user_data["store"]) del user_data["id"] del user_data["user"] @@ -608,7 +608,7 @@ class IDACSeason2(IDACBase): user_data["create_date"] = int(user_data["create_date"].timestamp()) # get the user's rank - r = self.data.profile.get_profile_rank(user_id, self.version) + r = await self.data.profile.get_profile_rank(user_id, self.version) rank_data = r._asdict() del rank_data["id"] del rank_data["user"] @@ -618,27 +618,27 @@ class IDACSeason2(IDACBase): user_data["mode_rank_data"] = rank_data # get the user's avatar - a = self.data.profile.get_profile_avatar(user_id) + a = await self.data.profile.get_profile_avatar(user_id) avatar_data = a._asdict() del avatar_data["id"] del avatar_data["user"] # get the user's stock - s = self.data.profile.get_profile_stock(user_id, self.version) + s = await self.data.profile.get_profile_stock(user_id, self.version) stock_data = s._asdict() del stock_data["id"] del stock_data["user"] del stock_data["version"] # get the user's config - c = self.data.profile.get_profile_config(user_id) + c = await self.data.profile.get_profile_config(user_id) config_data = c._asdict() del config_data["id"] del config_data["user"] config_data["id"] = config_data.pop("config_id") # get the user's ticket - tickets: list = self.data.item.get_tickets(user_id) + tickets: list = await self.data.item.get_tickets(user_id) """ ticket_id: @@ -658,7 +658,7 @@ class IDACSeason2(IDACBase): ) # get the user's course, required for the "course proeficiency" - courses = self.data.item.get_courses(user_id) + courses = await self.data.item.get_courses(user_id) course_data = [] for course in courses: course_data.append( @@ -673,7 +673,7 @@ class IDACSeason2(IDACBase): # get the profile theory data theory_data = {} - theory = self.data.profile.get_profile_theory(user_id, self.version) + theory = await self.data.profile.get_profile_theory(user_id, self.version) if theory is not None: theory_data = theory._asdict() del theory_data["id"] @@ -682,7 +682,7 @@ class IDACSeason2(IDACBase): # get the users theory course data theory_course_data = [] - theory_courses = self.data.item.get_theory_courses(user_id) + theory_courses = await self.data.item.get_theory_courses(user_id) for course in theory_courses: tmp = course._asdict() del tmp["id"] @@ -693,7 +693,7 @@ class IDACSeason2(IDACBase): # get the users theory partner data theory_partner_data = [] - theory_partners = self.data.item.get_theory_partners(user_id) + theory_partners = await self.data.item.get_theory_partners(user_id) for partner in theory_partners: tmp = partner._asdict() del tmp["id"] @@ -703,7 +703,7 @@ class IDACSeason2(IDACBase): # get the users theory running pram data theory_running_pram_data = [] - theory_running = self.data.item.get_theory_running(user_id) + theory_running = await self.data.item.get_theory_running(user_id) for running in theory_running: tmp = running._asdict() del tmp["id"] @@ -713,7 +713,7 @@ class IDACSeason2(IDACBase): # get the users vs info data vs_info_data = [] - vs_info = self.data.item.get_vs_infos(user_id) + vs_info = await self.data.item.get_vs_infos(user_id) for vs in vs_info: vs_info_data.append( { @@ -737,7 +737,7 @@ class IDACSeason2(IDACBase): ) # get the user's car - cars = self.data.item.get_cars(self.version, user_id, only_pickup=True) + cars = await self.data.item.get_cars(self.version, user_id, only_pickup=True) fulltune_count = 0 total_car_parts_count = 0 car_data = [] @@ -761,7 +761,7 @@ class IDACSeason2(IDACBase): user_data["have_car_cnt"] = len(car_data) # get the user's play stamps - stamps = self.data.item.get_stamps(user_id) + stamps = await self.data.item.get_stamps(user_id) stamp_event_data = [] for stamp in stamps: tmp = stamp._asdict() @@ -790,7 +790,7 @@ class IDACSeason2(IDACBase): tmp["weekly_bonus"] = 0 # update the play stamp in the database - self.data.item.put_stamp(user_id, tmp) + await self.data.item.put_stamp(user_id, tmp) del tmp["create_date_daily"] del tmp["create_date_weekly"] @@ -798,7 +798,7 @@ class IDACSeason2(IDACBase): # get the user's timetrial event data timetrial_event_data = {} - timetrial = self.data.item.get_timetrial_event(user_id, self.timetrial_event_id) + timetrial = await self.data.item.get_timetrial_event(user_id, self.timetrial_event_id) if timetrial is not None: timetrial_event_data = { "timetrial_event_id": timetrial["timetrial_event_id"], @@ -810,7 +810,7 @@ class IDACSeason2(IDACBase): "user_base_data": user_data, "avatar_data": avatar_data, "pick_up_car_data": car_data, - "story_data": self._generate_story_data(user_id), + "story_data": await self._generate_story_data(user_id), "vsinfo_data": vs_info_data, "stock_data": stock_data, "mission_data": { @@ -878,21 +878,21 @@ class IDACSeason2(IDACBase): "theory_course_data": theory_course_data, "theory_partner_data": theory_partner_data, "theory_running_pram_data": theory_running_pram_data, - "special_mode_data": self._generate_special_data(user_id), - "challenge_mode_data": self._generate_challenge_data(user_id), + "special_mode_data": await self._generate_special_data(user_id), + "challenge_mode_data": await self._generate_challenge_data(user_id), "season_rewards_data": [], "timetrial_event_data": timetrial_event_data, "special_mode_hint_data": {"story_type": 0, "hint_display_flag": 0}, } - def handle_timetrial_getbestrecordpreta_request(self, data: Dict, headers: Dict): + async def handle_timetrial_getbestrecordpreta_request(self, data: Dict, headers: Dict): user_id = headers["session"] for car_id in data["car_ids"]: pass course_mybest_data = [] - courses = self.data.item.get_time_trial_user_best_courses(self.version, user_id) + courses = await self.data.item.get_time_trial_user_best_courses(self.version, user_id) for course in courses: course_mybest_data.append( { @@ -920,10 +920,10 @@ class IDACSeason2(IDACBase): ) course_pickup_car_best_data = [] - courses = self.data.item.get_time_trial_courses(self.version) + courses = await self.data.item.get_time_trial_courses(self.version) for course in courses: car_list = [] - best_cars = self.data.item.get_time_trial_best_cars_by_course( + best_cars = await self.data.item.get_time_trial_best_cars_by_course( self.version, course["course_id"], user_id ) @@ -960,7 +960,7 @@ class IDACSeason2(IDACBase): "course_pickup_car_best_data": course_pickup_car_best_data, } - def handle_timetrial_getbestrecordprerace_request(self, data: Dict, headers: Dict): + async def handle_timetrial_getbestrecordprerace_request(self, data: Dict, headers: Dict): user_id = headers["session"] course_id = data["course_id"] @@ -969,7 +969,7 @@ class IDACSeason2(IDACBase): style_car_id = car["style_car_id"] # Not sure if this is actually correct - ranking = self.data.item.get_time_trial_ranking_by_course( + ranking = await self.data.item.get_time_trial_ranking_by_course( self.version, course_id ) course_best_data = [] @@ -977,8 +977,8 @@ class IDACSeason2(IDACBase): car_user_id = rank["user"] # get the username, country and store from the profile - profile = self.data.profile.get_profile(car_user_id, self.version) - arcade = self.data.arcade.get_arcade(profile["store"]) + profile = await self.data.profile.get_profile(car_user_id, self.version) + arcade = await self.data.arcade.get_arcade(profile["store"]) if arcade is None: arcade = {} @@ -1007,7 +1007,7 @@ class IDACSeason2(IDACBase): } ) - best_cars = self.data.item.get_time_trial_best_cars_by_course( + best_cars = await self.data.item.get_time_trial_best_cars_by_course( self.version, course_id ) @@ -1015,8 +1015,8 @@ class IDACSeason2(IDACBase): for i, rank in enumerate(best_cars): car_user_id = rank["user"] # get the username, country and store from the profile - profile = self.data.profile.get_profile(car_user_id, self.version) - arcade = self.data.arcade.get_arcade(profile["store"]) + profile = await self.data.profile.get_profile(car_user_id, self.version) + arcade = await self.data.arcade.get_arcade(profile["store"]) if arcade is None: arcade = {} @@ -1051,7 +1051,7 @@ class IDACSeason2(IDACBase): "course_best_data": course_best_data, } - def handle_user_createaccount_request(self, data: Dict, headers: Dict): + async def handle_user_createaccount_request(self, data: Dict, headers: Dict): user_id = headers["session"] car_data: Dict = data.pop("car_obj") @@ -1070,45 +1070,45 @@ class IDACSeason2(IDACBase): data["store"] = headers.get("a_store", 0) data["country"] = headers.get("a_country", 0) data["asset_version"] = headers.get("asset_version", 1) - self.data.profile.put_profile(user_id, self.version, data) + await self.data.profile.put_profile(user_id, self.version, data) # save rank data in database - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save tickets in database for ticket in takeover_ticket_list: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) config_data["config_id"] = config_data.pop("id") - self.data.profile.put_profile_config(user_id, config_data) - self.data.profile.put_profile_avatar(user_id, avatar_data) + await self.data.profile.put_profile_config(user_id, config_data) + await self.data.profile.put_profile_avatar(user_id, avatar_data) # save car data and car parts in database car_data["parts_list"] = parts_data - self.data.item.put_car(user_id, self.version, car_data) + await self.data.item.put_car(user_id, self.version, car_data) return {"status_code": "0"} - def handle_user_updatelogin_request(self, data: Dict, headers: Dict): + async def handle_user_updatelogin_request(self, data: Dict, headers: Dict): pass - def handle_timetrial_getcarbest_request(self, data: Dict, headers: Dict): + async def handle_timetrial_getcarbest_request(self, data: Dict, headers: Dict): pass - def handle_factory_avatargacharesult_request(self, data: Dict, headers: Dict): + async def handle_factory_avatargacharesult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") use_ticket_cnt = data["use_ticket_cnt"] # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # get the user's ticket - tickets: list = self.data.item.get_tickets(user_id) + tickets: list = await self.data.item.get_tickets(user_id) ticket_list = [] for ticket in tickets: # avatar tickets @@ -1119,7 +1119,7 @@ class IDACSeason2(IDACBase): } # update the ticket in the database - self.data.item.put_ticket(user_id, ticket_data) + await self.data.item.put_ticket(user_id, ticket_data) ticket_list.append(ticket_data) continue @@ -1133,15 +1133,15 @@ class IDACSeason2(IDACBase): return {"status_code": "0", "ticket_data": ticket_list} - def handle_factory_savefavoritecar_request(self, data: Dict, headers: Dict): + async def handle_factory_savefavoritecar_request(self, data: Dict, headers: Dict): user_id = headers["session"] # save favorite cars in database for car in data["pickup_on_car_ids"]: - self.data.item.put_car(user_id, self.version, car) + await self.data.item.put_car(user_id, self.version, car) for car in data["pickup_off_car_ids"]: - self.data.item.put_car( + await self.data.item.put_car( user_id, self.version, {"style_car_id": car["style_car_id"], "pickup_seq": 0}, @@ -1149,7 +1149,7 @@ class IDACSeason2(IDACBase): return {"status_code": "0"} - def handle_factory_updatemultiplecustomizeresult_request( + async def handle_factory_updatemultiplecustomizeresult_request( self, data: Dict, headers: Dict ): user_id = headers["session"] @@ -1162,15 +1162,15 @@ class IDACSeason2(IDACBase): # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) for car in car_list: # save car data and car parts in database - self.data.item.put_car(user_id, self.version, car) + await self.data.item.put_car(user_id, self.version, car) return {"status_code": "0"} - def handle_factory_updatecustomizeresult_request(self, data: Dict, headers: Dict): + async def handle_factory_updatecustomizeresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] parts_data: List = data.pop("parts_list") @@ -1178,18 +1178,18 @@ class IDACSeason2(IDACBase): # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save car data in database data["parts_list"] = parts_data - self.data.item.put_car(user_id, self.version, data) + await self.data.item.put_car(user_id, self.version, data) return {"status_code": "0"} - def handle_factory_getcardata_request(self, data: Dict, headers: Dict): + async def handle_factory_getcardata_request(self, data: Dict, headers: Dict): user_id = headers["session"] - cars = self.data.item.get_cars(self.version, user_id) + cars = await self.data.item.get_cars(self.version, user_id) car_data = [] for car in cars: tmp = car._asdict() @@ -1204,10 +1204,10 @@ class IDACSeason2(IDACBase): "car_data": car_data, } - def handle_factory_renamebefore_request(self, data: Dict, headers: Dict): + async def handle_factory_renamebefore_request(self, data: Dict, headers: Dict): pass - def handle_factory_buycarresult_request(self, data: Dict, headers: Dict): + async def handle_factory_buycarresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] parts_data: List = data.pop("parts_list") @@ -1224,7 +1224,7 @@ class IDACSeason2(IDACBase): if car["style_car_id"] == style_car_id: pickup_seq = car["pickup_seq"] else: - self.data.item.put_car(user_id, self.version, car) + await self.data.item.put_car(user_id, self.version, car) data["pickup_seq"] = pickup_seq @@ -1232,7 +1232,7 @@ class IDACSeason2(IDACBase): total_cash = data.pop("total_cash") # save the new cash in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, {"total_cash": total_cash, "cash": cash} ) @@ -1240,10 +1240,10 @@ class IDACSeason2(IDACBase): use_ticket = data.pop("use_ticket") if use_ticket: # get the user's tickets, full tune ticket id is 25 - ticket = self.data.item.get_ticket(user_id, ticket_id=25) + ticket = await self.data.item.get_ticket(user_id, ticket_id=25) # update the ticket in the database - self.data.item.put_ticket( + await self.data.item.put_ticket( user_id, { "ticket_id": ticket["ticket_id"], @@ -1256,17 +1256,17 @@ class IDACSeason2(IDACBase): # save car data and car parts in database data["parts_list"] = parts_data - self.data.item.put_car(user_id, self.version, data) + await self.data.item.put_car(user_id, self.version, data) for car in pickup_off_list: - self.data.item.put_car( + await self.data.item.put_car( user_id, self.version, {"style_car_id": car["style_car_id"], "pickup_seq": 0}, ) # get the user's car - cars = self.data.item.get_cars(self.version, user_id) + cars = await self.data.item.get_cars(self.version, user_id) fulltune_count = 0 total_car_parts_count = 0 for car in cars: @@ -1278,7 +1278,7 @@ class IDACSeason2(IDACBase): # total_car_parts_count += car["total_car_parts_count"] # get the user's ticket - tickets = self.data.item.get_tickets(user_id) + tickets = await self.data.item.get_tickets(user_id) ticket_data = [] for ticket in tickets: ticket_data.append( @@ -1297,54 +1297,54 @@ class IDACSeason2(IDACBase): "car_style_count": [], } - def handle_factory_renameresult_request(self, data: Dict, headers: Dict): + async def handle_factory_renameresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] new_username = data.get("username") # save new username in database if new_username: - self.data.profile.put_profile(user_id, self.version, data) + await self.data.profile.put_profile(user_id, self.version, data) return {"status_code": "0"} - def handle_factory_updatecustomizeavatar_request(self, data: Dict, headers: Dict): + async def handle_factory_updatecustomizeavatar_request(self, data: Dict, headers: Dict): user_id = headers["session"] avatar_data: Dict = data.pop("avatar_obj") stock_data: Dict = data.pop("stock_obj") # update the stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save avatar data and avatar parts in database - self.data.profile.put_profile_avatar(user_id, avatar_data) + await self.data.profile.put_profile_avatar(user_id, avatar_data) return {"status_code": "0"} - def handle_factory_updatecustomizeuser_request(self, data: Dict, headers: Dict): + async def handle_factory_updatecustomizeuser_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") # update the stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # update profile data and config in database - self.data.profile.put_profile(user_id, self.version, data) + await self.data.profile.put_profile(user_id, self.version, data) return {"status_code": "0"} - def handle_user_updatestampinfo_request(self, data: Dict, headers: Dict): + async def handle_user_updatestampinfo_request(self, data: Dict, headers: Dict): user_id = headers["session"] stamp_event_data = data.pop("stamp_event_data") for stamp in stamp_event_data: - self.data.item.put_stamp(user_id, stamp) + await self.data.item.put_stamp(user_id, stamp) return {"status_code": "0"} - def handle_user_updatetimetrialresult_request(self, data: Dict, headers: Dict): + async def handle_user_updatetimetrialresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") @@ -1357,22 +1357,22 @@ class IDACSeason2(IDACBase): event_point = data.pop("event_point") # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save mode rank data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # update profile - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -1392,7 +1392,7 @@ class IDACSeason2(IDACBase): # get the use_count and story_use_count of the used car style_car_id = data.get("style_car_id") car_mileage = data.pop("car_mileage") - used_car = self.data.item.get_car(user_id, self.version, style_car_id)._asdict() + used_car = await self.data.item.get_car(user_id, self.version, style_car_id)._asdict() # increase the use_count and story_use_count of the used car used_car["use_count"] += 1 @@ -1400,7 +1400,7 @@ class IDACSeason2(IDACBase): used_car["car_mileage"] = car_mileage # save the used car in database - self.data.item.put_car(user_id, self.version, used_car) + await self.data.item.put_car(user_id, self.version, used_car) # skill_level_exp is the "course proeficiency" and is saved # in the course table @@ -1409,12 +1409,12 @@ class IDACSeason2(IDACBase): skill_level_exp = data.pop("skill_level_exp") # get the course data - course = self.data.item.get_course(user_id, course_id) + course = await self.data.item.get_course(user_id, course_id) if course: # update run_counts run_counts = course["run_counts"] + 1 - self.data.item.put_course( + await self.data.item.put_course( user_id, { "course_id": course_id, @@ -1426,12 +1426,12 @@ class IDACSeason2(IDACBase): goal_time = data.get("goal_time") # grab the ranking data and count the numbers of rows with a faster time # than the current goal_time - course_rank = self.data.item.get_time_trial_ranking_by_course( + course_rank = await self.data.item.get_time_trial_ranking_by_course( self.version, course_id, limit=None ) course_rank = len([r for r in course_rank if r["goal_time"] < goal_time]) + 1 - car_course_rank = self.data.item.get_time_trial_ranking_by_course( + car_course_rank = await self.data.item.get_time_trial_ranking_by_course( self.version, course_id, style_car_id, limit=None ) car_course_rank = ( @@ -1442,7 +1442,7 @@ class IDACSeason2(IDACBase): if data.get("goal_time") > 0: # get the current best goal time best_time_trial = ( - self.data.item.get_time_trial_user_best_time_by_course_car( + await self.data.item.get_time_trial_user_best_time_by_course_car( self.version, user_id, course_id, style_car_id ) ) @@ -1453,10 +1453,10 @@ class IDACSeason2(IDACBase): ): # now finally save the time trial with updated timestamp data["play_dt"] = datetime.now() - self.data.item.put_time_trial(self.version, user_id, data) + await self.data.item.put_time_trial(self.version, user_id, data) # update the timetrial event points - self.data.item.put_timetrial_event( + await self.data.item.put_timetrial_event( user_id, self.timetrial_event_id, event_point ) @@ -1473,7 +1473,7 @@ class IDACSeason2(IDACBase): }, } - def handle_user_updatestoryresult_request(self, data: Dict, headers: Dict): + async def handle_user_updatestoryresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") @@ -1484,15 +1484,15 @@ class IDACSeason2(IDACBase): # stamp_event_data = data.pop("stamp_event_data") # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save mode rank data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # save the current story progress in database max_loop = data.get("chapter_loop_max") @@ -1503,7 +1503,7 @@ class IDACSeason2(IDACBase): play_status = data.get("play_status") # get the current loop from the database - story_data = self.data.item.get_story(user_id, chapter_id) + story_data = await self.data.item.get_story(user_id, chapter_id) # 1 = active, 2+ = cleared? loop_count = 1 if story_data: @@ -1517,13 +1517,13 @@ class IDACSeason2(IDACBase): # if the episode has already been cleared, set the play_status to 2 # so it won't be set to unplayed (play_status = 1) - episode_data = self.data.item.get_story_episode(user_id, episode_id) + episode_data = await self.data.item.get_story_episode(user_id, episode_id) if episode_data: if play_status < episode_data["play_status"]: play_status = 2 # save the current episode progress in database - self.data.item.put_story_episode( + await self.data.item.put_story_episode( user_id, chapter_id, { @@ -1537,9 +1537,9 @@ class IDACSeason2(IDACBase): loop_count += 1 # for the current chapter set all episode play_status back to 1 - self.data.item.put_story_episode_play_status(user_id, chapter_id, 1) + await self.data.item.put_story_episode_play_status(user_id, chapter_id, 1) - self.data.item.put_story( + await self.data.item.put_story( user_id, { "story_type": data.get("story_type"), @@ -1549,7 +1549,7 @@ class IDACSeason2(IDACBase): ) # save the current episode difficulty progress in database - self.data.item.put_story_episode_difficulty( + await self.data.item.put_story_episode_difficulty( user_id, episode_id, { @@ -1564,7 +1564,7 @@ class IDACSeason2(IDACBase): # get the use_count and story_use_count of the used car style_car_id = data.get("style_car_id") car_mileage = data.get("car_mileage") - used_car = self.data.item.get_car(user_id, self.version, style_car_id)._asdict() + used_car = await self.data.item.get_car(user_id, self.version, style_car_id)._asdict() # increase the use_count and story_use_count of the used car used_car["use_count"] += 1 @@ -1572,14 +1572,14 @@ class IDACSeason2(IDACBase): used_car["car_mileage"] = car_mileage # save the used car in database - self.data.item.put_car(user_id, self.version, used_car) + await self.data.item.put_car(user_id, self.version, used_car) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # save user profile in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -1598,12 +1598,12 @@ class IDACSeason2(IDACBase): return { "status_code": "0", - "story_data": self._generate_story_data(user_id), + "story_data": await self._generate_story_data(user_id), "car_use_count": [], "maker_use_count": [], } - def handle_user_updatespecialmoderesult_request(self, data: Dict, headers: Dict): + async def handle_user_updatespecialmoderesult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") @@ -1617,11 +1617,11 @@ class IDACSeason2(IDACBase): # get the vs use count from database and update it style_car_id = data.pop("style_car_id") - car_data = self.data.item.get_car(user_id, self.version, style_car_id) + car_data = await self.data.item.get_car(user_id, self.version, style_car_id) story_use_count = car_data["story_use_count"] + 1 # save car data in database - self.data.item.put_car( + await self.data.item.put_car( user_id, self.version, { @@ -1632,11 +1632,11 @@ class IDACSeason2(IDACBase): ) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # save user profile in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -1654,18 +1654,18 @@ class IDACSeason2(IDACBase): ) # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save ticket data in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save mode_rank and reward_dist data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # finally save the special mode with story_type=4 in database - self.data.item.put_challenge(user_id, data) + await self.data.item.put_challenge(user_id, data) return { "status_code": "0", @@ -1674,7 +1674,7 @@ class IDACSeason2(IDACBase): "maker_use_count": [], } - def handle_user_updatechallengemoderesult_request(self, data: Dict, headers: Dict): + async def handle_user_updatechallengemoderesult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") @@ -1685,11 +1685,11 @@ class IDACSeason2(IDACBase): # get the vs use count from database and update it style_car_id = data.get("style_car_id") - car_data = self.data.item.get_car(user_id, self.version, style_car_id) + car_data = await self.data.item.get_car(user_id, self.version, style_car_id) story_use_count = car_data["story_use_count"] + 1 # save car data in database - self.data.item.put_car( + await self.data.item.put_car( user_id, self.version, { @@ -1700,11 +1700,11 @@ class IDACSeason2(IDACBase): ) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # save user profile in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -1722,18 +1722,18 @@ class IDACSeason2(IDACBase): ) # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save ticket data in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save mode_rank and reward_dist data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # get the challenge mode data from database - challenge_data = self.data.item.get_challenge( + challenge_data = await self.data.item.get_challenge( user_id, data.get("vs_type"), data.get("play_difficulty") ) @@ -1743,7 +1743,7 @@ class IDACSeason2(IDACBase): data["play_count"] = play_count # finally save the challenge mode with story_type=3 in database - self.data.item.put_challenge(user_id, data) + await self.data.item.put_challenge(user_id, data) return { "status_code": "0", @@ -1752,11 +1752,11 @@ class IDACSeason2(IDACBase): "maker_use_count": [], } - def _generate_time_trial_data(self, season_id: int, user_id: int) -> List[Dict]: + async def _generate_time_trial_data(self, season_id: int, user_id: int) -> List[Dict]: # get the season time trial data from database timetrial_data = [] - courses = self.data.item.get_courses(user_id) + courses = await self.data.item.get_courses(user_id) if courses is None or len(courses) == 0: return {"status_code": "0", "timetrial_data": timetrial_data} @@ -1766,7 +1766,7 @@ class IDACSeason2(IDACBase): skill_level_exp = course["skill_level_exp"] # get the best time for the current course for the current user - best_trial = self.data.item.get_time_trial_best_ranking_by_course( + best_trial = await self.data.item.get_time_trial_best_ranking_by_course( season_id, user_id, course_id ) if not best_trial: @@ -1774,7 +1774,7 @@ class IDACSeason2(IDACBase): goal_time = best_trial["goal_time"] # get the rank for the current course - course_rank = self.data.item.get_time_trial_ranking_by_course( + course_rank = await self.data.item.get_time_trial_ranking_by_course( season_id, course_id, limit=None ) course_rank = ( @@ -1794,12 +1794,12 @@ class IDACSeason2(IDACBase): return timetrial_data - def handle_user_getpastseasontadata_request(self, data: Dict, headers: Dict): + async def handle_user_getpastseasontadata_request(self, data: Dict, headers: Dict): user_id = headers["session"] season_id = data.get("season_id") # so to get the season 1 data just subtract 1 from the season id - past_timetrial_data = self._generate_time_trial_data(season_id - 1, user_id) + past_timetrial_data = await self._generate_time_trial_data(season_id - 1, user_id) # TODO: get the current season timetrial data somehow, because after requesting # GetPastSeasonTAData the game will NOT request GetTAData?! @@ -1809,10 +1809,10 @@ class IDACSeason2(IDACBase): "past_season_timetrial_data": past_timetrial_data, } - def handle_user_gettadata_request(self, data: Dict, headers: Dict): + async def handle_user_gettadata_request(self, data: Dict, headers: Dict): user_id = headers["session"] - timetrial_data = self._generate_time_trial_data(self.version, user_id) + timetrial_data = await self._generate_time_trial_data(self.version, user_id) # TODO: get the past season timetrial data somehow, because after requesting # GetTAData the game will NOT request GetPastSeasonTAData?! @@ -1822,17 +1822,17 @@ class IDACSeason2(IDACBase): # "past_season_timetrial_data": timetrial_data, } - def handle_user_updatecartune_request(self, data: Dict, headers: Dict): + async def handle_user_updatecartune_request(self, data: Dict, headers: Dict): user_id = headers["session"] # full tune ticket use_ticket = data.pop("use_ticket") if use_ticket: # get the user's tickets, full tune ticket id is 25 - ticket = self.data.item.get_ticket(user_id, ticket_id=25) + ticket = await self.data.item.get_ticket(user_id, ticket_id=25) # update the ticket in the database - self.data.item.put_ticket( + await self.data.item.put_ticket( user_id, { "ticket_id": ticket["ticket_id"], @@ -1843,22 +1843,22 @@ class IDACSeason2(IDACBase): # also set the tune_level to 16 (fully tuned) data["tune_level"] = 16 - self.data.item.put_car(user_id, self.version, data) + await self.data.item.put_car(user_id, self.version, data) return { "status_code": "0", - "story_data": self._generate_story_data(user_id), + "story_data": await self._generate_story_data(user_id), "car_use_count": [], "maker_use_count": [], } - def handle_log_saveplaylog_request(self, data: Dict, headers: Dict): + async def handle_log_saveplaylog_request(self, data: Dict, headers: Dict): pass - def handle_log_saveendlog_request(self, data: Dict, headers: Dict): + async def handle_log_saveendlog_request(self, data: Dict, headers: Dict): pass - def handle_user_updatemoderesult_request(self, data: Dict, headers: Dict): + async def handle_user_updatemoderesult_request(self, data: Dict, headers: Dict): user_id = headers["session"] config_data: Dict = data.pop("config_obj") @@ -1872,30 +1872,30 @@ class IDACSeason2(IDACBase): tips_list = data.pop("tips_list") # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save rank dist data in database - self.data.profile.put_profile_rank(user_id, self.version, reward_dist_data) + await self.data.profile.put_profile_rank(user_id, self.version, reward_dist_data) # update profile data and config in database - self.data.profile.put_profile(user_id, self.version, data) + await self.data.profile.put_profile(user_id, self.version, data) config_data["config_id"] = config_data.pop("id") - self.data.profile.put_profile_config(user_id, config_data) + await self.data.profile.put_profile_config(user_id, config_data) return {"status_code": "0", "server_status": 1} - def _generate_theory_rival_data( + async def _generate_theory_rival_data( self, user_list: list, course_id: int, req_user_id: int ) -> list: rival_data = [] for user_id in user_list: # if not enough players are available just use the data from the req_user if user_id == -1: - profile = self.data.profile.get_profile(req_user_id, self.version) + profile = await self.data.profile.get_profile(req_user_id, self.version) profile = profile._asdict() # set the name to CPU profile["username"] = f"CPU" @@ -1908,9 +1908,9 @@ class IDACSeason2(IDACBase): profile["stamp_key_assign_3"] = 3 profile["mytitle_id"] = 0 else: - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) - rank = self.data.profile.get_profile_rank(profile["user"], self.version) + rank = await self.data.profile.get_profile_rank(profile["user"], self.version) avatars = [ { @@ -1978,21 +1978,21 @@ class IDACSeason2(IDACBase): if user_id == -1: # get a random avatar from the list and some random car from all users avatar = choice(avatars) - car = self.data.item.get_random_car(self.version) + car = await self.data.item.get_random_car(self.version) else: - avatar = self.data.profile.get_profile_avatar(profile["user"]) - car = self.data.item.get_random_user_car(profile["user"], self.version) + avatar = await self.data.profile.get_profile_avatar(profile["user"]) + car = await self.data.item.get_random_user_car(profile["user"], self.version) parts_list = [] for part in car["parts_list"]: parts_list.append(part["parts"]) - course = self.data.item.get_theory_course(profile["user"], course_id) + course = await self.data.item.get_theory_course(profile["user"], course_id) powerhose_lv = 0 if course: powerhose_lv = course["powerhouse_lv"] - theory_running = self.data.item.get_theory_running_by_course( + theory_running = await self.data.item.get_theory_running_by_course( profile["user"], course_id ) @@ -2011,13 +2011,13 @@ class IDACSeason2(IDACBase): # get the time trial ranking medal eval_id = 0 - time_trial = self.data.item.get_time_trial_best_ranking_by_course( + time_trial = await self.data.item.get_time_trial_best_ranking_by_course( self.version, profile["user"], course_id ) if time_trial: eval_id = time_trial["eval_id"] - arcade = self.data.arcade.get_arcade(profile["store"]) + arcade = await self.data.arcade.get_arcade(profile["store"]) if arcade is None: arcade = {} arcade["name"] = self.core_cfg.server.name @@ -2079,7 +2079,7 @@ class IDACSeason2(IDACBase): return rival_data - def handle_theory_matching_request(self, data: Dict, headers: Dict): + async def handle_theory_matching_request(self, data: Dict, headers: Dict): user_id = headers["session"] course_id = data.pop("course_id") @@ -2094,7 +2094,7 @@ class IDACSeason2(IDACBase): powerhose_lv = data.pop("powerhouse_lv") # get random profiles for auto match - profiles = self.data.profile.get_different_random_profiles( + profiles = await self.data.profile.get_different_random_profiles( user_id, self.version, count=count_auto_match ) @@ -2103,10 +2103,10 @@ class IDACSeason2(IDACBase): while len(user_list) < count_auto_match: user_list.append(-1) - auto_match = self._generate_theory_rival_data(user_list, course_id, user_id) + auto_match = await self._generate_theory_rival_data(user_list, course_id, user_id) # get profiles with the same powerhouse_lv for power match - theory_courses = self.data.item.get_theory_course_by_powerhouse_lv( + theory_courses = await self.data.item.get_theory_course_by_powerhouse_lv( user_id, course_id, powerhose_lv, count=count_power_match ) user_list = [course["user"] for course in theory_courses] @@ -2115,7 +2115,7 @@ class IDACSeason2(IDACBase): while len(user_list) < count_power_match: user_list.append(-1) - power_match = self._generate_theory_rival_data(user_list, course_id, user_id) + power_match = await self._generate_theory_rival_data(user_list, course_id, user_id) return { "status_code": "0", @@ -2126,7 +2126,7 @@ class IDACSeason2(IDACBase): }, } - def handle_user_updatetheoryresult_request(self, data: Dict, headers: Dict): + async def handle_user_updatetheoryresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") @@ -2136,15 +2136,15 @@ class IDACSeason2(IDACBase): driver_debut_data: Dict = data.pop("driver_debut_obj") # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save rank dist data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # save the profile theory data in database play_count = 1 @@ -2152,7 +2152,7 @@ class IDACSeason2(IDACBase): win_count = 0 win_count_multi = 0 - theory_data = self.data.profile.get_profile_theory(user_id, self.version) + theory_data = await self.data.profile.get_profile_theory(user_id, self.version) if theory_data: play_count = theory_data["play_count"] + 1 play_count_multi = theory_data["play_count_multi"] + 1 @@ -2170,7 +2170,7 @@ class IDACSeason2(IDACBase): win_count += 1 win_count_multi += 1 - self.data.profile.put_profile_theory( + await self.data.profile.put_profile_theory( user_id, self.version, { @@ -2190,7 +2190,7 @@ class IDACSeason2(IDACBase): ) # save theory course in database - self.data.item.put_theory_course( + await self.data.item.put_theory_course( user_id, { "course_id": data.get("course_id"), @@ -2205,7 +2205,7 @@ class IDACSeason2(IDACBase): ) # save the theory partner in database - self.data.item.put_theory_partner( + await self.data.item.put_theory_partner( user_id, { "partner_id": data.get("partner_id"), @@ -2215,7 +2215,7 @@ class IDACSeason2(IDACBase): ) # save the theory running in database? - self.data.item.put_theory_running( + await self.data.item.put_theory_running( user_id, { "course_id": data.get("course_id"), @@ -2230,7 +2230,7 @@ class IDACSeason2(IDACBase): # get the use_count and theory_use_count of the used car style_car_id = data.get("style_car_id") car_mileage = data.get("car_mileage") - used_car = self.data.item.get_car(user_id, self.version, style_car_id)._asdict() + used_car = await self.data.item.get_car(user_id, self.version, style_car_id)._asdict() # increase the use_count and theory_use_count of the used car used_car["use_count"] += 1 @@ -2238,14 +2238,14 @@ class IDACSeason2(IDACBase): used_car["car_mileage"] = car_mileage # save the used car in database - self.data.item.put_car(user_id, self.version, used_car) + await self.data.item.put_car(user_id, self.version, used_car) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # save the profile in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -2273,16 +2273,16 @@ class IDACSeason2(IDACBase): "win_count_multi": win_count_multi, } - def handle_timetrial_getbestrecordprebattle_request( + async def handle_timetrial_getbestrecordprebattle_request( self, data: Dict, headers: Dict ): user_id = headers["session"] course_pickup_car_best_data = [] - courses = self.data.item.get_time_trial_courses(self.version) + courses = await self.data.item.get_time_trial_courses(self.version) for course in courses: car_list = [] - best_cars = self.data.item.get_time_trial_best_cars_by_course( + best_cars = await self.data.item.get_time_trial_best_cars_by_course( self.version, course["course_id"], user_id ) @@ -2318,36 +2318,36 @@ class IDACSeason2(IDACBase): "course_pickup_car_best_data": course_pickup_car_best_data, } - def handle_user_updateonlinebattle_request(self, data: Dict, headers: Dict): + async def handle_user_updateonlinebattle_request(self, data: Dict, headers: Dict): return { "status_code": "0", "bothwin_penalty": 1, } - def handle_user_updateonlinebattleresult_request(self, data: Dict, headers: Dict): + async def handle_user_updateonlinebattleresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) ticket_data: List = data.pop("ticket_data") for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) reward_dist_data: Dict = data.pop("reward_dist_obj") rank_data: Dict = data.pop("mode_rank_obj") # save rank dist data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) driver_debut_data = data.pop("driver_debut_obj") # get the use_count and net_vs_use_count of the used car style_car_id = data.get("style_car_id") car_mileage = data.pop("car_mileage") - used_car = self.data.item.get_car(user_id, self.version, style_car_id)._asdict() + used_car = await self.data.item.get_car(user_id, self.version, style_car_id)._asdict() # increase the use_count and net_vs_use_count of the used car used_car["use_count"] += 1 @@ -2355,14 +2355,14 @@ class IDACSeason2(IDACBase): used_car["car_mileage"] = car_mileage # save the used car in database - self.data.item.put_car(user_id, self.version, used_car) + await self.data.item.put_car(user_id, self.version, used_car) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # save the profile in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -2379,7 +2379,7 @@ class IDACSeason2(IDACBase): }, ) - self.data.item.put_vs_info(user_id, data) + await self.data.item.put_vs_info(user_id, data) vs_info = { "battle_mode": 0, @@ -2416,7 +2416,7 @@ class IDACSeason2(IDACBase): "maker_use_count": [], } - def handle_user_updatestorebattleresult_request(self, data: Dict, headers: Dict): + async def handle_user_updatestorebattleresult_request(self, data: Dict, headers: Dict): user_id = headers["session"] stock_data: Dict = data.pop("stock_obj") @@ -2431,20 +2431,20 @@ class IDACSeason2(IDACBase): gift_id = data.pop("gift_id") # save stock data in database - self._save_stock_data(user_id, stock_data) + await self._save_stock_data(user_id, stock_data) # save tickets in database for ticket in ticket_data: - self.data.item.put_ticket(user_id, ticket) + await self.data.item.put_ticket(user_id, ticket) # save rank dist data in database rank_data.update(reward_dist_data) - self.data.profile.put_profile_rank(user_id, self.version, rank_data) + await self.data.profile.put_profile_rank(user_id, self.version, rank_data) # get the use_count and net_vs_use_count of the used car style_car_id = data.get("style_car_id") car_mileage = data.pop("car_mileage") - used_car = self.data.item.get_car(user_id, self.version, style_car_id)._asdict() + used_car = await self.data.item.get_car(user_id, self.version, style_car_id)._asdict() # increase the use_count and net_vs_use_count of the used car used_car["use_count"] += 1 @@ -2452,14 +2452,14 @@ class IDACSeason2(IDACBase): used_car["car_mileage"] = car_mileage # save the used car in database - self.data.item.put_car(user_id, self.version, used_car) + await self.data.item.put_car(user_id, self.version, used_car) # get the profile data, update total_play and daily_play, and save it - profile = self.data.profile.get_profile(user_id, self.version) + profile = await self.data.profile.get_profile(user_id, self.version) total_play = profile["total_play"] + 1 # save the profile in database - self.data.profile.put_profile( + await self.data.profile.put_profile( user_id, self.version, { @@ -2477,7 +2477,7 @@ class IDACSeason2(IDACBase): ) # save vs_info in database - self.data.item.put_vs_info(user_id, data) + await self.data.item.put_vs_info(user_id, data) vs_info = { "battle_mode": 0, diff --git a/titles/idz/userdb.py b/titles/idz/userdb.py index cd6ea9c..47a9102 100644 --- a/titles/idz/userdb.py +++ b/titles/idz/userdb.py @@ -81,7 +81,7 @@ class IDZUserDB: self.logger.debug("Connection closed") return - await self.dataReceived(data, reader, writer) + await self.data.Received(data, reader, writer) await writer.drain() except ConnectionResetError as e: diff --git a/titles/mai2/base.py b/titles/mai2/base.py index a9ddcab..5a5edb9 100644 --- a/titles/mai2/base.py +++ b/titles/mai2/base.py @@ -82,7 +82,7 @@ class Mai2Base: return {"length": 0, "gameTournamentInfoList": []} async def handle_get_game_event_api_request(self, data: Dict) -> Dict: - events = self.data.static.get_enabled_events(self.version) + events = await self.data.static.get_enabled_events(self.version) events_lst = [] if events is None or not events: self.logger.warning("No enabled events, did you run the reader?") @@ -112,7 +112,7 @@ class Mai2Base: return {"length": 0, "musicIdList": []} async def handle_get_game_charge_api_request(self, data: Dict) -> Dict: - game_charge_list = self.data.static.get_enabled_tickets(self.version, 1) + game_charge_list = await self.data.static.get_enabled_tickets(self.version, 1) if game_charge_list is None: return {"length": 0, "gameChargeList": []} @@ -143,8 +143,8 @@ class Mai2Base: return {"returnCode": 1, "apiName": "UpsertClientTestmodeApi"} async def handle_get_user_preview_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_detail(data["userId"], self.version, False) - w = self.data.profile.get_web_option(data["userId"], self.version) + p = await self.data.profile.get_profile_detail(data["userId"], self.version, False) + w = await self.data.profile.get_web_option(data["userId"], self.version) if p is None or w is None: return {} # Register profile = p._asdict() @@ -170,15 +170,15 @@ class Mai2Base: } async def handle_user_login_api_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_detail(data["userId"], self.version) - consec = self.data.profile.get_consec_login(data["userId"], self.version) + profile = await self.data.profile.get_profile_detail(data["userId"], self.version) + consec = await self.data.profile.get_consec_login(data["userId"], self.version) if profile is not None: lastLoginDate = profile["lastLoginDate"] loginCt = profile["playCount"] if "regionId" in data: - self.data.profile.put_profile_region(data["userId"], data["regionId"]) + await self.data.profile.put_profile_region(data["userId"], data["regionId"]) else: loginCt = 0 lastLoginDate = "2017-12-05 07:00:00.0" @@ -193,11 +193,11 @@ class Mai2Base: if lastlogindate_ < today_midnight: consec_ct = consec['logins'] + 1 - self.data.profile.add_consec_login(data["userId"], self.version) + await self.data.profile.add_consec_login(data["userId"], self.version) elif lastlogindate_ < yesterday_midnight: consec_ct = 1 - self.data.profile.reset_consec_login(data["userId"], self.version) + await self.data.profile.reset_consec_login(data["userId"], self.version) else: consec_ct = consec['logins'] @@ -214,7 +214,7 @@ class Mai2Base: user_id = data["userId"] playlog = data["userPlaylog"] - self.data.score.put_playlog(user_id, playlog) + await self.data.score.put_playlog(user_id, playlog) return {"returnCode": 1, "apiName": "UploadUserPlaylogApi"} @@ -224,7 +224,7 @@ class Mai2Base: # remove the ".0" from the date string, festival only? charge["purchaseDate"] = charge["purchaseDate"].replace(".0", "") - self.data.item.put_charge( + await self.data.item.put_charge( user_id, charge["chargeId"], charge["stock"], @@ -246,64 +246,64 @@ class Mai2Base: upsert["userData"][0].pop("accessCode") upsert["userData"][0].pop("userId") - self.data.profile.put_profile_detail( + await self.data.profile.put_profile_detail( user_id, self.version, upsert["userData"][0], False ) if "userWebOption" in upsert and len(upsert["userWebOption"]) > 0: upsert["userWebOption"][0]["isNetMember"] = True - self.data.profile.put_web_option( + await self.data.profile.put_web_option( user_id, self.version, upsert["userWebOption"][0] ) if "userGradeStatusList" in upsert and len(upsert["userGradeStatusList"]) > 0: - self.data.profile.put_grade_status( + await self.data.profile.put_grade_status( user_id, upsert["userGradeStatusList"][0] ) if "userBossList" in upsert and len(upsert["userBossList"]) > 0: - self.data.profile.put_boss_list( + await self.data.profile.put_boss_list( user_id, upsert["userBossList"][0] ) if "userPlaylogList" in upsert and len(upsert["userPlaylogList"]) > 0: for playlog in upsert["userPlaylogList"]: - self.data.score.put_playlog( + await self.data.score.put_playlog( user_id, playlog, False ) if "userExtend" in upsert and len(upsert["userExtend"]) > 0: - self.data.profile.put_profile_extend( + await self.data.profile.put_profile_extend( user_id, self.version, upsert["userExtend"][0] ) if "userGhost" in upsert: for ghost in upsert["userGhost"]: - self.data.profile.put_profile_ghost(user_id, self.version, ghost) + await self.data.profile.put_profile_ghost(user_id, self.version, ghost) if "userRecentRatingList" in upsert: - self.data.profile.put_recent_rating(user_id, upsert["userRecentRatingList"]) + await self.data.profile.put_recent_rating(user_id, upsert["userRecentRatingList"]) if "userOption" in upsert and len(upsert["userOption"]) > 0: upsert["userOption"][0].pop("userId") - self.data.profile.put_profile_option( + await self.data.profile.put_profile_option( user_id, self.version, upsert["userOption"][0], False ) if "userRatingList" in upsert and len(upsert["userRatingList"]) > 0: - self.data.profile.put_profile_rating( + await self.data.profile.put_profile_rating( user_id, self.version, upsert["userRatingList"][0] ) if "userActivityList" in upsert and len(upsert["userActivityList"]) > 0: for act in upsert["userActivityList"]: - self.data.profile.put_profile_activity(user_id, act) + await self.data.profile.put_profile_activity(user_id, act) if "userChargeList" in upsert and len(upsert["userChargeList"]) > 0: for charge in upsert["userChargeList"]: # remove the ".0" from the date string, festival only? charge["purchaseDate"] = charge["purchaseDate"].replace(".0", "") - self.data.item.put_charge( + await self.data.item.put_charge( user_id, charge["chargeId"], charge["stock"], @@ -313,14 +313,14 @@ class Mai2Base: if "userCharacterList" in upsert and len(upsert["userCharacterList"]) > 0: for char in upsert["userCharacterList"]: - self.data.item.put_character_( + await self.data.item.put_character_( user_id, char ) if "userItemList" in upsert and len(upsert["userItemList"]) > 0: for item in upsert["userItemList"]: - self.data.item.put_item( + await self.data.item.put_item( user_id, int(item["itemKind"]), item["itemId"], @@ -330,7 +330,7 @@ class Mai2Base: if "userLoginBonusList" in upsert and len(upsert["userLoginBonusList"]) > 0: for login_bonus in upsert["userLoginBonusList"]: - self.data.item.put_login_bonus( + await self.data.item.put_login_bonus( user_id, login_bonus["bonusId"], login_bonus["point"], @@ -340,7 +340,7 @@ class Mai2Base: if "userMapList" in upsert and len(upsert["userMapList"]) > 0: for map in upsert["userMapList"]: - self.data.item.put_map( + await self.data.item.put_map( user_id, map["mapId"], map["distance"], @@ -351,15 +351,15 @@ class Mai2Base: if "userMusicDetailList" in upsert and len(upsert["userMusicDetailList"]) > 0: for music in upsert["userMusicDetailList"]: - self.data.score.put_best_score(user_id, music, False) + await self.data.score.put_best_score(user_id, music, False) if "userCourseList" in upsert and len(upsert["userCourseList"]) > 0: for course in upsert["userCourseList"]: - self.data.score.put_course(user_id, course) + await self.data.score.put_course(user_id, course) if "userFavoriteList" in upsert and len(upsert["userFavoriteList"]) > 0: for fav in upsert["userFavoriteList"]: - self.data.item.put_favorite(user_id, fav["kind"], fav["itemIdList"]) + await self.data.item.put_favorite(user_id, fav["kind"], fav["itemIdList"]) if ( "userFriendSeasonRankingList" in upsert @@ -371,7 +371,7 @@ class Mai2Base: fsr["recordDate"], f"{Mai2Constants.DATE_TIME_FORMAT}.0" ), ) - self.data.item.put_friend_season_ranking(user_id, fsr) + await self.data.item.put_friend_season_ranking(user_id, fsr) return {"returnCode": 1, "apiName": "UpsertUserAllApi"} @@ -379,7 +379,7 @@ class Mai2Base: return {"returnCode": 1} async def handle_get_user_data_api_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_detail(data["userId"], self.version, False) + profile = await self.data.profile.get_profile_detail(data["userId"], self.version, False) if profile is None: return @@ -391,7 +391,7 @@ class Mai2Base: return {"userId": data["userId"], "userData": profile_dict} async def handle_get_user_extend_api_request(self, data: Dict) -> Dict: - extend = self.data.profile.get_profile_extend(data["userId"], self.version) + extend = await self.data.profile.get_profile_extend(data["userId"], self.version) if extend is None: return @@ -403,7 +403,7 @@ class Mai2Base: return {"userId": data["userId"], "userExtend": extend_dict} async def handle_get_user_option_api_request(self, data: Dict) -> Dict: - options = self.data.profile.get_profile_option(data["userId"], self.version, False) + options = await self.data.profile.get_profile_option(data["userId"], self.version, False) if options is None: return @@ -415,7 +415,7 @@ class Mai2Base: return {"userId": data["userId"], "userOption": options_dict} async def handle_get_user_card_api_request(self, data: Dict) -> Dict: - user_cards = self.data.item.get_cards(data["userId"]) + user_cards = await self.data.item.get_cards(data["userId"]) if user_cards is None: return {"userId": data["userId"], "nextIndex": 0, "userCardList": []} @@ -449,7 +449,7 @@ class Mai2Base: } async def handle_get_user_charge_api_request(self, data: Dict) -> Dict: - user_charges = self.data.item.get_charges(data["userId"]) + user_charges = await self.data.item.get_charges(data["userId"]) if user_charges is None: return {"userId": data["userId"], "length": 0, "userChargeList": []} @@ -477,7 +477,7 @@ class Mai2Base: return { "userId": data.get("userId", 0), "length": 0, "userPresentEventList": []} async def handle_get_user_boss_api_request(self, data: Dict) -> Dict: - b = self.data.profile.get_boss_list(data["userId"]) + b = await self.data.profile.get_boss_list(data["userId"]) if b is None: return { "userId": data.get("userId", 0), "userBossData": {}} boss_lst = b._asdict() @@ -489,7 +489,7 @@ class Mai2Base: async def handle_get_user_item_api_request(self, data: Dict) -> Dict: kind = int(data["nextIndex"] / 10000000000) next_idx = int(data["nextIndex"] % 10000000000) - user_item_list = self.data.item.get_items(data["userId"], kind) + user_item_list = await self.data.item.get_items(data["userId"], kind) items: List[Dict[str, Any]] = [] for i in range(next_idx, len(user_item_list)): @@ -515,7 +515,7 @@ class Mai2Base: } async def handle_get_user_character_api_request(self, data: Dict) -> Dict: - characters = self.data.item.get_characters(data["userId"]) + characters = await self.data.item.get_characters(data["userId"]) chara_list = [] for chara in characters: @@ -529,7 +529,7 @@ class Mai2Base: return {"userId": data["userId"], "userCharacterList": chara_list} async def handle_get_user_favorite_api_request(self, data: Dict) -> Dict: - favorites = self.data.item.get_favorites(data["userId"], data["itemKind"]) + favorites = await self.data.item.get_favorites(data["userId"], data["itemKind"]) if favorites is None: return @@ -546,7 +546,7 @@ class Mai2Base: return {"userId": data["userId"], "userFavoriteData": userFavs} async def handle_get_user_ghost_api_request(self, data: Dict) -> Dict: - ghost = self.data.profile.get_profile_ghost(data["userId"], self.version) + ghost = await self.data.profile.get_profile_ghost(data["userId"], self.version) if ghost is None: return @@ -558,7 +558,7 @@ class Mai2Base: return {"userId": data["userId"], "userGhost": ghost_dict} async def handle_get_user_recent_rating_api_request(self, data: Dict) -> Dict: - rating = self.data.profile.get_recent_rating(data["userId"]) + rating = await self.data.profile.get_recent_rating(data["userId"]) if rating is None: return @@ -568,7 +568,7 @@ class Mai2Base: return {"userId": data["userId"], "length": len(lst), "userRecentRatingList": lst} async def handle_get_user_rating_api_request(self, data: Dict) -> Dict: - rating = self.data.profile.get_profile_rating(data["userId"], self.version) + rating = await self.data.profile.get_profile_rating(data["userId"], self.version) if rating is None: return @@ -583,8 +583,8 @@ class Mai2Base: """ kind 1 is playlist, kind 2 is music list """ - playlist = self.data.profile.get_profile_activity(data["userId"], 1) - musiclist = self.data.profile.get_profile_activity(data["userId"], 2) + playlist = await self.data.profile.get_profile_activity(data["userId"], 1) + musiclist = await self.data.profile.get_profile_activity(data["userId"], 2) if playlist is None or musiclist is None: return @@ -608,7 +608,7 @@ class Mai2Base: return {"userActivity": {"playList": plst, "musicList": mlst}} async def handle_get_user_course_api_request(self, data: Dict) -> Dict: - user_courses = self.data.score.get_courses(data["userId"]) + user_courses = await self.data.score.get_courses(data["userId"]) if user_courses is None: return {"userId": data["userId"], "nextIndex": 0, "userCourseList": []} @@ -626,7 +626,7 @@ class Mai2Base: return {"length": 0, "userPortraitList": []} async def handle_get_user_friend_season_ranking_api_request(self, data: Dict) -> Dict: - friend_season_ranking = self.data.item.get_friend_season_ranking(data["userId"]) + friend_season_ranking = await self.data.item.get_friend_season_ranking(data["userId"]) if friend_season_ranking is None: return { "userId": data["userId"], @@ -662,7 +662,7 @@ class Mai2Base: } async def handle_get_user_map_api_request(self, data: Dict) -> Dict: - maps = self.data.item.get_maps(data["userId"]) + maps = await self.data.item.get_maps(data["userId"]) if maps is None: return { "userId": data["userId"], @@ -695,7 +695,7 @@ class Mai2Base: } async def handle_get_user_login_bonus_api_request(self, data: Dict) -> Dict: - login_bonuses = self.data.item.get_login_bonuses(data["userId"]) + login_bonuses = await self.data.item.get_login_bonuses(data["userId"]) if login_bonuses is None: return { "userId": data["userId"], @@ -731,7 +731,7 @@ class Mai2Base: return {"userId": data["userId"], "length": 0, "userRegionList": []} async def handle_get_user_web_option_api_request(self, data: Dict) -> Dict: - w = self.data.profile.get_web_option(data["userId"], self.version) + w = await self.data.profile.get_web_option(data["userId"], self.version) if w is None: return {"userId": data["userId"], "userWebOption": {}} @@ -746,7 +746,7 @@ class Mai2Base: return {"userId": data["userId"], "length": 0, "userSurvivalList": []} async def handle_get_user_grade_api_request(self, data: Dict) -> Dict: - g = self.data.profile.get_grade_status(data["userId"]) + g = await self.data.profile.get_grade_status(data["userId"]) if g is None: return {"userId": data["userId"], "userGradeStatus": {}, "length": 0, "userGradeList": []} grade_stat = g._asdict() @@ -766,7 +766,7 @@ class Mai2Base: self.logger.warning("handle_get_user_music_api_request: Could not find userid in data, or userId is 0") return {} - songs = self.data.score.get_best_scores(user_id, is_dx=False) + songs = await self.data.score.get_best_scores(user_id, is_dx=False) if songs is None: self.logger.debug("handle_get_user_music_api_request: get_best_scores returned None!") return { diff --git a/titles/mai2/dx.py b/titles/mai2/dx.py index 80a3bc2..f978eeb 100644 --- a/titles/mai2/dx.py +++ b/titles/mai2/dx.py @@ -34,8 +34,8 @@ class Mai2DX(Mai2Base): } async def handle_get_user_preview_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_detail(data["userId"], self.version) - o = self.data.profile.get_profile_option(data["userId"], self.version) + p = await self.data.profile.get_profile_detail(data["userId"], self.version) + o = await self.data.profile.get_profile_option(data["userId"], self.version) if p is None or o is None: return {} # Register profile = p._asdict() @@ -73,7 +73,7 @@ class Mai2DX(Mai2Base): user_id = data["userId"] playlog = data["userPlaylog"] - self.data.score.put_playlog(user_id, playlog) + await self.data.score.put_playlog(user_id, playlog) return {"returnCode": 1, "apiName": "UploadUserPlaylogApi"} @@ -83,7 +83,7 @@ class Mai2DX(Mai2Base): # remove the ".0" from the date string, festival only? charge["purchaseDate"] = charge["purchaseDate"].replace(".0", "") - self.data.item.put_charge( + await self.data.item.put_charge( user_id, charge["chargeId"], charge["stock"], @@ -104,39 +104,39 @@ class Mai2DX(Mai2Base): if "userData" in upsert and len(upsert["userData"]) > 0: upsert["userData"][0]["isNetMember"] = 1 upsert["userData"][0].pop("accessCode") - self.data.profile.put_profile_detail( + await self.data.profile.put_profile_detail( user_id, self.version, upsert["userData"][0] ) if "userExtend" in upsert and len(upsert["userExtend"]) > 0: - self.data.profile.put_profile_extend( + await self.data.profile.put_profile_extend( user_id, self.version, upsert["userExtend"][0] ) if "userGhost" in upsert: for ghost in upsert["userGhost"]: - self.data.profile.put_profile_ghost(user_id, self.version, ghost) + await self.data.profile.put_profile_ghost(user_id, self.version, ghost) if "userOption" in upsert and len(upsert["userOption"]) > 0: - self.data.profile.put_profile_option( + await self.data.profile.put_profile_option( user_id, self.version, upsert["userOption"][0] ) if "userRatingList" in upsert and len(upsert["userRatingList"]) > 0: - self.data.profile.put_profile_rating( + await self.data.profile.put_profile_rating( user_id, self.version, upsert["userRatingList"][0] ) if "userActivityList" in upsert and len(upsert["userActivityList"]) > 0: for k, v in upsert["userActivityList"][0].items(): for act in v: - self.data.profile.put_profile_activity(user_id, act) + await self.data.profile.put_profile_activity(user_id, act) if "userChargeList" in upsert and len(upsert["userChargeList"]) > 0: for charge in upsert["userChargeList"]: # remove the ".0" from the date string, festival only? charge["purchaseDate"] = charge["purchaseDate"].replace(".0", "") - self.data.item.put_charge( + await self.data.item.put_charge( user_id, charge["chargeId"], charge["stock"], @@ -150,7 +150,7 @@ class Mai2DX(Mai2Base): if "userCharacterList" in upsert and len(upsert["userCharacterList"]) > 0: for char in upsert["userCharacterList"]: - self.data.item.put_character( + await self.data.item.put_character( user_id, char["characterId"], char["level"], @@ -160,7 +160,7 @@ class Mai2DX(Mai2Base): if "userItemList" in upsert and len(upsert["userItemList"]) > 0: for item in upsert["userItemList"]: - self.data.item.put_item( + await self.data.item.put_item( user_id, int(item["itemKind"]), item["itemId"], @@ -170,7 +170,7 @@ class Mai2DX(Mai2Base): if "userLoginBonusList" in upsert and len(upsert["userLoginBonusList"]) > 0: for login_bonus in upsert["userLoginBonusList"]: - self.data.item.put_login_bonus( + await self.data.item.put_login_bonus( user_id, login_bonus["bonusId"], login_bonus["point"], @@ -180,7 +180,7 @@ class Mai2DX(Mai2Base): if "userMapList" in upsert and len(upsert["userMapList"]) > 0: for map in upsert["userMapList"]: - self.data.item.put_map( + await self.data.item.put_map( user_id, map["mapId"], map["distance"], @@ -191,15 +191,15 @@ class Mai2DX(Mai2Base): if "userMusicDetailList" in upsert and len(upsert["userMusicDetailList"]) > 0: for music in upsert["userMusicDetailList"]: - self.data.score.put_best_score(user_id, music) + await self.data.score.put_best_score(user_id, music) if "userCourseList" in upsert and len(upsert["userCourseList"]) > 0: for course in upsert["userCourseList"]: - self.data.score.put_course(user_id, course) + await self.data.score.put_course(user_id, course) if "userFavoriteList" in upsert and len(upsert["userFavoriteList"]) > 0: for fav in upsert["userFavoriteList"]: - self.data.item.put_favorite(user_id, fav["kind"], fav["itemIdList"]) + await self.data.item.put_favorite(user_id, fav["kind"], fav["itemIdList"]) if ( "userFriendSeasonRankingList" in upsert @@ -211,12 +211,12 @@ class Mai2DX(Mai2Base): fsr["recordDate"], f"{Mai2Constants.DATE_TIME_FORMAT}.0" ), ) - self.data.item.put_friend_season_ranking(user_id, fsr) + await self.data.item.put_friend_season_ranking(user_id, fsr) return {"returnCode": 1, "apiName": "UpsertUserAllApi"} async def handle_get_user_data_api_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_detail(data["userId"], self.version) + profile = await self.data.profile.get_profile_detail(data["userId"], self.version) if profile is None: return @@ -228,7 +228,7 @@ class Mai2DX(Mai2Base): return {"userId": data["userId"], "userData": profile_dict} async def handle_get_user_extend_api_request(self, data: Dict) -> Dict: - extend = self.data.profile.get_profile_extend(data["userId"], self.version) + extend = await self.data.profile.get_profile_extend(data["userId"], self.version) if extend is None: return @@ -240,7 +240,7 @@ class Mai2DX(Mai2Base): return {"userId": data["userId"], "userExtend": extend_dict} async def handle_get_user_option_api_request(self, data: Dict) -> Dict: - options = self.data.profile.get_profile_option(data["userId"], self.version) + options = await self.data.profile.get_profile_option(data["userId"], self.version) if options is None: return @@ -252,7 +252,7 @@ class Mai2DX(Mai2Base): return {"userId": data["userId"], "userOption": options_dict} async def handle_get_user_card_api_request(self, data: Dict) -> Dict: - user_cards = self.data.item.get_cards(data["userId"]) + user_cards = await self.data.item.get_cards(data["userId"]) if user_cards is None: return {"userId": data["userId"], "nextIndex": 0, "userCardList": []} @@ -286,7 +286,7 @@ class Mai2DX(Mai2Base): } async def handle_get_user_charge_api_request(self, data: Dict) -> Dict: - user_charges = self.data.item.get_charges(data["userId"]) + user_charges = await self.data.item.get_charges(data["userId"]) if user_charges is None: return {"userId": data["userId"], "length": 0, "userChargeList": []} @@ -313,7 +313,7 @@ class Mai2DX(Mai2Base): async def handle_get_user_item_api_request(self, data: Dict) -> Dict: kind = int(data["nextIndex"] / 10000000000) next_idx = int(data["nextIndex"] % 10000000000) - user_item_list = self.data.item.get_items(data["userId"], kind) + user_item_list = await self.data.item.get_items(data["userId"], kind) items: List[Dict[str, Any]] = [] for i in range(next_idx, len(user_item_list)): @@ -339,7 +339,7 @@ class Mai2DX(Mai2Base): } async def handle_get_user_character_api_request(self, data: Dict) -> Dict: - characters = self.data.item.get_characters(data["userId"]) + characters = await self.data.item.get_characters(data["userId"]) chara_list = [] for chara in characters: @@ -351,7 +351,7 @@ class Mai2DX(Mai2Base): return {"userId": data["userId"], "userCharacterList": chara_list} async def handle_get_user_favorite_api_request(self, data: Dict) -> Dict: - favorites = self.data.item.get_favorites(data["userId"], data["itemKind"]) + favorites = await self.data.item.get_favorites(data["userId"], data["itemKind"]) if favorites is None: return @@ -368,7 +368,7 @@ class Mai2DX(Mai2Base): return {"userId": data["userId"], "userFavoriteData": userFavs} async def handle_get_user_ghost_api_request(self, data: Dict) -> Dict: - ghost = self.data.profile.get_profile_ghost(data["userId"], self.version) + ghost = await self.data.profile.get_profile_ghost(data["userId"], self.version) if ghost is None: return @@ -380,7 +380,7 @@ class Mai2DX(Mai2Base): return {"userId": data["userId"], "userGhost": ghost_dict} async def handle_get_user_rating_api_request(self, data: Dict) -> Dict: - rating = self.data.profile.get_profile_rating(data["userId"], self.version) + rating = await self.data.profile.get_profile_rating(data["userId"], self.version) if rating is None: return @@ -395,8 +395,8 @@ class Mai2DX(Mai2Base): """ kind 1 is playlist, kind 2 is music list """ - playlist = self.data.profile.get_profile_activity(data["userId"], 1) - musiclist = self.data.profile.get_profile_activity(data["userId"], 2) + playlist = await self.data.profile.get_profile_activity(data["userId"], 1) + musiclist = await self.data.profile.get_profile_activity(data["userId"], 2) if playlist is None or musiclist is None: return @@ -420,7 +420,7 @@ class Mai2DX(Mai2Base): return {"userActivity": {"playList": plst, "musicList": mlst}} async def handle_get_user_course_api_request(self, data: Dict) -> Dict: - user_courses = self.data.score.get_courses(data["userId"]) + user_courses = await self.data.score.get_courses(data["userId"]) if user_courses is None: return {"userId": data["userId"], "nextIndex": 0, "userCourseList": []} @@ -438,7 +438,7 @@ class Mai2DX(Mai2Base): return {"length": 0, "userPortraitList": []} async def handle_get_user_friend_season_ranking_api_request(self, data: Dict) -> Dict: - friend_season_ranking = self.data.item.get_friend_season_ranking(data["userId"]) + friend_season_ranking = await self.data.item.get_friend_season_ranking(data["userId"]) if friend_season_ranking is None: return { "userId": data["userId"], @@ -474,7 +474,7 @@ class Mai2DX(Mai2Base): } async def handle_get_user_map_api_request(self, data: Dict) -> Dict: - maps = self.data.item.get_maps(data["userId"]) + maps = await self.data.item.get_maps(data["userId"]) if maps is None: return { "userId": data["userId"], @@ -507,7 +507,7 @@ class Mai2DX(Mai2Base): } async def handle_get_user_login_bonus_api_request(self, data: Dict) -> Dict: - login_bonuses = self.data.item.get_login_bonuses(data["userId"]) + login_bonuses = await self.data.item.get_login_bonuses(data["userId"]) if login_bonuses is None: return { "userId": data["userId"], @@ -588,7 +588,7 @@ class Mai2DX(Mai2Base): self.logger.warning("handle_get_user_music_api_request: Could not find userid in data, or userId is 0") return {} - songs = self.data.score.get_best_scores(user_id) + songs = await self.data.score.get_best_scores(user_id) if songs is None: self.logger.debug("handle_get_user_music_api_request: get_best_scores returned None!") return { diff --git a/titles/mai2/read.py b/titles/mai2/read.py index cc4f678..d9450ac 100644 --- a/titles/mai2/read.py +++ b/titles/mai2/read.py @@ -35,7 +35,7 @@ class Mai2Reader(BaseReader): self.logger.error(f"Invalid maimai DX version {version}") exit(1) - def read(self) -> None: + async def read(self) -> None: data_dirs = [] if self.version >= Mai2Constants.VER_MAIMAI_DX: if self.bin_dir is not None: @@ -46,10 +46,10 @@ class Mai2Reader(BaseReader): for dir in data_dirs: self.logger.info(f"Read from {dir}") - self.get_events(f"{dir}/event") - self.disable_events(f"{dir}/information", f"{dir}/scoreRanking") - self.read_music(f"{dir}/music") - self.read_tickets(f"{dir}/ticket") + await self.get_events(f"{dir}/event") + await self.disable_events(f"{dir}/information", f"{dir}/scoreRanking") + await self.read_music(f"{dir}/music") + await self.read_tickets(f"{dir}/ticket") else: if not os.path.exists(f"{self.bin_dir}/tables"): @@ -70,16 +70,16 @@ class Mai2Reader(BaseReader): txt_table = self.load_table_raw(f"{self.bin_dir}/tables", "mmtextout_jp.bin", key) score_table = self.load_table_raw(f"{self.bin_dir}/tables", "mmScore.bin", key) - self.read_old_events(evt_table) - self.read_old_music(score_table, txt_table) + await self.read_old_events(evt_table) + await self.read_old_music(score_table, txt_table) if self.opt_dir is not None: evt_table = self.load_table_raw(f"{self.opt_dir}/tables", "mmEvent.bin", key) txt_table = self.load_table_raw(f"{self.opt_dir}/tables", "mmtextout_jp.bin", key) score_table = self.load_table_raw(f"{self.opt_dir}/tables", "mmScore.bin", key) - self.read_old_events(evt_table) - self.read_old_music(score_table, txt_table) + await self.read_old_events(evt_table) + await self.read_old_music(score_table, txt_table) return @@ -179,7 +179,7 @@ class Mai2Reader(BaseReader): self.logger.warning("Failed load table content, skipping") return - def get_events(self, base_dir: str) -> None: + async def get_events(self, base_dir: str) -> None: self.logger.info(f"Reading events from {base_dir}...") for root, dirs, files in os.walk(base_dir): @@ -192,12 +192,12 @@ class Mai2Reader(BaseReader): id = int(troot.find("name").find("id").text) event_type = int(troot.find("infoType").text) - self.data.static.put_game_event( + await self.data.static.put_game_event( self.version, event_type, id, name ) self.logger.info(f"Added event {id}...") - def disable_events( + async def disable_events( self, base_information_dir: str, base_score_ranking_dir: str ) -> None: self.logger.info(f"Reading disabled events from {base_information_dir}...") @@ -210,7 +210,7 @@ class Mai2Reader(BaseReader): event_id = int(troot.find("name").find("id").text) - self.data.static.toggle_game_event( + await self.data.static.toggle_game_event( self.version, event_id, toggle=False ) self.logger.info(f"Disabled event {event_id}...") @@ -223,7 +223,7 @@ class Mai2Reader(BaseReader): event_id = int(troot.find("eventName").find("id").text) - self.data.static.toggle_game_event( + await self.data.static.toggle_game_event( self.version, event_id, toggle=False ) self.logger.info(f"Disabled event {event_id}...") @@ -252,10 +252,10 @@ class Mai2Reader(BaseReader): 22091518, 22091519, ]: - self.data.static.toggle_game_event(self.version, event_id, toggle=False) + await self.data.static.toggle_game_event(self.version, event_id, toggle=False) self.logger.info(f"Disabled event {event_id}...") - def read_music(self, base_dir: str) -> None: + async def read_music(self, base_dir: str) -> None: self.logger.info(f"Reading music from {base_dir}...") for root, dirs, files in os.walk(base_dir): @@ -285,7 +285,7 @@ class Mai2Reader(BaseReader): dif.find("notesDesigner").find("str").text ) - self.data.static.put_game_music( + await self.data.static.put_game_music( self.version, song_id, chart_id, @@ -302,7 +302,7 @@ class Mai2Reader(BaseReader): f"Added music id {song_id} chart {chart_id}" ) - def read_tickets(self, base_dir: str) -> None: + async def read_tickets(self, base_dir: str) -> None: self.logger.info(f"Reading tickets from {base_dir}...") for root, dirs, files in os.walk(base_dir): @@ -316,12 +316,12 @@ class Mai2Reader(BaseReader): ticket_type = int(troot.find("ticketKind").find("id").text) price = int(troot.find("creditNum").text) - self.data.static.put_game_ticket( + await self.data.static.put_game_ticket( self.version, id, ticket_type, price, name ) self.logger.info(f"Added ticket {id}...") - def read_old_events(self, events: Optional[List[Dict[str, str]]]) -> None: + async def read_old_events(self, events: Optional[List[Dict[str, str]]]) -> None: if events is None: return @@ -332,12 +332,12 @@ class Mai2Reader(BaseReader): is_aou = bool(int(event.get('AOU許可', '0'))) name = event.get('comment', f'evt_{evt_id}') - self.data.static.put_game_event(self.version, 0, evt_id, name) + await self.data.static.put_game_event(self.version, 0, evt_id, name) if not (is_exp or is_aou): - self.data.static.toggle_game_event(self.version, evt_id, False) + await self.data.static.toggle_game_event(self.version, evt_id, False) - def read_old_music(self, scores: Optional[List[Dict[str, str]]], text: Optional[List[Dict[str, str]]]) -> None: + async def read_old_music(self, scores: Optional[List[Dict[str, str]]], text: Optional[List[Dict[str, str]]]) -> None: if scores is None or text is None: return # TODO diff --git a/titles/mai2/schema/item.py b/titles/mai2/schema/item.py index a6ed876..9aaf592 100644 --- a/titles/mai2/schema/item.py +++ b/titles/mai2/schema/item.py @@ -186,7 +186,7 @@ print_detail = Table( class Mai2ItemData(BaseData): - def put_item( + async def put_item( self, user_id: int, item_kind: int, item_id: int, stock: int, is_valid: bool ) -> None: sql = insert(item).values( @@ -202,7 +202,7 @@ class Mai2ItemData(BaseData): isValid=is_valid, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_item: failed to insert item! user_id: {user_id}, item_kind: {item_kind}, item_id: {item_id}" @@ -210,7 +210,7 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_items(self, user_id: int, item_kind: int = None) -> Optional[List[Row]]: + async def get_items(self, user_id: int, item_kind: int = None) -> Optional[List[Row]]: if item_kind is None: sql = item.select(item.c.user == user_id) else: @@ -218,12 +218,12 @@ class Mai2ItemData(BaseData): and_(item.c.user == user_id, item.c.itemKind == item_kind) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_item(self, user_id: int, item_kind: int, item_id: int) -> Optional[Row]: + async def get_item(self, user_id: int, item_kind: int, item_id: int) -> Optional[Row]: sql = item.select( and_( item.c.user == user_id, @@ -232,12 +232,12 @@ class Mai2ItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_login_bonus( + async def put_login_bonus( self, user_id: int, bonus_id: int, @@ -259,7 +259,7 @@ class Mai2ItemData(BaseData): isComplete=is_complete, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_login_bonus: failed to insert item! user_id: {user_id}, bonus_id: {bonus_id}, point: {point}" @@ -267,25 +267,25 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_login_bonuses(self, user_id: int) -> Optional[List[Row]]: + async def get_login_bonuses(self, user_id: int) -> Optional[List[Row]]: sql = login_bonus.select(login_bonus.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_login_bonus(self, user_id: int, bonus_id: int) -> Optional[Row]: + async def get_login_bonus(self, user_id: int, bonus_id: int) -> Optional[Row]: sql = login_bonus.select( and_(login_bonus.c.user == user_id, login_bonus.c.bonus_id == bonus_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_map( + async def put_map( self, user_id: int, map_id: int, @@ -310,7 +310,7 @@ class Mai2ItemData(BaseData): isComplete=is_complete, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_map: failed to insert item! user_id: {user_id}, map_id: {map_id}, distance: {distance}" @@ -318,28 +318,28 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_maps(self, user_id: int) -> Optional[List[Row]]: + async def get_maps(self, user_id: int) -> Optional[List[Row]]: sql = map.select(map.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_map(self, user_id: int, map_id: int) -> Optional[Row]: + async def get_map(self, user_id: int, map_id: int) -> Optional[Row]: sql = map.select(and_(map.c.user == user_id, map.c.mapId == map_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_character_(self, user_id: int, char_data: Dict) -> Optional[int]: + async def put_character_(self, user_id: int, char_data: Dict) -> Optional[int]: char_data["user"] = user_id sql = insert(character).values(**char_data) conflict = sql.on_duplicate_key_update(**char_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_character_: failed to insert item! user_id: {user_id}" @@ -347,7 +347,7 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def put_character( + async def put_character( self, user_id: int, character_id: int, @@ -369,7 +369,7 @@ class Mai2ItemData(BaseData): useCount=use_count, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_character: failed to insert item! user_id: {user_id}, character_id: {character_id}, level: {level}" @@ -377,33 +377,33 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_characters(self, user_id: int) -> Optional[List[Row]]: + async def get_characters(self, user_id: int) -> Optional[List[Row]]: sql = character.select(character.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_character(self, user_id: int, character_id: int) -> Optional[Row]: + async def get_character(self, user_id: int, character_id: int) -> Optional[Row]: sql = character.select( and_(character.c.user == user_id, character.c.character_id == character_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_friend_season_ranking(self, user_id: int) -> Optional[Row]: + async def get_friend_season_ranking(self, user_id: int) -> Optional[Row]: sql = friend_season_ranking.select(friend_season_ranking.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_friend_season_ranking( + async def put_friend_season_ranking( self, aime_id: int, friend_season_ranking_data: Dict ) -> Optional[int]: sql = insert(friend_season_ranking).values( @@ -411,7 +411,7 @@ class Mai2ItemData(BaseData): ) conflict = sql.on_duplicate_key_update(**friend_season_ranking_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -421,7 +421,7 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def put_favorite( + async def put_favorite( self, user_id: int, kind: int, item_id_list: List[int] ) -> Optional[int]: sql = insert(favorite).values( @@ -430,7 +430,7 @@ class Mai2ItemData(BaseData): conflict = sql.on_duplicate_key_update(item_id_list=item_id_list) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_favorite: failed to insert item! user_id: {user_id}, kind: {kind}" @@ -438,7 +438,7 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_favorites(self, user_id: int, kind: int = None) -> Optional[Row]: + async def get_favorites(self, user_id: int, kind: int = None) -> Optional[Row]: if kind is None: sql = favorite.select(favorite.c.user == user_id) else: @@ -446,12 +446,12 @@ class Mai2ItemData(BaseData): and_(favorite.c.user == user_id, favorite.c.itemKind == kind) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_card( + async def put_card( self, user_id: int, card_type_id: int, @@ -475,7 +475,7 @@ class Mai2ItemData(BaseData): charaId=chara_id, mapId=map_id, startDate=start_date, endDate=end_date ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_card: failed to insert card! user_id: {user_id}, kind: {card_kind}" @@ -483,7 +483,7 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_cards(self, user_id: int, kind: int = None) -> Optional[Row]: + async def get_cards(self, user_id: int, kind: int = None) -> Optional[Row]: if kind is None: sql = card.select(card.c.user == user_id) else: @@ -491,12 +491,12 @@ class Mai2ItemData(BaseData): sql = sql.order_by(card.c.startDate.desc()) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_charge( + async def put_charge( self, user_id: int, charge_id: int, @@ -516,7 +516,7 @@ class Mai2ItemData(BaseData): stock=stock, purchaseDate=purchase_date, validDate=valid_date ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_card: failed to insert charge! user_id: {user_id}, chargeId: {charge_id}" @@ -524,15 +524,15 @@ class Mai2ItemData(BaseData): return None return result.lastrowid - def get_charges(self, user_id: int) -> Optional[Row]: + async def get_charges(self, user_id: int) -> Optional[Row]: sql = charge.select(charge.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_user_print_detail( + async def put_user_print_detail( self, aime_id: int, serial_id: str, user_print_data: Dict ) -> Optional[int]: sql = insert(print_detail).values( @@ -540,7 +540,7 @@ class Mai2ItemData(BaseData): ) conflict = sql.on_duplicate_key_update(**user_print_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( diff --git a/titles/mai2/schema/profile.py b/titles/mai2/schema/profile.py index 211440d..b4cdbd8 100644 --- a/titles/mai2/schema/profile.py +++ b/titles/mai2/schema/profile.py @@ -491,7 +491,7 @@ consec_logins = Table( class Mai2ProfileData(BaseData): - def put_profile_detail( + async def put_profile_detail( self, user_id: int, version: int, detail_data: Dict, is_dx: bool = True ) -> Optional[Row]: detail_data["user"] = user_id @@ -504,7 +504,7 @@ class Mai2ProfileData(BaseData): conflict = sql.on_duplicate_key_update(**detail_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile: Failed to create profile! user_id {user_id} is_dx {is_dx}" @@ -512,7 +512,7 @@ class Mai2ProfileData(BaseData): return None return result.lastrowid - def get_profile_detail( + async def get_profile_detail( self, user_id: int, version: int, is_dx: bool = True ) -> Optional[Row]: if is_dx: @@ -531,12 +531,12 @@ class Mai2ProfileData(BaseData): .order_by(detail_old.c.version.desc()) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_ghost( + async def put_profile_ghost( self, user_id: int, version: int, ghost_data: Dict ) -> Optional[int]: ghost_data["user"] = user_id @@ -545,25 +545,25 @@ class Mai2ProfileData(BaseData): sql = insert(ghost).values(**ghost_data) conflict = sql.on_duplicate_key_update(**ghost_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_profile_ghost: failed to update! {user_id}") return None return result.lastrowid - def get_profile_ghost(self, user_id: int, version: int) -> Optional[Row]: + async def get_profile_ghost(self, user_id: int, version: int) -> Optional[Row]: sql = ( select(ghost) .where(and_(ghost.c.user == user_id, ghost.c.version_int <= version)) .order_by(ghost.c.version.desc()) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_extend( + async def put_profile_extend( self, user_id: int, version: int, extend_data: Dict ) -> Optional[int]: extend_data["user"] = user_id @@ -572,25 +572,25 @@ class Mai2ProfileData(BaseData): sql = insert(extend).values(**extend_data) conflict = sql.on_duplicate_key_update(**extend_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_profile_extend: failed to update! {user_id}") return None return result.lastrowid - def get_profile_extend(self, user_id: int, version: int) -> Optional[Row]: + async def get_profile_extend(self, user_id: int, version: int) -> Optional[Row]: sql = ( select(extend) .where(and_(extend.c.user == user_id, extend.c.version <= version)) .order_by(extend.c.version.desc()) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_option( + async def put_profile_option( self, user_id: int, version: int, option_data: Dict, is_dx: bool = True ) -> Optional[int]: option_data["user"] = user_id @@ -602,7 +602,7 @@ class Mai2ProfileData(BaseData): sql = insert(option_old).values(**option_data) conflict = sql.on_duplicate_key_update(**option_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_option: failed to update! {user_id} is_dx {is_dx}" @@ -610,7 +610,7 @@ class Mai2ProfileData(BaseData): return None return result.lastrowid - def get_profile_option( + async def get_profile_option( self, user_id: int, version: int, is_dx: bool = True ) -> Optional[Row]: if is_dx: @@ -628,12 +628,12 @@ class Mai2ProfileData(BaseData): .order_by(option_old.c.version.desc()) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_rating( + async def put_profile_rating( self, user_id: int, version: int, rating_data: Dict ) -> Optional[int]: rating_data["user"] = user_id @@ -642,25 +642,25 @@ class Mai2ProfileData(BaseData): sql = insert(rating).values(**rating_data) conflict = sql.on_duplicate_key_update(**rating_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_profile_rating: failed to update! {user_id}") return None return result.lastrowid - def get_profile_rating(self, user_id: int, version: int) -> Optional[Row]: + async def get_profile_rating(self, user_id: int, version: int) -> Optional[Row]: sql = ( select(rating) .where(and_(rating.c.user == user_id, rating.c.version <= version)) .order_by(rating.c.version.desc()) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_profile_region(self, user_id: int, region_id: int) -> Optional[int]: + async def put_profile_region(self, user_id: int, region_id: int) -> Optional[int]: sql = insert(region).values( user=user_id, regionId=region_id, @@ -669,21 +669,21 @@ class Mai2ProfileData(BaseData): conflict = sql.on_duplicate_key_update(playCount=region.c.playCount + 1) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_region: failed to update! {user_id}") return None return result.lastrowid - def get_regions(self, user_id: int) -> Optional[List[Dict]]: + async def get_regions(self, user_id: int) -> Optional[List[Dict]]: sql = select(region).where(region.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_profile_activity(self, user_id: int, activity_data: Dict) -> Optional[int]: + async def put_profile_activity(self, user_id: int, activity_data: Dict) -> Optional[int]: if "id" in activity_data: activity_data["activityId"] = activity_data["id"] activity_data.pop("id") @@ -694,7 +694,7 @@ class Mai2ProfileData(BaseData): conflict = sql.on_duplicate_key_update(**activity_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_activity: failed to update! user_id: {user_id}" @@ -702,7 +702,7 @@ class Mai2ProfileData(BaseData): return None return result.lastrowid - def get_profile_activity( + async def get_profile_activity( self, user_id: int, kind: int = None ) -> Optional[List[Row]]: sql = activity.select( @@ -712,12 +712,12 @@ class Mai2ProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_web_option( + async def put_web_option( self, user_id: int, version: int, web_opts: Dict ) -> Optional[int]: web_opts["user"] = user_id @@ -726,29 +726,29 @@ class Mai2ProfileData(BaseData): conflict = sql.on_duplicate_key_update(**web_opts) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_web_option: failed to update! user_id: {user_id}") return None return result.lastrowid - def get_web_option(self, user_id: int, version: int) -> Optional[Row]: + async def get_web_option(self, user_id: int, version: int) -> Optional[Row]: sql = web_opt.select( and_(web_opt.c.user == user_id, web_opt.c.version == version) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_grade_status(self, user_id: int, grade_stat: Dict) -> Optional[int]: + async def put_grade_status(self, user_id: int, grade_stat: Dict) -> Optional[int]: grade_stat["user"] = user_id sql = insert(grade_status).values(**grade_stat) conflict = sql.on_duplicate_key_update(**grade_stat) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_grade_status: failed to update! user_id: {user_id}" @@ -756,40 +756,40 @@ class Mai2ProfileData(BaseData): return None return result.lastrowid - def get_grade_status(self, user_id: int) -> Optional[Row]: + async def get_grade_status(self, user_id: int) -> Optional[Row]: sql = grade_status.select(grade_status.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_boss_list(self, user_id: int, boss_stat: Dict) -> Optional[int]: + async def put_boss_list(self, user_id: int, boss_stat: Dict) -> Optional[int]: boss_stat["user"] = user_id sql = insert(boss).values(**boss_stat) conflict = sql.on_duplicate_key_update(**boss_stat) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_boss_list: failed to update! user_id: {user_id}") return None return result.lastrowid - def get_boss_list(self, user_id: int) -> Optional[Row]: + async def get_boss_list(self, user_id: int) -> Optional[Row]: sql = boss.select(boss.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_recent_rating(self, user_id: int, rr: Dict) -> Optional[int]: + async def put_recent_rating(self, user_id: int, rr: Dict) -> Optional[int]: sql = insert(recent_rating).values(user=user_id, userRecentRatingList=rr) conflict = sql.on_duplicate_key_update({"userRecentRatingList": rr}) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_recent_rating: failed to update! user_id: {user_id}" @@ -797,26 +797,26 @@ class Mai2ProfileData(BaseData): return None return result.lastrowid - def get_recent_rating(self, user_id: int) -> Optional[Row]: + async def get_recent_rating(self, user_id: int) -> Optional[Row]: sql = recent_rating.select(recent_rating.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def add_consec_login(self, user_id: int, version: int) -> None: + async def add_consec_login(self, user_id: int, version: int) -> None: sql = insert(consec_logins).values(user=user_id, version=version, logins=1) conflict = sql.on_duplicate_key_update(logins=consec_logins.c.logins + 1) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"Failed to update consecutive login count for user {user_id} version {version}" ) - def get_consec_login(self, user_id: int, version: int) -> Optional[Row]: + async def get_consec_login(self, user_id: int, version: int) -> Optional[Row]: sql = select(consec_logins).where( and_( consec_logins.c.user == user_id, @@ -824,12 +824,12 @@ class Mai2ProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def reset_consec_login(self, user_id: int, version: int) -> Optional[Row]: + async def reset_consec_login(self, user_id: int, version: int) -> Optional[Row]: sql = consec_logins.update( and_( consec_logins.c.user == user_id, @@ -837,7 +837,7 @@ class Mai2ProfileData(BaseData): ) ).values(logins=1) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/mai2/schema/score.py b/titles/mai2/schema/score.py index 181a895..51dcc18 100644 --- a/titles/mai2/schema/score.py +++ b/titles/mai2/schema/score.py @@ -273,7 +273,7 @@ best_score_old = Table( ) class Mai2ScoreData(BaseData): - def put_best_score(self, user_id: int, score_data: Dict, is_dx: bool = True) -> Optional[int]: + async def put_best_score(self, user_id: int, score_data: Dict, is_dx: bool = True) -> Optional[int]: score_data["user"] = user_id if is_dx: @@ -282,7 +282,7 @@ class Mai2ScoreData(BaseData): sql = insert(best_score_old).values(**score_data) conflict = sql.on_duplicate_key_update(**score_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"put_best_score: Failed to insert best score! user_id {user_id} is_dx {is_dx}" @@ -291,7 +291,7 @@ class Mai2ScoreData(BaseData): return result.lastrowid @cached(2) - def get_best_scores(self, user_id: int, song_id: int = None, is_dx: bool = True) -> Optional[List[Row]]: + async def get_best_scores(self, user_id: int, song_id: int = None, is_dx: bool = True) -> Optional[List[Row]]: if is_dx: sql = best_score.select( and_( @@ -307,12 +307,12 @@ class Mai2ScoreData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_best_score( + async def get_best_score( self, user_id: int, song_id: int, chart_id: int ) -> Optional[Row]: sql = best_score.select( @@ -323,12 +323,12 @@ class Mai2ScoreData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_playlog(self, user_id: int, playlog_data: Dict, is_dx: bool = True) -> Optional[int]: + async def put_playlog(self, user_id: int, playlog_data: Dict, is_dx: bool = True) -> Optional[int]: playlog_data["user"] = user_id if is_dx: @@ -338,28 +338,28 @@ class Mai2ScoreData(BaseData): conflict = sql.on_duplicate_key_update(**playlog_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"put_playlog: Failed to insert! user_id {user_id} is_dx {is_dx}") return None return result.lastrowid - def put_course(self, user_id: int, course_data: Dict) -> Optional[int]: + async def put_course(self, user_id: int, course_data: Dict) -> Optional[int]: course_data["user"] = user_id sql = insert(course).values(**course_data) conflict = sql.on_duplicate_key_update(**course_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"put_course: Failed to insert! user_id {user_id}") return None return result.lastrowid - def get_courses(self, user_id: int) -> Optional[List[Row]]: + async def get_courses(self, user_id: int) -> Optional[List[Row]]: sql = course.select(course.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/titles/mai2/schema/static.py b/titles/mai2/schema/static.py index 0f5bfad..e33e4ec 100644 --- a/titles/mai2/schema/static.py +++ b/titles/mai2/schema/static.py @@ -72,7 +72,7 @@ cards = Table( class Mai2StaticData(BaseData): - def put_game_event( + async def put_game_event( self, version: int, type: int, event_id: int, name: str ) -> Optional[int]: sql = insert(event).values( @@ -84,46 +84,46 @@ class Mai2StaticData(BaseData): conflict = sql.on_duplicate_key_update(eventId=event_id) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_game_event: Failed to insert event! event_id {event_id} type {type} name {name}" ) return result.lastrowid - def get_game_events(self, version: int) -> Optional[List[Row]]: + async def get_game_events(self, version: int) -> Optional[List[Row]]: sql = event.select(event.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_enabled_events(self, version: int) -> Optional[List[Row]]: + async def get_enabled_events(self, version: int) -> Optional[List[Row]]: sql = select(event).where( and_(event.c.version == version, event.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def toggle_game_event( + async def toggle_game_event( self, version: int, event_id: int, toggle: bool ) -> Optional[List]: sql = event.update( and_(event.c.version == version, event.c.eventId == event_id) ).values(enabled=int(toggle)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning( f"toggle_game_event: Failed to update event! event_id {event_id} toggle {toggle}" ) return result.last_updated_params() - def put_game_music( + async def put_game_music( self, version: int, song_id: int, @@ -159,13 +159,13 @@ class Mai2StaticData(BaseData): noteDesigner=note_designer, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert song {song_id} chart {chart_id}") return None return result.lastrowid - def put_game_ticket( + async def put_game_ticket( self, version: int, ticket_id: int, @@ -185,13 +185,13 @@ class Mai2StaticData(BaseData): conflict = sql.on_duplicate_key_update(price=ticket_price) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert charge {ticket_id} type {ticket_type}") return None return result.lastrowid - def get_enabled_tickets( + async def get_enabled_tickets( self, version: int, kind: int = None ) -> Optional[List[Row]]: if kind is not None: @@ -207,12 +207,12 @@ class Mai2StaticData(BaseData): and_(ticket.c.version == version, ticket.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_music_chart( + async def get_music_chart( self, version: int, song_id: int, chart_id: int ) -> Optional[List[Row]]: sql = select(music).where( @@ -223,28 +223,28 @@ class Mai2StaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_card(self, version: int, card_id: int, card_name: str, **card_data) -> int: + async def put_card(self, version: int, card_id: int, card_name: str, **card_data) -> int: sql = insert(cards).values( version=version, cardId=card_id, cardName=card_name, **card_data ) conflict = sql.on_duplicate_key_update(**card_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert card {card_id}") return None return result.lastrowid - def get_enabled_cards(self, version: int) -> Optional[List[Row]]: + async def get_enabled_cards(self, version: int) -> Optional[List[Row]]: sql = cards.select(and_(cards.c.version == version, cards.c.enabled == True)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/titles/mai2/universe.py b/titles/mai2/universe.py index a8d5b46..774ea60 100644 --- a/titles/mai2/universe.py +++ b/titles/mai2/universe.py @@ -16,7 +16,7 @@ class Mai2Universe(Mai2SplashPlus): self.version = Mai2Constants.VER_MAIMAI_DX_UNIVERSE async def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_detail(data["userId"], self.version) + p = await self.data.profile.get_profile_detail(data["userId"], self.version) if p is None: return {} @@ -32,9 +32,9 @@ class Mai2Universe(Mai2SplashPlus): async def handle_cm_get_user_data_api_request(self, data: Dict) -> Dict: # user already exists, because the preview checks that already - p = self.data.profile.get_profile_detail(data["userId"], self.version) + p = await self.data.profile.get_profile_detail(data["userId"], self.version) - cards = self.data.card.get_user_cards(data["userId"]) + cards = await self.data.card.get_user_cards(data["userId"]) if cards is None or len(cards) == 0: # This should never happen self.logger.error( @@ -59,7 +59,7 @@ class Mai2Universe(Mai2SplashPlus): return {"returnCode": 1} async def handle_cm_get_selling_card_api_request(self, data: Dict) -> Dict: - selling_cards = self.data.static.get_enabled_cards(self.version) + selling_cards = await self.data.static.get_enabled_cards(self.version) if selling_cards is None: return {"length": 0, "sellingCardList": []} @@ -89,7 +89,7 @@ class Mai2Universe(Mai2SplashPlus): return {"length": len(selling_card_list), "sellingCardList": selling_card_list} async def handle_cm_get_user_card_api_request(self, data: Dict) -> Dict: - user_cards = self.data.item.get_cards(data["userId"]) + user_cards = await self.data.item.get_cards(data["userId"]) if user_cards is None: return {"returnCode": 1, "length": 0, "nextIndex": 0, "userCardList": []} @@ -128,7 +128,7 @@ class Mai2Universe(Mai2SplashPlus): super().handle_get_user_item_api_request(data) async def handle_cm_get_user_character_api_request(self, data: Dict) -> Dict: - characters = self.data.item.get_characters(data["userId"]) + characters = await self.data.item.get_characters(data["userId"]) chara_list = [] for chara in characters: @@ -168,7 +168,7 @@ class Mai2Universe(Mai2SplashPlus): end_date = datetime.utcnow() + timedelta(days=15) user_card = upsert["userCard"] - self.data.item.put_card( + await self.data.item.put_card( user_id, user_card["cardId"], user_card["cardTypeId"], @@ -180,7 +180,7 @@ class Mai2Universe(Mai2SplashPlus): ) # get the profile extend to save the new bought card - extend = self.data.profile.get_profile_extend(user_id, self.version) + extend = await self.data.profile.get_profile_extend(user_id, self.version) if extend: extend = extend._asdict() # parse the selectedCardList @@ -192,14 +192,14 @@ class Mai2Universe(Mai2SplashPlus): selected_cards.insert(0, user_card["cardTypeId"]) extend["selectedCardList"] = selected_cards - self.data.profile.put_profile_extend(user_id, self.version, extend) + await self.data.profile.put_profile_extend(user_id, self.version, extend) # properly format userPrintDetail for the database upsert.pop("userCard") upsert.pop("serialId") upsert["printDate"] = datetime.strptime(upsert["printDate"], "%Y-%m-%d") - self.data.item.put_user_print_detail(user_id, serial_id, upsert) + await self.data.item.put_user_print_detail(user_id, serial_id, upsert) return { "returnCode": 1, diff --git a/titles/ongeki/base.py b/titles/ongeki/base.py index 2d50184..0ade9da 100644 --- a/titles/ongeki/base.py +++ b/titles/ongeki/base.py @@ -157,7 +157,7 @@ class OngekiBase: return {"type": data["type"], "length": 0, "gameIdlistList": []} async def handle_get_game_ranking_api_request(self, data: Dict) -> Dict: - game_ranking_list = self.data.static.get_ranking_list(self.version) + game_ranking_list = await self.data.static.get_ranking_list(self.version) ranking_list = [] for music in game_ranking_list: @@ -172,13 +172,13 @@ class OngekiBase: } async def handle_get_game_point_api_request(self, data: Dict) -> Dict: - get_game_point = self.data.static.get_static_game_point() + get_game_point = await self.data.static.get_static_game_point() game_point = [] if not get_game_point: self.logger.info(f"GP table is empty, inserting defaults") - self.data.static.put_static_game_point_defaults() - get_game_point = self.data.static.get_static_game_point() + await self.data.static.put_static_game_point_defaults() + get_game_point = await self.data.static.get_static_game_point() for gp in get_game_point: tmp = gp._asdict() game_point.append(tmp) @@ -204,7 +204,7 @@ class OngekiBase: return {"returnCode": 1, "apiName": "ExtendLockTimeApi"} async def handle_get_game_reward_api_request(self, data: Dict) -> Dict: - get_game_rewards = self.data.static.get_reward_list(self.version) + get_game_rewards = await self.data.static.get_reward_list(self.version) reward_list = [] for reward in get_game_rewards: @@ -222,7 +222,7 @@ class OngekiBase: } async def handle_get_game_present_api_request(self, data: Dict) -> Dict: - get_present = self.data.static.get_present_list(self.version) + get_present = await self.data.static.get_present_list(self.version) present_list = [] for present in get_present: @@ -245,7 +245,7 @@ class OngekiBase: return {"length": 0, "gameSaleList": []} async def handle_get_game_tech_music_api_request(self, data: Dict) -> Dict: - music_list = self.data.static.get_tech_music(self.version) + music_list = await self.data.static.get_tech_music(self.version) prep_music_list = [] for music in music_list: @@ -268,9 +268,9 @@ class OngekiBase: client_id = data["clientId"] client_setting_data = data["clientSetting"] - cab = self.data.arcade.get_machine(client_id) + cab = await self.data.arcade.get_machine(client_id) if cab is not None: - self.data.static.put_client_setting_data(cab['id'], client_setting_data) + await self.data.static.put_client_setting_data(cab['id'], client_setting_data) return {"returnCode": 1, "apiName": "UpsertClientSettingApi"} async def handle_upsert_client_testmode_api_request(self, data: Dict) -> Dict: @@ -279,7 +279,7 @@ class OngekiBase: region_id = data["regionId"] client_testmode_data = data["clientTestmode"] - self.data.static.put_client_testmode_data(region_id, client_testmode_data) + await self.data.static.put_client_testmode_data(region_id, client_testmode_data) return {"returnCode": 1, "apiName": "UpsertClientTestmodeApi"} async def handle_upsert_client_bookkeeping_api_request(self, data: Dict) -> Dict: @@ -296,7 +296,7 @@ class OngekiBase: if user >= 200000000000000: # Account for guest play user = None - self.data.log.put_gp_log( + await self.data.log.put_gp_log( user, data["usedCredit"], data["placeName"], @@ -313,7 +313,7 @@ class OngekiBase: return {"returnCode": 1, "apiName": "ExtendLockTimeApi"} async def handle_get_game_event_api_request(self, data: Dict) -> Dict: - evts = self.data.static.get_enabled_events(self.version) + evts = await self.data.static.get_enabled_events(self.version) if evts is None: return { @@ -366,7 +366,7 @@ class OngekiBase: return {"userId": data["userId"], "length": 0, "userRegionList": []} async def handle_get_user_preview_api_request(self, data: Dict) -> Dict: - profile = self.data.profile.get_profile_preview(data["userId"], self.version) + profile = await self.data.profile.get_profile_preview(data["userId"], self.version) if profile is None: return { @@ -422,7 +422,7 @@ class OngekiBase: Gets the number of AB and ABPs a player has per-difficulty (7, 7+, 8, etc) The game sends this in upsert so we don't have to calculate it all out thankfully """ - utcl = self.data.score.get_tech_count(data["userId"]) + utcl = await self.data.score.get_tech_count(data["userId"]) userTechCountList = [] for tc in utcl: @@ -437,7 +437,7 @@ class OngekiBase: } async def handle_get_user_tech_event_api_request(self, data: Dict) -> Dict: - user_tech_event_list = self.data.item.get_tech_event(self.version, data["userId"]) + user_tech_event_list = await self.data.item.get_tech_event(self.version, data["userId"]) if user_tech_event_list is None: return {} @@ -456,7 +456,7 @@ class OngekiBase: } async def handle_get_user_tech_event_ranking_api_request(self, data: Dict) -> Dict: - user_tech_event_ranks = self.data.item.get_tech_event_ranking(self.version, data["userId"]) + user_tech_event_ranks = await self.data.item.get_tech_event_ranking(self.version, data["userId"]) if user_tech_event_ranks is None: return { "userId": data["userId"], @@ -482,7 +482,7 @@ class OngekiBase: } async def handle_get_user_kop_api_request(self, data: Dict) -> Dict: - kop_list = self.data.profile.get_kop(data["userId"]) + kop_list = await self.data.profile.get_kop(data["userId"]) if kop_list is None: return {} @@ -518,7 +518,7 @@ class OngekiBase: async def handle_get_user_item_api_request(self, data: Dict) -> Dict: kind = data["nextIndex"] / 10000000000 - p = self.data.item.get_items(data["userId"], kind) + p = await self.data.item.get_items(data["userId"], kind) if p is None: return { @@ -553,7 +553,7 @@ class OngekiBase: } async def handle_get_user_option_api_request(self, data: Dict) -> Dict: - o = self.data.profile.get_profile_options(data["userId"]) + o = await self.data.profile.get_profile_options(data["userId"]) if o is None: return {} @@ -567,11 +567,11 @@ class OngekiBase: return {"userId": data["userId"], "userOption": user_opts} async def handle_get_user_data_api_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is None: return {} - cards = self.data.card.get_user_cards(data["userId"]) + cards = await self.data.card.get_user_cards(data["userId"]) if cards is None or len(cards) == 0: # This should never happen self.logger.error( @@ -595,7 +595,7 @@ class OngekiBase: return {"userId": data["userId"], "userData": user_data} async def handle_get_user_event_ranking_api_request(self, data: Dict) -> Dict: - user_event_ranking_list = self.data.item.get_ranking_event_ranks(self.version, data["userId"]) + user_event_ranking_list = await self.data.item.get_ranking_event_ranks(self.version, data["userId"]) if user_event_ranking_list is None: return {} @@ -618,7 +618,7 @@ class OngekiBase: } async def handle_get_user_login_bonus_api_request(self, data: Dict) -> Dict: - user_login_bonus_list = self.data.item.get_login_bonuses(data["userId"]) + user_login_bonus_list = await self.data.item.get_login_bonuses(data["userId"]) if user_login_bonus_list is None: return {} @@ -636,7 +636,7 @@ class OngekiBase: } async def handle_get_user_bp_base_request(self, data: Dict) -> Dict: - p = self.data.profile.get_profile( + p = await self.data.profile.get_profile( self.game, self.version, user_id=data["userId"] ) if p is None: @@ -649,7 +649,7 @@ class OngekiBase: } async def handle_get_user_recent_rating_api_request(self, data: Dict) -> Dict: - recent_rating = self.data.profile.get_profile_recent_rating(data["userId"]) + recent_rating = await self.data.profile.get_profile_recent_rating(data["userId"]) if recent_rating is None: return { "userId": data["userId"], @@ -666,7 +666,7 @@ class OngekiBase: } async def handle_get_user_activity_api_request(self, data: Dict) -> Dict: - activity = self.data.profile.get_profile_activity(data["userId"], data["kind"]) + activity = await self.data.profile.get_profile_activity(data["userId"], data["kind"]) if activity is None: return {} @@ -693,7 +693,7 @@ class OngekiBase: } async def handle_get_user_story_api_request(self, data: Dict) -> Dict: - user_stories = self.data.item.get_stories(data["userId"]) + user_stories = await self.data.item.get_stories(data["userId"]) if user_stories is None: return {} @@ -711,7 +711,7 @@ class OngekiBase: } async def handle_get_user_chapter_api_request(self, data: Dict) -> Dict: - user_chapters = self.data.item.get_chapters(data["userId"]) + user_chapters = await self.data.item.get_chapters(data["userId"]) if user_chapters is None: return {} @@ -736,7 +736,7 @@ class OngekiBase: } async def handle_get_user_character_api_request(self, data: Dict) -> Dict: - user_characters = self.data.item.get_characters(data["userId"]) + user_characters = await self.data.item.get_characters(data["userId"]) if user_characters is None: return {} @@ -754,7 +754,7 @@ class OngekiBase: } async def handle_get_user_card_api_request(self, data: Dict) -> Dict: - user_cards = self.data.item.get_cards(data["userId"]) + user_cards = await self.data.item.get_cards(data["userId"]) if user_cards is None: return {} @@ -773,7 +773,7 @@ class OngekiBase: async def handle_get_user_deck_by_key_api_request(self, data: Dict) -> Dict: # Auth key doesn't matter, it just wants all the decks - decks = self.data.item.get_decks(data["userId"]) + decks = await self.data.item.get_decks(data["userId"]) if decks is None: return {} @@ -791,7 +791,7 @@ class OngekiBase: } async def handle_get_user_trade_item_api_request(self, data: Dict) -> Dict: - user_trade_items = self.data.item.get_trade_items(data["userId"]) + user_trade_items = await self.data.item.get_trade_items(data["userId"]) if user_trade_items is None: return {} @@ -809,7 +809,7 @@ class OngekiBase: } async def handle_get_user_scenario_api_request(self, data: Dict) -> Dict: - user_scenerio = self.data.item.get_scenerios(data["userId"]) + user_scenerio = await self.data.item.get_scenerios(data["userId"]) if user_scenerio is None: return {} @@ -827,7 +827,7 @@ class OngekiBase: } async def handle_get_user_ratinglog_api_request(self, data: Dict) -> Dict: - rating_log = self.data.profile.get_profile_rating_log(data["userId"]) + rating_log = await self.data.profile.get_profile_rating_log(data["userId"]) if rating_log is None: return {} @@ -845,7 +845,7 @@ class OngekiBase: } async def handle_get_user_mission_point_api_request(self, data: Dict) -> Dict: - user_mission_point_list = self.data.item.get_mission_points(self.version, data["userId"]) + user_mission_point_list = await self.data.item.get_mission_points(self.version, data["userId"]) if user_mission_point_list is None: return {} @@ -865,7 +865,7 @@ class OngekiBase: } async def handle_get_user_event_point_api_request(self, data: Dict) -> Dict: - user_event_point_list = self.data.item.get_event_points(data["userId"]) + user_event_point_list = await self.data.item.get_event_points(data["userId"]) if user_event_point_list is None: return {} @@ -887,7 +887,7 @@ class OngekiBase: } async def handle_get_user_music_item_api_request(self, data: Dict) -> Dict: - user_music_item_list = self.data.item.get_music_items(data["userId"]) + user_music_item_list = await self.data.item.get_music_items(data["userId"]) if user_music_item_list is None: return {} @@ -905,7 +905,7 @@ class OngekiBase: } async def handle_get_user_event_music_api_request(self, data: Dict) -> Dict: - user_evt_music_list = self.data.item.get_event_music(data["userId"]) + user_evt_music_list = await self.data.item.get_event_music(data["userId"]) if user_evt_music_list is None: return {} @@ -923,7 +923,7 @@ class OngekiBase: } async def handle_get_user_boss_api_request(self, data: Dict) -> Dict: - p = self.data.item.get_bosses(data["userId"]) + p = await self.data.item.get_bosses(data["userId"]) if p is None: return {} @@ -947,20 +947,20 @@ class OngekiBase: # The isNew fields are new as of Red and up. We just won't use them for now. if "userData" in upsert and len(upsert["userData"]) > 0: - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) if "userOption" in upsert and len(upsert["userOption"]) > 0: - self.data.profile.put_profile_options(user_id, upsert["userOption"][0]) + await self.data.profile.put_profile_options(user_id, upsert["userOption"][0]) if "userPlaylogList" in upsert: for playlog in upsert["userPlaylogList"]: - self.data.score.put_playlog(user_id, playlog) + await self.data.score.put_playlog(user_id, playlog) if "userActivityList" in upsert: for act in upsert["userActivityList"]: - self.data.profile.put_profile_activity( + await self.data.profile.put_profile_activity( user_id, act["kind"], act["id"], @@ -972,101 +972,101 @@ class OngekiBase: ) if "userRecentRatingList" in upsert: - self.data.profile.put_profile_recent_rating( + await self.data.profile.put_profile_recent_rating( user_id, upsert["userRecentRatingList"] ) if "userBpBaseList" in upsert: - self.data.profile.put_profile_bp_list(user_id, upsert["userBpBaseList"]) + await self.data.profile.put_profile_bp_list(user_id, upsert["userBpBaseList"]) if "userMusicDetailList" in upsert: for x in upsert["userMusicDetailList"]: - self.data.score.put_best_score(user_id, x) + await self.data.score.put_best_score(user_id, x) if "userCharacterList" in upsert: for x in upsert["userCharacterList"]: - self.data.item.put_character(user_id, x) + await self.data.item.put_character(user_id, x) if "userCardList" in upsert: for x in upsert["userCardList"]: - self.data.item.put_card(user_id, x) + await self.data.item.put_card(user_id, x) if "userDeckList" in upsert: for x in upsert["userDeckList"]: - self.data.item.put_deck(user_id, x) + await self.data.item.put_deck(user_id, x) if "userTrainingRoomList" in upsert: for x in upsert["userTrainingRoomList"]: - self.data.profile.put_training_room(user_id, x) + await self.data.profile.put_training_room(user_id, x) if "userStoryList" in upsert: for x in upsert["userStoryList"]: - self.data.item.put_story(user_id, x) + await self.data.item.put_story(user_id, x) if "userChapterList" in upsert: for x in upsert["userChapterList"]: - self.data.item.put_chapter(user_id, x) + await self.data.item.put_chapter(user_id, x) if "userMemoryChapterList" in upsert: for x in upsert["userMemoryChapterList"]: - self.data.item.put_memorychapter(user_id, x) + await self.data.item.put_memorychapter(user_id, x) if "userItemList" in upsert: for x in upsert["userItemList"]: - self.data.item.put_item(user_id, x) + await self.data.item.put_item(user_id, x) if "userMusicItemList" in upsert: for x in upsert["userMusicItemList"]: - self.data.item.put_music_item(user_id, x) + await self.data.item.put_music_item(user_id, x) if "userLoginBonusList" in upsert: for x in upsert["userLoginBonusList"]: - self.data.item.put_login_bonus(user_id, x) + await self.data.item.put_login_bonus(user_id, x) if "userEventPointList" in upsert: for x in upsert["userEventPointList"]: - self.data.item.put_event_point(user_id, self.version, x) + await self.data.item.put_event_point(user_id, self.version, x) if "userMissionPointList" in upsert: for x in upsert["userMissionPointList"]: - self.data.item.put_mission_point(user_id, self.version, x) + await self.data.item.put_mission_point(user_id, self.version, x) if "userRatinglogList" in upsert: for x in upsert["userRatinglogList"]: - self.data.profile.put_profile_rating_log( + await self.data.profile.put_profile_rating_log( user_id, x["dataVersion"], x["highestRating"] ) if "userBossList" in upsert: for x in upsert["userBossList"]: - self.data.item.put_boss(user_id, x) + await self.data.item.put_boss(user_id, x) if "userTechCountList" in upsert: for x in upsert["userTechCountList"]: - self.data.score.put_tech_count(user_id, x) + await self.data.score.put_tech_count(user_id, x) if "userScenerioList" in upsert: for x in upsert["userScenerioList"]: - self.data.item.put_scenerio(user_id, x) + await self.data.item.put_scenerio(user_id, x) if "userTradeItemList" in upsert: for x in upsert["userTradeItemList"]: - self.data.item.put_trade_item(user_id, x) + await self.data.item.put_trade_item(user_id, x) if "userEventMusicList" in upsert: for x in upsert["userEventMusicList"]: - self.data.item.put_event_music(user_id, x) + await self.data.item.put_event_music(user_id, x) if "userTechEventList" in upsert: for x in upsert["userTechEventList"]: - self.data.item.put_tech_event(user_id, self.version, x) + await self.data.item.put_tech_event(user_id, self.version, x) # This should be updated once a day in maintenance window, but for time being we will push the update on each upsert - self.data.item.put_tech_event_ranking(user_id, self.version, x) + await self.data.item.put_tech_event_ranking(user_id, self.version, x) if "userKopList" in upsert: for x in upsert["userKopList"]: - self.data.profile.put_kop(user_id, x) + await self.data.profile.put_kop(user_id, x) return {"returnCode": 1, "apiName": "upsertUserAll"} @@ -1076,7 +1076,7 @@ class OngekiBase: """ rival_list = [] - user_rivals = self.data.profile.get_rivals(data["userId"]) + user_rivals = await self.data.profile.get_rivals(data["userId"]) for rival in user_rivals: tmp = {} tmp["rivalUserId"] = rival[0] @@ -1100,7 +1100,7 @@ class OngekiBase: """ rivals = [] for rival in data["userRivalList"]: - name = self.data.profile.get_profile_name( + name = await self.data.profile.get_profile_name( rival["rivalUserId"], self.version ) if name is None: @@ -1135,8 +1135,8 @@ class OngekiBase: } @cached(2) - def util_generate_music_list(self, user_id: int) -> List: - music_detail = self.data.score.get_best_scores(user_id) + async def util_generate_music_list(self, user_id: int) -> List: + music_detail = await self.data.score.get_best_scores(user_id) song_list = [] for md in music_detail: diff --git a/titles/ongeki/bright.py b/titles/ongeki/bright.py index 0af5127..aec9182 100644 --- a/titles/ongeki/bright.py +++ b/titles/ongeki/bright.py @@ -23,11 +23,11 @@ class OngekiBright(OngekiBase): async def handle_cm_get_user_data_api_request(self, data: Dict) -> Dict: # check for a bright profile - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is None: return {} - cards = self.data.card.get_user_cards(data["userId"]) + cards = await self.data.card.get_user_cards(data["userId"]) if cards is None or len(cards) == 0: # This should never happen self.logger.error( @@ -62,7 +62,7 @@ class OngekiBright(OngekiBase): return {"returnCode": 1} async def handle_cm_get_user_card_api_request(self, data: Dict) -> Dict: - user_cards = self.data.item.get_cards(data["userId"]) + user_cards = await self.data.item.get_cards(data["userId"]) if user_cards is None: return {} @@ -91,7 +91,7 @@ class OngekiBright(OngekiBase): } async def handle_cm_get_user_character_api_request(self, data: Dict) -> Dict: - user_characters = self.data.item.get_characters(data["userId"]) + user_characters = await self.data.item.get_characters(data["userId"]) if user_characters is None: return { "userId": data["userId"], @@ -125,7 +125,7 @@ class OngekiBright(OngekiBase): } async def handle_get_user_gacha_api_request(self, data: Dict) -> Dict: - user_gachas = self.data.item.get_user_gachas(data["userId"]) + user_gachas = await self.data.item.get_user_gachas(data["userId"]) if user_gachas is None: return {"userId": data["userId"], "length": 0, "userGachaList": []} @@ -148,7 +148,7 @@ class OngekiBright(OngekiBase): async def handle_cm_get_user_gacha_supply_api_request(self, data: Dict) -> Dict: # not used for now? not sure what it even does - user_gacha_supplies = self.data.item.get_user_gacha_supplies(data["userId"]) + user_gacha_supplies = await self.data.item.get_user_gacha_supplies(data["userId"]) if user_gacha_supplies is None: return {"supplyId": 1, "length": 0, "supplyCardList": []} @@ -168,7 +168,7 @@ class OngekiBright(OngekiBase): game_gachas = [] # for every gacha_id in the OngekiConfig, grab the banner from the db for gacha_id in self.game_cfg.gachas.enabled_gachas: - game_gacha = self.data.static.get_gacha(self.version, gacha_id) + game_gacha = await self.data.static.get_gacha(self.version, gacha_id) if game_gacha: game_gachas.append(game_gacha) @@ -265,26 +265,26 @@ class OngekiBright(OngekiBase): return self.handle_roll_gacha_api_request(data) # get a list of cards for each rarity - cards_r = self.data.static.get_cards_by_rarity(self.version, 1) + cards_r = await self.data.static.get_cards_by_rarity(self.version, 1) cards_sr, cards_ssr = [], [] # free gachas are only allowed to get their specific cards! (R irrelevant) if gacha_id in {1011, 1012}: - gacha_cards = self.data.static.get_gacha_cards(gacha_id) + gacha_cards = await self.data.static.get_gacha_cards(gacha_id) for card in gacha_cards: if card["rarity"] == 3: cards_sr.append({"cardId": card["cardId"], "rarity": 2}) elif card["rarity"] == 4: cards_ssr.append({"cardId": card["cardId"], "rarity": 3}) else: - cards_sr = self.data.static.get_cards_by_rarity(self.version, 2) - cards_ssr = self.data.static.get_cards_by_rarity(self.version, 3) + cards_sr = await self.data.static.get_cards_by_rarity(self.version, 2) + cards_ssr = await self.data.static.get_cards_by_rarity(self.version, 3) # get the promoted cards for that gacha and add them multiple # times to increase chances by factor chances chances = 10 - gacha_cards = self.data.static.get_gacha_cards(gacha_id) + gacha_cards = await self.data.static.get_gacha_cards(gacha_id) for card in gacha_cards: # make sure to add the cards to the corresponding rarity if card["rarity"] == 2: @@ -339,7 +339,7 @@ class OngekiBright(OngekiBase): daily_gacha_date = datetime.strptime("2000-01-01", "%Y-%m-%d") # check if the user previously rolled the exact same gacha - user_gacha = self.data.item.get_user_gacha(user_id, gacha_id) + user_gacha = await self.data.item.get_user_gacha(user_id, gacha_id) if user_gacha: total_gacha_count = user_gacha["totalGachaCnt"] ceiling_gacha_count = user_gacha["ceilingGachaCnt"] @@ -358,7 +358,7 @@ class OngekiBright(OngekiBase): daily_gacha_date = play_date daily_gacha_cnt = 0 - self.data.item.put_user_gacha( + await self.data.item.put_user_gacha( user_id, gacha_id, totalGachaCnt=total_gacha_count + gacha_count, @@ -375,29 +375,29 @@ class OngekiBright(OngekiBase): if "userData" in upsert and len(upsert["userData"]) > 0: # check if the profile is a bright memory profile - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is not None: # save the bright memory profile - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) else: # save the bright profile - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) if "userCharacterList" in upsert: for x in upsert["userCharacterList"]: - self.data.item.put_character(user_id, x) + await self.data.item.put_character(user_id, x) if "userItemList" in upsert: for x in upsert["userItemList"]: - self.data.item.put_item(user_id, x) + await self.data.item.put_item(user_id, x) if "userCardList" in upsert: for x in upsert["userCardList"]: - self.data.item.put_card(user_id, x) + await self.data.item.put_card(user_id, x) # TODO? # if "gameGachaCardList" in upsert: @@ -411,29 +411,29 @@ class OngekiBright(OngekiBase): if "userData" in upsert and len(upsert["userData"]) > 0: # check if the profile is a bright memory profile - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is not None: # save the bright memory profile - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) else: # save the bright profile - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) if "userCharacterList" in upsert: for x in upsert["userCharacterList"]: - self.data.item.put_character(user_id, x) + await self.data.item.put_character(user_id, x) if "userCardList" in upsert: for x in upsert["userCardList"]: - self.data.item.put_card(user_id, x) + await self.data.item.put_card(user_id, x) if "selectGachaLogList" in data: for x in data["selectGachaLogList"]: - self.data.item.put_user_gacha( + await self.data.item.put_user_gacha( user_id, x["gachaId"], selectPoint=0, @@ -443,7 +443,7 @@ class OngekiBright(OngekiBase): return {"returnCode": 1, "apiName": "cmUpsertUserSelectGacha"} async def handle_get_game_gacha_card_by_id_api_request(self, data: Dict) -> Dict: - game_gacha_cards = self.data.static.get_gacha_cards(data["gachaId"]) + game_gacha_cards = await self.data.static.get_gacha_cards(data["gachaId"]) if game_gacha_cards == []: # fallback to be at least able to select that gacha return { @@ -579,7 +579,7 @@ class OngekiBright(OngekiBase): ) # add the entry to the user print table with the random serialId - self.data.item.put_user_print_detail( + await self.data.item.put_user_print_detail( data["userId"], serial_id, user_print_detail ) @@ -595,21 +595,21 @@ class OngekiBright(OngekiBase): if "userData" in upsert and len(upsert["userData"]) > 0: # check if the profile is a bright memory profile - p = self.data.profile.get_profile_data(data["userId"], self.version) + p = await self.data.profile.get_profile_data(data["userId"], self.version) if p is not None: # save the bright memory profile - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) else: # save the bright profile - self.data.profile.put_profile_data( + await self.data.profile.put_profile_data( user_id, self.version, upsert["userData"][0] ) if "userActivityList" in upsert: for act in upsert["userActivityList"]: - self.data.profile.put_profile_activity( + await self.data.profile.put_profile_activity( user_id, act["kind"], act["id"], @@ -622,10 +622,10 @@ class OngekiBright(OngekiBase): if "userItemList" in upsert: for x in upsert["userItemList"]: - self.data.item.put_item(user_id, x) + await self.data.item.put_item(user_id, x) if "userCardList" in upsert: for x in upsert["userCardList"]: - self.data.item.put_card(user_id, x) + await self.data.item.put_card(user_id, x) return {"returnCode": 1, "apiName": "cmUpsertUserAll"} diff --git a/titles/ongeki/brightmemory.py b/titles/ongeki/brightmemory.py index 0bff264..6fdd60a 100644 --- a/titles/ongeki/brightmemory.py +++ b/titles/ongeki/brightmemory.py @@ -28,7 +28,7 @@ class OngekiBrightMemory(OngekiBright): return ret async def handle_get_user_memory_chapter_api_request(self, data: Dict) -> Dict: - memories = self.data.item.get_memorychapters(data["userId"]) + memories = await self.data.item.get_memorychapters(data["userId"]) if not memories: return { "userId": data["userId"], diff --git a/titles/ongeki/frontend.py b/titles/ongeki/frontend.py index 4c17165..c4d875b 100644 --- a/titles/ongeki/frontend.py +++ b/titles/ongeki/frontend.py @@ -28,7 +28,7 @@ class OngekiFrontend(FE_Base): self.nav_name = "O.N.G.E.K.I." self.version_list = OngekiConstants.VERSION_NAMES - def render_GET(self, request: Request) -> bytes: + async def render_GET(self, request: Request) -> bytes: template = self.environment.get_template( "titles/ongeki/frontend/ongeki_index.jinja" ) @@ -37,7 +37,7 @@ class OngekiFrontend(FE_Base): self.version = usr_sesh.ongeki_version if getattr(usr_sesh, "userId", 0) != 0: profile_data =self.data.profile.get_profile_data(usr_sesh.userId, self.version) - rival_list = self.data.profile.get_rivals(usr_sesh.userId) + rival_list = await self.data.profile.get_rivals(usr_sesh.userId) rival_data = { "userRivalList": rival_list, "userId": usr_sesh.userId @@ -58,20 +58,20 @@ class OngekiFrontend(FE_Base): else: return redirectTo(b"/gate/", request) - def render_POST(self, request: Request): + async def render_POST(self, request: Request): uri = request.uri.decode() sesh: Session = request.getSession() usr_sesh = IUserSession(sesh) if hasattr(usr_sesh, "userId"): if uri == "/game/ongeki/rival.add": rival_id = request.args[b"rivalUserId"][0].decode() - self.data.profile.put_rival(usr_sesh.userId, rival_id) + await self.data.profile.put_rival(usr_sesh.userId, rival_id) # self.logger.info(f"{usr_sesh.userId} added a rival") return redirectTo(b"/game/ongeki/", request) elif uri == "/game/ongeki/rival.delete": rival_id = request.args[b"rivalUserId"][0].decode() - self.data.profile.delete_rival(usr_sesh.userId, rival_id) + await self.data.profile.delete_rival(usr_sesh.userId, rival_id) # self.logger.info(f"{response}") return redirectTo(b"/game/ongeki/", request) diff --git a/titles/ongeki/read.py b/titles/ongeki/read.py index 6e94094..a804956 100644 --- a/titles/ongeki/read.py +++ b/titles/ongeki/read.py @@ -1,16 +1,11 @@ -from decimal import Decimal -import logging import os -import re import xml.etree.ElementTree as ET -from typing import Any, Dict, List, Optional +from typing import Optional from read import BaseReader from core.config import CoreConfig from titles.ongeki.database import OngekiData from titles.ongeki.const import OngekiConstants -from titles.ongeki.config import OngekiConfig - class OngekiReader(BaseReader): def __init__( @@ -32,7 +27,7 @@ class OngekiReader(BaseReader): self.logger.error(f"Invalid ongeki version {version}") exit(1) - def read(self) -> None: + async def read(self) -> None: data_dirs = [] if self.bin_dir is not None: data_dirs += self.get_data_directories(self.bin_dir) @@ -41,12 +36,12 @@ class OngekiReader(BaseReader): data_dirs += self.get_data_directories(self.opt_dir) for dir in data_dirs: - self.read_events(f"{dir}/event") - self.read_music(f"{dir}/music") - self.read_card(f"{dir}/card") - self.read_reward(f"{dir}/reward") + await self.read_events(f"{dir}/event") + await self.read_music(f"{dir}/music") + await self.read_card(f"{dir}/card") + await self.read_reward(f"{dir}/reward") - def read_card(self, base_dir: str) -> None: + async def read_card(self, base_dir: str) -> None: self.logger.info(f"Reading cards from {base_dir}...") version_ids = { @@ -70,7 +65,7 @@ class OngekiReader(BaseReader): # skip already existing cards if ( - self.data.static.get_card( + await self.data.static.get_card( OngekiConstants.VER_ONGEKI_BRIGHT_MEMORY, card_id ) is not None @@ -100,7 +95,7 @@ class OngekiReader(BaseReader): version = version_ids[troot.find("VersionID").find("id").text] card_number = troot.find("CardNumberString").text - self.data.static.put_card( + await self.data.static.put_card( version, card_id, name=name, @@ -117,7 +112,7 @@ class OngekiReader(BaseReader): ) self.logger.info(f"Added card {card_id}") - def read_events(self, base_dir: str) -> None: + async def read_events(self, base_dir: str) -> None: self.logger.info(f"Reading events from {base_dir}...") for root, dirs, files in os.walk(base_dir): @@ -132,10 +127,10 @@ class OngekiReader(BaseReader): troot.find("EventType").text ].value - self.data.static.put_event(self.version, id, event_type, name) + await self.data.static.put_event(self.version, id, event_type, name) self.logger.info(f"Added event {id}") - def read_music(self, base_dir: str) -> None: + async def read_music(self, base_dir: str) -> None: self.logger.info(f"Reading music from {base_dir}...") for root, dirs, files in os.walk(base_dir): @@ -168,12 +163,12 @@ class OngekiReader(BaseReader): f"{fumens_data.find('FumenConstIntegerPart').text}.{fumens_data.find('FumenConstFractionalPart').text}" ) - self.data.static.put_chart( + await self.data.static.put_chart( self.version, song_id, chart_id, title, artist, genre, level ) self.logger.info(f"Added song {song_id} chart {chart_id}") - def read_reward(self, base_dir: str) -> None: + async def read_reward(self, base_dir: str) -> None: self.logger.info(f"Reading rewards from {base_dir}...") for root, dirs, files in os.walk(base_dir): @@ -195,5 +190,5 @@ class OngekiReader(BaseReader): itemKind = OngekiConstants.REWARD_TYPES[troot.find("ItemType").text].value itemId = troot.find("RewardItem").find("ItemName").find("id").text - self.data.static.put_reward(self.version, rewardId, rewardname, itemKind, itemId) + await self.data.static.put_reward(self.version, rewardId, rewardname, itemKind, itemId) self.logger.info(f"Added reward {rewardId}") diff --git a/titles/ongeki/schema/item.py b/titles/ongeki/schema/item.py index 55b4c68..ca2de1f 100644 --- a/titles/ongeki/schema/item.py +++ b/titles/ongeki/schema/item.py @@ -339,147 +339,147 @@ print_detail = Table( ) class OngekiItemData(BaseData): - def put_card(self, aime_id: int, card_data: Dict) -> Optional[int]: + async def put_card(self, aime_id: int, card_data: Dict) -> Optional[int]: card_data["user"] = aime_id sql = insert(card).values(**card_data) conflict = sql.on_duplicate_key_update(**card_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_card: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_cards(self, aime_id: int) -> Optional[List[Dict]]: + async def get_cards(self, aime_id: int) -> Optional[List[Dict]]: sql = select(card).where(card.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_character(self, aime_id: int, character_data: Dict) -> Optional[int]: + async def put_character(self, aime_id: int, character_data: Dict) -> Optional[int]: character_data["user"] = aime_id sql = insert(character).values(**character_data) conflict = sql.on_duplicate_key_update(**character_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_character: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_characters(self, aime_id: int) -> Optional[List[Dict]]: + async def get_characters(self, aime_id: int) -> Optional[List[Dict]]: sql = select(character).where(character.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_deck(self, aime_id: int, deck_data: Dict) -> Optional[int]: + async def put_deck(self, aime_id: int, deck_data: Dict) -> Optional[int]: deck_data["user"] = aime_id sql = insert(deck).values(**deck_data) conflict = sql.on_duplicate_key_update(**deck_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_deck: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_deck(self, aime_id: int, deck_id: int) -> Optional[Dict]: + async def get_deck(self, aime_id: int, deck_id: int) -> Optional[Dict]: sql = select(deck).where(and_(deck.c.user == aime_id, deck.c.deckId == deck_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_decks(self, aime_id: int) -> Optional[List[Dict]]: + async def get_decks(self, aime_id: int) -> Optional[List[Dict]]: sql = select(deck).where(deck.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_boss(self, aime_id: int, boss_data: Dict) -> Optional[int]: + async def put_boss(self, aime_id: int, boss_data: Dict) -> Optional[int]: boss_data["user"] = aime_id sql = insert(boss).values(**boss_data) conflict = sql.on_duplicate_key_update(**boss_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_boss: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_story(self, aime_id: int, story_data: Dict) -> Optional[int]: + async def put_story(self, aime_id: int, story_data: Dict) -> Optional[int]: story_data["user"] = aime_id sql = insert(story).values(**story_data) conflict = sql.on_duplicate_key_update(**story_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_story: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_stories(self, aime_id: int) -> Optional[List[Dict]]: + async def get_stories(self, aime_id: int) -> Optional[List[Dict]]: sql = select(story).where(story.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_chapter(self, aime_id: int, chapter_data: Dict) -> Optional[int]: + async def put_chapter(self, aime_id: int, chapter_data: Dict) -> Optional[int]: chapter_data["user"] = aime_id sql = insert(chapter).values(**chapter_data) conflict = sql.on_duplicate_key_update(**chapter_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_chapter: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_chapters(self, aime_id: int) -> Optional[List[Dict]]: + async def get_chapters(self, aime_id: int) -> Optional[List[Dict]]: sql = select(chapter).where(chapter.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_item(self, aime_id: int, item_data: Dict) -> Optional[int]: + async def put_item(self, aime_id: int, item_data: Dict) -> Optional[int]: item_data["user"] = aime_id sql = insert(item).values(**item_data) conflict = sql.on_duplicate_key_update(**item_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_item: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_item(self, aime_id: int, item_id: int, item_kind: int) -> Optional[Dict]: + async def get_item(self, aime_id: int, item_id: int, item_kind: int) -> Optional[Dict]: sql = select(item).where(and_(item.c.user == aime_id, item.c.itemId == item_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_items(self, aime_id: int, item_kind: int = None) -> Optional[List[Dict]]: + async def get_items(self, aime_id: int, item_kind: int = None) -> Optional[List[Dict]]: if item_kind is None: sql = select(item).where(item.c.user == aime_id) else: @@ -487,73 +487,73 @@ class OngekiItemData(BaseData): and_(item.c.user == aime_id, item.c.itemKind == item_kind) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_music_item(self, aime_id: int, music_item_data: Dict) -> Optional[int]: + async def put_music_item(self, aime_id: int, music_item_data: Dict) -> Optional[int]: music_item_data["user"] = aime_id sql = insert(music_item).values(**music_item_data) conflict = sql.on_duplicate_key_update(**music_item_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_music_item: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_music_items(self, aime_id: int) -> Optional[List[Dict]]: + async def get_music_items(self, aime_id: int) -> Optional[List[Dict]]: sql = select(music_item).where(music_item.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_login_bonus(self, aime_id: int, login_bonus_data: Dict) -> Optional[int]: + async def put_login_bonus(self, aime_id: int, login_bonus_data: Dict) -> Optional[int]: login_bonus_data["user"] = aime_id sql = insert(login_bonus).values(**login_bonus_data) conflict = sql.on_duplicate_key_update(**login_bonus_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_login_bonus: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_login_bonuses(self, aime_id: int) -> Optional[List[Dict]]: + async def get_login_bonuses(self, aime_id: int) -> Optional[List[Dict]]: sql = select(login_bonus).where(login_bonus.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_mission_point(self, aime_id: int, version: int, mission_point_data: Dict) -> Optional[int]: + async def put_mission_point(self, aime_id: int, version: int, mission_point_data: Dict) -> Optional[int]: mission_point_data["version"] = version mission_point_data["user"] = aime_id sql = insert(mission_point).values(**mission_point_data) conflict = sql.on_duplicate_key_update(**mission_point_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_mission_point: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_mission_points(self, version: int, aime_id: int) -> Optional[List[Dict]]: + async def get_mission_points(self, version: int, aime_id: int) -> Optional[List[Dict]]: sql = select(mission_point).where(and_(mission_point.c.user == aime_id, mission_point.c.version == version)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_event_point(self, aime_id: int, version: int, event_point_data: Dict) -> Optional[int]: + async def put_event_point(self, aime_id: int, version: int, event_point_data: Dict) -> Optional[int]: # We update only the newest (type: 1) entry, in official spec game watches for both latest(type:1) and previous (type:2) entries to give an additional info how many ranks has player moved up or down # This fully featured is on TODO list, at the moment we just update the tables as data comes and give out rank as request comes event_point_data["user"] = aime_id @@ -564,95 +564,95 @@ class OngekiItemData(BaseData): sql = insert(event_point).values(**event_point_data) conflict = sql.on_duplicate_key_update(**event_point_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_event_point: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_event_points(self, aime_id: int) -> Optional[List[Dict]]: + async def get_event_points(self, aime_id: int) -> Optional[List[Dict]]: sql = select(event_point).where(event_point.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_scenerio(self, aime_id: int, scenerio_data: Dict) -> Optional[int]: + async def put_scenerio(self, aime_id: int, scenerio_data: Dict) -> Optional[int]: scenerio_data["user"] = aime_id sql = insert(scenerio).values(**scenerio_data) conflict = sql.on_duplicate_key_update(**scenerio_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_scenerio: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_scenerios(self, aime_id: int) -> Optional[List[Dict]]: + async def get_scenerios(self, aime_id: int) -> Optional[List[Dict]]: sql = select(scenerio).where(scenerio.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_trade_item(self, aime_id: int, trade_item_data: Dict) -> Optional[int]: + async def put_trade_item(self, aime_id: int, trade_item_data: Dict) -> Optional[int]: trade_item_data["user"] = aime_id sql = insert(trade_item).values(**trade_item_data) conflict = sql.on_duplicate_key_update(**trade_item_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_trade_item: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_trade_items(self, aime_id: int) -> Optional[List[Dict]]: + async def get_trade_items(self, aime_id: int) -> Optional[List[Dict]]: sql = select(trade_item).where(trade_item.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_event_music(self, aime_id: int, event_music_data: Dict) -> Optional[int]: + async def put_event_music(self, aime_id: int, event_music_data: Dict) -> Optional[int]: event_music_data["user"] = aime_id sql = insert(event_music).values(**event_music_data) conflict = sql.on_duplicate_key_update(**event_music_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_event_music: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_event_music(self, aime_id: int) -> Optional[List[Dict]]: + async def get_event_music(self, aime_id: int) -> Optional[List[Dict]]: sql = select(event_music).where(event_music.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_tech_event(self, aime_id: int, version: int, tech_event_data: Dict) -> Optional[int]: + async def put_tech_event(self, aime_id: int, version: int, tech_event_data: Dict) -> Optional[int]: tech_event_data["user"] = aime_id tech_event_data["version"] = version sql = insert(tech_event).values(**tech_event_data) conflict = sql.on_duplicate_key_update(**tech_event_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_tech_event: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_tech_event_ranking(self, aime_id: int, version: int, tech_event_data: Dict) -> Optional[int]: + async def put_tech_event_ranking(self, aime_id: int, version: int, tech_event_data: Dict) -> Optional[int]: tech_event_data["user"] = aime_id tech_event_data["version"] = version tech_event_data.pop("isRankingRewarded") @@ -662,87 +662,87 @@ class OngekiItemData(BaseData): sql = insert(tech_ranking).values(**tech_event_data) conflict = sql.on_duplicate_key_update(**tech_event_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_tech_event_ranking: Failed to update ranking! aime_id {aime_id}") return None return result.lastrowid - def get_tech_event(self, version: int, aime_id: int) -> Optional[List[Dict]]: + async def get_tech_event(self, version: int, aime_id: int) -> Optional[List[Dict]]: sql = select(tech_event).where(and_(tech_event.c.user == aime_id, tech_event.c.version == version)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_bosses(self, aime_id: int) -> Optional[List[Dict]]: + async def get_bosses(self, aime_id: int) -> Optional[List[Dict]]: sql = select(boss).where(boss.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_memorychapter( + async def put_memorychapter( self, aime_id: int, memorychapter_data: Dict ) -> Optional[int]: memorychapter_data["user"] = aime_id sql = insert(memorychapter).values(**memorychapter_data) conflict = sql.on_duplicate_key_update(**memorychapter_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_memorychapter: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_memorychapters(self, aime_id: int) -> Optional[List[Dict]]: + async def get_memorychapters(self, aime_id: int) -> Optional[List[Dict]]: sql = select(memorychapter).where(memorychapter.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_user_gacha(self, aime_id: int, gacha_id: int) -> Optional[Row]: + async def get_user_gacha(self, aime_id: int, gacha_id: int) -> Optional[Row]: sql = gacha.select(and_(gacha.c.user == aime_id, gacha.c.gachaId == gacha_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_user_gachas(self, aime_id: int) -> Optional[List[Row]]: + async def get_user_gachas(self, aime_id: int) -> Optional[List[Row]]: sql = gacha.select(gacha.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_user_gacha_supplies(self, aime_id: int) -> Optional[List[Row]]: + async def get_user_gacha_supplies(self, aime_id: int) -> Optional[List[Row]]: sql = gacha_supply.select(gacha_supply.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_user_gacha(self, aime_id: int, gacha_id: int, **data) -> Optional[int]: + async def put_user_gacha(self, aime_id: int, gacha_id: int, **data) -> Optional[int]: sql = insert(gacha).values(user=aime_id, gachaId=gacha_id, **data) conflict = sql.on_duplicate_key_update(user=aime_id, gachaId=gacha_id, **data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_user_gacha: Failed to insert! aime_id: {aime_id}") return None return result.lastrowid - def put_user_print_detail( + async def put_user_print_detail( self, aime_id: int, serial_id: str, user_print_data: Dict ) -> Optional[int]: sql = insert(print_detail).values( @@ -750,7 +750,7 @@ class OngekiItemData(BaseData): ) conflict = sql.on_duplicate_key_update(user=aime_id, **user_print_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -760,18 +760,18 @@ class OngekiItemData(BaseData): return result.lastrowid - def get_ranking_event_ranks(self, version: int, aime_id: int) -> Optional[List[Dict]]: + async def get_ranking_event_ranks(self, version: int, aime_id: int) -> Optional[List[Dict]]: # Calculates player rank on GameRequest from server, and sends it back, official spec would rank players in maintenance period, on TODO list sql = select(event_point.c.id, event_point.c.user, event_point.c.eventId, event_point.c.type, func.row_number().over(partition_by=event_point.c.eventId, order_by=event_point.c.point.desc()).label('rank'), event_point.c.date, event_point.c.point).where(event_point.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error(f"failed to rank aime_id: {aime_id} ranking event positions") return None return result.fetchall() - def get_tech_event_ranking(self, version: int, aime_id: int) -> Optional[List[Dict]]: + async def get_tech_event_ranking(self, version: int, aime_id: int) -> Optional[List[Dict]]: sql = select(tech_ranking.c.id, tech_ranking.c.user, tech_ranking.c.date, tech_ranking.c.eventId, func.row_number().over(partition_by=tech_ranking.c.eventId, order_by=[tech_ranking.c.totalTechScore.desc(),tech_ranking.c.totalPlatinumScore.desc()]).label('rank'), tech_ranking.c.totalTechScore, tech_ranking.c.totalPlatinumScore).where(tech_ranking.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"aime_id: {aime_id} has no tech ranking ranks") return None diff --git a/titles/ongeki/schema/log.py b/titles/ongeki/schema/log.py index bd5b071..fccd29f 100644 --- a/titles/ongeki/schema/log.py +++ b/titles/ongeki/schema/log.py @@ -39,7 +39,7 @@ session_log = Table( class OngekiLogData(BaseData): - def put_gp_log( + async def put_gp_log( self, aime_id: Optional[int], used_credit: int, @@ -61,7 +61,7 @@ class OngekiLogData(BaseData): currentGP=current_gp, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning( f"put_gp_log: Failed to insert GP log! aime_id: {aime_id} kind {kind} pattern {pattern} current_gp {current_gp}" diff --git a/titles/ongeki/schema/profile.py b/titles/ongeki/schema/profile.py index 6071bad..1f6bcab 100644 --- a/titles/ongeki/schema/profile.py +++ b/titles/ongeki/schema/profile.py @@ -255,12 +255,12 @@ class OngekiProfileData(BaseData): ) self.date_time_format_short = "%Y-%m-%d" - def get_profile_name(self, aime_id: int, version: int) -> Optional[str]: + async def get_profile_name(self, aime_id: int, version: int) -> Optional[str]: sql = select(profile.c.userName).where( and_(profile.c.user == aime_id, profile.c.version == version) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None @@ -270,19 +270,19 @@ class OngekiProfileData(BaseData): return row["userName"] - def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_preview(self, aime_id: int, version: int) -> Optional[Row]: sql = ( select([profile, option]) .join(option, profile.c.user == option.c.user) .filter(and_(profile.c.user == aime_id, profile.c.version == version)) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_data(self, aime_id: int, version: int) -> Optional[Row]: + async def get_profile_data(self, aime_id: int, version: int) -> Optional[Row]: sql = select(profile).where( and_( profile.c.user == aime_id, @@ -290,40 +290,40 @@ class OngekiProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_options(self, aime_id: int) -> Optional[Row]: + async def get_profile_options(self, aime_id: int) -> Optional[Row]: sql = select(option).where( and_( option.c.user == aime_id, ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_recent_rating(self, aime_id: int) -> Optional[List[Row]]: + async def get_profile_recent_rating(self, aime_id: int) -> Optional[List[Row]]: sql = select(recent_rating).where(recent_rating.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_profile_rating_log(self, aime_id: int) -> Optional[List[Row]]: + async def get_profile_rating_log(self, aime_id: int) -> Optional[List[Row]]: sql = select(rating_log).where(rating_log.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_profile_activity( + async def get_profile_activity( self, aime_id: int, kind: int = None ) -> Optional[List[Row]]: sql = select(activity).where( @@ -333,47 +333,47 @@ class OngekiProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_kop(self, aime_id: int) -> Optional[List[Row]]: + async def get_kop(self, aime_id: int) -> Optional[List[Row]]: sql = select(kop).where(kop.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_rivals(self, aime_id: int) -> Optional[List[Row]]: + async def get_rivals(self, aime_id: int) -> Optional[List[Row]]: sql = select(rival.c.rivalUserId).where(rival.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_profile_data(self, aime_id: int, version: int, data: Dict) -> Optional[int]: + async def put_profile_data(self, aime_id: int, version: int, data: Dict) -> Optional[int]: data["user"] = aime_id data["version"] = version data.pop("accessCode") sql = insert(profile).values(**data) conflict = sql.on_duplicate_key_update(**data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_profile_data: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def put_profile_options(self, aime_id: int, options_data: Dict) -> Optional[int]: + async def put_profile_options(self, aime_id: int, options_data: Dict) -> Optional[int]: options_data["user"] = aime_id sql = insert(option).values(**options_data) conflict = sql.on_duplicate_key_update(**options_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( @@ -382,7 +382,7 @@ class OngekiProfileData(BaseData): return None return result.lastrowid - def put_profile_recent_rating( + async def put_profile_recent_rating( self, aime_id: int, recent_rating_data: List[Dict] ) -> Optional[int]: sql = insert(recent_rating).values( @@ -391,7 +391,7 @@ class OngekiProfileData(BaseData): conflict = sql.on_duplicate_key_update(recentRating=recent_rating_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_recent_rating: failed to update recent rating! aime_id {aime_id}" @@ -399,12 +399,12 @@ class OngekiProfileData(BaseData): return None return result.lastrowid - def put_profile_bp_list( + async def put_profile_bp_list( self, aime_id: int, bp_base_list: List[Dict] ) -> Optional[int]: pass - def put_profile_rating_log( + async def put_profile_rating_log( self, aime_id: int, data_version: str, highest_rating: int ) -> Optional[int]: sql = insert(rating_log).values( @@ -413,7 +413,7 @@ class OngekiProfileData(BaseData): conflict = sql.on_duplicate_key_update(highestRating=highest_rating) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_rating_log: failed to update rating log! aime_id {aime_id} data_version {data_version} highest_rating {highest_rating}" @@ -421,7 +421,7 @@ class OngekiProfileData(BaseData): return None return result.lastrowid - def put_profile_activity( + async def put_profile_activity( self, aime_id: int, kind: int, @@ -447,7 +447,7 @@ class OngekiProfileData(BaseData): sortNumber=sort_num, param1=p1, param2=p2, param3=p3, param4=p4 ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_activity: failed to put activity! aime_id {aime_id} kind {kind} activity_id {activity_id}" @@ -455,7 +455,7 @@ class OngekiProfileData(BaseData): return None return result.lastrowid - def put_profile_region(self, aime_id: int, region: int, date: str) -> Optional[int]: + async def put_profile_region(self, aime_id: int, region: int, date: str) -> Optional[int]: sql = insert(activity).values( user=aime_id, region=region, playCount=1, created=date ) @@ -464,7 +464,7 @@ class OngekiProfileData(BaseData): playCount=activity.c.playCount + 1, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_profile_region: failed to update! aime_id {aime_id} region {region}" @@ -472,45 +472,45 @@ class OngekiProfileData(BaseData): return None return result.lastrowid - def put_training_room(self, aime_id: int, room_detail: Dict) -> Optional[int]: + async def put_training_room(self, aime_id: int, room_detail: Dict) -> Optional[int]: room_detail["user"] = aime_id sql = insert(training_room).values(**room_detail) conflict = sql.on_duplicate_key_update(**room_detail) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_best_score: Failed to add score! aime_id: {aime_id}") return None return result.lastrowid - def put_kop(self, aime_id: int, kop_data: Dict) -> Optional[int]: + async def put_kop(self, aime_id: int, kop_data: Dict) -> Optional[int]: kop_data["user"] = aime_id sql = insert(kop).values(**kop_data) conflict = sql.on_duplicate_key_update(**kop_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_kop: Failed to add score! aime_id: {aime_id}") return None return result.lastrowid - def put_rival(self, aime_id: int, rival_id: int) -> Optional[int]: + async def put_rival(self, aime_id: int, rival_id: int) -> Optional[int]: sql = insert(rival).values(user=aime_id, rivalUserId=rival_id) conflict = sql.on_duplicate_key_update(rivalUserId=rival_id) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_rival: failed to update! aime_id: {aime_id}, rival_id: {rival_id}" ) return None return result.lastrowid - def delete_rival(self, aime_id: int, rival_id: int) -> Optional[int]: + async def delete_rival(self, aime_id: int, rival_id: int) -> Optional[int]: sql = delete(rival).where(rival.c.user==aime_id, rival.c.rivalUserId==rival_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error(f"delete_rival: failed to delete! aime_id: {aime_id}, rival_id: {rival_id}") else: diff --git a/titles/ongeki/schema/score.py b/titles/ongeki/schema/score.py index 7c8ce15..4770725 100644 --- a/titles/ongeki/schema/score.py +++ b/titles/ongeki/schema/score.py @@ -128,52 +128,52 @@ tech_count = Table( class OngekiScoreData(BaseData): - def get_tech_count(self, aime_id: int) -> Optional[List[Dict]]: + async def get_tech_count(self, aime_id: int) -> Optional[List[Dict]]: return [] - def put_tech_count(self, aime_id: int, tech_count_data: Dict) -> Optional[int]: + async def put_tech_count(self, aime_id: int, tech_count_data: Dict) -> Optional[int]: tech_count_data["user"] = aime_id sql = insert(tech_count).values(**tech_count_data) conflict = sql.on_duplicate_key_update(**tech_count_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_tech_count: Failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_best_scores(self, aime_id: int) -> Optional[List[Dict]]: + async def get_best_scores(self, aime_id: int) -> Optional[List[Dict]]: sql = select(score_best).where(score_best.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_best_score( + async def get_best_score( self, aime_id: int, song_id: int, chart_id: int = None ) -> Optional[List[Dict]]: return [] - def put_best_score(self, aime_id: int, music_detail: Dict) -> Optional[int]: + async def put_best_score(self, aime_id: int, music_detail: Dict) -> Optional[int]: music_detail["user"] = aime_id sql = insert(score_best).values(**music_detail) conflict = sql.on_duplicate_key_update(**music_detail) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"put_best_score: Failed to add score! aime_id: {aime_id}") return None return result.lastrowid - def put_playlog(self, aime_id: int, playlog_data: Dict) -> Optional[int]: + async def put_playlog(self, aime_id: int, playlog_data: Dict) -> Optional[int]: playlog_data["user"] = aime_id sql = insert(playlog).values(**playlog_data) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"put_playlog: Failed to add playlog! aime_id: {aime_id}") return None diff --git a/titles/ongeki/schema/static.py b/titles/ongeki/schema/static.py index 695d39a..85a9df4 100644 --- a/titles/ongeki/schema/static.py +++ b/titles/ongeki/schema/static.py @@ -188,26 +188,26 @@ game_point = Table( ) class OngekiStaticData(BaseData): - def put_card(self, version: int, card_id: int, **card_data) -> Optional[int]: + async def put_card(self, version: int, card_id: int, **card_data) -> Optional[int]: sql = insert(cards).values(version=version, cardId=card_id, **card_data) conflict = sql.on_duplicate_key_update(**card_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert card! card_id {card_id}") return None return result.lastrowid - def get_card(self, version: int, card_id: int) -> Optional[Dict]: + async def get_card(self, version: int, card_id: int) -> Optional[Dict]: sql = cards.select(and_(cards.c.version <= version, cards.c.cardId == card_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_card_by_card_number(self, version: int, card_number: str) -> Optional[Dict]: + async def get_card_by_card_number(self, version: int, card_number: str) -> Optional[Dict]: if not card_number.startswith("[O.N.G.E.K.I.]"): card_number = f"[O.N.G.E.K.I.]{card_number}" @@ -215,36 +215,36 @@ class OngekiStaticData(BaseData): and_(cards.c.version <= version, cards.c.cardNumber == card_number) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_card_by_name(self, version: int, name: str) -> Optional[Dict]: + async def get_card_by_name(self, version: int, name: str) -> Optional[Dict]: sql = cards.select(and_(cards.c.version <= version, cards.c.name == name)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_cards(self, version: int) -> Optional[List[Dict]]: + async def get_cards(self, version: int) -> Optional[List[Dict]]: sql = cards.select(cards.c.version <= version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_cards_by_rarity(self, version: int, rarity: int) -> Optional[List[Dict]]: + async def get_cards_by_rarity(self, version: int, rarity: int) -> Optional[List[Dict]]: sql = cards.select(and_(cards.c.version <= version, cards.c.rarity == rarity)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_gacha( + async def put_gacha( self, version: int, gacha_id: int, @@ -268,33 +268,33 @@ class OngekiStaticData(BaseData): **gacha_data, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert gacha! gacha_id {gacha_id}") return None return result.lastrowid - def get_gacha(self, version: int, gacha_id: int) -> Optional[Dict]: + async def get_gacha(self, version: int, gacha_id: int) -> Optional[Dict]: sql = gachas.select( and_(gachas.c.version <= version, gachas.c.gachaId == gacha_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_gachas(self, version: int) -> Optional[List[Dict]]: + async def get_gachas(self, version: int) -> Optional[List[Dict]]: sql = gachas.select(gachas.c.version == version).order_by( gachas.c.gachaId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_gacha_card( + async def put_gacha_card( self, gacha_id: int, card_id: int, **gacha_card ) -> Optional[int]: sql = insert(gacha_cards).values(gachaId=gacha_id, cardId=card_id, **gacha_card) @@ -303,21 +303,21 @@ class OngekiStaticData(BaseData): gachaId=gacha_id, cardId=card_id, **gacha_card ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert gacha card! gacha_id {gacha_id}") return None return result.lastrowid - def get_gacha_cards(self, gacha_id: int) -> Optional[List[Dict]]: + async def get_gacha_cards(self, gacha_id: int) -> Optional[List[Dict]]: sql = gacha_cards.select(gacha_cards.c.gachaId == gacha_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_event( + async def put_event( self, version: int, event_id: int, event_type: int, event_name: str ) -> Optional[int]: sql = insert(events).values( @@ -332,41 +332,41 @@ class OngekiStaticData(BaseData): name=event_name, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert event! event_id {event_id}") return None return result.lastrowid - def get_event(self, version: int, event_id: int) -> Optional[List[Dict]]: + async def get_event(self, version: int, event_id: int) -> Optional[List[Dict]]: sql = select(events).where( and_(events.c.version == version, events.c.eventId == event_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_events(self, version: int) -> Optional[List[Dict]]: + async def get_events(self, version: int) -> Optional[List[Dict]]: sql = select(events).where(events.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_enabled_events(self, version: int) -> Optional[List[Dict]]: + async def get_enabled_events(self, version: int) -> Optional[List[Dict]]: sql = select(events).where( and_(events.c.version == version, events.c.enabled == True) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_chart( + async def put_chart( self, version: int, song_id: int, @@ -393,7 +393,7 @@ class OngekiStaticData(BaseData): level=level, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"Failed to insert chart! song_id: {song_id}, chart_id: {chart_id}" @@ -401,15 +401,15 @@ class OngekiStaticData(BaseData): return None return result.lastrowid - def get_chart( + async def get_chart( self, version: int, song_id: int, chart_id: int = None ) -> Optional[List[Dict]]: pass - def get_music(self, version: int) -> Optional[List[Dict]]: + async def get_music(self, version: int) -> Optional[List[Dict]]: pass - def get_music_chart( + async def get_music_chart( self, version: int, song_id: int, chart_id: int ) -> Optional[List[Row]]: sql = select(music).where( @@ -420,19 +420,19 @@ class OngekiStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_ranking_list(self, version: int) -> Optional[List[Dict]]: + async def get_ranking_list(self, version: int) -> Optional[List[Dict]]: sql = select(music_ranking.c.musicId.label('id'), music_ranking.c.point, music_ranking.c.userName).where(music_ranking.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_reward(self, version: int, rewardId: int, rewardname: str, itemKind: int, itemId: int) -> Optional[int]: + async def put_reward(self, version: int, rewardId: int, rewardname: str, itemKind: int, itemId: int) -> Optional[int]: sql = insert(rewards).values( version=version, rewardId=rewardId, @@ -443,70 +443,70 @@ class OngekiStaticData(BaseData): conflict = sql.on_duplicate_key_update( rewardname=rewardname, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert reward! reward_id: {rewardId}") return None return result.lastrowid - def get_reward_list(self, version: int) -> Optional[List[Dict]]: + async def get_reward_list(self, version: int) -> Optional[List[Dict]]: sql = select(rewards).where(rewards.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to load reward list") return None return result.fetchall() - def get_present_list(self, version: int) -> Optional[List[Dict]]: + async def get_present_list(self, version: int) -> Optional[List[Dict]]: sql = select(present).where(present.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to load present list") return None return result.fetchall() - def get_tech_music(self, version: int) -> Optional[List[Dict]]: + async def get_tech_music(self, version: int) -> Optional[List[Dict]]: sql = select(tech_music).where(tech_music.c.version == version) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_client_testmode_data(self, region_id: int, client_testmode_data: Dict) -> Optional[List[Dict]]: + async def put_client_testmode_data(self, region_id: int, client_testmode_data: Dict) -> Optional[List[Dict]]: sql = insert(client_testmode).values(regionId=region_id, **client_testmode_data) conflict = sql.on_duplicate_key_update(regionId=region_id, **client_testmode_data) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"region_id: {region_id} Failed to update ClientTestMode data"), return None return result.lastrowid - def put_client_setting_data(self, machine_id: int, client_setting_data: Dict) -> Optional[List[Dict]]: + async def put_client_setting_data(self, machine_id: int, client_setting_data: Dict) -> Optional[List[Dict]]: sql = machine.update(machine.c.id == machine_id).values(data=client_setting_data) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"machine_id: {machine_id} Failed to update ClientSetting data"), return None return result.lastrowid - def put_static_game_point_defaults(self) -> Optional[List[Dict]]: + async def put_static_game_point_defaults(self) -> Optional[List[Dict]]: game_point_defaults = [{"type": 0, "cost": 100},{"type": 1, "cost": 230},{"type": 2, "cost": 370},{"type": 3, "cost": 120},{"type": 4, "cost": 240},{"type": 5, "cost": 360}] sql = insert(game_point).values(game_point_defaults) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to insert default GP table!") return None return result.lastrowid - def get_static_game_point(self) -> Optional[List[Dict]]: + async def get_static_game_point(self) -> Optional[List[Dict]]: sql = select(game_point.c.type, game_point.c.cost, game_point.c.startDate, game_point.c.endDate) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() diff --git a/titles/pokken/base.py b/titles/pokken/base.py index 9eab298..562f3b9 100644 --- a/titles/pokken/base.py +++ b/titles/pokken/base.py @@ -132,11 +132,11 @@ class PokkenBase: res.type = jackal_pb2.MessageType.LOAD_USER access_code = request.load_user.access_code load_usr = jackal_pb2.LoadUserResponseData() - user_id = self.data.card.get_user_id_from_card(access_code) + user_id = await self.data.card.get_user_id_from_card(access_code) if user_id is None and self.game_cfg.server.auto_register: - user_id = self.data.user.create_user() - card_id = self.data.card.create_card(user_id, access_code) + user_id = await self.data.user.create_user() + card_id = await self.data.card.create_card(user_id, access_code) self.logger.info( f"Register new card {access_code} (UserId {user_id}, CardId {card_id})" @@ -160,7 +160,7 @@ class PokkenBase: event_achievement_flag event_achievement_param """ - profile = self.data.profile.get_profile(user_id) + profile = await self.data.profile.get_profile(user_id) load_usr.commidserv_result = 1 load_usr.load_hash = 1 load_usr.cardlock_status = False @@ -169,7 +169,7 @@ class PokkenBase: load_usr.precedent_release_flag = 0xFFFFFFFF if profile is None: - profile_id = self.data.profile.create_profile(user_id) + profile_id = await self.data.profile.create_profile(user_id) profile_dict = {"id": profile_id, "user": user_id} pokemon_data = [] tutorial_progress = [] @@ -184,7 +184,7 @@ class PokkenBase: self.logger.info( f"Card-in user {user_id} (Trainer name {profile_dict.get('trainer_name', '')})" ) - pokemon_data = self.data.profile.get_all_pokemon_data(user_id) + pokemon_data = await self.data.profile.get_all_pokemon_data(user_id) tutorial_progress = [] rankmatch_progress = [] achievement_flag = [] @@ -324,22 +324,22 @@ class PokkenBase: battle = req.battle_data mon = req.pokemon_data - p = self.data.profile.touch_profile(user_id) + p = await self.data.profile.touch_profile(user_id) if p is None or not p: - self.data.profile.create_profile(user_id) + await self.data.profile.create_profile(user_id) if req.trainer_name_pending is not None and req.trainer_name_pending: # we're saving for the first time - self.data.profile.set_profile_name(user_id, req.trainer_name_pending, req.avatar_gender if req.avatar_gender else None) + await self.data.profile.set_profile_name(user_id, req.trainer_name_pending, req.avatar_gender if req.avatar_gender else None) for tut_flg in req.tutorial_progress_flag: tut_flgs.append(tut_flg) - self.data.profile.update_profile_tutorial_flags(user_id, tut_flgs) + await self.data.profile.update_profile_tutorial_flags(user_id, tut_flgs) for ach_flg in req.achievement_flag: ach_flgs.append(ach_flg) - self.data.profile.update_profile_tutorial_flags(user_id, ach_flg) + await self.data.profile.update_profile_tutorial_flags(user_id, ach_flg) for evt_flg in req.event_achievement_flag: evt_flgs.append(evt_flg) @@ -347,29 +347,29 @@ class PokkenBase: for evt_param in req.event_achievement_param: evt_params.append(evt_param) - self.data.profile.update_profile_event(user_id, evt_state, evt_flgs, evt_params, req.last_play_event_id) + await self.data.profile.update_profile_event(user_id, evt_state, evt_flgs, evt_params, req.last_play_event_id) for reward in req.reward_data: - self.data.item.add_reward(user_id, reward.get_category_id, reward.get_content_id, reward.get_type_id) + await self.data.item.add_reward(user_id, reward.get_category_id, reward.get_content_id, reward.get_type_id) - self.data.profile.add_profile_points(user_id, get_rank_pts, get_money, get_score_pts, grade_max) + await self.data.profile.add_profile_points(user_id, get_rank_pts, get_money, get_score_pts, grade_max) - self.data.profile.update_support_team(user_id, 1, req.support_set_1[0], req.support_set_1[1]) - self.data.profile.update_support_team(user_id, 2, req.support_set_2[0], req.support_set_2[1]) - self.data.profile.update_support_team(user_id, 3, req.support_set_3[0], req.support_set_3[1]) + await self.data.profile.update_support_team(user_id, 1, req.support_set_1[0], req.support_set_1[1]) + await self.data.profile.update_support_team(user_id, 2, req.support_set_2[0], req.support_set_2[1]) + await self.data.profile.update_support_team(user_id, 3, req.support_set_3[0], req.support_set_3[1]) - self.data.profile.put_pokemon(user_id, mon.char_id, mon.illustration_book_no, mon.bp_point_atk, mon.bp_point_res, mon.bp_point_def, mon.bp_point_sp) - self.data.profile.add_pokemon_xp(user_id, mon.char_id, mon.get_pokemon_exp) + await self.data.profile.put_pokemon(user_id, mon.char_id, mon.illustration_book_no, mon.bp_point_atk, mon.bp_point_res, mon.bp_point_def, mon.bp_point_sp) + await self.data.profile.add_pokemon_xp(user_id, mon.char_id, mon.get_pokemon_exp) for x in range(len(battle.play_mode)): - self.data.profile.put_pokemon_battle_result( + await self.data.profile.put_pokemon_battle_result( user_id, mon.char_id, PokkenConstants.BATTLE_TYPE(battle.play_mode[x]), PokkenConstants.BATTLE_RESULT(battle.result[x]) ) - self.data.profile.put_stats( + await self.data.profile.put_stats( user_id, battle.ex_ko_num, battle.wko_num, @@ -379,7 +379,7 @@ class PokkenBase: num_continues ) - self.data.profile.put_extra( + await self.data.profile.put_extra( user_id, extra_counter, evt_reward_get_flg, diff --git a/titles/pokken/schema/item.py b/titles/pokken/schema/item.py index f68d6d9..cc633d7 100644 --- a/titles/pokken/schema/item.py +++ b/titles/pokken/schema/item.py @@ -31,7 +31,7 @@ class PokkenItemData(BaseData): Items obtained as rewards """ - def add_reward(self, user_id: int, category: int, content: int, item_type: int) -> Optional[int]: + async def add_reward(self, user_id: int, category: int, content: int, item_type: int) -> Optional[int]: sql = insert(item).values( user=user_id, category=category, @@ -43,7 +43,7 @@ class PokkenItemData(BaseData): content=content, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert reward for user {user_id}: {category}-{content}-{item_type}") return None diff --git a/titles/pokken/schema/match.py b/titles/pokken/schema/match.py index c84ec63..1c597d5 100644 --- a/titles/pokken/schema/match.py +++ b/titles/pokken/schema/match.py @@ -39,14 +39,14 @@ class PokkenMatchData(BaseData): Match logs """ - def save_match(self, user_id: int, match_data: Dict) -> Optional[int]: + async def save_match(self, user_id: int, match_data: Dict) -> Optional[int]: pass - def get_match(self, match_id: int) -> Optional[Row]: + async def get_match(self, match_id: int) -> Optional[Row]: pass - def get_matches_by_user(self, user_id: int) -> Optional[List[Row]]: + async def get_matches_by_user(self, user_id: int) -> Optional[List[Row]]: pass - def get_matches(self, limit: int = 20) -> Optional[List[Row]]: + async def get_matches(self, limit: int = 20) -> Optional[List[Row]]: pass diff --git a/titles/pokken/schema/profile.py b/titles/pokken/schema/profile.py index ab81d77..b7237de 100644 --- a/titles/pokken/schema/profile.py +++ b/titles/pokken/schema/profile.py @@ -138,36 +138,36 @@ pokemon_data = Table( class PokkenProfileData(BaseData): - def touch_profile(self, user_id: int) -> Optional[int]: + async def touch_profile(self, user_id: int) -> Optional[int]: sql = select([profile.c.id]).where(profile.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone()['id'] - def create_profile(self, user_id: int) -> Optional[int]: + async def create_profile(self, user_id: int) -> Optional[int]: sql = insert(profile).values(user=user_id) conflict = sql.on_duplicate_key_update(user=user_id) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"Failed to create pokken profile for user {user_id}!") return None return result.lastrowid - def set_profile_name(self, user_id: int, new_name: str, gender: Union[int, None] = None) -> None: + async def set_profile_name(self, user_id: int, new_name: str, gender: Union[int, None] = None) -> None: sql = update(profile).where(profile.c.user == user_id).values( trainer_name=new_name, avatar_gender=gender if gender is not None else profile.c.avatar_gender ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"Failed to update pokken profile name for user {user_id}!" ) - def put_extra( + async def put_extra( self, user_id: int, extra_counter: int, @@ -190,44 +190,44 @@ class PokkenProfileData(BaseData): last_play_event_id=last_evt ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error(f"Failed to put extra data for user {user_id}") - def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: List) -> None: + async def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: List) -> None: sql = update(profile).where(profile.c.user == user_id).values( tutorial_progress_flag=tutorial_flags, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"Failed to update pokken profile tutorial flags for user {user_id}!" ) - def update_profile_achievement_flags(self, user_id: int, achievement_flags: List) -> None: + async def update_profile_achievement_flags(self, user_id: int, achievement_flags: List) -> None: sql = update(profile).where(profile.c.user == user_id).values( achievement_flag=achievement_flags, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"Failed to update pokken profile achievement flags for user {user_id}!" ) - def update_profile_event(self, user_id: int, event_state: List, event_flags: List[int], event_param: List[int], last_evt: int = None) -> None: + async def update_profile_event(self, user_id: int, event_state: List, event_flags: List[int], event_param: List[int], last_evt: int = None) -> None: sql = update(profile).where(profile.c.user == user_id).values( event_state=event_state, event_achievement_flag=event_flags, event_achievement_param=event_param, last_play_event_id=last_evt if last_evt is not None else profile.c.last_play_event_id, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"Failed to update pokken profile event state for user {user_id}!" ) - def add_profile_points( + async def add_profile_points( self, user_id: int, rank_pts: int, money: int, score_pts: int, grade_max: int ) -> None: sql = update(profile).where(profile.c.user == user_id).values( @@ -237,14 +237,14 @@ class PokkenProfileData(BaseData): grade_max_num = grade_max ) - def get_profile(self, user_id: int) -> Optional[Row]: + async def get_profile(self, user_id: int) -> Optional[Row]: sql = profile.select(profile.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def put_pokemon( + async def put_pokemon( self, user_id: int, pokemon_id: int, @@ -281,13 +281,13 @@ class PokkenProfileData(BaseData): bp_point_sp=pokemon_data.c.bp_point_sp + sp, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert pokemon ID {pokemon_id} for user {user_id}") return None return result.lastrowid - def add_pokemon_xp( + async def add_pokemon_xp( self, user_id: int, pokemon_id: int, @@ -297,25 +297,25 @@ class PokkenProfileData(BaseData): pokemon_exp=coalesce(pokemon_data.c.pokemon_exp, 0) + xp ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to add {xp} XP to pokemon ID {pokemon_id} for user {user_id}") - def get_pokemon_data(self, user_id: int, pokemon_id: int) -> Optional[Row]: + async def get_pokemon_data(self, user_id: int, pokemon_id: int) -> Optional[Row]: sql = pokemon_data.select(and_(pokemon_data.c.user == user_id, pokemon_data.c.char_id == pokemon_id)) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_all_pokemon_data(self, user_id: int) -> Optional[List[Row]]: + async def get_all_pokemon_data(self, user_id: int) -> Optional[List[Row]]: sql = pokemon_data.select(pokemon_data.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def put_pokemon_battle_result( + async def put_pokemon_battle_result( self, user_id: int, pokemon_id: int, match_type: PokkenConstants.BATTLE_TYPE, match_result: PokkenConstants.BATTLE_RESULT ) -> None: """ @@ -336,11 +336,11 @@ class PokkenProfileData(BaseData): win_vs_wan=coalesce(pokemon_data.c.win_vs_wan, 0) + 1 if match_type==PokkenConstants.BATTLE_TYPE.WAN and match_result==PokkenConstants.BATTLE_RESULT.WIN else coalesce(pokemon_data.c.win_vs_wan, 0), ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to record match stats for user {user_id}'s pokemon {pokemon_id} (type {match_type.name} | result {match_result.name})") - def put_stats( + async def put_stats( self, user_id: int, exkos: int, @@ -362,11 +362,11 @@ class PokkenProfileData(BaseData): continue_num=continues, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to update stats for user {user_id}") - def update_support_team(self, user_id: int, support_id: int, support1: int = None, support2: int = None) -> None: + async def update_support_team(self, user_id: int, support_id: int, support1: int = None, support2: int = None) -> None: sql = update(profile).where(profile.c.user==user_id).values( support_set_1_1=support1 if support_id == 1 else profile.c.support_set_1_1, support_set_1_2=support2 if support_id == 1 else profile.c.support_set_1_2, @@ -376,6 +376,6 @@ class PokkenProfileData(BaseData): support_set_3_2=support2 if support_id == 3 else profile.c.support_set_3_2, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to update support team {support_id} for user {user_id}") diff --git a/titles/sao/handlers/base.py b/titles/sao/handlers/base.py index 4178640..5b63f78 100644 --- a/titles/sao/handlers/base.py +++ b/titles/sao/handlers/base.py @@ -16,7 +16,7 @@ class SaoRequestHeader: self.game_id: int = collection[4] self.version_id: int = collection[5] self.hash: str = collection[6] - self.data_len: str = collection[7] + self.data._len: str = collection[7] class SaoBaseRequest: def __init__(self, header: SaoRequestHeader, data: bytes) -> None: @@ -118,7 +118,7 @@ class SaoMasterDataVersionCheckResponse(SaoBaseResponse): super().__init__(cmd) self.result = 1 self.update_flag = 0 - self.data_version = 100 + self.data._version = 100 def make(self) -> bytes: # create a resp struct @@ -131,7 +131,7 @@ class SaoMasterDataVersionCheckResponse(SaoBaseResponse): resp_data = resp_struct.build(dict( result=self.result, update_flag=self.update_flag, - data_version=self.data_version, + data_version=self.data._version, )) self.length = len(resp_data) @@ -145,7 +145,7 @@ class SaoCommonGetAppVersionsRequest(SaoBaseResponse): def __init__(self, cmd) -> None: super().__init__(cmd) self.result = 1 - self.data_list_size = 1 # Number of arrays + self.data._list_size = 1 # Number of arrays self.version_app_id = 1 self.applying_start_date = "20230520193000" @@ -163,7 +163,7 @@ class SaoCommonGetAppVersionsRequest(SaoBaseResponse): resp_data = resp_struct.build(dict( result=self.result, - data_list_size=self.data_list_size, + data_list_size=self.data._list_size, version_app_id=self.version_app_id, applying_start_date_size=len(self.applying_start_date) * 2, @@ -2121,7 +2121,7 @@ class SaoGetYuiMedalBonusUserDataResponse(SaoBaseResponse): def __init__(self, cmd) -> None: super().__init__(cmd) self.result = 1 - self.data_size = 1 # number of arrays + self.data._size = 1 # number of arrays self.elapsed_days = 1 self.loop_num = 1 @@ -2144,7 +2144,7 @@ class SaoGetYuiMedalBonusUserDataResponse(SaoBaseResponse): resp_data = resp_struct.build(dict( result=self.result, - data_size=self.data_size, + data_size=self.data._size, elapsed_days=self.elapsed_days, loop_num=self.loop_num, @@ -3150,11 +3150,11 @@ class GetGashaMedalShopUserDataListResponse(SaoBaseResponse): def __init__(self, cmd_id: int) -> None: super().__init__(cmd_id) self.result = 1 # byte - self.data_list: List[GashaMedalShopUserData] = [] + self.data._list: List[GashaMedalShopUserData] = [] def make(self) -> bytes: ret = encode_byte(self.result) - ret += encode_arr_cls(self.data_list) + ret += encode_arr_cls(self.data._list) self.header.length = len(ret) return super().make() + ret @@ -3168,11 +3168,11 @@ class GetMYuiMedalShopDataResponse(SaoBaseResponse): def __init__(self, cmd_id: int) -> None: super().__init__(cmd_id) self.result = 1 # byte - self.data_list: List[YuiMedalShopData] = [] + self.data._list: List[YuiMedalShopData] = [] def make(self) -> bytes: ret = encode_byte(self.result) - ret += encode_arr_cls(self.data_list) + ret += encode_arr_cls(self.data._list) self.header.length = len(ret) return super().make() + ret @@ -3186,11 +3186,11 @@ class GetMYuiMedalShopItemsResponse(SaoBaseResponse): def __init__(self, cmd_id: int) -> None: super().__init__(cmd_id) self.result = 1 # byte - self.data_list: List[YuiMedalShopItemData] = [] + self.data._list: List[YuiMedalShopItemData] = [] def make(self) -> bytes: ret = encode_byte(self.result) - ret += encode_arr_cls(self.data_list) + ret += encode_arr_cls(self.data._list) self.header.length = len(ret) return super().make() + ret @@ -3204,11 +3204,11 @@ class GetMGashaMedalShopsResponse(SaoBaseResponse): def __init__(self, cmd_id: int) -> None: super().__init__(cmd_id) self.result = 1 # byte - self.data_list: List[GashaMedalShop] = [] + self.data._list: List[GashaMedalShop] = [] def make(self) -> bytes: ret = encode_byte(self.result) - ret += encode_arr_cls(self.data_list) + ret += encode_arr_cls(self.data._list) self.header.length = len(ret) return super().make() + ret @@ -3222,11 +3222,11 @@ class GetMResEarnCampaignShopsResponse(SaoBaseResponse): def __init__(self, cmd_id: int) -> None: super().__init__(cmd_id) self.result = 1 # byte - self.data_list: List[ResEarnCampaignShop] = [] + self.data._list: List[ResEarnCampaignShop] = [] def make(self) -> bytes: ret = encode_byte(self.result) - ret += encode_arr_cls(self.data_list) + ret += encode_arr_cls(self.data._list) self.header.length = len(ret) return super().make() + ret diff --git a/titles/sao/read.py b/titles/sao/read.py index dafb450..92aad8c 100644 --- a/titles/sao/read.py +++ b/titles/sao/read.py @@ -29,17 +29,15 @@ class SaoReader(BaseReader): self.logger.error(f"Invalid project SAO version {version}") exit(1) - def read(self) -> None: - pull_bin_ram = True + async def read(self) -> None: + if path.exists(self.bin_dir): + await self.read_csv(f"{self.bin_dir}") - if not path.exists(f"{self.bin_dir}"): - self.logger.warning(f"Couldn't find csv file in {self.bin_dir}, skipping") - pull_bin_ram = False + else: + self.logger.warn("Directory not found, nothing to import") + - if pull_bin_ram: - self.read_csv(f"{self.bin_dir}") - - def read_csv(self, bin_dir: str) -> None: + async def read_csv(self, bin_dir: str) -> None: self.logger.info(f"Read csv from {bin_dir}") self.logger.info("Now reading QuestScene.csv") @@ -56,7 +54,7 @@ class SaoReader(BaseReader): self.logger.info(f"Added quest {questSceneId} | Name: {name}") try: - self.data.static.put_quest( + await self.data.static.put_quest( questSceneId, 0, sortNo, @@ -86,7 +84,7 @@ class SaoReader(BaseReader): self.logger.info(f"Added hero {heroLogId} | Name: {name}") try: - self.data.static.put_hero( + await self.data.static.put_hero( 0, heroLogId, name, @@ -119,7 +117,7 @@ class SaoReader(BaseReader): self.logger.info(f"Added equipment {equipmentId} | Name: {name}") try: - self.data.static.put_equipment( + await self.data.static.put_equipment( 0, equipmentId, name, @@ -150,7 +148,7 @@ class SaoReader(BaseReader): self.logger.info(f"Added item {itemId} | Name: {name}") try: - self.data.static.put_item( + await self.data.static.put_item( 0, itemId, name, @@ -181,7 +179,7 @@ class SaoReader(BaseReader): self.logger.info(f"Added support log {supportLogId} | Name: {name}") try: - self.data.static.put_support_log( + await self.data.static.put_support_log( 0, supportLogId, charaId, @@ -213,7 +211,7 @@ class SaoReader(BaseReader): if len(titleId) > 5: try: - self.data.static.put_title( + await self.data.static.put_title( 0, titleId, displayName, @@ -242,7 +240,7 @@ class SaoReader(BaseReader): self.logger.info(f"Added rare drop {questRareDropId} | Reward: {commonRewardId}") try: - self.data.static.put_rare_drop( + await self.data.static.put_rare_drop( 0, questRareDropId, commonRewardId, diff --git a/titles/sao/schema/item.py b/titles/sao/schema/item.py index 11adf27..c490d9d 100644 --- a/titles/sao/schema/item.py +++ b/titles/sao/schema/item.py @@ -139,7 +139,7 @@ end_sessions = Table( ) class SaoItemData(BaseData): - def create_session(self, user_id: int, user_party_team_id: int, episode_id: int, play_mode: int, quest_drop_boost_apply_flag: int) -> Optional[int]: + async def create_session(self, user_id: int, user_party_team_id: int, episode_id: int, play_mode: int, quest_drop_boost_apply_flag: int) -> Optional[int]: sql = insert(sessions).values( user=user_id, user_party_team_id=user_party_team_id, @@ -150,13 +150,13 @@ class SaoItemData(BaseData): conflict = sql.on_duplicate_key_update(user=user_id) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"Failed to create SAO session for user {user_id}!") return None return result.lastrowid - def create_end_session(self, user_id: int, quest_id: int, play_result_flag: bool, reward_data: JSON) -> Optional[int]: + async def create_end_session(self, user_id: int, quest_id: int, play_result_flag: bool, reward_data: JSON) -> Optional[int]: sql = insert(end_sessions).values( user=user_id, quest_id=quest_id, @@ -166,13 +166,13 @@ class SaoItemData(BaseData): conflict = sql.on_duplicate_key_update(user=user_id) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"Failed to create SAO end session for user {user_id}!") return None return result.lastrowid - def put_item(self, user_id: int, item_id: int) -> Optional[int]: + async def put_item(self, user_id: int, item_id: int) -> Optional[int]: sql = insert(item_data).values( user=user_id, item_id=item_id, @@ -182,7 +182,7 @@ class SaoItemData(BaseData): item_id=item_id, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert item! user: {user_id}, item_id: {item_id}" @@ -191,7 +191,7 @@ class SaoItemData(BaseData): return result.lastrowid - def put_equipment_data(self, user_id: int, equipment_id: int, enhancement_value: int, enhancement_exp: int, awakening_exp: int, awakening_stage: int, possible_awakening_flag: int) -> Optional[int]: + async def put_equipment_data(self, user_id: int, equipment_id: int, enhancement_value: int, enhancement_exp: int, awakening_exp: int, awakening_stage: int, possible_awakening_flag: int) -> Optional[int]: sql = insert(equipment_data).values( user=user_id, equipment_id=equipment_id, @@ -210,7 +210,7 @@ class SaoItemData(BaseData): possible_awakening_flag=possible_awakening_flag, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert equipment! user: {user_id}, equipment_id: {equipment_id}" @@ -219,7 +219,7 @@ class SaoItemData(BaseData): return result.lastrowid - def put_hero_log(self, user_id: int, user_hero_log_id: int, log_level: int, log_exp: int, main_weapon: int, sub_equipment: int, skill_slot1_skill_id: int, skill_slot2_skill_id: int, skill_slot3_skill_id: int, skill_slot4_skill_id: int, skill_slot5_skill_id: int) -> Optional[int]: + async def put_hero_log(self, user_id: int, user_hero_log_id: int, log_level: int, log_exp: int, main_weapon: int, sub_equipment: int, skill_slot1_skill_id: int, skill_slot2_skill_id: int, skill_slot3_skill_id: int, skill_slot4_skill_id: int, skill_slot5_skill_id: int) -> Optional[int]: sql = insert(hero_log_data).values( user=user_id, user_hero_log_id=user_hero_log_id, @@ -246,7 +246,7 @@ class SaoItemData(BaseData): skill_slot5_skill_id=skill_slot5_skill_id, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert hero! user: {user_id}, user_hero_log_id: {user_hero_log_id}" @@ -255,7 +255,7 @@ class SaoItemData(BaseData): return result.lastrowid - def put_hero_party(self, user_id: int, user_party_team_id: int, user_hero_log_id_1: int, user_hero_log_id_2: int, user_hero_log_id_3: int) -> Optional[int]: + async def put_hero_party(self, user_id: int, user_party_team_id: int, user_hero_log_id_1: int, user_hero_log_id_2: int, user_hero_log_id_3: int) -> Optional[int]: sql = insert(hero_party).values( user=user_id, user_party_team_id=user_party_team_id, @@ -270,7 +270,7 @@ class SaoItemData(BaseData): user_hero_log_id_3=user_hero_log_id_3, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert hero party! user: {user_id}, user_party_team_id: {user_party_team_id}" @@ -279,7 +279,7 @@ class SaoItemData(BaseData): return result.lastrowid - def put_player_quest(self, user_id: int, episode_id: int, quest_clear_flag: bool, clear_time: int, combo_num: int, total_damage: int, concurrent_destroying_num: int) -> Optional[int]: + async def put_player_quest(self, user_id: int, episode_id: int, quest_clear_flag: bool, clear_time: int, combo_num: int, total_damage: int, concurrent_destroying_num: int) -> Optional[int]: sql = insert(quest).values( user=user_id, episode_id=episode_id, @@ -298,7 +298,7 @@ class SaoItemData(BaseData): concurrent_destroying_num=concurrent_destroying_num ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert quest! user: {user_id}, episode_id: {episode_id}" @@ -307,15 +307,15 @@ class SaoItemData(BaseData): return result.lastrowid - def get_user_equipment(self, user_id: int, equipment_id: int) -> Optional[Dict]: + async def get_user_equipment(self, user_id: int, equipment_id: int) -> Optional[Dict]: sql = equipment_data.select(equipment_data.c.user == user_id and equipment_data.c.equipment_id == equipment_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_user_equipments( + async def get_user_equipments( self, user_id: int ) -> Optional[List[Row]]: """ @@ -327,12 +327,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_user_items( + async def get_user_items( self, user_id: int ) -> Optional[List[Row]]: """ @@ -344,12 +344,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_hero_log( + async def get_hero_log( self, user_id: int, user_hero_log_id: int = None ) -> Optional[List[Row]]: """ @@ -362,12 +362,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_hero_logs( + async def get_hero_logs( self, user_id: int ) -> Optional[List[Row]]: """ @@ -379,12 +379,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_hero_party( + async def get_hero_party( self, user_id: int, user_party_team_id: int = None ) -> Optional[List[Row]]: sql = hero_party.select( @@ -394,12 +394,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_quest_log( + async def get_quest_log( self, user_id: int, episode_id: int = None ) -> Optional[List[Row]]: """ @@ -412,12 +412,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_quest_logs( + async def get_quest_logs( self, user_id: int ) -> Optional[List[Row]]: """ @@ -429,12 +429,12 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_session( + async def get_session( self, user_id: int = None ) -> Optional[List[Row]]: sql = sessions.select( @@ -445,12 +445,12 @@ class SaoItemData(BaseData): sessions.c.play_date.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_end_session( + async def get_end_session( self, user_id: int = None ) -> Optional[List[Row]]: sql = end_sessions.select( @@ -461,12 +461,12 @@ class SaoItemData(BaseData): end_sessions.c.play_date.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def remove_hero_log(self, user_id: int, user_hero_log_id: int) -> None: + async def remove_hero_log(self, user_id: int, user_hero_log_id: int) -> None: sql = hero_log_data.delete( and_( hero_log_data.c.user == user_id, @@ -474,31 +474,31 @@ class SaoItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to remove hero log! profile: {user_id}, user_hero_log_id: {user_hero_log_id}" ) return None - def remove_equipment(self, user_id: int, equipment_id: int) -> None: + async def remove_equipment(self, user_id: int, equipment_id: int) -> None: sql = equipment_data.delete( and_(equipment_data.c.user == user_id, equipment_data.c.equipment_id == equipment_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to remove equipment! profile: {user_id}, equipment_id: {equipment_id}" ) return None - def remove_item(self, user_id: int, item_id: int) -> None: + async def remove_item(self, user_id: int, item_id: int) -> None: sql = item_data.delete( and_(item_data.c.user == user_id, item_data.c.item_id == item_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to remove item! profile: {user_id}, item_id: {item_id}" diff --git a/titles/sao/schema/profile.py b/titles/sao/schema/profile.py index d7320cc..8368afb 100644 --- a/titles/sao/schema/profile.py +++ b/titles/sao/schema/profile.py @@ -30,17 +30,17 @@ profile = Table( ) class SaoProfileData(BaseData): - def create_profile(self, user_id: int) -> Optional[int]: + async def create_profile(self, user_id: int) -> Optional[int]: sql = insert(profile).values(user=user_id) conflict = sql.on_duplicate_key_update(user=user_id) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"Failed to create SAO profile for user {user_id}!") return None return result.lastrowid - def put_profile(self, user_id: int, user_type: int, nick_name: str, rank_num: int, rank_exp: int, own_col: int, own_vp: int, own_yui_medal: int, setting_title_id: int) -> Optional[int]: + async def put_profile(self, user_id: int, user_type: int, nick_name: str, rank_num: int, rank_exp: int, own_col: int, own_vp: int, own_yui_medal: int, setting_title_id: int) -> Optional[int]: sql = insert(profile).values( user=user_id, user_type=user_type, @@ -62,7 +62,7 @@ class SaoProfileData(BaseData): setting_title_id=setting_title_id ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert profile! user: {user_id}" @@ -71,9 +71,9 @@ class SaoProfileData(BaseData): return result.lastrowid - def get_profile(self, user_id: int) -> Optional[Row]: + async def get_profile(self, user_id: int) -> Optional[Row]: sql = profile.select(profile.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() \ No newline at end of file diff --git a/titles/sao/schema/static.py b/titles/sao/schema/static.py index ce9a6a9..8b5b1a1 100644 --- a/titles/sao/schema/static.py +++ b/titles/sao/schema/static.py @@ -128,25 +128,25 @@ title = Table( ) class SaoStaticData(BaseData): - def put_quest( self, questSceneId: int, version: int, sortNo: int, name: str, enabled: bool ) -> Optional[int]: + async def put_quest( self, questSceneId: int, version: int, sortNo: int, name: str, enabled: bool ) -> Optional[int]: sql = insert(quest).values( questSceneId=questSceneId, version=version, sortNo=sortNo, name=name, - tutorial=tutorial, + enabled=enabled, ) conflict = sql.on_duplicate_key_update( name=name, questSceneId=questSceneId, version=version ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_hero( self, version: int, heroLogId: int, name: str, nickname: str, rarity: int, skillTableSubId: int, awakeningExp: int, flavorText: str, enabled: bool ) -> Optional[int]: + async def put_hero( self, version: int, heroLogId: int, name: str, nickname: str, rarity: int, skillTableSubId: int, awakeningExp: int, flavorText: str, enabled: bool ) -> Optional[int]: sql = insert(hero).values( version=version, heroLogId=heroLogId, @@ -163,12 +163,12 @@ class SaoStaticData(BaseData): name=name, heroLogId=heroLogId ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_equipment( self, version: int, equipmentId: int, name: str, equipmentType: int, weaponTypeId:int, rarity: int, flavorText: str, enabled: bool ) -> Optional[int]: + async def put_equipment( self, version: int, equipmentId: int, name: str, equipmentType: int, weaponTypeId:int, rarity: int, flavorText: str, enabled: bool ) -> Optional[int]: sql = insert(equipment).values( version=version, equipmentId=equipmentId, @@ -184,12 +184,12 @@ class SaoStaticData(BaseData): name=name, equipmentId=equipmentId ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_item( self, version: int, itemId: int, name: str, itemTypeId: int, rarity: int, flavorText: str, enabled: bool ) -> Optional[int]: + async def put_item( self, version: int, itemId: int, name: str, itemTypeId: int, rarity: int, flavorText: str, enabled: bool ) -> Optional[int]: sql = insert(item).values( version=version, itemId=itemId, @@ -204,12 +204,12 @@ class SaoStaticData(BaseData): name=name, itemId=itemId ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_support_log( self, version: int, supportLogId: int, charaId: int, name: str, rarity: int, salePrice: int, skillName: str, enabled: bool ) -> Optional[int]: + async def put_support_log( self, version: int, supportLogId: int, charaId: int, name: str, rarity: int, salePrice: int, skillName: str, enabled: bool ) -> Optional[int]: sql = insert(support).values( version=version, supportLogId=supportLogId, @@ -225,12 +225,12 @@ class SaoStaticData(BaseData): name=name, supportLogId=supportLogId ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_rare_drop( self, version: int, questRareDropId: int, commonRewardId: int, enabled: bool ) -> Optional[int]: + async def put_rare_drop( self, version: int, questRareDropId: int, commonRewardId: int, enabled: bool ) -> Optional[int]: sql = insert(rare_drop).values( version=version, questRareDropId=questRareDropId, @@ -242,12 +242,12 @@ class SaoStaticData(BaseData): questRareDropId=questRareDropId, commonRewardId=commonRewardId, version=version ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def put_title( self, version: int, titleId: int, displayName: str, requirement: int, rank: int, imageFilePath: str, enabled: bool ) -> Optional[int]: + async def put_title( self, version: int, titleId: int, displayName: str, requirement: int, rank: int, imageFilePath: str, enabled: bool ) -> Optional[int]: sql = insert(title).values( version=version, titleId=titleId, @@ -262,107 +262,107 @@ class SaoStaticData(BaseData): displayName=displayName, titleId=titleId ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: return None return result.lastrowid - def get_quests_id(self, sortNo: int) -> Optional[Dict]: + async def get_quests_id(self, sortNo: int) -> Optional[Dict]: sql = quest.select(quest.c.sortNo == sortNo) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_quests_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: + async def get_quests_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = quest.select(quest.c.version == version and quest.c.enabled == enabled).order_by( quest.c.questSceneId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return [list[2] for list in result.fetchall()] - def get_hero_id(self, heroLogId: int) -> Optional[Dict]: + async def get_hero_id(self, heroLogId: int) -> Optional[Dict]: sql = hero.select(hero.c.heroLogId == heroLogId) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_hero_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: + async def get_hero_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = hero.select(hero.c.version == version and hero.c.enabled == enabled).order_by( hero.c.heroLogId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return [list[2] for list in result.fetchall()] - def get_equipment_id(self, equipmentId: int) -> Optional[Dict]: + async def get_equipment_id(self, equipmentId: int) -> Optional[Dict]: sql = equipment.select(equipment.c.equipmentId == equipmentId) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_equipment_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: + async def get_equipment_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = equipment.select(equipment.c.version == version and equipment.c.enabled == enabled).order_by( equipment.c.equipmentId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return [list[2] for list in result.fetchall()] - def get_item_id(self, itemId: int) -> Optional[Dict]: + async def get_item_id(self, itemId: int) -> Optional[Dict]: sql = item.select(item.c.itemId == itemId) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_rare_drop_id(self, questRareDropId: int) -> Optional[Dict]: + async def get_rare_drop_id(self, questRareDropId: int) -> Optional[Dict]: sql = rare_drop.select(rare_drop.c.questRareDropId == questRareDropId) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_item_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: + async def get_item_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = item.select(item.c.version == version and item.c.enabled == enabled).order_by( item.c.itemId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return [list[2] for list in result.fetchall()] - def get_support_log_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: + async def get_support_log_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = support.select(support.c.version == version and support.c.enabled == enabled).order_by( support.c.supportLogId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return [list[2] for list in result.fetchall()] - def get_title_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: + async def get_title_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = title.select(title.c.version == version and title.c.enabled == enabled).order_by( title.c.titleId.asc() ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return [list[2] for list in result.fetchall()] \ No newline at end of file diff --git a/titles/wacca/base.py b/titles/wacca/base.py index c0be449..8a37c2b 100644 --- a/titles/wacca/base.py +++ b/titles/wacca/base.py @@ -98,9 +98,9 @@ class WaccaBase: req = HousingStartRequestV1(data) allnet_region_id = None - machine = self.data.arcade.get_machine(req.chipId) + machine = await self.data.arcade.get_machine(req.chipId) if machine is not None: - arcade = self.data.arcade.get_arcade(machine["arcade"]) + arcade = await self.data.arcade.get_arcade(machine["arcade"]) allnet_region_id = arcade["region_id"] if req.appVersion.country == AllnetCountryCode.JAPAN.value: @@ -139,7 +139,7 @@ class WaccaBase: req = UserStatusGetRequest(data) resp = UserStatusGetV1Response() - profile = self.data.profile.get_profile(aime_id=req.aimeId) + profile = await self.data.profile.get_profile(aime_id=req.aimeId) if profile is None: self.logger.info(f"No user exists for aime id {req.aimeId}") resp.profileStatus = ProfileStatus.ProfileRegister @@ -159,14 +159,14 @@ class WaccaBase: resp.userStatus.wp = profile["wp"] resp.userStatus.useCount = profile["login_count"] - set_title_id = self.data.profile.get_options( + set_title_id = await self.data.profile.get_options( WaccaConstants.OPTIONS["set_title_id"], profile["user"] ) if set_title_id is None: set_title_id = self.OPTIONS_DEFAULTS["set_title_id"] resp.setTitleId = set_title_id - set_icon_id = self.data.profile.get_options( + set_icon_id = await self.data.profile.get_options( WaccaConstants.OPTIONS["set_title_id"], profile["user"] ) if set_icon_id is None: @@ -191,7 +191,7 @@ class WaccaBase: resp.lastLoginDate = 0 else: - profile = self.data.profile.get_profile(req.userId) + profile = await self.data.profile.get_profile(req.userId) if profile is None: self.logger.warning( f"Unknown user id {req.userId} attempted login from {req.chipId}" @@ -215,7 +215,7 @@ class WaccaBase: if midnight_today_ts - last_login_time > 86400: is_consec_day = False - self.data.profile.session_login( + await self.data.profile.session_login( req.userId, resp.firstLoginDaily, is_consec_day ) @@ -230,7 +230,7 @@ class WaccaBase: async def handle_user_status_create_request(self, data: Dict) -> Dict: req = UserStatusCreateRequest(data) - profileId = self.data.profile.create_profile( + profileId = await self.data.profile.create_profile( req.aimeId, req.username, self.version ) @@ -239,30 +239,30 @@ class WaccaBase: if profileId == 0: # We've already made this profile, just return success - new_user = self.data.profile.get_profile(aime_id=req.aimeId) + new_user = await self.data.profile.get_profile(aime_id=req.aimeId) profileId = new_user['id'] # Insert starting items - self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104001) - self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104002) - self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104003) - self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104005) + await self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104001) + await self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104002) + await self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104003) + await self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["title"], 104005) - self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["icon"], 102001) - self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["icon"], 102002) + await self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["icon"], 102001) + await self.data.item.put_item(req.aimeId, WaccaConstants.ITEM_TYPES["icon"], 102002) - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["note_color"], 103001 ) - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["note_color"], 203001 ) - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["note_sound"], 105001 ) - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210001 ) @@ -272,7 +272,7 @@ class WaccaBase: req = UserStatusGetDetailRequest(data) resp = UserStatusGetDetailResponseV1() - profile = self.data.profile.get_profile(req.userId) + profile = await self.data.profile.get_profile(req.userId) if profile is None: self.logger.warning(f"Unknown profile {req.userId}") return resp.make() @@ -280,12 +280,12 @@ class WaccaBase: self.logger.info(f"Get detail for profile {req.userId}") user_id = profile["user"] - profile_scores = self.data.score.get_best_scores(user_id) - profile_items = self.data.item.get_items(user_id) - profile_song_unlocks = self.data.item.get_song_unlocks(user_id) - profile_options = self.data.profile.get_options(user_id) - profile_trophies = self.data.item.get_trophies(user_id) - profile_tickets = self.data.item.get_tickets(user_id) + profile_scores = await self.data.score.get_best_scores(user_id) + profile_items = await self.data.item.get_items(user_id) + profile_song_unlocks = await self.data.item.get_song_unlocks(user_id) + profile_options = await self.data.profile.get_options(user_id) + profile_trophies = await self.data.item.get_trophies(user_id) + profile_tickets = await self.data.item.get_tickets(user_id) resp.songUpdateTime = int(profile["last_login_date"].timestamp()) resp.songPlayStatus = [profile["last_song_id"], 1] @@ -437,7 +437,7 @@ class WaccaBase: req = UserTrialGetRequest(data) resp = UserTrialGetResponse() - user_id = self.data.profile.profile_to_aime_user(req.profileId) + user_id = await self.data.profile.profile_to_aime_user(req.profileId) if user_id is None: self.logger.error( f"handle_user_trial_get_request: No profile with id {req.profileId}" @@ -445,7 +445,7 @@ class WaccaBase: return resp.make() self.logger.info(f"Get trial info for user {req.profileId}") - stages = self.data.score.get_stageup(user_id, self.version) + stages = await self.data.score.get_stageup(user_id, self.version) if stages is None: stages = [] @@ -485,15 +485,15 @@ class WaccaBase: while len(req.songScores) < 3: req.songScores.append(0) - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) user_id = profile["user"] - old_stage = self.data.score.get_stageup_stage( + old_stage = await self.data.score.get_stageup_stage( user_id, self.version, req.stageId ) if old_stage is None: - self.data.score.put_stageup( + await self.data.score.put_stageup( user_id, self.version, req.stageId, @@ -519,7 +519,7 @@ class WaccaBase: best_score2 = old_stage["song2_score"] best_score3 = old_stage["song3_score"] - self.data.score.put_stageup( + await self.data.score.put_stageup( user_id, self.version, req.stageId, @@ -537,17 +537,17 @@ class WaccaBase: req.stageLevel == profile["dan_level"] and req.clearType.value > profile["dan_type"] ): - self.data.profile.update_profile_dan( + await self.data.profile.update_profile_dan( req.profileId, req.stageLevel, req.clearType.value ) - self.util_put_items(req.profileId, user_id, req.itemsObtained) + await self.util_put_items(req.profileId, user_id, req.itemsObtained) # user/status/update isn't called after stageup so we have to do some things now - current_icon = self.data.profile.get_options( + current_icon = await self.data.profile.get_options( user_id, WaccaConstants.OPTIONS["set_icon_id"] ) - current_nav = self.data.profile.get_options( + current_nav = await self.data.profile.get_options( user_id, WaccaConstants.OPTIONS["set_nav_id"] ) @@ -560,13 +560,13 @@ class WaccaBase: else: current_nav = current_nav["value"] - self.data.item.put_item( + await self.data.item.put_item( user_id, WaccaConstants.ITEM_TYPES["icon"], current_icon ) - self.data.item.put_item( + await self.data.item.put_item( user_id, WaccaConstants.ITEM_TYPES["navigator"], current_nav ) - self.data.profile.update_profile_playtype( + await self.data.profile.update_profile_playtype( req.profileId, 4, data["appVersion"][:7] ) return BaseResponse().make() @@ -583,16 +583,16 @@ class WaccaBase: req = UserSugarokuUpdateRequestV2(data) mission_flg = req.mission_flag - user_id = self.data.profile.profile_to_aime_user(req.profileId) + user_id = await self.data.profile.profile_to_aime_user(req.profileId) if user_id is None: self.logger.info( f"handle_user_sugoroku_update_request unknwon profile ID {req.profileId}" ) return resp.make() - self.util_put_items(req.profileId, user_id, req.itemsObtainted) + await self.util_put_items(req.profileId, user_id, req.itemsObtainted) - self.data.profile.update_gate( + await self.data.profile.update_gate( user_id, req.gateId, req.page, @@ -609,13 +609,13 @@ class WaccaBase: async def handle_user_music_unlock_request(self, data: Dict) -> Dict: req = UserMusicUnlockRequest(data) - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) if profile is None: return BaseResponse().make() user_id = profile["user"] current_wp = profile["wp"] - tickets = self.data.item.get_tickets(user_id) + tickets = await self.data.item.get_tickets(user_id) new_tickets: List[TicketItem] = [] for ticket in tickets: @@ -628,7 +628,7 @@ class WaccaBase: ): if current_wp >= item.quantity: current_wp -= item.quantity - self.data.profile.spend_wp(req.profileId, item.quantity) + await self.data.profile.spend_wp(req.profileId, item.quantity) else: return BaseResponse().make() @@ -641,21 +641,21 @@ class WaccaBase: self.logger.debug( f"Remove ticket ID {new_tickets[x].userTicketId} type {new_tickets[x].ticketId} from {user_id}" ) - self.data.item.spend_ticket(new_tickets[x].userTicketId) + await self.data.item.spend_ticket(new_tickets[x].userTicketId) new_tickets.pop(x) break # wp, ticket info if req.difficulty > WaccaConstants.Difficulty.HARD.value: - old_score = self.data.score.get_best_score( + old_score = await self.data.score.get_best_score( user_id, req.songId, req.difficulty ) if not old_score: - self.data.score.put_best_score( + await self.data.score.put_best_score( user_id, req.songId, req.difficulty, 0, [0] * 5, [0] * 13, 0, 0 ) - self.data.item.unlock_song( + await self.data.item.unlock_song( user_id, req.songId, req.difficulty @@ -698,7 +698,7 @@ class WaccaBase: ) return resp.make() - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) if profile is None: self.logger.warning( @@ -707,7 +707,7 @@ class WaccaBase: return resp.make() user_id = profile["user"] - self.util_put_items(req.profileId, user_id, req.itemsObtained) + await self.util_put_items(req.profileId, user_id, req.itemsObtained) playlog_clear_status = ( req.songDetail.flagCleared @@ -716,7 +716,7 @@ class WaccaBase: + req.songDetail.flagAllMarvelous ) - self.data.score.put_playlog( + await self.data.score.put_playlog( user_id, req.songDetail.songId, req.songDetail.difficulty, @@ -733,7 +733,7 @@ class WaccaBase: self.season, ) - old_score = self.data.score.get_best_score( + old_score = await self.data.score.get_best_score( user_id, req.songDetail.songId, req.songDetail.difficulty ) @@ -749,7 +749,7 @@ class WaccaBase: grades[req.songDetail.grade.value - 1] = 1 - self.data.score.put_best_score( + await self.data.score.put_best_score( user_id, req.songDetail.songId, req.songDetail.difficulty, @@ -805,7 +805,7 @@ class WaccaBase: old_score["rating"], ) - self.data.score.put_best_score( + await self.data.score.put_best_score( user_id, req.songDetail.songId, req.songDetail.difficulty, @@ -846,17 +846,17 @@ class WaccaBase: req = UserMissionUpdateRequest(data) page_status = req.params[1][1] - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) if profile is None: return BaseResponse().make() if len(req.itemsObtained) > 0: - self.util_put_items(req.profileId, profile["user"], req.itemsObtained) + await self.util_put_items(req.profileId, profile["user"], req.itemsObtained) - self.data.profile.update_bingo( + await self.data.profile.update_bingo( profile["user"], req.bingoDetail.pageNumber, page_status ) - self.data.profile.update_tutorial_flags(req.profileId, req.params[3]) + await self.data.profile.update_tutorial_flags(req.profileId, req.params[3]) return BaseResponse().make() @@ -864,7 +864,7 @@ class WaccaBase: req = UserGoodsPurchaseRequest(data) resp = UserGoodsPurchaseResponse() - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) if profile is None: return BaseResponse().make() @@ -876,20 +876,20 @@ class WaccaBase: and not self.game_config.mods.infinite_wp ): resp.currentWp -= req.cost - self.data.profile.spend_wp(req.profileId, req.cost) + await self.data.profile.spend_wp(req.profileId, req.cost) elif req.purchaseType == PurchaseType.PurchaseTypeCredit: self.logger.info( f"User {req.profileId} Purchased item {req.itemObtained.itemType} id {req.itemObtained.itemId} for {req.cost} credits on machine {req.chipId}" ) - self.util_put_items(req.profileId, user_id, [req.itemObtained]) + await self.util_put_items(req.profileId, user_id, [req.itemObtained]) if self.game_config.mods.infinite_tickets: for x in range(5): resp.tickets.append(TicketItem(x, 106002, 0)) else: - tickets = self.data.item.get_tickets(user_id) + tickets = await self.data.item.get_tickets(user_id) for ticket in tickets: resp.tickets.append( @@ -914,7 +914,7 @@ class WaccaBase: async def handle_user_rating_update_request(self, data: Dict) -> Dict: req = UserRatingUpdateRequest(data) - user_id = self.data.profile.profile_to_aime_user(req.profileId) + user_id = await self.data.profile.profile_to_aime_user(req.profileId) if user_id is None: self.logger.error( @@ -923,33 +923,33 @@ class WaccaBase: return BaseResponse().make() for song in req.songs: - self.data.score.update_song_rating( + await self.data.score.update_song_rating( user_id, song.songId, song.difficulty, song.rating ) - self.data.profile.update_user_rating(req.profileId, req.totalRating) + await self.data.profile.update_user_rating(req.profileId, req.totalRating) return BaseResponse().make() async def handle_user_status_update_request(self, data: Dict) -> Dict: req = UserStatusUpdateRequestV1(data) - user_id = self.data.profile.profile_to_aime_user(req.profileId) + user_id = await self.data.profile.profile_to_aime_user(req.profileId) if user_id is None: self.logger.info( f"handle_user_status_update_request: No profile with ID {req.profileId}" ) return BaseResponse().make() - self.util_put_items(req.profileId, user_id, req.itemsRecieved) - self.data.profile.update_profile_playtype( + await self.util_put_items(req.profileId, user_id, req.itemsRecieved) + await self.data.profile.update_profile_playtype( req.profileId, req.playType.value, data["appVersion"][:7] ) - current_icon = self.data.profile.get_options( + current_icon = await self.data.profile.get_options( user_id, WaccaConstants.OPTIONS["set_icon_id"] ) - current_nav = self.data.profile.get_options( + current_nav = await self.data.profile.get_options( user_id, WaccaConstants.OPTIONS["set_nav_id"] ) @@ -962,10 +962,10 @@ class WaccaBase: else: current_nav = current_nav["value"] - self.data.item.put_item( + await self.data.item.put_item( user_id, WaccaConstants.ITEM_TYPES["icon"], current_icon ) - self.data.item.put_item( + await self.data.item.put_item( user_id, WaccaConstants.ITEM_TYPES["navigator"], current_nav ) return BaseResponse().make() @@ -973,19 +973,19 @@ class WaccaBase: async def handle_user_info_update_request(self, data: Dict) -> Dict: req = UserInfoUpdateRequest(data) - user_id = self.data.profile.profile_to_aime_user(req.profileId) + user_id = await self.data.profile.profile_to_aime_user(req.profileId) for opt in req.optsUpdated: - self.data.profile.update_option(user_id, opt.optId, opt.optVal) + await self.data.profile.update_option(user_id, opt.optId, opt.optVal) for update in req.datesUpdated: pass for fav in req.favoritesAdded: - self.data.profile.add_favorite_song(user_id, fav) + await self.data.profile.add_favorite_song(user_id, fav) for unfav in req.favoritesRemoved: - self.data.profile.remove_favorite_song(user_id, unfav) + await self.data.profile.remove_favorite_song(user_id, unfav) return BaseResponse().make() @@ -993,7 +993,7 @@ class WaccaBase: req = UserVipGetRequest(data) resp = UserVipGetResponse() - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) if profile is None: self.logger.warning( f"handle_user_vip_get_request no profile with ID {req.profileId}" @@ -1024,7 +1024,7 @@ class WaccaBase: async def handle_user_vip_start_request(self, data: Dict) -> Dict: req = UserVipStartRequest(data) - profile = self.data.profile.get_profile(req.profileId) + profile = await self.data.profile.get_profile(req.profileId) if profile is None: return BaseResponse().make() @@ -1040,10 +1040,10 @@ class WaccaBase: ).make() vip_exp_time = self.srvtime + timedelta(days=req.days) - self.data.profile.update_vip_time(req.profileId, vip_exp_time) + await self.data.profile.update_vip_time(req.profileId, vip_exp_time) return UserVipStartResponse(int(vip_exp_time.timestamp())).make() - def util_put_items( + async def util_put_items( self, profile_id: int, user_id: int, items_obtained: List[GenericItemRecv] ) -> None: if user_id is None or profile_id <= 0: @@ -1052,10 +1052,10 @@ class WaccaBase: if items_obtained: for item in items_obtained: if item.itemType == WaccaConstants.ITEM_TYPES["xp"]: - self.data.profile.add_xp(profile_id, item.quantity) + await self.data.profile.add_xp(profile_id, item.quantity) elif item.itemType == WaccaConstants.ITEM_TYPES["wp"]: - self.data.profile.add_wp(profile_id, item.quantity) + await self.data.profile.add_wp(profile_id, item.quantity) elif ( item.itemType @@ -1063,11 +1063,11 @@ class WaccaBase: or item.itemType == WaccaConstants.ITEM_TYPES["music_unlock"] ): if item.quantity > WaccaConstants.Difficulty.HARD.value: - old_score = self.data.score.get_best_score( + old_score = await self.data.score.get_best_score( user_id, item.itemId, item.quantity ) if not old_score: - self.data.score.put_best_score( + await self.data.score.put_best_score( user_id, item.itemId, item.quantity, @@ -1080,18 +1080,18 @@ class WaccaBase: if item.quantity == 0: item.quantity = WaccaConstants.Difficulty.HARD.value - self.data.item.unlock_song(user_id, item.itemId, item.quantity) + await self.data.item.unlock_song(user_id, item.itemId, item.quantity) elif item.itemType == WaccaConstants.ITEM_TYPES["ticket"]: - self.data.item.add_ticket(user_id, item.itemId) + await self.data.item.add_ticket(user_id, item.itemId) elif item.itemType == WaccaConstants.ITEM_TYPES["trophy"]: - self.data.item.update_trophy( + await self.data.item.update_trophy( user_id, item.itemId, self.season, item.quantity, 0 ) else: - self.data.item.put_item(user_id, item.itemType, item.itemId) + await self.data.item.put_item(user_id, item.itemType, item.itemId) def util_calc_song_rating(self, score: int, difficulty: float) -> int: if score >= 990000: diff --git a/titles/wacca/frontend.py b/titles/wacca/frontend.py index fb55de1..cd915bb 100644 --- a/titles/wacca/frontend.py +++ b/titles/wacca/frontend.py @@ -24,7 +24,7 @@ class WaccaFrontend(FE_Base): ) self.nav_name = "Wacca" - def render_GET(self, request: Request) -> bytes: + async def render_GET(self, request: Request) -> bytes: template = self.environment.get_template( "titles/wacca/frontend/wacca_index.jinja" ) diff --git a/titles/wacca/lily.py b/titles/wacca/lily.py index d92e417..9f3f817 100644 --- a/titles/wacca/lily.py +++ b/titles/wacca/lily.py @@ -45,20 +45,20 @@ class WaccaLily(WaccaS): req = UserStatusCreateRequest(data) ret = await super().handle_user_status_create_request(data) - new_user = self.data.profile.get_profile(aime_id=req.aimeId) + new_user = await self.data.profile.get_profile(aime_id=req.aimeId) if new_user is None: return BaseResponse().make() - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["user_plate"], 211001 ) # Added lily - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["note_sound"], 205005 ) # Added lily - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210002 ) # Lily, Added Lily @@ -68,13 +68,13 @@ class WaccaLily(WaccaS): req = UserStatusGetRequest(data) resp = UserStatusGetV2Response() - profile = self.data.profile.get_profile(aime_id=req.aimeId) + profile = await self.data.profile.get_profile(aime_id=req.aimeId) if profile is None: self.logger.info(f"No user exists for aime id {req.aimeId}") resp.profileStatus = ProfileStatus.ProfileRegister return resp.make() - opts = self.data.profile.get_options(req.aimeId) + opts = await self.data.profile.get_options(req.aimeId) self.logger.info(f"User preview for {req.aimeId} from {req.chipId}") if profile["last_game_ver"] is None: @@ -94,14 +94,14 @@ class WaccaLily(WaccaS): resp.userStatus.loginsToday = profile["login_count_today"] resp.userStatus.rating = profile["rating"] - set_title_id = self.data.profile.get_options( + set_title_id = await self.data.profile.get_options( WaccaConstants.OPTIONS["set_title_id"], profile["user"] ) if set_title_id is None: set_title_id = self.OPTIONS_DEFAULTS["set_title_id"] resp.setTitleId = set_title_id - set_icon_id = self.data.profile.get_options( + set_icon_id = await self.data.profile.get_options( WaccaConstants.OPTIONS["set_title_id"], profile["user"] ) if set_icon_id is None: @@ -155,7 +155,7 @@ class WaccaLily(WaccaS): resp.lastLoginDate = 0 else: - profile = self.data.profile.get_profile(req.userId) + profile = await self.data.profile.get_profile(req.userId) if profile is None: self.logger.warning( f"Unknown user id {req.userId} attempted login from {req.chipId}" @@ -179,7 +179,7 @@ class WaccaLily(WaccaS): if midnight_today_ts - last_login_time > 86400: is_consec_day = False - self.data.profile.session_login( + await self.data.profile.session_login( req.userId, resp.firstLoginDaily, is_consec_day ) resp.vipInfo.pageYear = datetime.now().year @@ -196,7 +196,7 @@ class WaccaLily(WaccaS): else: resp = UserStatusGetDetailResponseV2() - profile = self.data.profile.get_profile(req.userId) + profile = await self.data.profile.get_profile(req.userId) if profile is None: self.logger.warning(f"Unknown profile {req.userId}") return resp.make() @@ -204,14 +204,14 @@ class WaccaLily(WaccaS): self.logger.info(f"Get detail for profile {req.userId}") user_id = profile["user"] - profile_scores = self.data.score.get_best_scores(user_id) - profile_items = self.data.item.get_items(user_id) - profile_song_unlocks = self.data.item.get_song_unlocks(user_id) - profile_options = self.data.profile.get_options(user_id) - profile_favorites = self.data.profile.get_favorite_songs(user_id) - profile_gates = self.data.profile.get_gates(user_id) - profile_trophies = self.data.item.get_trophies(user_id) - profile_tickets = self.data.item.get_tickets(user_id) + profile_scores = await self.data.score.get_best_scores(user_id) + profile_items = await self.data.item.get_items(user_id) + profile_song_unlocks = await self.data.item.get_song_unlocks(user_id) + profile_options = await self.data.profile.get_options(user_id) + profile_favorites = await self.data.profile.get_favorite_songs(user_id) + profile_gates = await self.data.profile.get_gates(user_id) + profile_trophies = await self.data.item.get_trophies(user_id) + profile_tickets = await self.data.item.get_tickets(user_id) if profile["vip_expire_time"] is None: resp.userStatus.vipExpireTime = 0 @@ -446,7 +446,7 @@ class WaccaLily(WaccaS): async def handle_user_status_update_request(self, data: Dict) -> Dict: super().handle_user_status_update_request(data) req = UserStatusUpdateRequestV2(data) - self.data.profile.update_profile_lastplayed( + await self.data.profile.update_profile_lastplayed( req.profileId, req.lastSongInfo.lastSongId, req.lastSongInfo.lastSongDiff, diff --git a/titles/wacca/lilyr.py b/titles/wacca/lilyr.py index 83f9bf6..204a656 100644 --- a/titles/wacca/lilyr.py +++ b/titles/wacca/lilyr.py @@ -43,9 +43,9 @@ class WaccaLilyR(WaccaLily): req = HousingStartRequestV2(data) allnet_region_id = None - machine = self.data.arcade.get_machine(req.chipId) + machine = await self.data.arcade.get_machine(req.chipId) if machine is not None: - arcade = self.data.arcade.get_arcade(machine["arcade"]) + arcade = await self.data.arcade.get_arcade(machine["arcade"]) allnet_region_id = arcade["region_id"] if req.appVersion.country == AllnetCountryCode.JAPAN.value: @@ -75,28 +75,28 @@ class WaccaLilyR(WaccaLily): req = UserStatusCreateRequest(data) resp = await super().handle_user_status_create_request(data) - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210054 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210055 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210056 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210057 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210058 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210059 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210060 ) # Added lily r - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 210061 ) # Added lily r diff --git a/titles/wacca/read.py b/titles/wacca/read.py index 8fe5b6a..91fae03 100644 --- a/titles/wacca/read.py +++ b/titles/wacca/read.py @@ -29,7 +29,7 @@ class WaccaReader(BaseReader): self.logger.error(f"Invalid wacca version {version}") exit(1) - def read(self) -> None: + async def read(self) -> None: if not ( path.exists(f"{self.bin_dir}/Table") and path.exists(f"{self.bin_dir}/Message") @@ -37,9 +37,9 @@ class WaccaReader(BaseReader): self.logger.error("Could not find Table or Message folder, nothing to read") return - self.read_music(f"{self.bin_dir}/Table", "MusicParameterTable") + await self.read_music(f"{self.bin_dir}/Table", "MusicParameterTable") - def read_music(self, base_dir: str, table: str) -> None: + async def read_music(self, base_dir: str, table: str) -> None: if not self.check_valid_pair(base_dir, table): self.logger.warning( f"Cannot find {table} uasset/uexp pair at {base_dir}, music will not be read" @@ -67,7 +67,7 @@ class WaccaReader(BaseReader): designer = wacca_data[str(key)]["NotesDesignerNormal"] if diff > 0: - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 1, @@ -84,7 +84,7 @@ class WaccaReader(BaseReader): designer = wacca_data[str(key)]["NotesDesignerHard"] if diff > 0: - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 2, @@ -101,7 +101,7 @@ class WaccaReader(BaseReader): designer = wacca_data[str(key)]["NotesDesignerExpert"] if diff > 0: - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 3, @@ -118,7 +118,7 @@ class WaccaReader(BaseReader): designer = wacca_data[str(key)]["NotesDesignerInferno"] if diff > 0: - self.data.static.put_music( + await self.data.static.put_music( self.version, song_id, 4, diff --git a/titles/wacca/reverse.py b/titles/wacca/reverse.py index 51e8c63..be34024 100644 --- a/titles/wacca/reverse.py +++ b/titles/wacca/reverse.py @@ -56,7 +56,7 @@ class WaccaReverse(WaccaLilyR): req = UserStatusGetDetailRequest(data) resp = UserStatusGetDetailResponseV4() - profile = self.data.profile.get_profile(req.userId) + profile = await self.data.profile.get_profile(req.userId) if profile is None: self.logger.warning(f"Unknown profile {req.userId}") return resp.make() @@ -64,15 +64,15 @@ class WaccaReverse(WaccaLilyR): self.logger.info(f"Get detail for profile {req.userId}") user_id = profile["user"] - profile_scores = self.data.score.get_best_scores(user_id) - profile_items = self.data.item.get_items(user_id) - profile_song_unlocks = self.data.item.get_song_unlocks(user_id) - profile_options = self.data.profile.get_options(user_id) - profile_favorites = self.data.profile.get_favorite_songs(user_id) - profile_gates = self.data.profile.get_gates(user_id) - profile_bingo = self.data.profile.get_bingo(user_id) - profile_trophies = self.data.item.get_trophies(user_id) - profile_tickets = self.data.item.get_tickets(user_id) + profile_scores = await self.data.score.get_best_scores(user_id) + profile_items = await self.data.item.get_items(user_id) + profile_song_unlocks = await self.data.item.get_song_unlocks(user_id) + profile_options = await self.data.profile.get_options(user_id) + profile_favorites = await self.data.profile.get_favorite_songs(user_id) + profile_gates = await self.data.profile.get_gates(user_id) + profile_bingo = await self.data.profile.get_bingo(user_id) + profile_trophies = await self.data.item.get_trophies(user_id) + profile_tickets = await self.data.item.get_tickets(user_id) if profile["gate_tutorial_flags"] is not None: for x in profile["gate_tutorial_flags"]: @@ -309,17 +309,17 @@ class WaccaReverse(WaccaLilyR): req = UserStatusCreateRequest(data) resp = await super().handle_user_status_create_request(data) - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 310001 ) # Added reverse - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["navigator"], 310002 ) # Added reverse - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["touch_effect"], 312000 ) # Added reverse - self.data.item.put_item( + await self.data.item.put_item( req.aimeId, WaccaConstants.ITEM_TYPES["touch_effect"], 312001 ) # Added reverse diff --git a/titles/wacca/schema/item.py b/titles/wacca/schema/item.py index df3380a..413b133 100644 --- a/titles/wacca/schema/item.py +++ b/titles/wacca/schema/item.py @@ -75,16 +75,16 @@ trophy = Table( class WaccaItemData(BaseData): - def get_song_unlocks(self, user_id: int) -> Optional[List[Row]]: + async def get_song_unlocks(self, user_id: int) -> Optional[List[Row]]: sql = song_unlock.select(song_unlock.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def unlock_song(self, user_id: int, song_id: int, difficulty: int) -> Optional[int]: + async def unlock_song(self, user_id: int, song_id: int, difficulty: int) -> Optional[int]: sql = insert(song_unlock).values( user=user_id, song_id=song_id, highest_difficulty=difficulty ) @@ -99,7 +99,7 @@ class WaccaItemData(BaseData): ) ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to unlock song! user: {user_id}, song_id: {song_id}, difficulty: {difficulty}" @@ -108,7 +108,7 @@ class WaccaItemData(BaseData): return result.lastrowid - def put_item(self, user_id: int, item_type: int, item_id: int) -> Optional[int]: + async def put_item(self, user_id: int, item_type: int, item_id: int) -> Optional[int]: sql = insert(item).values( user=user_id, item_id=item_id, @@ -117,7 +117,7 @@ class WaccaItemData(BaseData): conflict = sql.on_duplicate_key_update(use_count=item.c.use_count + 1) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert item! user: {user_id}, item_id: {item_id}, item_type: {item_type}" @@ -126,7 +126,7 @@ class WaccaItemData(BaseData): return result.lastrowid - def get_items( + async def get_items( self, user_id: int, item_type: int = None, item_id: int = None ) -> Optional[List[Row]]: """ @@ -140,23 +140,23 @@ class WaccaItemData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_tickets(self, user_id: int) -> Optional[List[Row]]: + async def get_tickets(self, user_id: int) -> Optional[List[Row]]: sql = select(ticket).where(ticket.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def add_ticket(self, user_id: int, ticket_id: int) -> None: + async def add_ticket(self, user_id: int, ticket_id: int) -> None: sql = insert(ticket).values(user=user_id, ticket_id=ticket_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"add_ticket: Failed to insert wacca ticket! user_id: {user_id} ticket_id {ticket_id}" @@ -164,15 +164,15 @@ class WaccaItemData(BaseData): return None return result.lastrowid - def spend_ticket(self, id: int) -> None: + async def spend_ticket(self, id: int) -> None: sql = delete(ticket).where(ticket.c.id == id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning(f"Failed to delete ticket id {id}") return None - def get_trophies(self, user_id: int, season: int = None) -> Optional[List[Row]]: + async def get_trophies(self, user_id: int, season: int = None) -> Optional[List[Row]]: if season is None: sql = select(trophy).where(trophy.c.user == user_id) else: @@ -180,12 +180,12 @@ class WaccaItemData(BaseData): and_(trophy.c.user == user_id, trophy.c.season == season) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def update_trophy( + async def update_trophy( self, user_id: int, trophy_id: int, season: int, progress: int, badge_type: int ) -> Optional[int]: sql = insert(trophy).values( @@ -198,7 +198,7 @@ class WaccaItemData(BaseData): conflict = sql.on_duplicate_key_update(progress=progress) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"update_trophy: Failed to insert wacca trophy! user_id: {user_id} trophy_id: {trophy_id} progress {progress}" diff --git a/titles/wacca/schema/profile.py b/titles/wacca/schema/profile.py index ff13782..9e09142 100644 --- a/titles/wacca/schema/profile.py +++ b/titles/wacca/schema/profile.py @@ -139,7 +139,7 @@ gate = Table( class WaccaProfileData(BaseData): - def create_profile( + async def create_profile( self, aime_id: int, username: str, version: int ) -> Optional[int]: """ @@ -149,7 +149,7 @@ class WaccaProfileData(BaseData): conflict = sql.on_duplicate_key_update(username=sql.inserted.username) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} Failed to insert wacca profile! aime id: {aime_id} username: {username}" @@ -157,7 +157,7 @@ class WaccaProfileData(BaseData): return None return result.lastrowid - def update_profile_playtype( + async def update_profile_playtype( self, profile_id: int, play_type: int, game_version: str ) -> None: sql = profile.update(profile.c.id == profile_id).values( @@ -179,14 +179,14 @@ class WaccaProfileData(BaseData): last_game_ver=game_version, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"update_profile: failed to update profile! profile: {profile_id}" ) return None - def update_profile_lastplayed( + async def update_profile_lastplayed( self, profile_id: int, last_song_id: int, @@ -202,21 +202,21 @@ class WaccaProfileData(BaseData): last_folder_id=last_folder_id, last_song_order=last_song_order, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"update_profile_lastplayed: failed to update profile! profile: {profile_id}" ) return None - def update_profile_dan( + async def update_profile_dan( self, profile_id: int, dan_level: int, dan_type: int ) -> Optional[int]: sql = profile.update(profile.c.id == profile_id).values( dan_level=dan_level, dan_type=dan_type ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.warning( f"update_profile_dan: Failed to update! profile {profile_id}" @@ -224,7 +224,7 @@ class WaccaProfileData(BaseData): return None return result.lastrowid - def get_profile(self, profile_id: int = 0, aime_id: int = None) -> Optional[Row]: + async def get_profile(self, profile_id: int = 0, aime_id: int = None) -> Optional[Row]: """ Given a game version and either a profile or aime id, return the profile """ @@ -238,12 +238,12 @@ class WaccaProfileData(BaseData): ) return None - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_options(self, user_id: int, option_id: int = None) -> Optional[List[Row]]: + async def get_options(self, user_id: int, option_id: int = None) -> Optional[List[Row]]: """ Get a specific user option for a profile, or all of them if none specified """ @@ -254,7 +254,7 @@ class WaccaProfileData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None if option_id is not None: @@ -262,12 +262,12 @@ class WaccaProfileData(BaseData): else: return result.fetchall() - def update_option(self, user_id: int, option_id: int, value: int) -> Optional[int]: + async def update_option(self, user_id: int, option_id: int, value: int) -> Optional[int]: sql = insert(option).values(user=user_id, opt_id=option_id, value=value) conflict = sql.on_duplicate_key_update(value=value) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to insert option! profile: {user_id}, option: {option_id}, value: {value}" @@ -276,10 +276,10 @@ class WaccaProfileData(BaseData): return result.lastrowid - def add_favorite_song(self, user_id: int, song_id: int) -> Optional[int]: + async def add_favorite_song(self, user_id: int, song_id: int) -> Optional[int]: sql = favorite.insert().values(user=user_id, song_id=song_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to insert favorite! profile: {user_id}, song_id: {song_id}" @@ -287,35 +287,35 @@ class WaccaProfileData(BaseData): return None return result.lastrowid - def remove_favorite_song(self, user_id: int, song_id: int) -> None: + async def remove_favorite_song(self, user_id: int, song_id: int) -> None: sql = favorite.delete( and_(favorite.c.user == user_id, favorite.c.song_id == song_id) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to remove favorite! profile: {user_id}, song_id: {song_id}" ) return None - def get_favorite_songs(self, user_id: int) -> Optional[List[Row]]: + async def get_favorite_songs(self, user_id: int) -> Optional[List[Row]]: sql = favorite.select(favorite.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_gates(self, user_id: int) -> Optional[List[Row]]: + async def get_gates(self, user_id: int) -> Optional[List[Row]]: sql = select(gate).where(gate.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def update_gate( + async def update_gate( self, user_id: int, gate_id: int, @@ -343,7 +343,7 @@ class WaccaProfileData(BaseData): total_points=sql.inserted.total_points, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__} failed to update gate! user: {user_id}, gate_id: {gate_id}" @@ -351,18 +351,18 @@ class WaccaProfileData(BaseData): return None return result.lastrowid - def get_friends(self, user_id: int) -> Optional[List[Row]]: + async def get_friends(self, user_id: int) -> Optional[List[Row]]: sql = friend.select(friend.c.profile_sender == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def profile_to_aime_user(self, profile_id: int) -> Optional[int]: + async def profile_to_aime_user(self, profile_id: int) -> Optional[int]: sql = select(profile.c.user).where(profile.c.id == profile_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.info( f"profile_to_aime_user: No user found for profile {profile_id}" @@ -378,7 +378,7 @@ class WaccaProfileData(BaseData): return this_profile["user"] - def session_login( + async def session_login( self, profile_id: int, is_new_day: bool, is_consec_day: bool ) -> None: # TODO: Reset consec days counter @@ -395,127 +395,127 @@ class WaccaProfileData(BaseData): last_login_date=func.now(), ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"session_login: failed to update profile! profile: {profile_id}" ) return None - def session_logout(self, profile_id: int) -> None: + async def session_logout(self, profile_id: int) -> None: sql = profile.update(profile.c.id == id).values(login_count_consec=0) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to update profile! profile: {profile_id}" ) return None - def add_xp(self, profile_id: int, xp: int) -> None: + async def add_xp(self, profile_id: int, xp: int) -> None: sql = profile.update(profile.c.id == profile_id).values(xp=profile.c.xp + xp) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"add_xp: Failed to update profile! profile_id {profile_id} xp {xp}" ) return None - def add_wp(self, profile_id: int, wp: int) -> None: + async def add_wp(self, profile_id: int, wp: int) -> None: sql = profile.update(profile.c.id == profile_id).values( wp=profile.c.wp + wp, wp_total=profile.c.wp_total + wp, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"add_wp: Failed to update profile! profile_id {profile_id} wp {wp}" ) return None - def spend_wp(self, profile_id: int, wp: int) -> None: + async def spend_wp(self, profile_id: int, wp: int) -> None: sql = profile.update(profile.c.id == profile_id).values( wp=profile.c.wp - wp, wp_spent=profile.c.wp_spent + wp, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"spend_wp: Failed to update profile! profile_id {profile_id} wp {wp}" ) return None - def activate_vip(self, profile_id: int, expire_time) -> None: + async def activate_vip(self, profile_id: int, expire_time) -> None: sql = profile.update(profile.c.id == profile_id).values( vip_expire_time=expire_time ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"activate_vip: Failed to update profile! profile_id {profile_id} expire_time {expire_time}" ) return None - def update_user_rating(self, profile_id: int, new_rating: int) -> None: + async def update_user_rating(self, profile_id: int, new_rating: int) -> None: sql = profile.update(profile.c.id == profile_id).values(rating=new_rating) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"update_user_rating: Failed to update profile! profile_id {profile_id} new_rating {new_rating}" ) return None - def update_bingo(self, aime_id: int, page: int, progress: int) -> Optional[int]: + async def update_bingo(self, aime_id: int, page: int, progress: int) -> Optional[int]: sql = insert(bingo).values( user=aime_id, page_number=page, page_progress=progress ) conflict = sql.on_duplicate_key_update(page_number=page, page_progress=progress) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error(f"put_bingo: failed to update! aime_id: {aime_id}") return None return result.lastrowid - def get_bingo(self, aime_id: int) -> Optional[List[Row]]: + async def get_bingo(self, aime_id: int) -> Optional[List[Row]]: sql = select(bingo).where(bingo.c.user == aime_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_bingo_page(self, aime_id: int, page: Dict) -> Optional[List[Row]]: + async def get_bingo_page(self, aime_id: int, page: Dict) -> Optional[List[Row]]: sql = select(bingo).where( and_(bingo.c.user == aime_id, bingo.c.page_number == page) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def update_vip_time(self, profile_id: int, time_left) -> None: + async def update_vip_time(self, profile_id: int, time_left) -> None: sql = profile.update(profile.c.id == profile_id).values( vip_expire_time=time_left ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error(f"Failed to update VIP time for profile {profile_id}") - def update_tutorial_flags(self, profile_id: int, flags: Dict) -> None: + async def update_tutorial_flags(self, profile_id: int, flags: Dict) -> None: sql = profile.update(profile.c.id == profile_id).values( gate_tutorial_flags=flags ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"Failed to update tutorial flags for profile {profile_id}" diff --git a/titles/wacca/schema/score.py b/titles/wacca/schema/score.py index 5a3a53f..114cce3 100644 --- a/titles/wacca/schema/score.py +++ b/titles/wacca/schema/score.py @@ -95,7 +95,7 @@ stageup = Table( class WaccaScoreData(BaseData): - def put_best_score( + async def put_best_score( self, user_id: int, song_id: int, @@ -164,7 +164,7 @@ class WaccaScoreData(BaseData): lowest_miss_ct=lowest_miss_ct, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.error( f"{__name__}: failed to insert best score! profile: {user_id}, song: {song_id}, chart: {chart_id}" @@ -173,7 +173,7 @@ class WaccaScoreData(BaseData): return result.lastrowid - def put_playlog( + async def put_playlog( self, user_id: int, song_id: int, @@ -210,7 +210,7 @@ class WaccaScoreData(BaseData): season=season, ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {chart_id}" @@ -219,7 +219,7 @@ class WaccaScoreData(BaseData): return result.lastrowid - def get_best_score( + async def get_best_score( self, user_id: int, song_id: int, chart_id: int ) -> Optional[Row]: sql = best_score.select( @@ -230,20 +230,20 @@ class WaccaScoreData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() - def get_best_scores(self, user_id: int) -> Optional[List[Row]]: + async def get_best_scores(self, user_id: int) -> Optional[List[Row]]: sql = best_score.select(best_score.c.user == user_id) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def update_song_rating( + async def update_song_rating( self, user_id: int, song_id: int, chart_id: int, new_rating: int ) -> None: sql = best_score.update( @@ -254,14 +254,14 @@ class WaccaScoreData(BaseData): ) ).values(rating=new_rating) - result = self.execute(sql) + result = await self.execute(sql) if result is None: self.logger.error( f"update_song_rating: failed to update rating! user_id: {user_id} song_id: {song_id} chart_id {chart_id} new_rating {new_rating}" ) return None - def put_stageup( + async def put_stageup( self, user_id: int, version: int, @@ -292,7 +292,7 @@ class WaccaScoreData(BaseData): play_ct=stageup.c.play_ct + 1, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning( f"put_stageup: failed to update! user_id: {user_id} version: {version} stage_id: {stage_id}" @@ -300,17 +300,17 @@ class WaccaScoreData(BaseData): return None return result.lastrowid - def get_stageup(self, user_id: int, version: int) -> Optional[List[Row]]: + async def get_stageup(self, user_id: int, version: int) -> Optional[List[Row]]: sql = select(stageup).where( and_(stageup.c.user == user_id, stageup.c.version == version) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchall() - def get_stageup_stage( + async def get_stageup_stage( self, user_id: int, version: int, stage_id: int ) -> Optional[Row]: sql = select(stageup).where( @@ -321,7 +321,7 @@ class WaccaScoreData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone() diff --git a/titles/wacca/schema/static.py b/titles/wacca/schema/static.py index 18e4e23..1714016 100644 --- a/titles/wacca/schema/static.py +++ b/titles/wacca/schema/static.py @@ -28,7 +28,7 @@ music = Table( class WaccaStaticData(BaseData): - def put_music( + async def put_music( self, version: int, song_id: int, @@ -61,13 +61,13 @@ class WaccaStaticData(BaseData): jacketFile=jacket, ) - result = self.execute(conflict) + result = await self.execute(conflict) if result is None: self.logger.warning(f"Failed to insert music {song_id} chart {chart_id}") return None return result.lastrowid - def get_music_chart( + async def get_music_chart( self, version: int, song_id: int, chart_id: int ) -> Optional[List[Row]]: sql = select(music).where( @@ -78,7 +78,7 @@ class WaccaStaticData(BaseData): ) ) - result = self.execute(sql) + result = await self.execute(sql) if result is None: return None return result.fetchone()