抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

预览

碎碎念

python、nonebot2语法,来实现一些插件功能。

preview

TODO

碎碎念

bbb

引入库

碎碎念

以下引入的库并不是全都是我们需要的,但是这些是我整理的,还是建议留着。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from nonebot import on_notice
from nonebot.adapters.onebot.v11 import (
Adapter,
Bot,
Event,
Message,
MessageEvent,
MessageSegment,
GroupDecreaseNoticeEvent,
GroupIncreaseNoticeEvent
)
from nonebot.matcher import Matcher
from nonebot.params import Arg, CommandArg, ArgPlainText, State
from nonebot.plugin import on_command, on_notice
from nonebot.rule import to_me
from nonebot.typing import T_State

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
group_member_event = on_notice()

# 进群
@group_member_event.handle()
async def _group_member_join_handle_(bot: Bot, event: GroupIncreaseNoticeEvent):
uid = event.get_user_id()
at_ = "[CQ:at,qq={}]".format(uid)
msg = at_ + "外来的旅行者。" + f"我是小葱,「天理」的维系者,在此终结「人之子」的僭越。"
msg = Message(msg)
await group_member_event.finish(msg)

# 退群
@group_member_event.handle()
async def _group_member_left_(bot: Bot, event: GroupDecreaseNoticeEvent):
uid = event.get_user_id()
avatar = f"https://q1.qlogo.cn/g?b=qq&s=0&nk={uid}"
avatar_img = MessageSegment.image(f"{avatar}")
msg = avatar_img + '\n' + "旅行者离开了我们... ..."
msg = Message(msg)
await group_member_event.finish(msg)

最终代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from nonebot import on_notice
from nonebot.adapters.onebot.v11 import (
Adapter,
Bot,
Event,
Message,
MessageEvent,
MessageSegment,
GroupDecreaseNoticeEvent,
GroupIncreaseNoticeEvent
)
from nonebot.matcher import Matcher
from nonebot.params import Arg, CommandArg, ArgPlainText, State
from nonebot.plugin import on_command, on_notice
from nonebot.rule import to_me
from nonebot.typing import T_State

#
group_member_event = on_notice()
@group_member_event.handle()

# 进群
async def _group_member_join_handle_(bot: Bot, event: GroupIncreaseNoticeEvent):
uid = event.get_user_id()
at_ = "[CQ:at,qq={}]".format(uid)
msg = at_ + "外来的旅行者。" + f"我是小葱,「天理」的维系者,在此终结「人之子」的僭越。"
msg = Message(msg)
await group_member_event.finish(msg)

# 退群
@group_member_event.handle()
async def _group_member_left_(bot: Bot, event: GroupDecreaseNoticeEvent):
uid = event.get_user_id()
avatar = f"https://q1.qlogo.cn/g?b=qq&s=0&nk={uid}"
avatar_img = MessageSegment.image(f"{avatar}")
msg = avatar_img + '\n' + "旅行者离开了我们... ..."
msg = Message(msg)
await group_member_event.finish(msg)

评论

君既已浏览至此,何不留一句?