zhenxun_bot/plugins/one_friend/__init__.py
2021-12-16 11:16:28 +08:00

75 lines
2.6 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from io import BytesIO
from random import choice
from nonebot import on_regex
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
from utils.utils import get_message_text, get_message_at, get_user_avatar
from utils.message_builder import image
import re
from utils.image_utils import BuildImage
__zx_plugin_name__ = "我有一个朋友"
__plugin_usage__ = """
usage
我有一个朋友他...,不知道是不是你
指令:
我有一个朋友想问问 [文本] ?[at]: 当at时你的朋友就是艾特对象
""".strip()
__plugin_des__ = "我有一个朋友想问问..."
__plugin_cmd__ = ["我有一个朋友想问问[文本] ?[at]"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["我有一个朋友想问问", "我有一个朋友"],
}
one_friend = on_regex(
"^我.*?朋友.*?(想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问).*",
priority=4,
block=True,
)
@one_friend.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
msg = get_message_text(event.json())
qq = get_message_at(event.json())
if not qq:
qq = choice(
[
x["user_id"]
for x in await bot.get_group_member_list(
self_id=event.self_id, group_id=event.group_id
)
]
)
user_name = "朋友"
else:
qq = qq[0]
at_user = await bot.get_group_member_info(group_id=event.group_id, user_id=qq)
user_name = at_user["card"] if at_user["card"] else at_user["nickname"]
msg = re.search(
r"^我.*?朋友.*?(想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问)(.*)", msg
)
msg = msg.group(2)
if not msg:
msg = "都不知道问什么"
msg = msg.replace("", "").replace("", "").replace("", "")
x = await get_user_avatar(qq)
if x:
ava = BuildImage(200, 100, background=BytesIO(x))
else:
ava = BuildImage(200, 100, color=(0, 0, 0))
ava.circle()
text = BuildImage(300, 30, font_size=30)
text.text((0, 0), user_name)
A = BuildImage(700, 150, font_size=25, color="white")
A.paste(ava, (30, 25), True)
A.paste(text, (150, 38))
A.text((150, 85), msg, (125, 125, 125))
await one_friend.send(image(b64=A.pic2bs4()))