diff --git a/assets/bg2/avatar_mask.png b/assets/bg2/avatar_mask.png new file mode 100644 index 0000000..d73dbdd Binary files /dev/null and b/assets/bg2/avatar_mask.png differ diff --git a/defs/mys2.py b/defs/mys2.py index 60a5ade..521eff3 100644 --- a/defs/mys2.py +++ b/defs/mys2.py @@ -16,7 +16,7 @@ from wordcloud import WordCloud from PIL import Image, ImageDraw, ImageFilter, ImageFont from pyrogram.types import Message -from ci import client +from ci import app from defs.db import GetAward, MysSign, GetSignInfo, GetSignList, GetDaily, cacheDB, GetMysInfo, \ errorDB, GetCharacter, GetInfo, GetSpiralAbyssInfo, MybSign, get_spiral_abyss_info, get_calculate_info from defs.event import ys_font @@ -429,7 +429,8 @@ async def draw_pic(uid, message: Message, nickname="1", mode=2, role_level=None) panle3_path = os.path.join(BG2_PATH, "panle_3.png") avatar_bg_path = os.path.join(BG2_PATH, "avatar_bg.png") - avatar_fg_path = os.path.join(BG2_PATH, "avatar_fg.png") + # 头像 + avatar_fg_path = await get_tg_avatar(message) all_mask_path = os.path.join(BG2_PATH, "All_Mask.png") @@ -1233,7 +1234,7 @@ class CustomizeImage: return 0, 0, 0 # Error -async def draw_info_pic(uid: str, image=None) -> str: +async def draw_info_pic(uid: str, message: Message, image=None) -> str: def seconds2hours(seconds: int) -> str: m, s = divmod(int(seconds), 60) h, m = divmod(m, 60) @@ -1268,7 +1269,7 @@ async def draw_info_pic(uid: str, image=None) -> str: info3_path = os.path.join(BG2_PATH, "info_3.png") avatar_bg_path = os.path.join(BG2_PATH, "avatar_bg.png") - avatar_fg_path = os.path.join(BG2_PATH, "avatar_fg.png") + avatar_fg_path = await get_tg_avatar(message) all_mask_path = os.path.join(BG2_PATH, "All_Mask.png") @@ -1420,3 +1421,26 @@ async def draw_info_pic(uid: str, image=None) -> str: bg_img = bg_img.convert('RGB') bg_img.save(f"temp{os.sep}info.jpg", format='JPEG', subsampling=0, quality=90) return f"temp{os.sep}info.jpg" + + +async def get_tg_avatar(message: Message) -> str: + avatar_fg_path = await app.get_profile_photos(message.from_user.id, limit=1) + if avatar_fg_path: + avatar_fg_path = await app.download_media(avatar_fg_path[0].file_id) + photo = Image.open(avatar_fg_path) + mask = Image.open(os.path.join(BG2_PATH, "avatar_mask.png")) + mask_size = mask.size + photo_size = photo.size + scale = photo_size[1] / mask_size[1] + photo = photo.resize((int(photo_size[0] / scale), int(photo_size[1] / scale)), Image.LANCZOS) + mask1 = Image.new("RGBA", mask.size) + mask1.paste(photo, mask=mask) + mask1.save(f"temp{os.sep}avatar.png") + try: + os.remove(avatar_fg_path) + except: + pass + avatar_fg_path = f"temp{os.sep}avatar.png" + else: + avatar_fg_path = os.path.join(BG2_PATH, "avatar_fg.png") + return avatar_fg_path diff --git a/plugins/mys2.py b/plugins/mys2.py index 0c58b93..a6c2704 100644 --- a/plugins/mys2.py +++ b/plugins/mys2.py @@ -104,7 +104,7 @@ async def mys2_msg(client: Client, message: Message): try: uid = await selectDB(message.from_user.id, mode="uid") uid = uid[0] - im = await draw_info_pic(uid) + im = await draw_info_pic(uid, message) if not im: await message.reply("未查找到该用户的当前信息。", quote=True) else: @@ -200,7 +200,7 @@ async def mys2_qun_msg(client: Client, message: Message): try: uid = await selectDB(message.from_user.id, mode="uid") uid = uid[0] - im = await draw_info_pic(uid) + im = await draw_info_pic(uid, message) if not im: await message.reply("未查找到该用户的当前信息。") else: diff --git a/plugins/start.py b/plugins/start.py index 78a92ec..6aab4c2 100644 --- a/plugins/start.py +++ b/plugins/start.py @@ -4,7 +4,7 @@ from pyrogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineK ReplyKeyboardRemove HELP_MSG_PRE = 'PaimonBot ' \ - '0.4.2beta By Xtao-Labs\n\n' \ + '0.4.3beta By Xtao-Labs\n\n' \ '🔅 以下是小派蒙我学会了的功能(部分):\n' HELP_MSG = """① [武器/今日武器] 查看今日武器材料和武器 ② [天赋/今日天赋] 查看今日天赋材料和角色