Skip to content

Commit

Permalink
🎨 Optimized initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
AirportR committed Mar 5, 2024
1 parent 1647519 commit 51bfc0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions botmodule/init_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,20 @@ def init_proxy_client():
config.reload()


def check_version() -> str:
return Init.init_commit_string()


def check_py_version() -> None:
if sys.version_info < (3, 9):
py_url = "https://www.python.org/downloads/"
logger.info(f"您的Python版本为{sys.version}\n至少需要Python3.9才能运行此程序。前往: {py_url}下载新版本。")
sys.exit()


def check_init():
check_py_version()
check_args()
if config.getClashBranch() == 'meta':
logger.info('✅检测到启用clash.meta系内核配置')
Init.init_emoji()
Expand All @@ -203,11 +216,7 @@ def check_init():
Init.init_proxy_client()


def check_version() -> str:
return Init.init_commit_string()


def parse_proxy():
def parse_bot_proxy():
_proxies = None
try:
_proxy = config.get_bot_proxy(isjoint=False).split(':')
Expand Down Expand Up @@ -243,22 +252,19 @@ def parse_proxy():
return _proxies


# 获取远程仓库的最新提交哈希
latest_version_hash = Init.init_commit_string()

logger.add("./logs/fulltclash_{time}.log", rotation='7 days')
check_init()

# 获取远程仓库的最新提交哈希
latest_version_hash = Init.init_commit_string()
botconfig = config.getBotconfig()
api_id = botconfig.get('api_id', None)
api_hash = botconfig.get('api_hash', None)
bot_token = botconfig.get('bot_token', None)
CLASH_PATH = config.get_clash_path() # 为代理客户端运行路径

USER_TARGET = config.getuser() # 这是用户列表,从配置文件读取
logger.info("管理员名单加载:" + str(admin))
check_args()
check_init()
proxies = parse_proxy()
BOT_PROXY = parse_bot_proxy()

logger.info("配置已加载, Telegram bot程序开始运行...")


Expand Down
4 changes: 2 additions & 2 deletions glovar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
api_id=init_bot.api_id,
api_hash=init_bot.api_hash,
bot_token=bot_token,
proxy=init_bot.proxies,
proxy=init_bot.BOT_PROXY,
app_version=__version__,
ipv6=False
)
Expand All @@ -31,7 +31,7 @@
app2 = Client("my_user",
api_id=init_bot.api_id,
api_hash=init_bot.api_hash,
proxy=init_bot.proxies,
proxy=init_bot.BOT_PROXY,
app_version=__version__,
ipv6=False
)
Expand Down
4 changes: 2 additions & 2 deletions utils/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ def batch_ipcu(host: list):
return ipcu


def unzip_targz(input_file: str | Path, output_path: str | Path) -> List[str]:
def unzip_targz(input_file: Union[str, Path], output_path: Union[str, Path]) -> List[str]:
"""解压 tar.gz 文件, 返回解压后的文件名称列表"""
unzip_files = []
try:
Expand Down Expand Up @@ -1862,7 +1862,7 @@ def unzip_targz(input_file: str | Path, output_path: str | Path) -> List[str]:
return unzip_files


def unzip(input_file: str | Path, output_path: str | Path):
def unzip(input_file: Union[str, Path], output_path: Union[str, Path]):
"""解压zip文件"""
try:
output_path = Path(output_path) if isinstance(output_path, Path) else output_path
Expand Down

0 comments on commit 51bfc0c

Please sign in to comment.