Lawnmower/defs/need_char.py
2022-04-30 22:47:55 +08:00

27 lines
667 B
Python

import json
from typing import Optional
from resources.Char import characters
from os import sep
def nic2name(name):
with open(f"resources{sep}nickname.json", 'r', encoding='utf-8') as f:
all_name = json.load(f)
f.close()
for i in all_name:
for x in i.values():
if name in x:
return x[0]
return name
def get_character(name: str) -> Optional[int]:
# 角色常见昵称转换为官方角色名
nick_name = name
if name not in ["", ""]:
nick_name = nic2name(name)
for key, value in characters.items():
if nick_name in value:
return key
return None