Add method to update local command.yml
This commit is contained in:
parent
baf3b8e1dc
commit
49adcdd788
@ -8,13 +8,15 @@ from pyrogram.types import Message
|
||||
from tools.constants import (SYCGRAM, SYCGRAM_ERROR, SYCGRAM_INFO,
|
||||
SYCGRAM_WARNING, UPDATE_CMD)
|
||||
from tools.helpers import Parameters, basher, get_cmd_error
|
||||
from tools.updates import get_alias_of_cmds, reset_cmd_alias, update_cmd_alias, update_cmd_prefix
|
||||
from tools.updates import (get_alias_of_cmds, pull_and_update_command_yml,
|
||||
reset_cmd_alias, update_cmd_alias,
|
||||
update_cmd_prefix)
|
||||
|
||||
|
||||
@Client.on_message(command("restart"))
|
||||
async def restart(_: Client, msg: Message):
|
||||
"""重启容器"""
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `Restarting {SYCGRAM} ......`"
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `Restarting {SYCGRAM} ...`"
|
||||
await msg.edit_text(text=text, parse_mode='md')
|
||||
sys.exit()
|
||||
|
||||
@ -22,16 +24,17 @@ async def restart(_: Client, msg: Message):
|
||||
@Client.on_message(command("update"))
|
||||
async def update(_: Client, msg: Message):
|
||||
"""更新sycgram到主分支的最新版本"""
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `It's updating container to the latest version......`"
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `It's updating {SYCGRAM} ...`"
|
||||
await msg.edit_text(text, parse_mode='md')
|
||||
try:
|
||||
await pull_and_update_command_yml()
|
||||
_ = await basher(UPDATE_CMD, timeout=60)
|
||||
except asyncio.exceptions.TimeoutError:
|
||||
text = f"**{SYCGRAM_WARNING}**\n> # `Update Timeout!`"
|
||||
except Exception as e:
|
||||
text = f"**{SYCGRAM_ERROR}**\n> # `{e}`"
|
||||
else:
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `Your {SYCGRAM} version is the latest.`"
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `{SYCGRAM.title()} is already the latest version.`"
|
||||
finally:
|
||||
await msg.edit_text(text, parse_mode='md')
|
||||
|
||||
|
@ -6,6 +6,7 @@ SYCGRAM_INFO: str = f"{SYCGRAM.title()} | INFO"
|
||||
SYCGRAM_ERROR: str = f"{SYCGRAM.title()} | ERROR"
|
||||
SYCGRAM_WARNING: str = f"{SYCGRAM.title()} | WARNING"
|
||||
COMMAND_YML: str = './data/command.yml'
|
||||
CMD_YML_REMOTE: str = "https://raw.githubusercontent.com/iwumingz/sycgram/main/data/command.yml"
|
||||
UPDATE_CMD: str = f"""
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
|
@ -1,8 +1,10 @@
|
||||
import re
|
||||
from typing import Any, Dict
|
||||
|
||||
import yaml
|
||||
|
||||
from tools.constants import COMMAND_YML
|
||||
from .constants import CMD_YML_REMOTE, COMMAND_YML
|
||||
from .sessions import session
|
||||
|
||||
|
||||
def update_cmd_yml(cmd_yml: Dict[str, Any]):
|
||||
@ -76,3 +78,18 @@ def get_alias_of_cmds() -> str:
|
||||
f"`{k}` | `{v.get('cmd')}`\n" for k, v in cmd_yml.items()
|
||||
)
|
||||
return f"**⭐️ 指令别名:**\n**源名** | **别名**\n{tmp}"
|
||||
|
||||
|
||||
async def pull_and_update_command_yml() -> None:
|
||||
# 读取远程command.yml
|
||||
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)
|
||||
# 合并到本地,以本地为主
|
||||
update_cmd_yml(data)
|
||||
resp.raise_for_status()
|
||||
|
Loading…
Reference in New Issue
Block a user