diva: improved update_profile() function

This commit is contained in:
Dniel97 2023-02-19 22:56:09 +01:00
parent 8bdc2071da
commit a7821fade8
Signed by untrusted user: Dniel97
GPG Key ID: 6180B3C768FB2E08
2 changed files with 51 additions and 61 deletions

View File

@ -162,7 +162,10 @@ class DivaBase():
new_vcld_pts = profile["vcld_pts"] - int(data["mdl_price"]) new_vcld_pts = profile["vcld_pts"] - int(data["mdl_price"])
self.data.profile.update_profile(data["pd_id"], profile["lv_num"], profile["lv_pnt"], new_vcld_pts, profile["hp_vol"], profile["btn_se_vol"], profile["btn_se_vol2"], profile["sldr_se_vol2"], profile["sort_kind"], profile["use_pv_mdl_eqp"], profile["use_mdl_pri"], profile["use_pv_skn_eqp"], profile["use_pv_btn_se_eqp"], profile["use_pv_sld_se_eqp"], profile["use_pv_chn_sld_se_eqp"], profile["use_pv_sldr_tch_se_eqp"], profile["nxt_pv_id"], profile["nxt_dffclty"], profile["nxt_edtn"], profile["dsp_clr_brdr"], profile["dsp_intrm_rnk"], profile["dsp_clr_sts"], profile["rgo_sts"], profile["lv_efct_id"], profile["lv_plt_id"], profile["my_qst_id"], profile["my_qst_sts"]) 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"]) self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"])
# generate the mdl_have string # generate the mdl_have string
@ -214,9 +217,10 @@ class DivaBase():
new_vcld_pts = profile["vcld_pts"] - int(data["cstmz_itm_price"]) new_vcld_pts = profile["vcld_pts"] - int(data["cstmz_itm_price"])
# save new Vocaloid Points balance # save new Vocaloid Points balance
profile = dict(profile) self.data.profile.update_profile(
profile["vcld_pts"] = new_vcld_pts profile["user"],
self.data.profile.update_profile(profile) vcld_pts=new_vcld_pts
)
self.data.customize.put_customize_item(data["pd_id"], self.version, data["cstmz_itm_id"]) self.data.customize.put_customize_item(data["pd_id"], self.version, data["cstmz_itm_id"])
@ -613,21 +617,21 @@ class DivaBase():
response += f"&lv_pnt_old={int(profile['lv_pnt'])}" response += f"&lv_pnt_old={int(profile['lv_pnt'])}"
# update the profile and commit changes to the db # update the profile and commit changes to the db
profile = dict(profile) self.data.profile.update_profile(
profile["lv_num"] = new_level profile["user"],
profile["lv_pnt"] = new_level_pnt lv_num=new_level,
profile["vcld_pts"] = int(data["vcld_pts"]) lv_pnt=new_level_pnt,
profile["hp_vol"] = int(data["hp_vol"]) vcld_pts=int(data["vcld_pts"]),
profile["btn_se_vol"] = int(data["btn_se_vol"]) hp_vol=int(data["hp_vol"]),
profile["sldr_se_vol2"] = int(data["sldr_se_vol2"]) btn_se_vol=int(data["btn_se_vol"]),
profile["sort_kind"] = int(data["sort_kind"]) sldr_se_vol2=int(data["sldr_se_vol2"]),
profile["nxt_pv_id"] = int(data["ply_pv_id"]) sort_kind=int(data["sort_kind"]),
profile["nxt_dffclty"] = int(data["nxt_dffclty"]) nxt_pv_id=int(data["ply_pv_id"]),
profile["nxt_edtn"] = int(data["nxt_edtn"]) nxt_dffclty=int(data["nxt_dffclty"]),
profile["my_qst_id"] = data["my_qst_id"] nxt_edtn=int(data["nxt_edtn"]),
profile["my_qst_sts"] = data["my_qst_sts"] my_qst_id=data["my_qst_id"],
my_qst_sts=data["my_qst_sts"]
self.data.profile.update_profile(profile) )
response += f"&lv_num={new_level}" response += f"&lv_num={new_level}"
response += f"&lv_str={profile['lv_str']}" response += f"&lv_str={profile['lv_str']}"
@ -664,11 +668,11 @@ class DivaBase():
def handle_end_request(self, data: Dict) -> Dict: def handle_end_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile(data["pd_id"], self.version) profile = self.data.profile.get_profile(data["pd_id"], self.version)
profile = dict(profile) self.data.profile.update_profile(
profile["my_qst_id"] = data["my_qst_id"] profile["user"],
profile["my_qst_sts"] = data["my_qst_sts"] my_qst_id=data["my_qst_id"],
my_qst_sts=data["my_qst_sts"]
self.data.profile.update_profile(profile) )
return (f'') return (f'')
def handle_shop_exit_request(self, data: Dict) -> Dict: def handle_shop_exit_request(self, data: Dict) -> Dict:
@ -711,28 +715,33 @@ class DivaBase():
return "&cd_adm_result=0" return "&cd_adm_result=0"
# update the vocaloid points and player name # update the vocaloid points and player name
profile = dict(profile) new_vcld_pts = profile["vcld_pts"] - int(data["chg_name_price"])
profile["vcld_pts"] -= int(data["chg_name_price"]) self.data.profile.update_profile(
profile["player_name"] = data["player_name"] profile["user"],
player_name=data["player_name"],
self.data.profile.update_profile(profile) vcld_pts=new_vcld_pts
)
response = "&cd_adm_result=1" response = "&cd_adm_result=1"
response += "&accept_idx=100" response += "&accept_idx=100"
response += f"&pd_id={profile['user']}" response += f"&pd_id={profile['user']}"
response += f"&player_name={profile['player_name']}" response += f"&player_name={data['player_name']}"
return response return response
def handle_change_passwd_request(self, data: Dict) -> str: def handle_change_passwd_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version) profile = self.data.profile.get_profile(data["pd_id"], self.version)
# set password to true and update the saved password # TODO: return correct error number instead of 0
profile = dict(profile) if (data["passwd"] != profile["passwd"]):
profile["passwd_stat"] = 1 return "&cd_adm_result=0"
profile["passwd"] = data["new_passwd"]
self.data.profile.update_profile(profile) # set password to true and update the saved password
self.data.profile.update_profile(
profile["user"],
passwd_stat=1,
passwd=data["new_passwd"]
)
response = "&cd_adm_result=1" response = "&cd_adm_result=1"
response += "&accept_idx=100" response += "&accept_idx=100"

View File

@ -76,36 +76,17 @@ class DivaProfileData(BaseData):
return None return None
return result.lastrowid return result.lastrowid
def update_profile(self, profile_updated: Dict) -> None: def update_profile(self, aime_id: int, **profile_args) -> None:
sql = profile.update(profile.c.user == profile_updated["user"]).values( """
player_name=profile_updated["player_name"], Given an aime_id update the profile corresponding to the arguments
lv_num=profile_updated["lv_num"], which are the diva_profile Columns
lv_pnt=profile_updated["lv_pnt"], """
vcld_pts=profile_updated["vcld_pts"], sql = profile.update(profile.c.user == aime_id).values(**profile_args)
hp_vol=profile_updated["hp_vol"],
btn_se_vol=profile_updated["btn_se_vol"],
btn_se_vol2=profile_updated["btn_se_vol2"],
sldr_se_vol2=profile_updated["sldr_se_vol2"],
sort_kind=profile_updated["sort_kind"],
nxt_pv_id=profile_updated["nxt_pv_id"],
nxt_dffclty=profile_updated["nxt_dffclty"],
nxt_edtn=profile_updated["nxt_edtn"],
dsp_clr_brdr=profile_updated["dsp_clr_brdr"],
dsp_intrm_rnk=profile_updated["dsp_intrm_rnk"],
dsp_clr_sts=profile_updated["dsp_clr_sts"],
rgo_sts=profile_updated["rgo_sts"],
lv_efct_id=profile_updated["lv_efct_id"],
lv_plt_id=profile_updated["lv_plt_id"],
my_qst_id=profile_updated["my_qst_id"],
my_qst_sts=profile_updated["my_qst_sts"],
passwd_stat=profile_updated["passwd_stat"],
passwd=profile_updated["passwd"]
)
result = self.execute(sql) result = self.execute(sql)
if result is None: if result is None:
self.logger.error( self.logger.error(
f"update_profile: failed to update profile! profile: {profile_id}") f"update_profile: failed to update profile! profile: {aime_id}")
return None return None
def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]: def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]: