diff --git a/tools/helpers.py b/tools/helpers.py index 12518f7..bcde5ac 100644 --- a/tools/helpers.py +++ b/tools/helpers.py @@ -66,6 +66,12 @@ def get_dc_text(name: str, dc_id: int) -> str: return "❗️ 无法获取该用户/群组的数据中心 ..." +def get_sender_name(msg: Message) -> str: + if msg.from_user: + return get_fullname(msg.from_user) + return msg.sender_chat.title + + def get_fullname(user: User) -> str: if user: if user.last_name: diff --git a/tools/updates.py b/tools/updates.py index 9d16496..9dff116 100644 --- a/tools/updates.py +++ b/tools/updates.py @@ -77,16 +77,15 @@ def get_alias_of_cmds() -> Dict[str, str]: return dict(zip(cmd_yml.keys(), (v.get('cmd') for v in cmd_yml.values()))) -async def pull_and_update_command_yml() -> None: +async def pull_and_update_command_yml(is_update: bool = True) -> None: # 读取远程command.yml - async with session.get( - CMD_YML_REMOTE, timeout=9.9, - ) as resp: + async with session.get(CMD_YML_REMOTE, timeout=9.9) as resp: if resp.status == 200: data = yaml.full_load(await resp.text()) - with open(COMMAND_YML, "rb") as f: - cmd_yml: Dict[str, Dict[str, str]] = yaml.full_load(f) - data.update(cmd_yml) + if is_update: + with open(COMMAND_YML, "rb") as f: + cmd_yml: Dict[str, Dict[str, str]] = yaml.full_load(f) + data.update(cmd_yml) # 合并到本地,以本地为主 update_cmd_yml(data) resp.raise_for_status()