Skip to content

Commit

Permalink
weightをサーバーから取得
Browse files Browse the repository at this point in the history
  • Loading branch information
lenlino committed Mar 27, 2024
1 parent 05e39b9 commit c65209e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion commands/CardCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def button_callback(interaction):
# 重み
weight_text = ""
avatar_id = json_parsed["characters"][select_number]['id']
weight_dict = generate.utils.get_weight(avatar_id)
weight_dict = await generate.utils.get_weight(avatar_id)

for k, v in weight_dict.items():
if v == 0:
Expand Down
24 changes: 20 additions & 4 deletions generate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ async def get_image_from_url(url: str):
return f"{os.path.dirname(os.path.abspath(__file__))}/{replaced_path}"


async def get_json_from_urlpath(path: str):
async with aiohttp.ClientSession(connector_owner=False, connector=conn) as session:
async with session.get(f"https://hcs.lenlino.com{path}") as response:
if response.status == 200:
result_json = await response.json()
return result_json
return None


async def get_json_from_url(uid: str, lang: str):
result_json = {}
async with aiohttp.ClientSession(connector_owner=False, connector=conn) as session:
Expand Down Expand Up @@ -255,11 +264,18 @@ def get_mihomo_lang(discord_lang):
else:
return "en"

weight_dict = {}

def get_weight(chara_id):
with open(f"{os.path.dirname(os.path.abspath(__file__))}/weight.json") as f:
weight_json = json.load(f)
return weight_json[str(chara_id)]["weight"]

async def get_weight(chara_id):
"""with open(f"{os.path.dirname(os.path.abspath(__file__))}/weight.json") as f:
weight_json = json.load(f)"""

if weight_dict[str(chara_id)]:
return weight_dict[str(chara_id)]["weight"]
else:
weight_dict[str(chara_id)] = await get_json_from_urlpath(f"/weight/{chara_id}")
return await get_weight(chara_id)


def get_score_rank(chara_id, uid, score):
Expand Down

0 comments on commit c65209e

Please sign in to comment.