This commit is contained in:
CMHopeSunshine 2022-06-22 13:29:53 +08:00
parent e7f26925ed
commit c417d15ed1
2 changed files with 9 additions and 8 deletions

View File

@ -563,15 +563,19 @@ async def _(event: MessageEvent, state: T_State, msg: Message = CommandArg()):
if msg_seg.type == "at": if msg_seg.type == "at":
user = msg_seg.data['qq'] user = msg_seg.data['qq']
if user: if user:
state['uid'] = await get_last_query(str(user)) uid = await get_last_query(str(user))
if uid:
state['uid'] = uid
else: else:
state['uid'] = await get_last_query(str(event.user_id)) uid = await get_last_query(str(event.user_id))
if uid:
state['uid'] = uid
msg = msg.extract_plain_text().replace(state['uid'], '').strip() msg = msg.extract_plain_text().replace(state['uid'], '').strip()
if not msg: if not msg:
await role_info.finish('请把要查询角色名给派蒙哦~') await role_info.finish('请把要查询角色名给派蒙哦~')
else: else:
match_alias = get_match_alias(msg, 'roles', True) match_alias = get_match_alias(msg, 'roles', True)
state['role'] = tuple(match_alias.keys())[0] state['role'] = match_alias if isinstance(match_alias, str) else tuple(match_alias.keys())[0]
@role_info.got('uid', prompt='请把要查询的uid给派蒙哦~') @role_info.got('uid', prompt='请把要查询的uid给派蒙哦~')

View File

@ -58,13 +58,10 @@ def get_match_alias(msg: str, type: str = 'roles', single_to_dict: bool = False)
for role_id, alias in alias_list.items(): for role_id, alias in alias_list.items():
match_list = difflib.get_close_matches(msg, alias, cutoff=0.6, n=3) match_list = difflib.get_close_matches(msg, alias, cutoff=0.6, n=3)
if msg in match_list: if msg in match_list:
if single_to_dict: return {alias[0]: role_id} if single_to_dict else alias[0]
return {alias[0]: role_id}
else:
return alias[0]
elif match_list: elif match_list:
if len(match_list) == 1: if len(match_list) == 1:
return alias[0] return {alias[0]: role_id} if single_to_dict else alias[0]
possible[alias[0]] = role_id possible[alias[0]] = role_id
return possible return possible
elif type == 'weapons': elif type == 'weapons':