zhenxun_bot/plugins/one_friend/__init__.py

72 lines
2.4 KiB
Python
Raw Normal View History

2021-05-20 19:23:32 +08:00
from io import BytesIO
from random import choice
from nonebot import on_regex
from nonebot.typing import T_State
2022-02-19 18:20:19 +08:00
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
from utils.utils import get_message_at, get_user_avatar
2021-07-30 21:21:51 +08:00
from utils.message_builder import image
2021-12-16 11:16:28 +08:00
from utils.image_utils import BuildImage
2022-02-19 18:20:19 +08:00
from nonebot.params import RegexGroup
from typing import Tuple, Any
2021-05-20 19:23:32 +08:00
2021-10-03 14:24:07 +08:00
__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": ["我有一个朋友想问问", "我有一个朋友"],
}
2021-06-15 10:57:08 +08:00
2021-07-30 21:21:51 +08:00
one_friend = on_regex(
2022-02-19 18:20:19 +08:00
"^我.*?朋友.*?(想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问)(.*)",
2021-09-05 02:21:38 +08:00
priority=4,
2021-07-30 21:21:51 +08:00
block=True,
)
2021-05-20 19:23:32 +08:00
@one_friend.handle()
2022-02-19 18:20:19 +08:00
async def _(bot: Bot, event: GroupMessageEvent, state: T_State, reg_group: Tuple[Any, ...] = RegexGroup()):
2021-06-04 18:01:33 +08:00
qq = get_message_at(event.json())
if not qq:
2021-07-30 21:21:51 +08:00
qq = choice(
[
x["user_id"]
for x in await bot.get_group_member_list(
2022-02-19 18:20:19 +08:00
group_id=event.group_id
2021-07-30 21:21:51 +08:00
)
]
)
2021-10-03 14:24:07 +08:00
user_name = "朋友"
2021-06-04 18:01:33 +08:00
else:
qq = qq[0]
2021-08-17 23:17:08 +08:00
at_user = await bot.get_group_member_info(group_id=event.group_id, user_id=qq)
2022-02-19 18:20:19 +08:00
user_name = at_user["card"] or at_user["nickname"]
msg = reg_group[1]
2021-05-20 19:23:32 +08:00
if not msg:
2021-07-30 21:21:51 +08:00
msg = "都不知道问什么"
msg = msg.replace("", "").replace("", "").replace("", "")
2021-11-04 16:11:50 +08:00
x = await get_user_avatar(qq)
2021-10-03 14:24:07 +08:00
if x:
2021-12-16 11:16:28 +08:00
ava = BuildImage(200, 100, background=BytesIO(x))
2021-10-03 14:24:07 +08:00
else:
2021-12-16 11:16:28 +08:00
ava = BuildImage(200, 100, color=(0, 0, 0))
2021-06-15 16:45:48 +08:00
ava.circle()
2022-02-19 18:20:19 +08:00
text = BuildImage(400, 30, font_size=30)
2021-08-17 23:17:08 +08:00
text.text((0, 0), user_name)
2021-12-16 11:16:28 +08:00
A = BuildImage(700, 150, font_size=25, color="white")
2022-02-19 18:20:19 +08:00
await A.apaste(ava, (30, 25), True)
await A.apaste(text, (150, 38))
await A.atext((150, 85), msg, (125, 125, 125))
2021-06-15 16:45:48 +08:00
await one_friend.send(image(b64=A.pic2bs4()))