diff --git a/docker-compose.gen.yml b/docker-compose.gen.yml index 7655931..5faed2c 100644 --- a/docker-compose.gen.yml +++ b/docker-compose.gen.yml @@ -8,7 +8,7 @@ services: # ports: # 是否开启网页控制面板 # - "3333:3333" volumes: - - ./:/pagermaid/workdir + - ./data:/pagermaid/workdir/data environment: # - WEB_ENABLE=true # - WEB_SECRET_KEY=控制台密码 diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index ab7469c..4612ec8 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -16,13 +16,14 @@ from logging import ( ) from os import getcwd +import pagermaid.update from pagermaid.config import Config from pagermaid.scheduler import scheduler import pyromod.listen from pyrogram import Client -pgm_version = "1.4.2" -pgm_version_code = 1402 +pgm_version = "1.4.3" +pgm_version_code = 1403 CMD_LIST = {} module_dir = __path__[0] working_dir = getcwd() @@ -47,9 +48,9 @@ root_logger = getLogger() root_logger.setLevel(DEBUG if Config.DEBUG else CRITICAL) root_logger.addHandler(logging_handler) pyro_logger = getLogger("pyrogram") -pyro_logger.setLevel(CRITICAL) +pyro_logger.setLevel(INFO if Config.DEBUG else CRITICAL) pyro_logger.addHandler(logging_handler) -file_handler = FileHandler(filename="pagermaid.log.txt", mode="w", encoding="utf-8") +file_handler = FileHandler(filename="data/pagermaid.log.txt", mode="w", encoding="utf-8") file_handler.setFormatter(Formatter(logging_format)) root_logger.addHandler(file_handler) basicConfig(level=DEBUG if Config.DEBUG else INFO) @@ -77,6 +78,7 @@ bot = Client( ipv6=Config.IPV6, proxy=Config.PROXY, app_version=f"PGP {pgm_version}", + workdir="data", ) bot.job = scheduler diff --git a/pagermaid/config.py b/pagermaid/config.py index a197fc2..c3fad26 100644 --- a/pagermaid/config.py +++ b/pagermaid/config.py @@ -25,12 +25,12 @@ def strtobool(val, default=False): try: - config: Dict = load(open(r"config.yml", encoding="utf-8"), Loader=FullLoader) + config: Dict = load(open(r"data/config.yml", encoding="utf-8"), Loader=FullLoader) except FileNotFoundError: print( "The configuration file does not exist, and a new configuration file is being generated." ) - copyfile(f"{os.getcwd()}{os.sep}config.gen.yml", "config.yml") + copyfile(f"{os.getcwd()}{os.sep}config.gen.yml", "data/config.yml") sys.exit(1) diff --git a/pagermaid/modules/backup.py b/pagermaid/modules/backup.py index 066a187..23354f8 100644 --- a/pagermaid/modules/backup.py +++ b/pagermaid/modules/backup.py @@ -60,7 +60,7 @@ async def backup(message: Message): os.remove(f"data{os.sep}{i}") # run backup function - make_tar_gz(pgm_backup_zip_name, ["data", "plugins", "config.yml"]) + make_tar_gz(pgm_backup_zip_name, ["data", "plugins"]) if Config.LOG: try: await upload_attachment(pgm_backup_zip_name, Config.LOG_ID, None) diff --git a/pagermaid/update/__init__.py b/pagermaid/update/__init__.py new file mode 100644 index 0000000..8d3b703 --- /dev/null +++ b/pagermaid/update/__init__.py @@ -0,0 +1,5 @@ +import pkgutil +from pathlib import Path + +for _, file, _ in pkgutil.iter_modules([str(Path(__file__).parent.absolute())]): + __import__(file, globals(), level=1) diff --git a/pagermaid/update/v1402.py b/pagermaid/update/v1402.py new file mode 100644 index 0000000..911f2f5 --- /dev/null +++ b/pagermaid/update/v1402.py @@ -0,0 +1,16 @@ +from pathlib import Path + +# move file +# session +session = Path("pagermaid.session") +if session.exists(): + session.rename("data/pagermaid.session") +# config +config = Path("config.yml") +if config.exists(): + config.rename("data/config.yml") +# delete file +# log +log = Path("pagermaid.log.txt") +if log.exists(): + log.unlink() diff --git a/pyromod/methods/sign_in_qrcode.py b/pyromod/methods/sign_in_qrcode.py index 45d0ea0..a9ac226 100644 --- a/pyromod/methods/sign_in_qrcode.py +++ b/pyromod/methods/sign_in_qrcode.py @@ -103,7 +103,7 @@ async def authorize_by_qrcode( if isinstance(qrcode, str): qr_obj = QRCode(qrcode) try: - qr_obj.png("qrcode.png", scale=6) + qr_obj.png("data/qrcode.png", scale=6) except Exception: print("Save qrcode.png failed.") print(qr_obj.terminal()) diff --git a/utils/docker-config.sh b/utils/docker-config.sh index 185e957..7a6fc60 100644 --- a/utils/docker-config.sh +++ b/utils/docker-config.sh @@ -49,7 +49,7 @@ login () { echo "请在账户授权完毕后,按 Ctrl + C 使 Docker 在后台模式下运行。" echo "如果已开启网页登录,请直接使用 Ctrl + C 使 Docker 在后台模式下运行。" echo - echo "Hello world!" > /pagermaid/workdir/install.lock + echo "Hello world!" > /pagermaid/workdir/data/install.lock sleep 2 python -m pagermaid exit 0 @@ -57,12 +57,12 @@ login () { main () { cd /pagermaid/workdir || exit - if [ ! -s "/pagermaid/workdir/install.lock" ]; then + if [ ! -s "/pagermaid/workdir/data/install.lock" ]; then welcome configure login else - if [ ! -f "/pagermaid/workdir/pagermaid.session" ]; then + if [ ! -f "/pagermaid/workdir/data/pagermaid.session" ]; then welcome configure fi diff --git a/utils/docker.sh b/utils/docker.sh index 6aa15cc..6e049d5 100644 --- a/utils/docker.sh +++ b/utils/docker.sh @@ -78,7 +78,7 @@ need_web_login () { PGM_WEB_LOGIN=false case $PGM_WEB in true) - printf "请问是否需要启用 Web 登录界面 [Y/n] :" + printf "请问是否需要启用通过 Web 登录?(不建议开启) [Y/n] :" read -r web_login <&1 case $web_login in [yY][eE][sS] | [yY])