Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #174

Merged
merged 2 commits into from
Mar 5, 2024
Merged

Dev #174

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
aiohttp>=3.8.5
async_timeout>=4.0.2
Pillow>=9.5.0
Pillow==10.1
pilmoji>=2.0.1
Pyrogram==2.0.106
PyYAML>=6.0
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
10 changes: 7 additions & 3 deletions utils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def draw_watermark(self, original_image: Image.Image) -> Image.Image:
uid = self.allinfo.get('task', {}).get('initiator', '')
if uid and uid not in self.config.getuser():
watermark = self.image.get('watermark2', {})
if not self.image['watermark']['enable']:
if not watermark['enable']:
return original_image
watermark_text = watermark['text']
shadow = bool(watermark.get('shadow', False)) # 是否是盲水印
Expand All @@ -433,7 +433,8 @@ def draw_watermark(self, original_image: Image.Image) -> Image.Image:
watermark_text += f" UID:{uid}"
if not shadow:
font = ImageFont.truetype(self.config.getFont(), int(watermark['font_size']))
text_image = Image.new('RGBA', font.getsize(watermark_text), (255, 255, 255, 0))
_, __, wm_width, wm_height = font.getbbox(watermark_text)
text_image = Image.new('RGBA', (wm_width, wm_width), (255, 255, 255, 0))
text_draw = ImageDraw.Draw(text_image)

rgb = ImageColor.getrgb(watermark['color'])
Expand Down Expand Up @@ -978,6 +979,8 @@ def text_width(self, text: str, emoji: bool = False):
if emoji:
img = Image.new("RGBA", (1, 1), (255, 255, 255, 255))
pm = Pilmoji(img, source=emoji_source.TwemojiLocalSource)
# https://www.osgeo.cn/pillow/releasenotes/10.0.0.html#font-size-and-offset-methods,此方法为pilmoji特别优化。
# 请勿在正常的PIL中使用此方法。
x, _ = pm.getsize(text, font=self.__font)
return x
else:
Expand Down Expand Up @@ -1052,7 +1055,8 @@ def draw_watermark(self, original_image, taskinfo: dict = None):
return original_image
watermark_text = watermark['text']
font = ImageFont.truetype(self.config.getFont(), int(watermark['font_size']))
text_image = Image.new('RGBA', font.getsize(watermark_text), (255, 255, 255, 0))
_, __, wm_width, wm_height = font.getbbox(watermark_text)
text_image = Image.new('RGBA', (wm_width, wm_height), (255, 255, 255, 0))
text_draw = ImageDraw.Draw(text_image)

rgb = ImageColor.getrgb(watermark['color'])
Expand Down