Update version and add update plugin
This commit is contained in:
parent
8f1c35a010
commit
d3bb82aedb
@ -4,7 +4,7 @@
|
||||
@File : custom.py
|
||||
@Time : 2022/04/02 10:17:03
|
||||
@Author : Viperorz
|
||||
@Version : 1.0.0
|
||||
@Version : 1.0.5
|
||||
@License : (C)Copyright 2021-2022
|
||||
@Desc : None
|
||||
"""
|
||||
|
33
plugins/update.py
Normal file
33
plugins/update.py
Normal file
@ -0,0 +1,33 @@
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from core import command
|
||||
from pyrogram import Client
|
||||
from pyrogram.types import Message
|
||||
from tools.constants import SYCGRAM, SYCGRAM_ERROR, SYCGRAM_INFO, SYCGRAM_WARNING, UPDATE_CMD
|
||||
from tools.helpers import basher
|
||||
|
||||
|
||||
@Client.on_message(command("restart"))
|
||||
async def restart(_: Client, msg: Message):
|
||||
"""重启容器"""
|
||||
text = f"**{SYCGRAM_INFO}**\n> # `The {SYCGRAM} is restarting......`"
|
||||
await msg.edit_text(text=text, parse_mode='md')
|
||||
sys.exit()
|
||||
|
||||
|
||||
@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......`"
|
||||
await msg.edit_text(text, parse_mode='md')
|
||||
try:
|
||||
_ = 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.`"
|
||||
finally:
|
||||
await msg.edit_text(text, parse_mode='md')
|
@ -1,5 +1,18 @@
|
||||
from typing import Dict, List
|
||||
|
||||
# Some params of sycgram
|
||||
SYCGRAM: str = "sycgram"
|
||||
SYCGRAM_INFO: str = f"{SYCGRAM.title()} | INFO"
|
||||
SYCGRAM_ERROR: str = f"{SYCGRAM.title()} | ERROR"
|
||||
SYCGRAM_WARNING: str = f"{SYCGRAM.title()} | WARNING"
|
||||
UPDATE_CMD: str = f"""
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower \
|
||||
--cleanup \
|
||||
--run-once \
|
||||
{SYCGRAM}
|
||||
"""
|
||||
|
||||
# ------------- rate --------------
|
||||
RATE_API: str = 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies'
|
||||
|
@ -156,8 +156,8 @@ async def execute(command: str) -> Dict[str, Any]:
|
||||
return {'output': '', 'error': str(e)}
|
||||
else:
|
||||
return {
|
||||
'output': stdout.decode('utf-8', 'ignore'),
|
||||
'error': stderr.decode('utf-8', 'ignore')
|
||||
'output': stdout.decode('utf-8', 'ignore').strip(),
|
||||
'error': stderr.decode('utf-8', 'ignore').strip()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user