Lawnmower/defs/need_char.py

27 lines
667 B
Python
Raw Permalink Normal View History

2022-04-30 14:47:55 +00:00
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