27 lines
667 B
Python
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
|