mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Update __init__.py
This commit is contained in:
parent
2232361812
commit
6d67157860
@ -1,18 +1,15 @@
|
||||
|
||||
import os
|
||||
import aiohttp
|
||||
from util.user_agent import get_user_agent
|
||||
from io import BytesIO
|
||||
from random import choice
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from nonebot import on_regex
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
|
||||
from util.utils import get_message_text, get_local_proxy, get_message_at
|
||||
from util.img_utils import pic2b64
|
||||
from configs.path_config import TTF_PATH
|
||||
from util.init_result import image
|
||||
import re
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from util.img_utils import CreateImg
|
||||
|
||||
__plugin_name__ = '我有一个朋友'
|
||||
|
||||
@ -35,9 +32,8 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
qq = get_message_at(event.json())
|
||||
if not qq:
|
||||
member_list = await bot.get_group_member_list(self_id=event.self_id, group_id=event.group_id)
|
||||
for member in member_list:
|
||||
arr.append(member['user_id'])
|
||||
qq = choice([x['user_id'] for x in
|
||||
await bot.get_group_member_list(self_id=event.self_id, group_id=event.group_id)])
|
||||
else:
|
||||
qq = qq[0]
|
||||
msg = re.search(r'^我.*?朋友.*?'
|
||||
@ -46,31 +42,15 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
msg = msg.group(2)
|
||||
if not msg:
|
||||
msg = '都不知道问什么'
|
||||
msg = msg.replace('他', '我').replace('她', '我')
|
||||
image = Image.open(BytesIO(await get_pic(choice(arr) if not qq else qq)))
|
||||
img_origin = Image.new('RGBA', (100, 100), (255, 255, 255))
|
||||
scale = 3
|
||||
# 使用新的半径构建alpha层
|
||||
r = 100 * scale
|
||||
alpha_layer = Image.new('L', (r, r), 0)
|
||||
draw = ImageDraw.Draw(alpha_layer)
|
||||
draw.ellipse((0, 0, r, r), fill=255)
|
||||
# 使用ANTIALIAS采样器缩小图像
|
||||
alpha_layer = alpha_layer.resize((100, 100), Image.ANTIALIAS)
|
||||
img_origin.paste(image, (0, 0), alpha_layer)
|
||||
msg = msg.replace('他', '我').replace('她', '我').replace('它', '我')
|
||||
ava = CreateImg(100, 100, background=BytesIO(await get_pic(qq)))
|
||||
ava.circle()
|
||||
text = CreateImg(60, 30, font_size=30)
|
||||
text.text((0, 0), '朋友')
|
||||
# text.show()
|
||||
A = CreateImg(700, 150, font_size=25, color='white')
|
||||
A.paste(ava, (30, 25), True)
|
||||
A.paste(text, (150, 40))
|
||||
A.text((150, 85), msg, (125, 125, 125))
|
||||
|
||||
# 创建Font对象:
|
||||
font = ImageFont.truetype(os.path.join(os.path.dirname(__file__), TTF_PATH + 'yz.ttf'), 30)
|
||||
font2 = ImageFont.truetype(os.path.join(os.path.dirname(__file__), TTF_PATH + 'yz.ttf'), 25)
|
||||
|
||||
# 创建Draw对象:
|
||||
image_text = Image.new('RGB', (450, 150), (255, 255, 255))
|
||||
draw = ImageDraw.Draw(image_text)
|
||||
draw.text((0, 0), '朋友', fill=(0, 0, 0), font=font)
|
||||
draw.text((0, 40), msg, fill=(125, 125, 125), font=font2)
|
||||
|
||||
image_back = Image.new('RGB', (700, 150), (255, 255, 255))
|
||||
image_back.paste(img_origin, (25, 25))
|
||||
image_back.paste(image_text, (150, 40))
|
||||
|
||||
await one_friend.send(MessageSegment.image(pic2b64(image_back)))
|
||||
await one_friend.send(image(b64=A.pic2bs4()))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user