mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-02-14 11:47:28 +08:00
move to async database
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user