Compare commits

...

1094 Commits

Author SHA1 Message Date
noneflow[bot]
eeaf823ea9 🔖 Release 2.3.3 2024-08-18 03:57:17 +00:00
Ju4tCode
2195e07998 🔖 bump version 2.3.3 (#2903) 2024-08-18 11:53:33 +08:00
noneflow[bot]
70fb8fc8c6 📝 Update changelog 2024-08-18 03:03:33 +00:00
shoucandanghehe
b78ae1ef0d 🍻 publish plugin nonebot-plugin-wait-a-minute (#2901) 2024-08-18 03:02:40 +00:00
noneflow[bot]
6af5566466 📝 Update changelog 2024-08-18 02:58:50 +00:00
tkgs0
8ceca0a90d 🍻 publish plugin 你看我像 (#2894) 2024-08-18 02:57:59 +00:00
noneflow[bot]
08fa6dbfc8 📝 Update changelog 2024-08-18 02:56:16 +00:00
gsskk
967aa758d3 🍻 publish plugin dify插件 (#2888) 2024-08-18 02:55:19 +00:00
noneflow[bot]
e3b10fbdc2 📝 Update changelog 2024-08-17 15:15:03 +00:00
shengwang52005
2115e5c6ec 🍻 publish plugin mai2_pcount (#2890) 2024-08-17 15:14:05 +00:00
noneflow[bot]
41dc908032 📝 Update changelog 2024-08-17 02:49:42 +00:00
N791
2b2f24628d 🍻 publish plugin nonebot-plugin-ehentai-search (#2884) 2024-08-17 02:48:53 +00:00
noneflow[bot]
1cc5d1af33 📝 Update changelog 2024-08-16 13:27:05 +00:00
shengwang52005
88074cf5c3 🍻 publish plugin pokepoke_miss (#2878) 2024-08-16 13:25:54 +00:00
noneflow[bot]
5d637eed95 📝 Update changelog 2024-08-15 03:35:09 +00:00
lm175
362c43ce5f 🍻 publish plugin 聊天截图伪造 (#2879) 2024-08-15 03:34:08 +00:00
noneflow[bot]
622b8eb51e 📝 Update changelog 2024-08-13 11:23:45 +00:00
hanasa2023
c369dcf781 🍻 publish plugin ba-tools (#2863) 2024-08-13 11:22:46 +00:00
noneflow[bot]
53d1e1dee9 📝 Update changelog 2024-08-13 07:39:10 +00:00
Leo Q
75f5825cff 📝 Docs: 添加 Windows Powershell 设置环境变量方法 (#2874)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-08-13 15:38:17 +08:00
noneflow[bot]
d05c90787c 📝 Update changelog 2024-08-12 15:23:00 +00:00
BEISNWKZNAN
e07ba36a4a 🍻 publish plugin 精华消息管理 (#2872) 2024-08-12 15:22:10 +00:00
noneflow[bot]
f7c05d9a08 📝 Update changelog 2024-08-11 15:24:59 +00:00
kawaiior
59c5a1a35d 🍻 publish plugin B站收藏夹监视器 (#2868) 2024-08-11 15:24:07 +00:00
noneflow[bot]
3eb653821e 📝 Update changelog 2024-08-11 12:47:36 +00:00
Ju4tCode
214bc838c2 📝 Docs: 更新 localstore 插件文档 (#2871) 2024-08-11 20:46:41 +08:00
noneflow[bot]
79c7ea5bab 📝 Update changelog 2024-08-11 07:17:00 +00:00
Ju4tCode
b59b1be6ff Feature: 优化依赖注入在 pydantic v2 下的性能 (#2870) 2024-08-11 15:15:59 +08:00
noneflow[bot]
aeb75a6ce3 📝 Update changelog 2024-08-11 07:05:13 +00:00
iam57ao
847325a119 🍻 publish plugin Alist (#2864) 2024-08-11 07:04:22 +00:00
noneflow[bot]
26eabfaf6f 📝 Update changelog 2024-08-09 12:18:53 +00:00
月ヶ瀬
40a7b97220 ✏️ Plugin: 修改插件 system-command 信息 (#2862)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-09 20:18:01 +08:00
noneflow[bot]
91b40748c4 📝 Update changelog 2024-08-09 12:14:40 +00:00
SamuNatsu
013a2f94d6 🍻 publish plugin nonebot-plugin-deer-pipe (#2858) 2024-08-09 12:13:51 +00:00
noneflow[bot]
74d280ed75 📝 Update changelog 2024-08-08 09:04:11 +00:00
luosheng520qaq
b7d46de10e 🍻 publish plugin 漂流瓶 (#2860) 2024-08-08 09:03:15 +00:00
noneflow[bot]
c37b5bbbca 📝 Update changelog 2024-08-07 13:11:34 +00:00
zhongwen-4
5e08e73698 🍻 publish plugin 奇怪的小功能 (#2850) 2024-08-07 13:10:40 +00:00
pre-commit-ci[bot]
b27bb92d03 ⬆️ auto update by pre-commit hooks (#2857)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-06 14:43:44 +08:00
noneflow[bot]
6bf8858cc6 📝 Update changelog 2024-08-06 06:20:30 +00:00
Ju4tCode
c97a780645 Feature: 添加遗漏的类型标注 (#2856) 2024-08-06 14:19:17 +08:00
noneflow[bot]
976c1cd8e0 📝 Update changelog 2024-08-03 13:21:57 +00:00
ALittleBot
26fd6f8a6c ✏️ Plugin: 修改 nonebot-plugin-fishing 插件作者 (#2854) 2024-08-03 21:20:57 +08:00
noneflow[bot]
0020ad28ba 📝 Update changelog 2024-08-03 09:53:27 +00:00
CCYellowStar2
ba9ca63f10 🍻 publish plugin SunoAI音乐生成 (#2852) 2024-08-03 09:52:24 +00:00
noneflow[bot]
28b5b732c2 📝 Update changelog 2024-07-29 12:38:05 +00:00
KomoriDev
b944da8445 🍻 publish plugin 谁是卷王 (#2848) 2024-07-29 12:37:02 +00:00
noneflow[bot]
5cab166d6b 📝 Update changelog 2024-07-28 15:04:05 +00:00
zhaomaoniu
546cdb4229 🍻 publish plugin GPT-SoVITS 语音合成 (#2846) 2024-07-28 15:02:59 +00:00
noneflow[bot]
77790fad1f 📝 Update changelog 2024-07-28 12:41:01 +00:00
Alpaca4610
bcf849c98f 🍻 publish plugin 基于清影的AI视频生成 (#2842) 2024-07-28 12:40:00 +00:00
noneflow[bot]
f7b3c8af02 📝 Update changelog 2024-07-26 03:42:50 +00:00
tkgs0
cced60589c 🍻 publish plugin 命令行 (#2839) 2024-07-26 03:41:42 +00:00
noneflow[bot]
62adb32c94 📝 Update changelog 2024-07-22 07:10:44 +00:00
Lonely-Sails
6ab752dcdb ✏️ Bot: 更新 Minecraft QQBot 信息 (#2838) 2024-07-22 15:09:31 +08:00
noneflow[bot]
4d6f071739 📝 Update changelog 2024-07-21 14:58:12 +00:00
wyf7685
bd140c2ceb 🍻 publish plugin exe_code (#2834) 2024-07-21 14:57:09 +00:00
noneflow[bot]
59d9991aa4 📝 Update changelog 2024-07-21 12:56:40 +00:00
Lonely-Sails
55e7f59e40 🍻 publish bot Minecraft_QQBot (#2836) 2024-07-21 12:55:37 +00:00
noneflow[bot]
bb83483020 📝 Update changelog 2024-07-21 12:36:25 +00:00
This-is-XiaoDeng
5300ef5119 🍻 publish plugin nonebot-plugin-autopush (#2832) 2024-07-21 12:35:17 +00:00
noneflow[bot]
5a50d4203c 📝 Update changelog 2024-07-21 10:07:54 +00:00
SwedishDoveCooker
01a96f3086 🍻 publish plugin vv_helper (#2820) 2024-07-21 10:06:53 +00:00
noneflow[bot]
0570d779ee 📝 Update changelog 2024-07-21 04:51:31 +00:00
Cvandia
18d0bc2c81 🍻 publish plugin nonebot_plugin_game_torrent (#2826) 2024-07-21 04:50:31 +00:00
Ju4tCode
87e0d8148f 👷 Fix: preview alias and commit status (#2831) 2024-07-21 12:40:50 +08:00
Ju4tCode
53d8989145 🐛 Fix: website preview CD (#2830) 2024-07-21 12:14:18 +08:00
noneflow[bot]
5433b4ebdf 📝 Update changelog 2024-07-21 03:29:14 +00:00
wyeeeee
f10cecf16a 🍻 publish plugin 每日油价 (#2821) 2024-07-21 03:28:10 +00:00
Ju4tCode
60a3f6f4cc 👷 Security: 拆分 PR Website CI/CD (#2829) 2024-07-21 11:23:15 +08:00
noneflow[bot]
f70ae89098 📝 Update changelog 2024-07-20 06:04:34 +00:00
Ju4tCode
2f60c5e9b4 🚨 Fix: 错误的类型标注和 annotated 处理 (#2828) 2024-07-20 14:03:32 +08:00
noneflow[bot]
015ddd9517 📝 Update changelog 2024-07-18 15:18:51 +00:00
StarXinXin
f1539d9ec4 🍻 publish bot 星辰 Bot (#2823) 2024-07-18 15:17:48 +00:00
noneflow[bot]
2d0444ba75 📝 Update changelog 2024-07-18 13:35:13 +00:00
shiyihang2007
ed2c222e83 🍻 publish plugin wordle (#2817) 2024-07-18 13:34:08 +00:00
noneflow[bot]
ed048913a4 📝 Update changelog 2024-07-17 15:07:06 +00:00
SuperGuGuGu
121ba17698 ✏️ Plugin: 移除 kanonbot 插件 (#2819) 2024-07-17 23:05:55 +08:00
noneflow[bot]
d0f5a76c47 📝 Update changelog 2024-07-15 14:21:24 +00:00
NCBM
f809f1d089 🍻 publish plugin 再润 (#2815) 2024-07-15 14:20:12 +00:00
noneflow[bot]
070ad18781 📝 Update changelog 2024-07-13 13:10:45 +00:00
Shenyi Chen
56119ef1cc ✏️ Plugin: 更新插件 sparkapi 信息 (#2812) 2024-07-13 21:09:41 +08:00
noneflow[bot]
30195a35dc 📝 Update changelog 2024-07-13 12:07:10 +00:00
Asankilp
0500b7baab 🍻 publish plugin 漫展/展览查询 (#2810) 2024-07-13 12:06:04 +00:00
noneflow[bot]
08473a5c25 📝 Update changelog 2024-07-11 09:47:40 +00:00
Lumine
37ad14c277 ✏️ Plugin: 修改插件 miragetank & charpic 信息 (#2807) 2024-07-11 17:46:41 +08:00
noneflow[bot]
3e8c6ce541 📝 Update changelog 2024-07-11 09:41:38 +00:00
shi-yingyingjiang
3dd5539dc7 🍻 publish plugin 鸣潮wiki (#2801) 2024-07-11 09:40:36 +00:00
noneflow[bot]
559a0320a8 📝 Update changelog 2024-07-11 09:34:58 +00:00
1v7w
8646d885f0 🍻 publish plugin cloudfare R2 客服端 (#2805) 2024-07-11 09:33:53 +00:00
noneflow[bot]
84c008cdce 📝 Update changelog 2024-07-10 13:41:24 +00:00
QuickLAW
2671cb5b72 🍻 publish plugin AnyMate小助手 (#2760) 2024-07-10 13:40:12 +00:00
noneflow[bot]
379440708f 📝 Update changelog 2024-07-06 12:54:50 +00:00
noneflow[bot]
4d070f5b48 🔖 Release 2.3.2 2024-07-06 12:34:00 +00:00
Ju4tCode
82138454bc 🔖 bump version 2.3.2 (#2799) 2024-07-06 20:24:00 +08:00
noneflow[bot]
d98fe53d56 📝 Update changelog 2024-07-05 12:49:09 +00:00
Komorebi
278b9e92c2 📝 Docs: 修改导航栏开源之夏链接 (#2798) 2024-07-05 20:48:06 +08:00
noneflow[bot]
45418ccfae 📝 Update changelog 2024-07-04 15:06:15 +00:00
fallllllllsleep
2ad2922565 📝 Docs: on_keyword 参数类型错误 (#2795)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-07-04 23:04:58 +08:00
pre-commit-ci[bot]
84ebcb4ce6 ⬆️ auto update by pre-commit hooks (#2794)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-07-02 21:50:54 +08:00
noneflow[bot]
6a0caacfd6 📝 Update changelog 2024-07-02 13:30:22 +00:00
tianyisama
a8f3940cbc 🍻 publish plugin 指令更新NapCat (#2790) 2024-07-02 13:29:12 +00:00
noneflow[bot]
15d3910462 📝 Update changelog 2024-07-01 13:18:15 +00:00
Autuamn
edfd0eb887 🍻 publish plugin QQ群-Discord 互通 (#2787) 2024-07-01 13:17:10 +00:00
noneflow[bot]
fe63717848 📝 Update changelog 2024-06-28 12:30:26 +00:00
Dongyanmio
63424bc3ac 🍻 publish plugin nonebot_plugin_obastatus (#2779) 2024-06-28 12:29:23 +00:00
noneflow[bot]
99b1d0ed96 📝 Update changelog 2024-06-25 15:18:44 +00:00
BraveCowardp
90c7fd4747 🍻 publish plugin b站消息转发 (#2784) 2024-06-25 15:17:40 +00:00
noneflow[bot]
c1a9758a18 📝 Update changelog 2024-06-25 15:06:02 +00:00
WMGray
17e7a0c029 🍻 publish plugin Daily Task (#2768) 2024-06-25 15:04:50 +00:00
noneflow[bot]
df6a948c08 📝 Update changelog 2024-06-25 14:05:42 +00:00
zifox666
9f19eb7a96 🍻 publish plugin EVE ONLINE 多功能机器人 (#2781) 2024-06-25 14:04:38 +00:00
noneflow[bot]
2b68428526 📝 Update changelog 2024-06-25 13:45:54 +00:00
kanbereina
d62c6561c2 🍻 publish plugin NTQQ自动登录/断连重启 (#2783) 2024-06-25 13:44:51 +00:00
noneflow[bot]
fc3bb5ff1f 📝 Update changelog 2024-06-25 13:13:53 +00:00
CCYellowStar2
76b1bbb443 🍻 publish plugin asmr (#2774) 2024-06-25 13:12:48 +00:00
noneflow[bot]
7b724925ba 📝 Update changelog 2024-06-20 12:50:21 +00:00
uy/sun
62dc2574c7 🐛 Fix: 修复 ForwardRef eval 时参数 recursive_guard 缺失 (#2778) 2024-06-20 20:49:17 +08:00
noneflow[bot]
ea40ae3a18 📝 Update changelog 2024-06-19 18:08:39 +00:00
ElainaFanBoy
f94e7d9b5b 🍻 publish plugin 日麻猜手牌小游戏 (#2776) 2024-06-19 18:07:12 +00:00
noneflow[bot]
c8ba973280 📝 Update changelog 2024-06-19 10:08:21 +00:00
SherkeyXD
35e062c588 🍻 publish plugin 绝地潜兵信息查询小助手 (#2771) 2024-06-19 10:07:19 +00:00
noneflow[bot]
53724487d3 📝 Update changelog 2024-06-19 08:56:41 +00:00
LiLuo-B
a3003b0ff6 🍻 publish plugin MCSM小助手 (#2770) 2024-06-19 08:55:32 +00:00
noneflow[bot]
96ecd415cd 📝 Update changelog 2024-06-18 21:42:46 +00:00
syagina
e8ef4735ea 🍻 publish plugin 多模态AI工具 (#2754) 2024-06-18 21:41:43 +00:00
noneflow[bot]
b78b08ed81 📝 Update changelog 2024-06-14 14:23:26 +00:00
phquathi
e11ea52276 🍻 publish plugin nonebot-plugin-easymarkdown (#2766) 2024-06-14 14:22:20 +00:00
noneflow[bot]
819e7334b2 📝 Update changelog 2024-06-14 14:08:12 +00:00
AzideCupric
1ebafaa9a5 🍻 publish plugin 峯驰外包 (#2764) 2024-06-14 14:07:04 +00:00
noneflow[bot]
3554292d5f 📝 Update changelog 2024-06-12 11:08:37 +00:00
BraveCowardp
ec9ef9a760 🍻 publish plugin 鸣潮抽卡记录分析 (#2762) 2024-06-12 11:07:23 +00:00
noneflow[bot]
74663c7c5e 📝 Update changelog 2024-06-11 13:48:36 +00:00
ajdgg
cbc99be031 🍻 publish plugin nonebot-plugin-xjie-weather (#2755) 2024-06-11 13:47:34 +00:00
noneflow[bot]
81e9bdd7ec 📝 Update changelog 2024-06-08 04:39:27 +00:00
KomoriDev
323038ecc6 🍻 publish plugin 颜值评分 (#2751) 2024-06-08 04:38:23 +00:00
noneflow[bot]
7091beb809 📝 Update changelog 2024-06-07 09:42:23 +00:00
ikarosf
010c48d30f 🍻 publish plugin 学园偶像大师算分插件 (#2749) 2024-06-07 09:41:19 +00:00
noneflow[bot]
a5b2dd38d5 📝 Update changelog 2024-06-05 13:38:04 +00:00
050644zf
fa5f295fe7 🍻 publish plugin nonebot-plugin-lynchpined (#2747) 2024-06-05 13:36:59 +00:00
pre-commit-ci[bot]
7f7b23bd2f ⬆️ auto update by pre-commit hooks (#2746)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-06-04 10:40:10 +08:00
noneflow[bot]
0434e12b8a 📝 Update changelog 2024-06-03 04:39:22 +00:00
yejue
425d140161 🍻 publish plugin QQShell (#2744) 2024-06-03 04:38:08 +00:00
noneflow[bot]
64d8f7843a 📝 Update changelog 2024-06-02 14:31:34 +00:00
CCYellowStar2
a0a6427540 🍻 publish plugin ai唱歌 (#2742) 2024-06-02 14:30:24 +00:00
noneflow[bot]
31fe8e6582 📝 Update changelog 2024-05-30 06:14:11 +00:00
mobyw
38e42919b7 📝 Docs: 修复单元测试示例代码 (#2741) 2024-05-30 14:13:11 +08:00
noneflow[bot]
c769f95688 📝 Update changelog 2024-05-29 12:53:55 +00:00
yejue
d642897a5b 🍻 publish plugin 复读姬+1 PlusOne (#2731) 2024-05-29 12:52:45 +00:00
noneflow[bot]
d7931f8ec2 📝 Update changelog 2024-05-27 13:22:56 +00:00
Sclock
8a0b989718 🍻 publish plugin 高优先级关闭信号钩子插件 (#2736) 2024-05-27 13:21:55 +00:00
noneflow[bot]
4fbbb646c3 📝 Update changelog 2024-05-25 14:17:07 +00:00
cubstaryow
75856e63f6 🍻 publish plugin 插件响应鉴权 (#2726) 2024-05-25 14:16:03 +00:00
noneflow[bot]
98213f50db 📝 Update changelog 2024-05-25 04:21:01 +00:00
Weltolk
5bce1db24e 📝 Docs: 修改依赖注入定义链接 (#2733) 2024-05-25 12:19:48 +08:00
noneflow[bot]
380ace5780 📝 Update changelog 2024-05-21 20:14:18 +00:00
Ljzd-PRO
6e5b01a3d4 🍻 publish plugin DG-Lab-Play (#2728) 2024-05-21 20:13:16 +00:00
noneflow[bot]
622e8e8af3 🔖 Release 2.3.1 2024-05-20 14:19:50 +00:00
Ju4tCode
2bbb83d3f2 🔖 bump version 2.3.1 (#2725) 2024-05-20 22:09:51 +08:00
noneflow[bot]
54756134d4 📝 Update changelog 2024-05-20 13:31:40 +00:00
Alpaca4610
932b212e04 🍻 publish plugin 自定义人格和AI绘图的混合聊天BOT (#2723) 2024-05-20 13:30:32 +00:00
noneflow[bot]
3b40e5b20c 📝 Update changelog 2024-05-18 15:32:15 +00:00
ajdgg
f594db207d 🍻 publish plugin nonebot-plugin-calc24 (#2720) 2024-05-18 15:31:14 +00:00
noneflow[bot]
70e23427e8 📝 Update changelog 2024-05-18 14:47:10 +00:00
WindowsSov8forUs
c1a303fd3d 🍻 publish plugin nonebot-plugin-tsugu-bangdream-bot (#2718) 2024-05-18 14:46:02 +00:00
noneflow[bot]
a62b9a5e1a 📝 Update changelog 2024-05-18 03:44:44 +00:00
Komorebi
36eece311a 📝 Docs: 修正 匹配扩展 中的示例 (#2722) 2024-05-18 11:43:39 +08:00
noneflow[bot]
29ea5f5787 📝 Update changelog 2024-05-17 05:58:08 +00:00
CCLMSY
c00e3aacfc 🍻 publish plugin 科大讯飞星火大语言模型官方API聊天机器人插件 (#2716) 2024-05-17 05:57:07 +00:00
noneflow[bot]
cf9f78528c 📝 Update changelog 2024-05-15 02:03:18 +00:00
Tarrailt
68d4795de6 📝 Docs: 更新 Mirai 适配器说明 (#2715)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-15 10:02:12 +08:00
noneflow[bot]
e689d7f7d2 📝 Update changelog 2024-05-14 17:06:21 +00:00
RF-Tar-Railt
a607f868c2 🍻 publish adapter Mirai (#2713) 2024-05-14 17:05:19 +00:00
noneflow[bot]
84ac1c4bad 📝 Update changelog 2024-05-14 15:27:34 +00:00
worldmozara
e11ff528e2 🗑️ 移除已在 PyPI 上删除的 covid 插件和 molar-mass 插件 (#2712) 2024-05-14 23:26:26 +08:00
noneflow[bot]
047f4d1878 📝 Update changelog 2024-05-14 04:28:53 +00:00
LiLuo-B
0294c33baf 🍻 publish plugin nonebot_plugin_valve_server_query (#2710) 2024-05-14 04:27:43 +00:00
noneflow[bot]
11a8b6e40b 📝 Update changelog 2024-05-13 14:06:07 +00:00
ConcyWee
cade86b62a 🍻 publish plugin 库洛游戏信息 (#2702) 2024-05-13 14:04:58 +00:00
noneflow[bot]
df836ec1c6 📝 Update changelog 2024-05-12 09:46:03 +00:00
zhaomaoniu
12cc00a3d3 🍻 publish plugin BanG Dream! Tsugu Frontend (#2707) 2024-05-12 09:45:00 +00:00
noneflow[bot]
24aa81f0be 📝 Update changelog 2024-05-12 09:33:27 +00:00
Yan-Zero
339706a3a6 🍻 publish plugin 神秘学助手 (#2699) 2024-05-12 09:32:25 +00:00
noneflow[bot]
b43c9adb7a 📝 Update changelog 2024-05-12 02:42:57 +00:00
Ekac00
c2783039d4 🍻 publish plugin nonebot-plugin-furryfusion (#2704) 2024-05-12 02:41:50 +00:00
noneflow[bot]
c4706e4123 📝 Update changelog 2024-05-12 02:30:10 +00:00
Ekac00
8a997540b3 🍻 publish plugin nonebot-plugin-RanFurryPic (#2701) 2024-05-12 02:28:59 +00:00
noneflow[bot]
045022b22a 📝 Update changelog 2024-05-09 07:10:05 +00:00
Ju4tCode
723fa4b3d8 🐛 Fix: State ForwardRef 检测错误 (#2698) 2024-05-09 15:08:49 +08:00
noneflow[bot]
41b59cff06 📝 Update changelog 2024-05-09 02:38:47 +00:00
yejue
bed1b46527 🍻 publish plugin with_ai_agents (#2696) 2024-05-09 02:37:44 +00:00
pre-commit-ci[bot]
ad695ca6e8 ⬆️ auto update by pre-commit hooks (#2695)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-07 13:35:53 +08:00
noneflow[bot]
33e997708c 📝 Update changelog 2024-05-05 05:48:08 +00:00
zhaomaoniu
56b6ee1d38 🍻 publish plugin nonebot_plugin_anime_downloader (#2690) 2024-05-05 05:47:03 +00:00
noneflow[bot]
27b2cf52a5 📝 Update changelog 2024-05-05 04:56:01 +00:00
eya46
b532130f6e 📝 Docs: 添加 Tailchat 适配器说明 (#2694)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-05-05 12:54:51 +08:00
noneflow[bot]
d16b8594ad 📝 Update changelog 2024-05-05 04:42:08 +00:00
eya46
ad8442c6de 🍻 publish adapter Tailchat (#2692) 2024-05-05 04:40:57 +00:00
noneflow[bot]
4edf7e2c2c 📝 Update changelog 2024-05-01 14:29:42 +00:00
StarHeart
ea49318809 📝 Docs: 添加 uwu logo (#2689) 2024-05-01 22:28:36 +08:00
noneflow[bot]
a9a86aba61 🔖 Release 2.3.0 2024-05-01 09:01:32 +00:00
Ju4tCode
6e95d5366c 🔖 bump version 2.3.0 (#2688) 2024-05-01 16:55:17 +08:00
noneflow[bot]
445711e1cb 📝 Update changelog 2024-05-01 08:17:06 +00:00
Bryan不可思议
dfd2096fe5 📝 Docs: 数据库最佳实践 (#2545)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-05-01 16:16:02 +08:00
noneflow[bot]
d469c6f287 📝 Update changelog 2024-05-01 05:39:50 +00:00
Ju4tCode
9655b941f3 🐛 Fix: none 系列驱动器启动失败时未退出应用 (#2687) 2024-05-01 13:38:47 +08:00
noneflow[bot]
4254fdfd8c 📝 Update changelog 2024-05-01 03:35:49 +00:00
Tarrailt
1b3cd7e2e2 📝 Docs: 更新最佳实践的 Alconna 部分 (#2686) 2024-05-01 11:34:33 +08:00
noneflow[bot]
897498b7f5 📝 Update changelog 2024-04-29 12:27:53 +00:00
Ju4tCode
34770e4463 🧑‍💻 CI: 修复 NoneFlow reaction 范围 (#2685) 2024-04-29 20:26:35 +08:00
noneflow[bot]
9d14f72249 📝 Update changelog 2024-04-27 09:58:35 +00:00
colasama
87f6e81ffc 🍻 publish plugin 表情包保存器 (#2683) 2024-04-27 09:57:30 +00:00
noneflow[bot]
c3373e141a 📝 Update changelog 2024-04-26 03:12:24 +00:00
StarHeart
a5f2d97b04 👷 CI: 修复测试 (#2682) 2024-04-26 11:11:13 +08:00
noneflow[bot]
80ac6a5ae9 📝 Update changelog 2024-04-25 03:13:26 +00:00
cubstaryow
496475e0ca 🍻 publish plugin HelpWithPic (#2680) 2024-04-25 03:12:15 +00:00
noneflow[bot]
982dbbccdf 📝 Update changelog 2024-04-24 06:57:06 +00:00
cubstaryow
3f9c20c60b 🍻 publish plugin cyberfurry (#2678) 2024-04-24 06:55:56 +00:00
noneflow[bot]
cabb3c6c45 📝 Update changelog 2024-04-23 04:37:41 +00:00
afterow
03bf1fdcfe 🍻 publish plugin 三爻易数 (#2674) 2024-04-23 04:36:36 +00:00
noneflow[bot]
f36f8d1bcc 📝 Update changelog 2024-04-22 07:59:57 +00:00
Ju4tCode
5c2c1770a2 👷 CI: NoneFlow 添加 reaction 响应提示 (#2677) 2024-04-22 15:58:48 +08:00
noneflow[bot]
6810af1e1d 📝 Update changelog 2024-04-22 07:27:58 +00:00
Ju4tCode
78ba6ce973 📝 Docs: 添加 OSPP 2024 项目说明 (#2676) 2024-04-22 15:26:48 +08:00
noneflow[bot]
15bcb7e374 📝 Update changelog 2024-04-22 06:35:01 +00:00
shi-yingyingjiang
7dd7ccbff5 🍻 publish plugin 战双表情 (#2668) 2024-04-22 06:33:57 +00:00
noneflow[bot]
5b17c8de71 📝 Update changelog 2024-04-21 02:39:49 +00:00
Autuamn
5cf4ff66a3 🍻 publish plugin QQ频道-Discord 互通 (#2666) 2024-04-21 02:38:40 +00:00
noneflow[bot]
b6be8a178e 📝 Update changelog 2024-04-20 15:41:30 +00:00
YuxiCN
b77c3b2d0c 🍻 publish plugin Yinying-Chat (#2653) 2024-04-20 15:40:30 +00:00
noneflow[bot]
e4a210b47c 📝 Update changelog 2024-04-20 06:48:21 +00:00
Ju4tCode
6bf10aafb7 Feature: 嵌套插件名称作用域优化 (#2665) 2024-04-20 14:47:12 +08:00
noneflow[bot]
e15d544341 📝 Update changelog 2024-04-19 03:49:38 +00:00
惜月
acdb5787db 📝 Docs: 更新 Villa 适配器说明 (#2661) 2024-04-19 11:48:34 +08:00
noneflow[bot]
18f0c9b500 📝 Update changelog 2024-04-19 02:56:24 +00:00
shi-yingyingjiang
b36e721274 🍻 publish plugin 淫语 (#2649) 2024-04-19 02:55:16 +00:00
noneflow[bot]
9fdc50cd0e 📝 Update changelog 2024-04-19 02:52:46 +00:00
Tarrailt
41abf077bc 📝 Docs: 添加 Kritor 适配器说明 (#2660)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-04-19 10:51:37 +08:00
noneflow[bot]
27a4e5a55b 📝 Update changelog 2024-04-19 02:43:27 +00:00
Ju4tCode
65f6a104e9 Update assets/adapters.json 2024-04-19 02:42:17 +00:00
RF-Tar-Railt
415bd07c0d 🍻 publish adapter Kritor (#2658) 2024-04-19 02:42:17 +00:00
noneflow[bot]
3fd26dd937 📝 Update changelog 2024-04-18 10:51:15 +00:00
Azide
f5f5d93b64 🐛 Bug: inherit_supported_adapters 在展开缩写前取交集 (#2654)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-18 18:50:11 +08:00
noneflow[bot]
b497bb8c83 📝 Update changelog 2024-04-18 10:30:35 +00:00
Tarrailt
b0d554eacb 📝 Docs: 更新最佳实践的 Alconna 部分 (#2656)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-18 18:28:31 +08:00
noneflow[bot]
cbecc7b930 📝 Update changelog 2024-04-18 06:11:20 +00:00
baiqwerdvd
5e0921aca9 🍻 publish plugin 飞花令 (#2647) 2024-04-18 06:10:11 +00:00
noneflow[bot]
7e8015e828 📝 Update changelog 2024-04-17 11:14:50 +00:00
huanxin996
bef5bdf0bf 🍻 publish plugin Hx_YinYing (#2645) 2024-04-17 11:13:39 +00:00
noneflow[bot]
c04cd5e83e 📝 Update changelog 2024-04-17 09:25:33 +00:00
Ju4tCode
30d3c1bbce Feature: 优化调用栈识别 (#2644) 2024-04-17 17:24:38 +08:00
noneflow[bot]
5e72461391 📝 Update changelog 2024-04-16 12:52:07 +00:00
KarisAya
54fdf71d91 🍻 publish plugin clovers插件框架 (#2642) 2024-04-16 12:51:10 +00:00
noneflow[bot]
420d0cfdc4 📝 Update changelog 2024-04-16 06:45:23 +00:00
zhulinyv
84bfba7a82 🍻 publish plugin nonebot-plugin-nai3 (#2638) 2024-04-16 06:44:27 +00:00
noneflow[bot]
9fd89a6822 📝 Update changelog 2024-04-15 16:34:44 +00:00
Ju4tCode
4a02dde83f 💥 Remove: 移除 Python 3.8 支持 (#2641) 2024-04-16 00:33:48 +08:00
noneflow[bot]
e93ee1ffec 📝 Update changelog 2024-04-14 14:27:20 +00:00
Ju4tCode
e2b6fb12c7 📝 Docs: 添加 RocketChat 适配器说明 (#2640)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-14 22:26:23 +08:00
noneflow[bot]
7836073c7e 📝 Update changelog 2024-04-11 05:33:11 +00:00
IllTamer
3119626d89 🍻 publish adapter RocketChat (#2636) 2024-04-11 05:32:21 +00:00
noneflow[bot]
19bebdd923 📝 Update changelog 2024-04-09 03:28:08 +00:00
Well2333
0b0dd8b552 🍻 publish plugin nonebot-plugin-auto-bot-selector (#2634) 2024-04-09 03:27:14 +00:00
noneflow[bot]
47ce7a633f 📝 Update changelog 2024-04-08 12:23:18 +00:00
StarHeart
ca32f68787 📝 Docs: 商店卡片样式调整 (#2633) 2024-04-08 20:22:29 +08:00
noneflow[bot]
0b972ad302 📝 Update changelog 2024-04-08 12:17:53 +00:00
Ju4tCode
9b4b1526b1 🐛 Bug: 添加 HTTP 客户端会话上下文检查 (#2632) 2024-04-08 20:17:03 +08:00
noneflow[bot]
7a232c7a4a 📝 Update changelog 2024-04-06 12:08:18 +00:00
Azide
983351f0b7 📝 Docs: 为商店插件卡片添加更多展示内容 (#2626) 2024-04-06 20:07:09 +08:00
noneflow[bot]
16fb5ac121 📝 Update changelog 2024-04-05 13:44:11 +00:00
mrqx0195
bb1fbca4a7 🍻 publish plugin Chikari_economy (#2630) 2024-04-05 13:43:17 +00:00
noneflow[bot]
b7c0b6b8e0 📝 Update changelog 2024-04-05 13:11:57 +00:00
Ju4tCode
485aa62755 Feature: 支持 HTTP 客户端会话 (#2627) 2024-04-05 21:11:05 +08:00
noneflow[bot]
53e2a86dd9 📝 Update changelog 2024-04-05 03:36:21 +00:00
zhzhongshi
312095d1df 🍻 publish plugin diffsinger (#2624) 2024-04-05 03:35:33 +00:00
noneflow[bot]
b498be1092 📝 Update changelog 2024-04-04 08:13:35 +00:00
Akirami
211ea8427f 📝 Docs: 修复 RegexMatched 文档类型标注错误 (#2629) 2024-04-04 16:12:39 +08:00
noneflow[bot]
407eb69568 📝 Update changelog 2024-04-04 07:30:23 +00:00
Akirami
8a44b4d6ee 📝 Docs: 修复 RegexMatched​ 文档高亮行错误 (#2628) 2024-04-04 15:29:33 +08:00
noneflow[bot]
bc58fbb741 📝 Update changelog 2024-04-02 14:55:01 +00:00
Azide
0c977f5fd7 📝 Docs: 为商店的详情卡片添加跳转链接 (#2623) 2024-04-02 22:54:10 +08:00
noneflow[bot]
7eeccbcb14 📝 Update changelog 2024-04-02 02:04:37 +00:00
Jigsaw
020d2a5687 🐛 Fix: 将 aiohttp 的 quote_fields 默认设为 False (#2619) 2024-04-02 10:03:46 +08:00
pre-commit-ci[bot]
83d61fcffd ⬆️ auto update by pre-commit hooks (#2620)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-02 09:55:19 +08:00
noneflow[bot]
c0b222a5fa 📝 Update changelog 2024-04-02 01:38:09 +00:00
Akirami
236e4ea9aa 📝 Docs: 添加 RegexMatched 依赖注入文档 (#2618)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-04-02 09:37:02 +08:00
noneflow[bot]
0622e16d18 📝 Update changelog 2024-04-02 01:21:36 +00:00
Lipraty
159ca84e46 🍻 publish plugin ghtiles (#2621) 2024-04-02 01:20:19 +00:00
noneflow[bot]
142a61ce5c 📝 Update changelog 2024-03-24 13:17:39 +00:00
QuanhuZeYu
7f226af541 🍻 publish plugin 人类友好数据配置 (#2615) 2024-03-24 13:16:37 +00:00
noneflow[bot]
8bf912499a 📝 Update changelog 2024-03-23 12:20:18 +00:00
Redmomn
a55b10cfa3 🍻 publish plugin nonebot-plugin-pallas-repeater (#2613) 2024-03-23 12:19:13 +00:00
noneflow[bot]
1a4f889b40 📝 Update changelog 2024-03-23 05:24:00 +00:00
Redmomn
f9bc2de4e4 🍻 publish plugin nonebot-plugin-duel (#2611) 2024-03-23 05:22:54 +00:00
noneflow[bot]
5a1c635083 📝 Update changelog 2024-03-23 05:14:56 +00:00
Agnes4m
76e8567f1e 🍻 publish plugin Sekai Stickers (#2609) 2024-03-23 05:13:57 +00:00
noneflow[bot]
9bd349d933 📝 Update changelog 2024-03-17 12:58:31 +00:00
GLDYM
5e8a67b605 🍻 publish plugin 100orangejuice (#2600) 2024-03-17 12:57:28 +00:00
noneflow[bot]
e16799d500 📝 Update changelog 2024-03-15 14:36:09 +00:00
zhaomaoniu
a189846194 🍻 publish plugin Steam Info (#2607) 2024-03-15 14:35:03 +00:00
noneflow[bot]
fcd536aada 📝 Update changelog 2024-03-13 03:32:46 +00:00
KroMiose
c89bafc2c9 🍻 publish plugin nonebot-plugin-dice-narrator (#2604) 2024-03-13 03:31:42 +00:00
dependabot[bot]
f5855a9f9a ⬆️ Bump the actions group with 1 update (#2605)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 13:56:57 +08:00
noneflow[bot]
a49b4bccc6 📝 Update changelog 2024-03-11 05:27:16 +00:00
NanakaNeko
b434da29b1 🍻 publish plugin a2s查询 (#2602) 2024-03-11 05:26:16 +00:00
noneflow[bot]
514b3a5afe 📝 Update changelog 2024-03-11 02:35:56 +00:00
student_2333
0d30f81ddb ✏️ Plugin: 移除不维护的插件 eitherchoice (#2599) 2024-03-11 10:34:44 +08:00
noneflow[bot]
9a86c00f62 📝 Update changelog 2024-03-09 05:54:47 +00:00
noneflow[bot]
7648138902 🍻 publish plugin 赛博钓鱼 (#2596)
Co-authored-by: C14H22O <C14H22O@users.noreply.github.com>
2024-03-09 13:53:45 +08:00
noneflow[bot]
2055f092f2 📝 Update changelog 2024-03-07 06:58:32 +00:00
uy/sun
9ff7f4baba 🧑‍💻 Develop: 添加 ruff RUF 规则 (#2598)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-03-07 14:57:26 +08:00
noneflow[bot]
92ba99c34c 📝 Update changelog 2024-03-05 05:42:03 +00:00
XTxiaoting14332
876cff4daf 🍻 publish plugin 人性化的ChatGLM (#2591) 2024-03-05 05:40:55 +00:00
noneflow[bot]
1ac6a612b0 📝 Update changelog 2024-03-04 09:12:55 +00:00
Redmomn
15ecad9f87 🍻 publish plugin nonebot-plugin-vits-tts (#2594) 2024-03-04 09:11:47 +00:00
noneflow[bot]
587d3f7c7e 📝 Update changelog 2024-03-02 09:49:10 +00:00
Ju4tCode
10e4ea6743 📝 Docs: 添加百度搜索资源验证 (#2590)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-03-02 17:48:04 +08:00
noneflow[bot]
d1601bf2fe 🔖 Release 2.2.1 2024-02-24 04:35:38 +00:00
Ju4tCode
2994945c64 🔖 bump version 2.2.1 (#2589) 2024-02-24 12:25:17 +08:00
noneflow[bot]
c9e3cad738 📝 Update changelog 2024-02-23 08:03:12 +00:00
XTxiaoting14332
7c36964812 ✏️ Plugin: 修改 phigros 相关内容 (#2578) 2024-02-23 16:02:00 +08:00
noneflow[bot]
0e02d13c67 📝 Update changelog 2024-02-23 07:55:58 +00:00
KomoriDev
f7aeea2f3d 🍻 publish plugin 运行状态 (#2586) 2024-02-23 07:54:48 +00:00
noneflow[bot]
b2da7d4cae 📝 Update changelog 2024-02-23 02:33:43 +00:00
SAFEluren
239f9769c2 🍻 publish plugin nonebot-plugin-bf1marneserverlist (#2583) 2024-02-23 02:32:43 +00:00
noneflow[bot]
f5947518b1 📝 Update changelog 2024-02-22 06:01:08 +00:00
MingxuanGame
1a4afa406b 📝 Docs: 更新 Session Expire Timeout​ 文档 (#2585) 2024-02-22 13:59:57 +08:00
noneflow[bot]
412b879f39 📝 Update changelog 2024-02-17 15:18:51 +00:00
MingxuanGame
a830346545 Feature: 优化 pydantic 兼容函数 model_dumptype_validate_json (#2579)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-17 23:18:00 +08:00
noneflow[bot]
fbb8320a25 📝 Update changelog 2024-02-17 04:07:01 +00:00
Cypas
14f4a0f701 🍻 publish plugin splatoon3游戏nso查询 (#2575) 2024-02-17 04:06:04 +00:00
noneflow[bot]
e82e2817d5 📝 Update changelog 2024-02-16 13:17:36 +00:00
Ju4tCode
ffbd1f9aeb 🐛 Fix: 修改遗漏的过时 Pydantic 方法 (#2577) 2024-02-16 21:16:46 +08:00
noneflow[bot]
5ab418a3cf 📝 Update changelog 2024-02-14 03:14:08 +00:00
mrqx0195
a58e00b206 🍻 publish plugin Chikari_yinpa (#2571) 2024-02-14 03:13:14 +00:00
noneflow[bot]
a74682bbf6 📝 Update changelog 2024-02-12 09:54:54 +00:00
student_2333
11142253fb 🐛 Fix: Message.__contains__() 未考虑 bool(MessageSegment) 存在 False 情况导致的异常结果 (#2572)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-02-12 17:53:50 +08:00
noneflow[bot]
ef7782167f 📝 Update changelog 2024-02-10 09:53:22 +00:00
Ju4tCode
f4a2682e6c 📝 Docs: 添加适配器测试注意事项 (#2570) 2024-02-10 17:52:29 +08:00
noneflow[bot]
35cee22cf6 🔖 Release 2.2.0 2024-02-09 08:21:37 +00:00
Ju4tCode
fbb55228f2 🔖 bump version 2.2.0 (#2569) 2024-02-09 16:14:15 +08:00
noneflow[bot]
391ac00d81 📝 Update changelog 2024-02-09 06:49:39 +00:00
lengmianzz
277b744ca3 📝 Docs: 更新 Alconna 文档 (#2568)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-09 14:48:48 +08:00
noneflow[bot]
a89c67a50e 📝 Update changelog 2024-02-07 08:00:35 +00:00
Ju4tCode
26b30a7b22 📝 Docs: 添加产品赞助列表 (#2566) 2024-02-07 15:59:36 +08:00
pre-commit-ci[bot]
4dae23d3bb ⬆️ auto update by pre-commit hooks (#2565)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-02-06 12:48:23 +08:00
noneflow[bot]
07e6c3f977 📝 Update changelog 2024-02-05 06:01:56 +00:00
Ju4tCode
dace63d9d2 Feature: 添加插件 Pydantic 相关使用方法 (#2563) 2024-02-05 14:00:49 +08:00
dependabot[bot]
2ebf956599 ⬆️ Bump the actions group with 1 update (#2564)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-05 13:35:34 +08:00
noneflow[bot]
b20793c67a 📝 Update changelog 2024-02-04 05:40:22 +00:00
velor2012
47e9f59cc8 🍻 publish plugin 定时提醒 (#2557) 2024-02-04 05:39:12 +00:00
noneflow[bot]
e27cac7fef 📝 Update changelog 2024-02-04 02:16:43 +00:00
Johnny Hsieh
5bfda6e2bc ✏️ Plugin: 移除不再维护的几款插件 (#2561) 2024-02-04 10:15:27 +08:00
noneflow[bot]
ef2ab7df48 📝 Update changelog 2024-02-02 02:48:11 +00:00
bingqiu456
ac1d9147d2 🍻 publish plugin 黑名单插件 (#2553) 2024-02-02 02:47:02 +00:00
dependabot[bot]
f2350909d2 ⬆️ Bump the actions group with 1 update (#2560)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2024-02-01 13:59:22 +08:00
noneflow[bot]
f14ef93808 📝 Update changelog 2024-02-01 02:42:50 +00:00
nek0us
45bd4252bf 🍻 publish plugin ChatGPT 聊天 (#2555) 2024-02-01 02:41:43 +00:00
noneflow[bot]
6b4456bf0e 📝 Update changelog 2024-02-01 02:30:11 +00:00
StarHeart
c5e114dc7f 🐛 Docs: 修复表单标签状态更新 (#2558) 2024-02-01 10:29:03 +08:00
noneflow[bot]
30ceea4287 📝 Update changelog 2024-01-29 02:40:32 +00:00
lengmianzz
380f9ff013 🍻 publish plugin BA模拟抽卡 (#2549) 2024-01-29 02:39:21 +00:00
noneflow[bot]
19ac119714 📝 Update changelog 2024-01-27 09:40:31 +00:00
HuParry
236f70183c 🍻 publish plugin 随机发送图片 (#2547) 2024-01-27 09:39:24 +00:00
noneflow[bot]
117bc35653 📝 Update changelog 2024-01-27 02:56:19 +00:00
eya46
4fcaa8d3d6 🍻 publish plugin 哪吒监控插件 (#2551) 2024-01-27 02:55:17 +00:00
noneflow[bot]
536889d3df 📝 Update changelog 2024-01-26 03:14:04 +00:00
Ju4tCode
bbd13c04cc Feature: 兼容 Pydantic v2 (#2544)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-26 11:12:57 +08:00
noneflow[bot]
82e4ccb227 📝 Update changelog 2024-01-24 07:25:25 +00:00
StarHeart
626cfa474f 👷 CI: 更新 prettier 配置 (#2546)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-24 15:24:21 +08:00
noneflow[bot]
18e9a9afd3 📝 Update changelog 2024-01-21 11:49:59 +00:00
pre-commit-ci[bot]
41b7d5a3a0 🚨 auto fix by pre-commit hooks 2024-01-21 11:48:50 +00:00
eya46
16fcd4c639 🍻 publish plugin SakuraFrp (#2542) 2024-01-21 11:48:50 +00:00
noneflow[bot]
ef3641efa6 📝 Update changelog 2024-01-21 11:32:33 +00:00
boxie123
8d95a32672 🍻 publish plugin haruka_bot_red (#2540) 2024-01-21 11:31:24 +00:00
dependabot[bot]
3a3a718779 ⬆️ Bump the actions group with 2 updates (#2539)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-18 13:58:14 +08:00
noneflow[bot]
3d1955211a 📝 Update changelog 2024-01-17 08:48:23 +00:00
zhaomaoniu
8d87715d6f 🍻 publish plugin nonebot-plugin-gemini (#2526) 2024-01-17 08:47:26 +00:00
noneflow[bot]
3c535b8e99 📝 Update changelog 2024-01-17 08:40:30 +00:00
Ju4tCode
2c6affecea 🐛 Fix: websockets 驱动器连接关闭 code 获取错误 (#2537) 2024-01-17 16:39:35 +08:00
noneflow[bot]
c2d2169a9f 📝 Update changelog 2024-01-15 05:25:48 +00:00
Ju4tCode
1153c5ff17 Feature: 使用自定义配置加载替代 pydantic-settings (#2521)
Co-authored-by: uy/sun <hmy0119@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-15 13:24:55 +08:00
noneflow[bot]
6c532f5926 📝 Update changelog 2024-01-15 03:52:20 +00:00
Perseus037
7083394bc9 🍻 publish plugin 最终台词 (#2522) 2024-01-15 03:51:29 +00:00
noneflow[bot]
7c58410868 📝 Update changelog 2024-01-15 02:50:11 +00:00
pk5ls20
00c3e3b713 🍻 publish plugin nonebot-plugin-nekoimage (#2532) 2024-01-15 02:49:14 +00:00
noneflow[bot]
9d4a72766d 📝 Update changelog 2024-01-15 02:38:31 +00:00
Alpaca4610
82e16b4438 🍻 publish plugin 谷歌Bard聊天 (#2528) 2024-01-15 02:37:37 +00:00
noneflow[bot]
56353f2d0a 📝 Update changelog 2024-01-15 02:31:11 +00:00
tianyisama
4d0eb94a6f 🍻 publish plugin nonebot-plugin-mypower (#2530) 2024-01-15 02:30:14 +00:00
noneflow[bot]
e1a494ecbd 📝 Update changelog 2024-01-14 06:50:02 +00:00
Ju4tCode
6b1e34da63 🐛 Fix: 修复 echo 发送空消息 (#2525) 2024-01-14 14:49:05 +08:00
noneflow[bot]
ccf9597102 📝 Update changelog 2024-01-11 03:53:02 +00:00
Bryan不可思议
5a6f4b9e1c Feature: 带参数的 RegexStr() (#2499) 2024-01-11 11:52:07 +08:00
noneflow[bot]
9b09b42f97 📝 Update changelog 2024-01-10 14:48:29 +00:00
Ju4tCode
854345e16f 📝 Docs: 添加 CITATION 文件 (#2520) 2024-01-10 22:47:27 +08:00
noneflow[bot]
e0ee865b87 📝 Update changelog 2024-01-10 02:34:49 +00:00
Pasumao
dad0c01335 🍻 publish plugin 文心一言4适配 (#2515) 2024-01-10 02:33:56 +00:00
noneflow[bot]
79ef5af19b 📝 Update changelog 2024-01-10 02:17:24 +00:00
lgc2333
b349959f93 🍻 publish plugin 最佳平替 (#2518) 2024-01-10 02:16:11 +00:00
noneflow[bot]
2e7f9612af 📝 Update changelog 2024-01-08 03:11:55 +00:00
wlm3201
8ff2303b22 🍻 publish plugin 随机MC图 (#2511) 2024-01-08 03:10:43 +00:00
noneflow[bot]
b681fdd6d6 📝 Update changelog 2024-01-04 03:12:42 +00:00
Johnny Hsieh
b65b3b438c 🐛 Fix: MessageTemplate 禁止访问私有属性 (#2509)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-04 11:11:37 +08:00
pre-commit-ci[bot]
580d6bab36 ⬆️ auto update by pre-commit hooks (#2510)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-02 11:01:26 +08:00
noneflow[bot]
90349ddd7d 📝 Update changelog 2023-12-29 08:46:49 +00:00
Perseus037
dcac421bc0 🍻 publish plugin nonebot_plugin_nikke (#2507) 2023-12-29 08:45:51 +00:00
noneflow[bot]
b4f643577f 📝 Update changelog 2023-12-29 08:25:46 +00:00
phquathi
411e7168b3 🍻 publish plugin nonebot-plugin-imagemaster (#2503) 2023-12-29 08:24:39 +00:00
noneflow[bot]
fef072a62a 📝 Update changelog 2023-12-28 08:19:24 +00:00
RF-Tar-Railt
f529e9cb23 🍻 publish plugin Waiter 插件 (#2505) 2023-12-28 08:18:34 +00:00
noneflow[bot]
cfa3bfd88c 📝 Update changelog 2023-12-28 06:51:55 +00:00
student_2333
321c99f12b ✏️ Plugin: 恢复删除的插件 nonebot-plugin-eitherchoice (#2502) 2023-12-28 14:50:54 +08:00
noneflow[bot]
73ad4992ee 📝 Update changelog 2023-12-27 02:09:54 +00:00
phquathi
ddbf37c1be 🍻 publish plugin AntiMonkey (#2500) 2023-12-27 02:08:54 +00:00
noneflow[bot]
b9392371c7 🔖 Release 2.1.3 2023-12-25 03:57:43 +00:00
Ju4tCode
d3c26a1548 🔖 bump version 2.1.3 (#2498) 2023-12-25 11:51:10 +08:00
noneflow[bot]
31c2a61cce 📝 Update changelog 2023-12-23 05:56:49 +00:00
XTxiaoting14332
f84ba9768b 🍻 publish plugin Phigros查分器(Adapter-qq) (#2496) 2023-12-23 05:55:59 +00:00
dependabot[bot]
1faa935527 ⬆️ Bump aiohttp from 3.9.0b1 to 3.9.0 (#2495)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-21 11:31:38 +08:00
noneflow[bot]
5f940ff309 📝 Update changelog 2023-12-18 07:30:21 +00:00
Cypas_Nya
4c4c0ea0ba ✏️ Plugin: 更新 splatoon3 插件地址 (#2494) 2023-12-18 15:29:23 +08:00
noneflow[bot]
787b40a99e 📝 Update changelog 2023-12-16 06:47:19 +00:00
lgc2333
fd6a0ae747 🍻 publish plugin Riffusion (#2492) 2023-12-16 06:46:29 +00:00
noneflow[bot]
298a32c096 📝 Update changelog 2023-12-15 02:53:22 +00:00
student_2333
aecff5ffd6 ✏️ Plugin: 删除不维护的插件 (#2491) 2023-12-15 10:52:30 +08:00
noneflow[bot]
c1a6b7b787 📝 Update changelog 2023-12-12 03:06:41 +00:00
Perseus037
0903f19f9c 🍻 publish plugin nonebot_plugin_longtu (#2489) 2023-12-12 03:05:45 +00:00
noneflow[bot]
51aa23817a 📝 Update changelog 2023-12-10 10:13:05 +00:00
Bryan不可思议
8f3f385cb6 🐛 Fix: 新增 Lifespan._on_ready() 供适配器使用 (#2483)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-12-10 18:12:10 +08:00
noneflow[bot]
915274081d 📝 Update changelog 2023-12-09 03:23:48 +00:00
lgc2333
a388c52b3f 🍻 publish plugin CNRail (#2487) 2023-12-09 03:22:56 +00:00
noneflow[bot]
b4d3cd4d4d 📝 Update changelog 2023-12-08 07:04:59 +00:00
Ju4tCode
50c03b0675 🚨 make pyright happy (#2486) 2023-12-08 15:03:59 +08:00
dependabot[bot]
fa3bb96417 ⬆️ Bump the actions group (#2484)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-08 13:26:19 +08:00
dependabot[bot]
09bde57835 ⬆️ Bump the actions group with 1 update (#2485)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-08 13:22:29 +08:00
noneflow[bot]
76ac2a8843 📝 Update changelog 2023-12-05 14:12:53 +00:00
Perseus037
f6ec6962ab 🍻 publish plugin ba塔罗牌,运势与魔法占卜! (#2480) 2023-12-05 14:11:43 +00:00
pre-commit-ci[bot]
28ad6829cd ⬆️ auto update by pre-commit hooks (#2482)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-12-05 14:02:02 +08:00
noneflow[bot]
7f4b002a87 📝 Update changelog 2023-12-03 11:37:26 +00:00
iyume
7e073b6ff4 🍻 publish plugin 群聊 NSFW 图片检测 (#2476) 2023-12-03 11:36:22 +00:00
noneflow[bot]
fa3781efe5 📝 Update changelog 2023-11-30 08:10:45 +00:00
StarHeart
bec74d85cd 📝 Docs: 商店详情卡片添加宽度限制与文本省略 (#2473) 2023-11-30 16:09:29 +08:00
noneflow[bot]
abc3829c64 📝 Update changelog 2023-11-30 05:53:17 +00:00
Jigsaw
18f5d6eab9 ✏️ Plugin: 移除不再维护的插件 (#2474) 2023-11-30 13:52:17 +08:00
noneflow[bot]
00f3e30930 📝 Update changelog 2023-11-29 12:42:03 +00:00
worldmozara
97cd21d004 ✏️ Plugin: 移除不再维护的插件 (#2472) 2023-11-29 20:40:55 +08:00
noneflow[bot]
09b4d44f23 📝 Update changelog 2023-11-29 07:52:04 +00:00
MeetWq
3536bf56bd ✏️ Plugin: 移除不再维护的插件 (#2471) 2023-11-29 15:51:01 +08:00
noneflow[bot]
f8eaf5def0 📝 Update changelog 2023-11-24 02:24:57 +00:00
mobyw
6077f85e52 🍻 publish plugin sm.ms图床 (#2469) 2023-11-24 02:23:50 +00:00
noneflow[bot]
e2976a3859 📝 Update changelog 2023-11-24 02:11:57 +00:00
Ju4tCode
1e25fde22e Update assets/plugins.json 2023-11-24 02:10:51 +00:00
mnixry
55d88b7dae 🍻 publish plugin 文件托管支持 (#2467) 2023-11-24 02:10:51 +00:00
noneflow[bot]
de30f8917f 📝 Update changelog 2023-11-23 10:52:02 +00:00
StarHeartHunt
52653fa005 🍻 publish plugin 短链接服务支持 (#2465) 2023-11-23 10:50:57 +00:00
noneflow[bot]
4628358add 📝 Update changelog 2023-11-22 08:33:21 +00:00
StarHeart
117b08a73e 📝 Docs: 修复商店发布 上一步 按钮显示问题 (#2464) 2023-11-22 16:32:14 +08:00
noneflow[bot]
700888a8e0 📝 Update changelog 2023-11-22 06:05:31 +00:00
StarHeart
ef882927f3 📝 Docs: 添加商店表单支持 (#2460)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-11-22 14:04:22 +08:00
noneflow[bot]
af9327de14 📝 Update changelog 2023-11-22 02:48:30 +00:00
he0119
2881d42bf5 🍻 publish plugin 用户 (#2462) 2023-11-22 02:47:21 +00:00
noneflow[bot]
dc3a49fe57 📝 Update changelog 2023-11-20 02:22:18 +00:00
student_2333
addabd6396 📝 Docs: 修复事件后处理函数类型 docstring 错误 (#2459) 2023-11-20 10:21:10 +08:00
noneflow[bot]
3341c641cc 📝 Update changelog 2023-11-12 04:18:10 +00:00
bingyue
363413e1e6 📝 Docs: 修改 QQ 频道为 QQ (#2457)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-11-12 12:17:05 +08:00
noneflow[bot]
b675d27a30 📝 Update changelog 2023-11-10 12:05:29 +00:00
pre-commit-ci[bot]
796023408a 🚨 auto fix by pre-commit hooks 2023-11-10 12:03:46 +00:00
惜月
983a8512b2 📝 更新README 2023-11-10 12:03:46 +00:00
CMHopeSunshine
6593102632 🍻 publish adapter DoDo (#2455) 2023-11-10 12:03:46 +00:00
noneflow[bot]
65fff13150 📝 Update changelog 2023-11-09 06:14:11 +00:00
Alpaca4610
edd1a140d7 🍻 publish plugin DALL-E 3绘图 (#2451) 2023-11-09 06:12:43 +00:00
noneflow[bot]
18070baad4 📝 Update changelog 2023-11-08 02:47:58 +00:00
tiehu
acf729f6e7 🍻 publish plugin 局域网唤醒 (#2448) 2023-11-08 02:46:59 +00:00
noneflow[bot]
6dbc8eac03 📝 Update changelog 2023-11-08 02:31:28 +00:00
StarHeart
35944bcbdc 👷 CI: 测试矩阵添加 Python 3.12 (#2441) 2023-11-08 10:30:00 +08:00
noneflow[bot]
3f919f91c1 📝 Update changelog 2023-11-07 06:40:21 +00:00
Tarrailt
443a20d83d 📝 Docs: 更新最佳实践的 Alconna 部分 (#2443)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: StarHeartHunt <starheart233@gmail.com>
2023-11-07 14:39:05 +08:00
noneflow[bot]
2fca26eaae 📝 Update changelog 2023-11-07 06:29:54 +00:00
jiangyuxiaoxiao
ebc8141971 🍻 publish plugin nonebot-plugin-bertvits2 (#2445) 2023-11-07 06:28:15 +00:00
pre-commit-ci[bot]
5d6bcc9b9b ⬆️ auto update by pre-commit hooks (#2447)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-07 14:14:49 +08:00
noneflow[bot]
55fca332ba 📝 Update changelog 2023-11-05 09:08:57 +00:00
MelodyYuuka
6b65c5fe69 🍻 publish plugin Nonebot2 Any 多平台服务 (#2440) 2023-11-05 09:07:36 +00:00
noneflow[bot]
3e4dbe1015 📝 Update changelog 2023-11-05 03:23:34 +00:00
zhaomaoniu
20197e64b2 🍻 publish bot Sakiko (#2438) 2023-11-05 03:22:31 +00:00
noneflow[bot]
94eecaf448 🔖 Release 2.1.2 2023-10-31 10:05:03 +00:00
Ju4tCode
fa91e0e79b 🔖 bump version 2.1.2 (#2437) 2023-10-31 17:55:31 +08:00
noneflow[bot]
891adc38fc 📝 Update changelog 2023-10-31 09:27:26 +00:00
Ju4tCode
af6cc63db2 ⬆️ upgrade pytest-asyncio and fix test (#2436) 2023-10-31 17:26:06 +08:00
noneflow[bot]
af73e14b64 📝 Update changelog 2023-10-27 15:11:11 +00:00
Ju4tCode
9305fe7875 🐛 修复依赖注入对 Literal 检查报错 (#2433) 2023-10-27 23:09:32 +08:00
noneflow[bot]
613fde4639 📝 Update changelog 2023-10-25 02:57:15 +00:00
T0nyX1ang
61db2c898b 🍻 publish plugin 定时广播插件 (#2431) 2023-10-25 02:55:43 +00:00
dependabot[bot]
acf313c420 ⬆️ Bump the actions group (#2430)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-24 13:47:28 +08:00
noneflow[bot]
15fca08641 📝 Update changelog 2023-10-22 06:29:50 +00:00
StarHeart
e2cbe3c1f8 📝 Docs: 修复 Alconna 文档 typo (#2429) 2023-10-22 14:28:29 +08:00
noneflow[bot]
d3883ea3ae 📝 Update changelog 2023-10-21 12:25:27 +00:00
SherkeyXD
8b2c4b3e60 🍻 publish plugin 选择困难症 (#2427) 2023-10-21 12:23:54 +00:00
noneflow[bot]
65d0d00591 📝 Update changelog 2023-10-18 07:56:54 +00:00
RainEggplant
97a57c2f6e Feature: 添加多消息段命令解析支持 (#2419)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-10-18 15:55:09 +08:00
noneflow[bot]
6559b2ff27 📝 Update changelog 2023-10-17 10:51:13 +00:00
StarHeartHunt
4c1deeb899 🍻 publish bot 芙芙 (#2425) 2023-10-17 10:49:41 +00:00
noneflow[bot]
a65ea6805d 📝 Update changelog 2023-10-17 02:13:27 +00:00
hanasa2023
effe65b034 🍻 publish plugin nonebot-plugin-getbapics (#2420) 2023-10-17 02:11:40 +00:00
noneflow[bot]
37296cf048 📝 Update changelog 2023-10-16 14:31:07 +00:00
StarHeart
1b597c1301 📝 add baidu statistic script (#2424) 2023-10-16 09:29:48 -05:00
noneflow[bot]
c2454d0689 📝 Update changelog 2023-10-15 07:33:10 +00:00
Yuri-YuzuChaN
9b60b44554 🍻 publish plugin nonebot-plugin-maimaidx (#2421) 2023-10-15 07:31:48 +00:00
noneflow[bot]
75516bdafb 📝 Update changelog 2023-10-14 12:33:47 +00:00
MerCuJerry
12f5a487c1 🍻 publish plugin BlueArchive Title Generator (#2417) 2023-10-14 12:32:20 +00:00
noneflow[bot]
8d128d5035 📝 Update changelog 2023-10-13 06:13:24 +00:00
Agnes4m
cfa7117e64 🍻 publish plugin VRChat查询 (#2410) 2023-10-13 06:12:10 +00:00
noneflow[bot]
7880bf0dc1 📝 Update changelog 2023-10-13 05:50:53 +00:00
influ3nza
0054041829 🍻 publish plugin nonebot_plugin_fgoavatarguess (#2415) 2023-10-13 05:49:26 +00:00
noneflow[bot]
99931f785a 📝 Update changelog 2023-10-10 12:35:55 +00:00
jiangyuxiaoxiao
5e121269f0 🍻 publish bot 妃爱 (#2412) 2023-10-10 12:34:36 +00:00
noneflow[bot]
38ced0243f 📝 Update changelog 2023-10-10 06:28:40 +00:00
EuDs63
869db878e1 🍻 publish plugin nonebot-plugin-yesman​ (#2408) 2023-10-10 06:27:23 +00:00
noneflow[bot]
e6c6e355e1 📝 Update changelog 2023-10-09 02:19:46 +00:00
ninthseason
6221b9a5fd 🍻 publish plugin morep-finder (#2406) 2023-10-09 02:18:19 +00:00
noneflow[bot]
5f2c9c935b 📝 Update changelog 2023-10-08 10:11:53 +00:00
Ju4tCode
76559b253c Update assets/adapters.json 2023-10-08 10:10:28 +00:00
pre-commit-ci[bot]
3c54655c39 🚨 auto fix by pre-commit hooks 2023-10-08 10:10:28 +00:00
Ju4tCode
7a851ac199 Apply suggestions from code review 2023-10-08 10:10:28 +00:00
pre-commit-ci[bot]
b2ba5dfcd1 🚨 auto fix by pre-commit hooks 2023-10-08 10:10:28 +00:00
Tarrailt
4a4fae8f8c Update README.md 2023-10-08 10:10:28 +00:00
RF-Tar-Railt
de894ce7b2 🍻 publish adapter Satori (#2404) 2023-10-08 10:10:28 +00:00
noneflow[bot]
09c4a955c9 📝 Update changelog 2023-10-07 07:31:56 +00:00
ninthseason
db1581a0a2 🍻 publish plugin op-finder (#2402) 2023-10-07 07:30:07 +00:00
noneflow[bot]
db9d7b3060 📝 Update changelog 2023-10-07 04:07:34 +00:00
Tarrailt
7e0c29472e 📝 Docs: 更新最佳实践 Alconna (#2401)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-07 12:06:07 +08:00
noneflow[bot]
d13492070d 📝 Update changelog 2023-10-06 10:04:18 +00:00
Ohdmire
695ede51ea 🍻 publish plugin nonebot-plugin-playercheck (#2399) 2023-10-06 10:02:52 +00:00
noneflow[bot]
168f382aa6 📝 Update changelog 2023-10-06 06:23:20 +00:00
nikissXI
5bd433318d ✏️ Plugin: 移除 nonebot-plugin-nya-music 插件 (#2398) 2023-10-06 14:21:51 +08:00
noneflow[bot]
d1cd2a793e 📝 Update changelog 2023-10-06 03:17:45 +00:00
nikissXI
5a4464f338 🍻 publish plugin talk with eop ai (#2396) 2023-10-06 03:16:15 +00:00
noneflow[bot]
561d25320b 📝 Update changelog 2023-10-04 10:21:51 +00:00
Komorebi
b225c2dd3b 📝 Docs: 修改商店发布的跳转链接 (#2387)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-10-04 18:20:06 +08:00
noneflow[bot]
2a2e357513 📝 Update changelog 2023-10-04 10:13:30 +00:00
zhuhiki
28bfe1ecb8 🍻 publish plugin 算法比赛查询和今日比赛自动提醒 (#2394) 2023-10-04 10:12:01 +00:00
pre-commit-ci[bot]
cc12f0af7e ⬆️ auto update by pre-commit hooks (#2393)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-03 21:49:16 +08:00
noneflow[bot]
da831a1b08 📝 Update changelog 2023-10-03 11:59:10 +00:00
MelodyKnit
eb97be17dd 🍻 publish plugin 屏蔽词插件 (#2386) 2023-10-03 11:57:53 +00:00
noneflow[bot]
2dd1c9b2ad 📝 Update changelog 2023-10-03 11:38:02 +00:00
MingxuanGame
41191db863 🐛 Docs: 修复文档主页 Features 不居中 (#2390) 2023-10-03 19:36:40 +08:00
noneflow[bot]
ee20204b22 📝 Update changelog 2023-10-03 10:53:54 +00:00
Dobiichi-Origami
f1032804bb 🍻 publish plugin Nonebot Agent (#2388) 2023-10-03 10:52:35 +00:00
noneflow[bot]
ba1540d75b 📝 Update changelog 2023-10-02 15:04:27 +00:00
uy/sun
f5c87f80e1 🧑‍💻 CI: 调整商店数据存放位置与内容 (#2385) 2023-10-02 23:03:05 +08:00
noneflow[bot]
d2d7603ff5 📝 Update changelog 2023-10-02 06:44:11 +00:00
KomoriDev
56013dca48 🍻 publish plugin 聚能环 (#2383) 2023-10-02 06:42:55 +00:00
noneflow[bot]
d33ed4a69f 📝 Update changelog 2023-10-02 06:38:57 +00:00
Ju4tCode
ed753b5564 ✏️ Adapter: 修改频道适配器为 QQ 适配器 (#2382)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-02 14:37:28 +08:00
Ju4tCode
7e65552d01 👷 fix doc package publish ci 2023-10-01 07:31:27 +00:00
Ju4tCode
f77dc523e6 👷 CI: 修复 Release 权限错误 (#2381) 2023-10-01 15:15:32 +08:00
noneflow[bot]
0d84bf3592 🔖 Release 2.1.1 2023-10-01 06:38:37 +00:00
Ju4tCode
94dff49e60 🔖 bump version 2.1.1 (#2380) 2023-10-01 14:27:31 +08:00
noneflow[bot]
5d4cf7e421 📝 Update changelog 2023-10-01 03:45:36 +00:00
Ju4tCode
0e3e16e809 🚨 make pyright happy (#2379) 2023-10-01 11:44:00 +08:00
noneflow[bot]
183fc8defb 📝 Update changelog 2023-09-29 11:15:25 +00:00
Komorebi
8712e89322 ✏️ 修复商店搜索信息的错字 (#2377) 2023-09-29 19:13:33 +08:00
noneflow[bot]
e2b49f9b65 📝 Update changelog 2023-09-27 10:27:33 +00:00
Ju4tCode
7e11f3a3d6 📝 Docs: 修复侧边栏 TOC 在 SSR 模式下的渲染问题 (#2376) 2023-09-27 18:26:13 +08:00
noneflow[bot]
71bebb6ec7 📝 Update changelog 2023-09-27 08:01:54 +00:00
Ju4tCode
842c6ff4c6 📝 Docs: 升级新版 NonePress 主题 (#2375) 2023-09-27 16:00:26 +08:00
noneflow[bot]
7754f6da1d 📝 Update changelog 2023-09-25 03:04:05 +00:00
Ailitonia
60e0752f1a 🐛 Fix: bot.call_api 在被 called api hook mock 后应该忽略 exception (#2374)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-09-25 11:02:50 +08:00
noneflow[bot]
ede1a20c53 📝 Update changelog 2023-09-23 09:21:01 +00:00
student_2333
04289fd50f ✏️ Plugin: 修改 Sekai Stickers 插件信息 (#2372) 2023-09-23 17:19:38 +08:00
noneflow[bot]
ba3efa9e7c 📝 Update changelog 2023-09-22 02:55:04 +00:00
StarHeart
c5a66a6ed0 📝 Docs: 增加赞助者显示 (#2371)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-09-22 10:53:33 +08:00
noneflow[bot]
8a23b1554a 📝 Update changelog 2023-09-22 02:39:17 +00:00
lgc2333
d73f226cbd 🍻 publish plugin 大电老师活字印刷 (#2369) 2023-09-22 02:38:08 +00:00
noneflow[bot]
fd9ba678ec 📝 Update changelog 2023-09-20 05:54:15 +00:00
Q1351998764
d29ba62ff9 🍻 publish plugin nonebot-plugin-video-api (#2366) 2023-09-20 05:52:59 +00:00
noneflow[bot]
00c97fd18f 📝 Update changelog 2023-09-13 16:22:19 +00:00
uy/sun
9531c3fa74 👷 CI: 使用更现代的功能 (#2362) 2023-09-14 00:21:06 +08:00
noneflow[bot]
94293122e8 📝 Update changelog 2023-09-13 16:16:15 +00:00
Bryan不可思议
7aaa66c8ba Feature: 优先使用 Annotated 的最后一个子依赖 (#2360)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-09-14 00:14:45 +08:00
noneflow[bot]
0030bf725e 📝 Update changelog 2023-09-13 05:57:07 +00:00
Ju4tCode
22b6062900 Docs: 添加 wwads (#2361) 2023-09-13 13:55:48 +08:00
noneflow[bot]
005968ab70 📝 Update changelog 2023-09-12 07:14:46 +00:00
Akirami
dc6c194701 Feature: 优化检查事件响应器的日志 (#2355)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-12 15:13:35 +08:00
noneflow[bot]
9b8772b590 📝 Update changelog 2023-09-12 06:32:51 +00:00
Akirami
ae8ba9f55d 📝 Docs: 更新 get_asgi 函数的文档字符串 (#2359) 2023-09-12 14:31:41 +08:00
noneflow[bot]
f4a7ce2c09 📝 Update changelog 2023-09-11 05:03:01 +00:00
TeenStudyFlow
c84723668f 🍻 publish plugin 青年大学习提交 (#2356) 2023-09-11 05:01:50 +00:00
dependabot[bot]
bd3ed4207a ⬆️ Bump tibdex/github-app-token from 1 to 2 (#2358)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-11 12:52:59 +08:00
noneflow[bot]
1e8c2cfc9f 🔖 Release 2.1.0 2023-09-10 03:45:49 +00:00
Ju4tCode
5ce0238ace 🔖 bump version 2.1.0 (#2354) 2023-09-10 11:34:15 +08:00
noneflow[bot]
4e6b52b85c 📝 Update changelog 2023-09-09 17:22:00 +00:00
幼稚园园长
05fe7bb715 ✏️ Plugin: 删除插件 nonebot-plugin-heisi (#2353) 2023-09-10 01:20:48 +08:00
noneflow[bot]
c555e2fac6 📝 Update changelog 2023-09-09 13:00:23 +00:00
Tarrailt
fd126ae154 Feature: 为 Matcher.HANDLER_PARAM_TYPES 补增类型 (#2352)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-09-09 20:58:50 +08:00
noneflow[bot]
6c7b6a9575 📝 Update changelog 2023-09-09 05:47:23 +00:00
Ju4tCode
c4716e3e17 Feature: 为事件响应器添加更多源码信息 (#2351) 2023-09-09 13:46:09 +08:00
noneflow[bot]
3601a33f20 📝 Update changelog 2023-09-09 03:54:56 +00:00
Tarrailt
451023518b 📝 Docs: 更新最佳实践部分的 Alconna 章节 (#2349)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-09 11:53:06 +08:00
noneflow[bot]
2bd377a221 📝 Update changelog 2023-09-07 04:02:19 +00:00
Noctulus
66384adad4 🍻 publish plugin 文心一言 (#2341) 2023-09-07 04:00:51 +00:00
pre-commit-ci[bot]
ec1f7ba5bc ⬆️ auto update by pre-commit hooks (#2347)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-05 18:33:56 +08:00
dependabot[bot]
e7fc5b7b7e ⬆️ Bump actions/checkout from 3 to 4 (#2345)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-05 12:00:44 +08:00
noneflow[bot]
11477ea9d7 📝 Update changelog 2023-09-05 02:50:44 +00:00
StarHeart
6adf40f45d ⬆️ bump node version to 18 (#2344) 2023-09-05 10:49:09 +08:00
noneflow[bot]
1bdf169980 📝 Update changelog 2023-09-04 16:19:22 +00:00
Akirami
81cb356503 📝 Feature: 补充依赖注入部分情况下类型错误时的日志提示 (#2343) 2023-09-05 00:17:55 +08:00
noneflow[bot]
805778794c 📝 Update changelog 2023-09-04 03:58:08 +00:00
Rikka-desu
28cd8dd08a 🍻 publish plugin nonebot_plugin_group_whitelist (#2319) 2023-09-04 03:56:46 +00:00
noneflow[bot]
139b39984e 📝 Update changelog 2023-09-03 10:59:42 +00:00
GuGuMur
f9b5fece80 🍻 publish plugin 森空岛明日方舟签到器 (#2339) 2023-09-03 10:58:10 +00:00
noneflow[bot]
8076c6bc0a 📝 Update changelog 2023-09-03 05:40:53 +00:00
Ju4tCode
44b89d13f8 🚨 fix ruff error (#2338) 2023-09-03 13:39:26 +08:00
noneflow[bot]
fbc4225110 📝 Update changelog 2023-09-03 02:48:40 +00:00
Lfhsheng
f07f35ccc1 🍻 publish plugin 女装 ! (#2335) 2023-09-03 02:47:25 +00:00
noneflow[bot]
111dfbf164 📝 Update changelog 2023-09-02 11:38:52 +00:00
fR0Z863xF
c713c7723b 🍻 publish plugin helper_plus (#2322) 2023-09-02 11:37:35 +00:00
noneflow[bot]
4fa2af41b0 📝 Update changelog 2023-09-02 03:47:51 +00:00
xiaoWangSec
39c09d22d1 🍻 publish plugin nonebot-plugin-souti (#2333) 2023-09-02 03:46:33 +00:00
noneflow[bot]
4819b21f52 📝 Update changelog 2023-09-02 02:45:09 +00:00
uy/sun
6ef6721527 👷 插件测试使用最新的稳定版 Python 版本 (#2336) 2023-09-02 10:43:48 +08:00
noneflow[bot]
14cb447874 📝 Update changelog 2023-08-31 09:34:31 +00:00
ZM25XC
1b2b89074d ✏️ Plugin: 删除不再维护的插件 (#2330)
Co-authored-by: ZM25XC <xingling25@qq.com>
2023-08-31 17:32:52 +08:00
noneflow[bot]
75c5678782 📝 Update changelog 2023-08-30 15:50:29 +00:00
RF-Tar-Railt
45ec5cdfb4 🍻 publish plugin Alconna 帮助工具 (#2325) 2023-08-30 15:49:08 +00:00
noneflow[bot]
f6dd98825b 📝 Update changelog 2023-08-29 10:46:36 +00:00
Ju4tCode
f59271bd47 Feature: 支持子依赖定义 Pydantic 类型校验 (#2310) 2023-08-29 18:45:12 +08:00
noneflow[bot]
79f833b946 📝 Update changelog 2023-08-29 07:04:44 +00:00
惜月
9ad562bbfd 📝 Docs: 添加 Discord 适配器描述,补充 Villa 适配器协议链接 (#2316)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-29 15:03:21 +08:00
noneflow[bot]
267b49247d 📝 Update changelog 2023-08-29 05:53:43 +00:00
Ju4tCode
dbda4150fb Update website/static/adapters.json 2023-08-29 05:52:08 +00:00
CMHopeSunshine
a4e17f0c49 🍻 publish adapter Discord (#2314) 2023-08-29 05:52:08 +00:00
noneflow[bot]
8d8d1169d1 📝 Update changelog 2023-08-29 02:26:38 +00:00
Cvandia
7bc9e61985 🍻 publish plugin 消息伪造 (#2311) 2023-08-29 02:24:53 +00:00
Tarrailt
35cc6011b5 📝 Docs: 添加 Red 适配器描述 (#2313)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-29 10:23:17 +08:00
noneflow[bot]
086af8fd22 📝 Update changelog 2023-08-28 03:49:31 +00:00
tomorinao-www
a60d1520e6 🍻 publish plugin 二维码 (#2301) 2023-08-28 03:48:12 +00:00
noneflow[bot]
30c22ba25a 📝 Update changelog 2023-08-28 02:30:21 +00:00
nikissXI
41fbaec42c ✏️ Plugin: 删除插件 poe ai (#2308) 2023-08-28 10:29:04 +08:00
noneflow[bot]
562ec79e3b 📝 Update changelog 2023-08-27 15:11:41 +00:00
XTxiaoting14332
f620bd8eb2 🍻 publish plugin httpcat-状态猫😺 (#2305) 2023-08-27 15:10:11 +00:00
noneflow[bot]
13e40458d7 📝 Update changelog 2023-08-26 13:51:15 +00:00
Tarrailt
dc4ac6d8d7 📝 Docs: 更新最佳实践部分的 Alconna 章节 (#2303)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-26 21:49:28 +08:00
noneflow[bot]
41498bdf21 📝 Update changelog 2023-08-26 03:14:28 +00:00
Agnes4m
b8eae2eb82 🍻 publish plugin 雪豹闭嘴 (#2299) 2023-08-26 03:12:53 +00:00
noneflow[bot]
039c2b5509 📝 Update changelog 2023-08-26 03:05:06 +00:00
Ju4tCode
2e635370bb Feature: 细化 driver 职责类型 (#2296) 2023-08-26 11:03:24 +08:00
noneflow[bot]
807a86371d 📝 Update changelog 2023-08-24 02:36:22 +00:00
Ailitonia
c66953779c 🍻 publish plugin Nonebot Requests (#2293) 2023-08-24 02:34:50 +00:00
noneflow[bot]
117ef18f1c 📝 Update changelog 2023-08-23 06:36:32 +00:00
Well404
520dd03d77 ✏️ Plugin: 移除不再维护的插件,修改插件信息 (#2292) 2023-08-23 14:35:13 +08:00
noneflow[bot]
63f3ca2f6f 📝 Update changelog 2023-08-23 06:15:39 +00:00
eya46
2e8230e9f4 🐛 Fix: 设置 file request 默认 filename (#2284)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-08-23 14:14:07 +08:00
noneflow[bot]
4bfea99e54 📝 Update changelog 2023-08-23 02:55:04 +00:00
bingqiu456
f58eba7975 🍻 publish plugin 双向聊天插件 (#2264) 2023-08-23 02:53:48 +00:00
noneflow[bot]
53d1de4aec 📝 Update changelog 2023-08-19 12:46:43 +00:00
tomorinao-www
00f18c1bd8 🍻 publish plugin 识别动漫gal角色 (#2287) 2023-08-19 12:45:05 +00:00
noneflow[bot]
ba4fbb2ec3 📝 Update changelog 2023-08-19 05:43:52 +00:00
LuckySJTU
b3722bd637 🍻 publish plugin arxiv订阅 (#2281) 2023-08-19 05:42:43 +00:00
noneflow[bot]
012bd6d4fb 📝 Update changelog 2023-08-18 11:08:58 +00:00
Ju4tCode
9c4ca28d61 🚨 make linter happy (#2286) 2023-08-18 19:07:35 +08:00
noneflow[bot]
53bcae04ff 📝 Update changelog 2023-08-18 07:01:12 +00:00
This-is-XiaoDeng
754c54e268 🍻 publish plugin SUDO (#2276) 2023-08-18 06:59:44 +00:00
noneflow[bot]
f97fbc814e 📝 Update changelog 2023-08-18 05:50:08 +00:00
mobyw
b8856a0577 🍻 publish plugin 消息推送插件 (#2272) 2023-08-18 05:48:49 +00:00
noneflow[bot]
1c0e88907b 📝 Update changelog 2023-08-18 03:47:58 +00:00
Komorebi
31b6df5b39 📝 Docs: 修复 Alconna 中 CommandResult 描述错误 (#2282) 2023-08-18 11:46:39 +08:00
noneflow[bot]
bca9e4fd08 📝 Update changelog 2023-08-18 03:12:30 +00:00
Akirami
026ceb5028 📝 Docs: 修复子依赖部分代码行号错误 (#2279) 2023-08-18 11:11:23 +08:00
noneflow[bot]
47d5a647b7 📝 Update changelog 2023-08-18 03:02:49 +00:00
Akirami
37d7230949 📝 Docs: 补充 get_last_receive 示例 (#2278) 2023-08-18 11:01:23 +08:00
noneflow[bot]
be458b1d5e 📝 Update changelog 2023-08-17 05:34:53 +00:00
fu050409
f375a4a723 🍻 publish plugin 周易蓍草占卜 (#2267) 2023-08-17 05:33:24 +00:00
noneflow[bot]
3edce9a630 📝 Update changelog 2023-08-16 16:47:20 +00:00
Akirami
c525bda1e0 📝 Docs: 修复文档中错误的标点 (#2275) 2023-08-17 00:45:53 +08:00
noneflow[bot]
417f586e0d 📝 Update changelog 2023-08-16 02:19:02 +00:00
ACnoway
80d7e68835 🍻 publish bot OCNbot (#2260) 2023-08-16 02:17:44 +00:00
noneflow[bot]
a284e6df5c 📝 Update changelog 2023-08-14 13:11:21 +00:00
Akirami
7176a69f81 📝 Docs: 修复配置文档中 Nickname 属性的描述错误 (#2271) 2023-08-14 21:09:56 +08:00
noneflow[bot]
e3a1c02e8a 📝 Update changelog 2023-08-14 02:48:09 +00:00
fu050409
5e789ae4e0 🍻 publish plugin 欧若可骰娘 (#2265) 2023-08-14 02:46:51 +00:00
noneflow[bot]
bb684e20cb 📝 Update changelog 2023-08-13 03:20:03 +00:00
惜月
e11293e46b 📝 Docs: 适配器编写教程 (#2079)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-13 11:18:41 +08:00
noneflow[bot]
e0d74a1657 📝 Update changelog 2023-08-12 12:43:00 +00:00
A-kirami
fdd36565b1 🍻 publish bot 星见Kirami (#2262) 2023-08-12 12:41:43 +00:00
noneflow[bot]
28c53fe0d7 📝 Update changelog 2023-08-12 03:13:01 +00:00
Alpaca4610
26539bf2b1 🍻 publish plugin 科大讯飞星火大模型聊天 (#2257) 2023-08-12 03:11:53 +00:00
dependabot[bot]
347889c822 ⬆️ Bump actions/setup-node in /.github/actions/setup-node (#2259)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-11 20:32:11 +08:00
noneflow[bot]
91849b762c 📝 Update changelog 2023-08-11 12:23:01 +00:00
Ju4tCode
5d1319ddb9 🔧 add dependabot actions check (#2256) 2023-08-11 20:21:31 +08:00
noneflow[bot]
d98228926e 📝 Update changelog 2023-08-09 14:44:06 +00:00
Akirami
493997d998 📝 Docs: 更新贡献指南 (#2255) 2023-08-09 22:42:38 +08:00
noneflow[bot]
3098b7c153 📝 Update changelog 2023-08-09 07:59:41 +00:00
fuyang0811
2b0a050226 🍻 publish plugin 剑网三查询和推送 (#2253) 2023-08-09 07:58:33 +00:00
noneflow[bot]
1f3abc2bb9 📝 Update changelog 2023-08-08 13:24:50 +00:00
XTxiaoting14332
dd5541e658 🍻 publish plugin Muteme(我禁我自己) (#2251) 2023-08-08 13:23:28 +00:00
noneflow[bot]
a76bf27f60 📝 Update changelog 2023-08-08 02:21:17 +00:00
CN171-1
d70ce366cc 🍻 publish plugin MC版本更新检测 (#2246) 2023-08-08 02:19:18 +00:00
noneflow[bot]
f94b802c9b 📝 Update changelog 2023-08-07 12:47:46 +00:00
itsevin
17d7bd4e31 🍻 publish bot 不正经的妹妹 (#2248) 2023-08-07 12:46:37 +00:00
noneflow[bot]
76a40b60ff 📝 Update changelog 2023-08-07 12:40:29 +00:00
SuperGuGuGu
469efedab2 🍻 publish plugin KanonBot (#2243) 2023-08-07 12:39:09 +00:00
noneflow[bot]
383699a8b4 📝 Update changelog 2023-08-05 06:03:22 +00:00
eya46
1b9a07b923 🐛 Docs: 修复文档 Last updated author 错误 (#2241) 2023-08-05 14:01:53 +08:00
noneflow[bot]
15b76c266c 📝 Update changelog 2023-08-04 10:12:23 +00:00
zhaomaoniu
dfdecaddb1 🍻 publish adapter RedProtocol (#2238) 2023-08-04 10:11:11 +00:00
noneflow[bot]
5de9de903d 📝 Update changelog 2023-08-04 09:34:00 +00:00
Tarrailt
327f3fa441 📝 Docs: 更新最佳实践部分的 Alconna 章节 (#2237)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-04 17:32:43 +08:00
noneflow[bot]
08fde7580c 📝 Update changelog 2023-08-04 04:08:03 +00:00
Sydrr0
4ca91ecc7e 🍻 publish plugin CSGO饰品查询机器人 (#2224) 2023-08-04 04:06:38 +00:00
noneflow[bot]
885db90bc0 📝 Update changelog 2023-08-04 02:55:40 +00:00
nikissXI
c43d631eb5 🍻 publish plugin talk with poe ai (#2229) 2023-08-04 02:54:21 +00:00
noneflow[bot]
cfda433d14 📝 Update changelog 2023-08-03 02:34:48 +00:00
EmiyaGm
ea4a27bf89 🍻 publish plugin 命运方舟流浪商人卡牌刷新提示 (#2233) 2023-08-03 02:33:28 +00:00
noneflow[bot]
23944833f2 📝 Update changelog 2023-08-02 06:50:39 +00:00
Yan-Zero
4a40782be0 🍻 publish plugin Savepic (#2231) 2023-08-02 06:49:20 +00:00
noneflow[bot]
babafcaa87 📝 Update changelog 2023-08-01 13:45:03 +00:00
canxin121
9b164a6f5a 🍻 publish plugin 跨平台账户绑定 (#2226) 2023-08-01 13:43:42 +00:00
pre-commit-ci[bot]
4a07981972 ⬆️ auto update by pre-commit hooks (#2228)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-01 20:53:53 +08:00
noneflow[bot]
6bb2c46f8a 📝 Update changelog 2023-07-30 02:44:17 +00:00
qwqZYLqwq
2054655912 🍻 publish plugin Among US中的TOH模组职业介绍 (#2220) 2023-07-30 02:43:07 +00:00
noneflow[bot]
062af45367 📝 Update changelog 2023-07-27 11:25:39 +00:00
lgc2333
83c3ed5966 🍻 publish plugin NoneMeme (#2218) 2023-07-27 11:24:31 +00:00
noneflow[bot]
a2f2b818a7 📝 Update changelog 2023-07-25 06:53:29 +00:00
A-kirami
e7941efd9a 🍻 publish plugin The World (#2215) 2023-07-25 06:52:10 +00:00
noneflow[bot]
aa6faba9ae 📝 Update changelog 2023-07-25 02:34:07 +00:00
ZM25XC
8ca72f3c64 🍻 publish plugin Bot上下线邮件通知 (#2213) 2023-07-25 02:32:47 +00:00
noneflow[bot]
45e10e7139 📝 Update changelog 2023-07-24 15:05:00 +00:00
Cypas
73d1b19669 🍻 publish plugin bot断连通知 (#2211) 2023-07-24 15:03:43 +00:00
noneflow[bot]
ad4cf86a96 📝 Update changelog 2023-07-24 03:35:45 +00:00
Ju4tCode
48b3e3aaf3 add git attributes (#2210) 2023-07-24 11:34:34 +08:00
noneflow[bot]
f2b0b1752b 🔖 Release 2.0.1 2023-07-23 08:24:19 +00:00
Ju4tCode
81dcc65f99 🔖 bump version 2.0.1 (#2209) 2023-07-23 16:21:58 +08:00
noneflow[bot]
ac90df929e 📝 Update changelog 2023-07-21 14:38:47 +00:00
Tarrailt
555268239f 📝 Docs: 移动 Alconna 文档至最佳实践 (#2208)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-07-21 22:37:34 +08:00
noneflow[bot]
7009c8e8c1 📝 Update changelog 2023-07-21 12:53:17 +00:00
Jigsaw
2f3cc84f82 📝 Docs: 移除商店中不符合现规范的 tag (#2205) 2023-07-21 20:51:48 +08:00
noneflow[bot]
9444e01f0f 📝 Update changelog 2023-07-21 08:57:14 +00:00
NCBM
23b7a94b9a 🍻 publish plugin 方寸狭间 (#2206) 2023-07-21 08:56:06 +00:00
noneflow[bot]
70ece41b66 📝 Update changelog 2023-07-19 05:23:59 +00:00
Rockytkg
a5bb6e4220 🍻 publish plugin DALL-E绘图 (#2200) 2023-07-19 05:22:34 +00:00
noneflow[bot]
4fc99771c5 📝 Update changelog 2023-07-19 02:49:00 +00:00
canxin121
6601def5f7 🍻 publish plugin 指定戳一戳 (#2201) 2023-07-19 02:47:51 +00:00
noneflow[bot]
b2edea141e 📝 Update changelog 2023-07-19 02:15:58 +00:00
Ju4tCode
38886b9651 📝 Docs: 添加 scoped 插件配置指南 (#2198) 2023-07-19 10:14:36 +08:00
noneflow[bot]
1b225cbbca 📝 Update changelog 2023-07-18 05:36:22 +00:00
canxin121
b4f004c500 🍻 publish plugin templates_render (#2196) 2023-07-18 05:34:54 +00:00
noneflow[bot]
7a345714aa 📝 Update changelog 2023-07-17 12:43:28 +00:00
Ju4tCode
cb9fcae64c 🧑‍💻 Develop: 添加 Pyright 检查 (#2194) 2023-07-17 20:42:15 +08:00
noneflow[bot]
6ebeefed79 📝 Update changelog 2023-07-17 07:57:36 +00:00
Ju4tCode
6dc87a9455 use typing.override instead (#2193) 2023-07-17 15:56:27 +08:00
noneflow[bot]
7dd7c927bf 📝 Update changelog 2023-07-17 07:02:34 +00:00
Ju4tCode
e167865686 🐛 fix quart context error (#2192) 2023-07-17 15:01:21 +08:00
noneflow[bot]
29364679c4 📝 Update changelog 2023-07-16 13:43:30 +00:00
LambdaYH
ebbe8beec0 🍻 publish bot 米缸 (#2190) 2023-07-16 13:42:16 +00:00
noneflow[bot]
a04580e79e 📝 Update changelog 2023-07-14 16:28:15 +00:00
Well2333
bfe9e7e253 🍻 publish plugin MongoDB (#2188) 2023-07-14 16:26:50 +00:00
noneflow[bot]
720398198f 📝 Update changelog 2023-07-12 14:19:44 +00:00
Agnes4m
5ebf349886 🍻 publish plugin pjsk表情 (#2186) 2023-07-12 14:18:32 +00:00
noneflow[bot]
f8f5750c3b 📝 Update changelog 2023-07-11 15:16:11 +00:00
Q1351998764
8d9be61406 🍻 publish plugin nonebot-plugin-wenan (#2183) 2023-07-11 15:15:01 +00:00
noneflow[bot]
42ea650509 📝 Update changelog 2023-07-11 12:15:30 +00:00
mute23-code
a941a0f292 🍻 publish bot 林汐 (#2181) 2023-07-11 12:14:17 +00:00
noneflow[bot]
89f8745425 📝 Update changelog 2023-07-11 11:19:00 +00:00
Q1351998764
cc476528d8 🍻 publish plugin nonebot-plugin-picture-api (#2179) 2023-07-11 11:17:50 +00:00
noneflow[bot]
64f6c2dd4c 📝 Update changelog 2023-07-11 05:23:32 +00:00
MerCuJerry
81d9531b42 🍻 publish plugin Blocker (#2177) 2023-07-11 05:22:13 +00:00
noneflow[bot]
3512b0ab98 📝 Update changelog 2023-07-10 15:48:44 +00:00
Lptr-byte
ab3e916770 🍻 publish plugin nonebot-plugin-nobahpicture (#2175) 2023-07-10 15:47:23 +00:00
noneflow[bot]
21376a5bfa 📝 Update changelog 2023-07-08 07:35:00 +00:00
Akirami
5046b2a86e 📝 Docs: 钩子函数代码片段补充 (#2173) 2023-07-08 15:33:45 +08:00
noneflow[bot]
910c768910 📝 Update changelog 2023-07-08 07:27:52 +00:00
Akirami
5a526ddb40 📝 Docs: 格式化钩子函数中的代码片段 (#2172) 2023-07-08 15:26:30 +08:00
noneflow[bot]
4c5c97dca6 📝 Update changelog 2023-07-08 07:04:46 +00:00
Akirami
b3e0fb4830 ✏️ Plugin: 黑白名单添加标签 (#2170) 2023-07-08 15:03:35 +08:00
noneflow[bot]
258aa7d2d7 📝 Update changelog 2023-07-08 05:43:41 +00:00
A-kirami
5c72fd5ba7 🍻 publish plugin 过期事件过滤器 (#2168) 2023-07-08 05:42:28 +00:00
noneflow[bot]
26e4f23a67 📝 Update changelog 2023-07-08 03:41:39 +00:00
HuParry
28fc6c35f0 🍻 publish plugin 猫猫虫咖波图片发送 (#2166) 2023-07-08 03:40:25 +00:00
noneflow[bot]
3ef1d7d5d7 📝 Update changelog 2023-07-08 02:23:24 +00:00
Cypas
8474d8987e 🍻 publish plugin nonebot-plugin-splatoon3 (#2163) 2023-07-08 02:22:08 +00:00
noneflow[bot]
13ddfa1bdd 📝 Update changelog 2023-07-07 17:33:46 +00:00
coyude
ec8be10f26 🍻 publish plugin nonebot-plugin-cfassistant (#2162) 2023-07-07 17:32:16 +00:00
noneflow[bot]
511c521a68 📝 Update changelog 2023-07-07 13:28:22 +00:00
HuParry
0ef5940d0f 🍻 publish plugin 算法竞赛比赛查询 (#2158) 2023-07-07 13:26:51 +00:00
noneflow[bot]
eecc881cd8 📝 Update changelog 2023-07-07 03:29:19 +00:00
eya46
770141cf0a 📝 Docs: 补充 Message.only 文档 (#2155) 2023-07-07 11:28:08 +08:00
noneflow[bot]
b2b20ffc4a 📝 Update changelog 2023-07-06 07:29:30 +00:00
eya46
94a6067a4b Feature: 补充响应器组属性 (#2154)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-07-06 15:18:08 +08:00
noneflow[bot]
77220d9d1f 📝 Update changelog 2023-07-05 15:57:33 +00:00
djkcyl
647ad9ff8f 🍻 publish plugin nonebot-plugin-update (#2152) 2023-07-05 15:56:15 +00:00
pre-commit-ci[bot]
04182eefba ⬆️ auto update by pre-commit hooks (#2149)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-07-04 16:39:12 +08:00
noneflow[bot]
7b4aa08c54 📝 Update changelog 2023-07-04 02:47:02 +00:00
eya46
0033d7c686 🐛 Fix: 修复 dotenv 配置项为 None 将会跳过赋值 (#2143)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-07-04 10:45:55 +08:00
noneflow[bot]
c40b95f3e9 📝 Update changelog 2023-07-03 02:29:35 +00:00
Fireinsect
1fa44ca5c1 ✏️ Plugin: 修改 nonebot-plugin-ocgbot-v2 插件名称 (#2147) 2023-07-03 10:28:27 +08:00
noneflow[bot]
381f6633f6 📝 Update changelog 2023-07-03 02:18:44 +00:00
Agnes4m
d617508e32 🍻 publish plugin 远程同意好友 (#2145) 2023-07-03 02:17:36 +00:00
noneflow[bot]
8248e88686 📝 Update changelog 2023-07-02 14:28:26 +00:00
canxin
25649373a6 ✏️ Plugin: 更新 SparkGPT 插件描述 (#2144)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-07-02 22:27:13 +08:00
noneflow[bot]
3bee189598 📝 Update changelog 2023-07-01 07:41:39 +00:00
eya46
c1b1742b20 Feature: CommandGroup 支持命令别名添加前缀选项 (#2134)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-07-01 15:40:30 +08:00
noneflow[bot]
3e826cab72 📝 Update changelog 2023-07-01 05:55:19 +00:00
Fireinsect
4ef4bb0042 ✏️ Plugin: 修改 nonebot-plugin-ocgbot-v2 插件名称 (#2141) 2023-07-01 13:54:09 +08:00
Agnes4m
25ac653623 🍻 publish plugin 戳一戳事件 (#2138) 2023-06-30 12:45:13 +00:00
noneflow[bot]
b35bdfe6dc 📝 Update changelog 2023-06-30 12:44:37 +00:00
17TheWord
f06efca8cc 📝 Docs: 修复日志自定义文档 typo (#2140) 2023-06-30 20:43:26 +08:00
noneflow[bot]
a899523607 📝 Update changelog 2023-06-29 02:27:59 +00:00
lgc2333
2c162335cb 🍻 publish plugin EitherChoice (#2136) 2023-06-29 02:26:32 +00:00
noneflow[bot]
3a12984d4b 📝 Update changelog 2023-06-28 12:23:53 +00:00
MeetWq
7211f24a7d 🍻 publish plugin 用户信息 (#2132) 2023-06-28 12:22:35 +00:00
noneflow[bot]
649624ed80 📝 Update changelog 2023-06-27 08:26:35 +00:00
worldmozara
c03ff4e676 Feature: 添加用于动态继承支持适配器数据的方法 (#2127) 2023-06-27 16:25:27 +08:00
noneflow[bot]
0b5a18cb63 📝 Update changelog 2023-06-27 02:13:28 +00:00
wsdtl
518bf16082 🍻 publish bot web_bot (#2129) 2023-06-27 02:12:19 +00:00
noneflow[bot]
b625a5d19a 📝 Update changelog 2023-06-26 05:27:55 +00:00
kexue
acca22e179 ✏️ Plugin: 删除 nonebot-plugin-phlogo (#2128) 2023-06-26 13:26:26 +08:00
noneflow[bot]
a3009d45dc 📝 Update changelog 2023-06-25 15:02:27 +00:00
QBkira
fd3d1bb115 🍻 publish plugin Diablo4地狱狂潮boss提醒小助手 (#2121) 2023-06-25 15:01:22 +00:00
noneflow[bot]
7282da8b04 📝 Update changelog 2023-06-25 03:30:28 +00:00
eya46
7a3c7476fb 📝 Docs: 修复依赖注入文档 ArgStr 3.9+ 和 3.8+ 版本代码写反 (#2126)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-25 11:29:10 +08:00
noneflow[bot]
f1046cfb11 📝 Update changelog 2023-06-24 11:19:31 +00:00
eya46
8de25447b3 🐛 Fix: 修复 ArgParam 不支持 Annotated (#2124)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-24 19:18:24 +08:00
noneflow[bot]
3cdbf35dc6 📝 Update changelog 2023-06-24 09:06:04 +00:00
Agnes Digital
0228e255e1 ✏️ Plugin: 修改 nonebot-plugin-gw2 模块名 (#2123)
Co-authored-by: Agnes Digital <Z735803792@163.com>
2023-06-24 17:04:50 +08:00
noneflow[bot]
353d16ebfd 📝 Update changelog 2023-06-24 06:48:39 +00:00
Ju4tCode
3d5dd5969c 🚨 Develop: 添加 ruff linter (#2114) 2023-06-24 14:47:35 +08:00
noneflow[bot]
fe21cbfa1d 📝 Update changelog 2023-06-23 14:00:26 +00:00
fireinsect
c20f65636f 🍻 publish plugin nonbot-plugin-ocgbot-v2 (#2118) 2023-06-23 13:59:13 +00:00
noneflow[bot]
eade8face6 📝 Update changelog 2023-06-23 12:28:20 +00:00
worldmozara
ab75133e9d ✏️ Plugin: 更新 nonebot-plugin-msgbuf 插件的名称等信息 (#2119) 2023-06-23 20:27:08 +08:00
noneflow[bot]
89596fb708 📝 Update changelog 2023-06-22 02:42:23 +00:00
ssttkkl
eedcf0779d 🍻 publish plugin 错误告警 (#2116) 2023-06-22 02:41:06 +00:00
noneflow[bot]
05333260b7 📝 Update changelog 2023-06-21 05:28:42 +00:00
Agnes Digital
55fd447230 ✏️ Plugin: 修改插件信息和仓库地址 (#2115)
Co-authored-by: Agnes Digital <Z735803792@163.com>
2023-06-21 13:27:37 +08:00
noneflow[bot]
263e6b25e2 📝 Update changelog 2023-06-20 05:51:13 +00:00
Ju4tCode
e00890033e add plugin metadata to builtin plugins (#2113) 2023-06-20 13:50:05 +08:00
noneflow[bot]
20d3d62bd5 📝 Update changelog 2023-06-19 09:50:07 +00:00
Ju4tCode
080b876d93 👷 Test: 移除 httpbin 并整理测试 (#2110) 2023-06-19 17:48:59 +08:00
noneflow[bot]
27a3d1f0bb 📝 Update changelog 2023-06-19 08:48:59 +00:00
CMHopeSunshine
7a47985c2b 🍻 publish plugin follow_withdraw (#2111) 2023-06-19 08:47:51 +00:00
noneflow[bot]
8d97081948 📝 Update changelog 2023-06-18 13:17:46 +00:00
ThirdBlood
f4ffa07c8b 🍻 publish bot ReimeiBot-黎明机器人 (#2106) 2023-06-18 13:16:43 +00:00
noneflow[bot]
1b1ddc5c0f 📝 Update changelog 2023-06-14 09:07:00 +00:00
uy/sun
30dbd270a6 👷 CI: 缓存 NoneFlow 所需的 pre-commit hooks (#2104) 2023-06-14 17:05:52 +08:00
noneflow[bot]
7d3c7c4933 📝 Update changelog 2023-06-14 05:05:52 +00:00
0Neptune0
8c8436a94f 🍻 publish plugin 战雷查水表 (#2102) 2023-06-14 05:04:44 +00:00
noneflow[bot]
8601942ed3 📝 Update changelog 2023-06-13 13:46:01 +00:00
pre-commit-ci[bot]
4cc958ca17 🚨 auto fix by pre-commit hooks 2023-06-13 13:44:48 +00:00
SuperGuGuGu
472a2c7866 🍻 publish plugin bili_push (#2100) 2023-06-13 13:44:48 +00:00
noneflow[bot]
222609182e 📝 Update changelog 2023-06-12 13:19:50 +00:00
forchannot
dccf2f3ca8 🔥 Docs: 删除商店插件发布多余模块 (#2095)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-12 21:18:25 +08:00
noneflow[bot]
156807c365 📝 Update changelog 2023-06-12 12:40:57 +00:00
worldmozara
50941f5259 📝 Docs: 微调插件元数据的部分描述 (#2096) 2023-06-12 20:39:28 +08:00
noneflow[bot]
2de1524a89 📝 Update changelog 2023-06-11 15:49:49 +00:00
uy/sun
bdd17b62cc Feature: 插件商店适配最新的插件元数据 (#2094)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-11 23:48:37 +08:00
noneflow[bot]
3a9e800a58 📝 Update changelog 2023-06-11 15:42:26 +00:00
worldmozara
cb8d48c362 📝 Docs: 完成发布插件教程 (#2078)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
Co-authored-by: uy/sun <hmy0119@hotmail.com>
2023-06-11 23:41:16 +08:00
noneflow[bot]
a5981c05d5 📝 Update changelog 2023-06-11 13:06:02 +00:00
worldmozara
4cb87e596d 📝 Docs: 更新插件元数据的相关描述 (#2087) 2023-06-11 21:04:58 +08:00
noneflow[bot]
2725a0a324 📝 Update changelog 2023-06-11 07:34:45 +00:00
Ju4tCode
f6b0809e5f Feature: 依赖注入支持 Generic TypeVar 和 Matcher 重载 (#2089) 2023-06-11 15:33:33 +08:00
noneflow[bot]
6181c1760f 📝 Update changelog 2023-06-11 07:00:08 +00:00
Jigsaw
324277091c 🐛 Fix: aiohttp 请求时 data 和 file 不能同时存在 (#2088) 2023-06-11 14:59:05 +08:00
noneflow[bot]
6eef863b70 📝 Update changelog 2023-06-11 06:50:18 +00:00
Alpaca4610
7d52f5af4d 🍻 publish plugin AI作曲 (#2092) 2023-06-11 06:48:53 +00:00
noneflow[bot]
0a70721ec0 📝 Update changelog 2023-06-11 04:47:10 +00:00
reine-ishyanami
f430f061ec 🍻 publish plugin pcrjjc (#2090) 2023-06-11 04:46:06 +00:00
noneflow[bot]
572be1eb47 📝 Update changelog 2023-06-07 09:33:36 +00:00
惜月
29cf7de1a6 📝 add Villa adapter to README (#2086) 2023-06-07 17:32:31 +08:00
noneflow[bot]
c61e3cab90 📝 Update changelog 2023-06-06 16:23:08 +00:00
CMHopeSunshine
77bdc5ecba 🍻 publish adapter 大别野 (#2084) 2023-06-06 16:22:06 +00:00
pre-commit-ci[bot]
16054d18c6 ⬆️ auto update by pre-commit hooks (#2083)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-06 17:22:45 +08:00
noneflow[bot]
f0361295c3 📝 Update changelog 2023-06-05 09:18:27 +00:00
nek0us
9bd1964ae2 🍻 publish plugin twitter订阅 (#2081) 2023-06-05 09:17:09 +00:00
noneflow[bot]
9141c88f77 📝 Update changelog 2023-06-03 14:46:48 +00:00
DiheChen
491855876b 🐛 Fix: 修复因 loguru 更新导致的启动和关闭日志 name 不正常 (#2080)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-06-03 22:45:46 +08:00
noneflow[bot]
6df28dd2a8 📝 Update changelog 2023-06-03 03:28:06 +00:00
ssttkkl
142d0f4d95 🍻 publish plugin 链接防夹 (#2073) 2023-06-03 03:27:04 +00:00
noneflow[bot]
0127d765ae 📝 Update changelog 2023-06-02 10:14:15 +00:00
Bill Chen
207c6b3c15 ✏️ Plugin: 移除过时未更新的插件&Bot (#2072) 2023-06-02 18:13:04 +08:00
noneflow[bot]
d2e699a13a 📝 Update changelog 2023-06-02 10:10:24 +00:00
Agnes4m
ce9ba7dd9b 🍻 publish plugin 碧蓝航线攻略 (#2075) 2023-06-02 10:09:13 +00:00
noneflow[bot]
2af23c9d89 📝 Update changelog 2023-06-01 15:55:58 +00:00
BalconyJH
8ee0f5efc4 ✏️ Plugin: 删除插件 nonebot_plugin_r6s (#2071) 2023-06-01 23:54:46 +08:00
noneflow[bot]
8dcfe92f13 🔖 Release 2.0.0 2023-06-01 06:26:07 +00:00
Ju4tCode
f3d5c1f226 🔖 Release: v2.0.0 (#2070) 2023-06-01 14:18:16 +08:00
noneflow[bot]
8af21f6e76 📝 Update changelog 2023-05-31 14:35:34 +00:00
Tarrailt
9bf3dc4274 📝 Docs: 添加 Alconna 响应器介绍 (#2069)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-05-31 22:34:10 +08:00
noneflow[bot]
40d2f975cb 📝 Update changelog 2023-05-30 08:18:36 +00:00
Ju4tCode
784ba287aa 📝 Docs: 更新 README 适配器链接 (#2068) 2023-05-30 16:17:24 +08:00
noneflow[bot]
3b9cf6cc51 📝 Update changelog 2023-05-30 07:21:42 +00:00
Ju4tCode
f52abc8314 Feature: 优化事件分发方法 (#2067) 2023-05-30 15:20:31 +08:00
noneflow[bot]
3199fc454a 📝 Update changelog 2023-05-28 14:00:27 +00:00
DiaoDaiaChan
738f8cae3b 🍻 publish plugin stablediffusion绘画插件 (#2065) 2023-05-28 13:59:10 +00:00
noneflow[bot]
9406c117a6 📝 Update changelog 2023-05-28 13:20:29 +00:00
Ikaros-521
7b0e62c128 🍻 publish plugin 随机抽取自定义内容 (#2063) 2023-05-28 13:19:05 +00:00
noneflow[bot]
5d0d91b87b 📝 Update changelog 2023-05-28 11:34:55 +00:00
ssttkkl
ed687d8ff6 🍻 publish plugin NAGA公交车 (#2061) 2023-05-28 11:33:36 +00:00
noneflow[bot]
cc214c320d 📝 Update changelog 2023-05-24 16:10:20 +00:00
Xie-Tiao
0897f3b0f7 🍻 publish plugin 本子标题关键词提取 (#2055) 2023-05-24 16:09:01 +00:00
noneflow[bot]
7986c45b3f 📝 Update changelog 2023-05-24 09:54:54 +00:00
Akirami
8ea0241aa2 ✏️ Plugin: Hello World 添加 tag (#2056) 2023-05-24 17:53:28 +08:00
noneflow[bot]
fabc2faa4c 📝 Update changelog 2023-05-24 09:39:52 +00:00
Akirami
3216479530 ✏️ 修改 nonebot-plugin-logpile 的名称和描述 (#2057) 2023-05-24 17:38:06 +08:00
noneflow[bot]
6c66a54223 📝 Update changelog 2023-05-24 03:01:50 +00:00
initialencounter
e760290beb 🍻 publish plugin puzzle (#2053) 2023-05-24 03:00:26 +00:00
noneflow[bot]
3beefdff72 📝 Update changelog 2023-05-24 02:53:49 +00:00
Special-Week
104f610ea7 🍻 publish plugin homo_mathematician (#2051) 2023-05-24 02:51:54 +00:00
noneflow[bot]
2b337e1310 📝 Update changelog 2023-05-23 16:06:23 +00:00
initialencounter
b78455f910 🍻 publish plugin cuber (#2045) 2023-05-23 16:05:13 +00:00
noneflow[bot]
c3d6e20120 📝 Update changelog 2023-05-23 15:56:26 +00:00
synodriver
b32af0f6ba 🍻 publish plugin nonebot-plugin-lua (#2047) 2023-05-23 15:55:09 +00:00
noneflow[bot]
3469b0dbb7 📝 Update changelog 2023-05-23 02:26:54 +00:00
ElainaFanBoy
0fd7396665 🍻 publish plugin Github仓库卡片 (#2041) 2023-05-23 02:25:40 +00:00
noneflow[bot]
c6f41e1975 📝 Update changelog 2023-05-21 16:01:58 +00:00
Ju4tCode
2cfc20c143 🐛 fix require new plugin context error (#2040) 2023-05-22 00:00:50 +08:00
noneflow[bot]
99197f30f6 📝 Update changelog 2023-05-21 08:03:01 +00:00
Ju4tCode
aa48299d5d improve dependency injection params (#2034) 2023-05-21 16:01:55 +08:00
noneflow[bot]
dd80191761 📝 Update changelog 2023-05-20 09:32:41 +00:00
canxin
34c1c33996 ✏️ Plugin: 移除 nonebot_paddle_ocrnonebot_poe_chat (#2039) 2023-05-20 17:31:20 +08:00
noneflow[bot]
2dcbce9cd7 📝 Update changelog 2023-05-20 06:02:19 +00:00
MingxuanGame
c4fbd1cac3 🔥 remove plugin nonebot-plugin-rtfm (#2037) 2023-05-20 14:01:16 +08:00
noneflow[bot]
575e3fb920 📝 Update changelog 2023-05-20 03:12:19 +00:00
Calanosay
50fd4acccb 🍻 publish plugin 股票看盘助手 (#2031) 2023-05-20 03:11:15 +00:00
noneflow[bot]
f9e214de93 📝 Update changelog 2023-05-19 09:42:59 +00:00
xi-yue-233
f28d354875 🍻 publish plugin 便携插件安装器 (#2026) 2023-05-19 09:41:47 +00:00
noneflow[bot]
648b838a75 📝 Update changelog 2023-05-19 09:10:44 +00:00
worldmozara
157fe31051 ✏️ Plugin: 移除 extrautils 工具拓展插件(暂停维护) (#2033) 2023-05-19 17:09:33 +08:00
noneflow[bot]
170fb94896 📝 Update changelog 2023-05-18 08:01:35 +00:00
Ju4tCode
9616b4c0ca Feature: 添加插件元数据字段 type homepage supported_adapters (#2012) 2023-05-18 16:00:10 +08:00
noneflow[bot]
0c4a040394 📝 Update changelog 2023-05-16 14:55:41 +00:00
MeetWq
8592e77e15 🍻 publish plugin 会话 id (#2024) 2023-05-16 14:54:33 +00:00
noneflow[bot]
fc8850496e 📝 Update changelog 2023-05-16 08:44:08 +00:00
evan-gyy
227afbfd8d 🍻 publish plugin SD绘画插件 (#2022) 2023-05-16 08:42:50 +00:00
noneflow[bot]
4672af12fe 📝 Update changelog 2023-05-16 08:38:57 +00:00
xi-yue-233
079996d936 🍻 publish plugin 《女神异闻录5》预告信生成器 (#2016) 2023-05-16 08:37:36 +00:00
noneflow[bot]
bd9b05b990 📝 Update changelog 2023-05-15 07:01:11 +00:00
chaichaisi
f2f3f7ab8e 🍻 publish plugin 小小的WEBAPI调用插件 (#2019) 2023-05-15 06:59:55 +00:00
noneflow[bot]
22222e79b6 📝 Update changelog 2023-05-15 04:42:14 +00:00
lgc2333
55164e8ece 🍻 publish plugin MultiNCM (#2017) 2023-05-15 04:41:11 +00:00
noneflow[bot]
336822ff5c 📝 Update changelog 2023-05-14 14:44:54 +00:00
zhulinyv
82e8417b9a 🍻 publish plugin 签到 (#2013) 2023-05-14 14:43:48 +00:00
noneflow[bot]
9c0ecb441f 📝 Update changelog 2023-05-13 10:10:24 +00:00
mute23-code
0c0fabcb89 🍻 publish plugin 链接解析 (#1959) 2023-05-13 10:09:14 +00:00
noneflow[bot]
202f437aea 📝 Update changelog 2023-05-13 07:33:31 +00:00
Ju4tCode
a8b06aa7c7 publish to store using issue form (#2010) 2023-05-13 15:32:28 +08:00
noneflow[bot]
a5e634319a 📝 Update changelog 2023-05-13 03:27:01 +00:00
bingqiu456
6d1262f402 🍻 publish bot 狐尾 (#2007) 2023-05-13 03:25:46 +00:00
noneflow[bot]
a5fd182bd0 📝 Update changelog 2023-05-13 02:31:25 +00:00
NCBM
771cf8bdcf 🍻 publish plugin 信鸽巴夫 (#2006) 2023-05-13 02:29:55 +00:00
noneflow[bot]
56304aea8d 📝 Update changelog 2023-05-12 15:22:56 +00:00
RF-Tar-Railt
c6e69ddc17 🍻 publish plugin 明日方舟抽卡模拟 (#2004) 2023-05-12 15:21:31 +00:00
noneflow[bot]
ae55ec3e1b 📝 Update changelog 2023-05-11 14:56:56 +00:00
Well2333
f72243304f 🍻 publish plugin 雷神工业 (#2002) 2023-05-11 14:55:42 +00:00
noneflow[bot]
5425180aec 📝 Update changelog 2023-05-10 10:34:12 +00:00
A-kirami
a496db4ddf 🍻 publish plugin nonebot-plugin-logpile (#1998) 2023-05-10 10:33:02 +00:00
noneflow[bot]
26bad8eb4b 📝 Update changelog 2023-05-10 10:10:30 +00:00
canxin121
f526080611 🍻 publish plugin Spark-GPT (#1996) 2023-05-10 10:09:04 +00:00
noneflow[bot]
6c269825c9 📝 Update changelog 2023-05-09 03:41:33 +00:00
AzideCupric
17959b7056 🍻 publish plugin 企鹅物流统计数据查询 (#1994) 2023-05-09 03:40:32 +00:00
noneflow[bot]
17a8ed379a 📝 Update changelog 2023-05-07 12:33:29 +00:00
863109569
163e5001d3 🍻 publish bot ay机器人 (#1992) 2023-05-07 12:32:26 +00:00
noneflow[bot]
5d27646ef9 📝 Update changelog 2023-05-07 03:21:34 +00:00
lgc2333
38be147e8a 🍻 publish plugin CallAPI (#1989) 2023-05-07 03:20:30 +00:00
noneflow[bot]
93829aeb80 📝 Update changelog 2023-05-07 03:11:18 +00:00
ZM25XC
9098dbae9a 🍻 publish plugin 群聊人数锁定 (#1987) 2023-05-07 03:10:13 +00:00
noneflow[bot]
9edc51c2a4 📝 Update changelog 2023-05-07 03:06:01 +00:00
roiiiu
f1aa2b1cb2 🍻 publish plugin CSGO开箱模拟器 (#1985) 2023-05-07 03:04:51 +00:00
noneflow[bot]
bbb2cb3a2c 📝 Update changelog 2023-05-06 17:04:48 +00:00
Lptr-byte
7a0a32398b 📝 Docs: 修复获取事件信息文档代码范例中的高亮行 (#1983) 2023-05-07 01:03:43 +08:00
noneflow[bot]
272ed8e85c 📝 Update changelog 2023-05-06 16:57:35 +00:00
Lptr-byte
e308d4cfac Docs: 修复事件处理函数文档代码范例中缺失的 import (#1982) 2023-05-07 00:56:22 +08:00
noneflow[bot]
0162360cfe 📝 Update changelog 2023-05-06 16:14:46 +00:00
Lptr-byte
4ba4c0bebc 📝 Docs: 修复获取事件信息文档代码范例中缺失的 import (#1980)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-05-07 00:13:44 +08:00
noneflow[bot]
4b0b1e69a4 📝 Update changelog 2023-05-05 13:05:45 +00:00
mobyw
22c0f81054 🍻 publish bot March7th (#1977) 2023-05-05 13:04:32 +00:00
noneflow[bot]
2494e615fd 📝 Update changelog 2023-05-05 11:34:56 +00:00
Special-Week
ab637d217b 🍻 publish plugin wordle_help (#1973) 2023-05-05 11:33:34 +00:00
noneflow[bot]
9d8f16f940 📝 Update changelog 2023-05-04 06:26:26 +00:00
Ju4tCode
dc2c5e3c80 🐛 fix command whitespace if no arg (#1975) 2023-05-04 14:25:09 +08:00
noneflow[bot]
6cfdbbe597 📝 Update changelog 2023-05-03 07:52:31 +00:00
17TheWord
487867a967 ✏️ Adapter: 更新 Minecraft 适配器 (#1972)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-05-03 15:51:21 +08:00
noneflow[bot]
f3a692d294 📝 Update changelog 2023-05-03 07:39:16 +00:00
synodriver
72b798f7ae 🐛 Fix: run_sync 上下文 (#1968) 2023-05-03 15:37:53 +08:00
pre-commit-ci[bot]
50237fb778 ⬆️ auto update by pre-commit hooks (#1971)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-05-02 14:11:59 +08:00
noneflow[bot]
fa5b8853af 📝 Update changelog 2023-05-02 04:51:39 +00:00
nicklly
0cd2282640 🍻 publish plugin 星穹铁道活动日历 (#1969) 2023-05-02 04:50:35 +00:00
noneflow[bot]
c2cea75bb7 📝 Update changelog 2023-05-02 04:13:18 +00:00
X-Skirt-X
b832ae742b 🍻 publish plugin 水印大师 (#1962) 2023-05-02 04:12:07 +00:00
noneflow[bot]
e98d28f3b4 📝 Update changelog 2023-04-30 14:28:36 +00:00
Akirami
b2e26cd6bd ✏️ Docs: 更正 issue 表单部分内容 (#1961)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-04-30 22:27:32 +08:00
noneflow[bot]
cfe182f452 📝 Update changelog 2023-04-29 04:15:20 +00:00
maoxig
729a894a04 🍻 publish plugin 图片/漫画翻译 (#1954) 2023-04-29 04:14:09 +00:00
noneflow[bot]
7231d493d0 📝 Update changelog 2023-04-29 03:29:31 +00:00
youlanan
abf1d52168 🍻 publish plugin 为美好群聊献上爆炎 (#1952) 2023-04-29 03:28:28 +00:00
noneflow[bot]
a5618f163f 📝 Update changelog 2023-04-29 00:45:55 +00:00
djkcyl
7d6c512f27 🍻 publish plugin 公共画板插件 (#1956) 2023-04-29 00:44:41 +00:00
noneflow[bot]
f00c0ae71c 📝 Update changelog 2023-04-27 14:00:11 +00:00
Ju4tCode
93b79ddcb3 Feature: 支持 re.Match 依赖注入 (#1950) 2023-04-27 21:58:56 +08:00
Ju4tCode
6691f6ef70 support exit none driver (#1951) 2023-04-27 17:26:59 +08:00
noneflow[bot]
6173836bdb 📝 Update changelog 2023-04-24 08:15:02 +00:00
student_2333
a2a88c1414 ✏️ Plugin: 更新 AutoReply 插件描述 (#1949) 2023-04-24 16:13:57 +08:00
noneflow[bot]
6114867e34 📝 Update changelog 2023-04-24 06:50:20 +00:00
Yincmewy
3c5cd6046d 🍻 publish plugin 运行代码 (#1941) 2023-04-24 06:49:10 +00:00
noneflow[bot]
7dc3702db5 📝 Update changelog 2023-04-24 02:46:05 +00:00
17TheWord
791f75c13e ✏️ Plugin: 移除 MC_QQ_MCRcon (#1948) 2023-04-24 10:44:53 +08:00
noneflow[bot]
4cfc8fcb44 📝 Update changelog 2023-04-24 02:36:03 +00:00
campanulamediuml
57fc04e4aa 🍻 publish plugin brainfuck (#1943) 2023-04-24 02:34:51 +00:00
noneflow[bot]
1e74c4eacf 📝 Update changelog 2023-04-24 02:34:33 +00:00
Well404
e55052ecfd 📝 Docs: 新增插件跨平台指南 (#1938)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-04-24 10:33:23 +08:00
noneflow[bot]
dc0aea9e3e 📝 Update changelog 2023-04-23 12:31:49 +00:00
NCBM
295b55da44 🍻 publish plugin Mixin (#1946) 2023-04-23 12:30:45 +00:00
noneflow[bot]
4b9ae5fd68 📝 Update changelog 2023-04-23 07:08:13 +00:00
Ju4tCode
cc8b6fa7a2 ✏️ enable blank issues (#1945) 2023-04-23 15:06:52 +08:00
noneflow[bot]
f28de96ea9 📝 Update changelog 2023-04-23 03:59:29 +00:00
Akirami
5e225b2898 📝 Docs: 使用 issue 表单替换 issue 模板 (#1928)
Co-authored-by: StarHeart <starheart233@gmail.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-04-23 11:58:25 +08:00
noneflow[bot]
392502dd68 📝 Update changelog 2023-04-22 07:35:22 +00:00
XZhouQD
ba329e5ef2 🍻 publish plugin AppInsights日志监控 (#1939) 2023-04-22 07:34:17 +00:00
noneflow[bot]
68b64a6004 📝 Update changelog 2023-04-22 03:18:34 +00:00
student_2333
0f694aa157 ✏️ Plugin: 更新 lgc2333 插件仓库地址 (#1935) 2023-04-22 11:17:24 +08:00
noneflow[bot]
0d7c399094 📝 Update changelog 2023-04-22 01:56:49 +00:00
canxin121
2f6685ab45 🍻 publish plugin nonebot_poe_chat (#1936) 2023-04-22 01:55:36 +00:00
noneflow[bot]
2061887276 📝 Update changelog 2023-04-20 02:05:46 +00:00
forchannot
2f40024edb 🍻 publish plugin 更改BOT群名片 (#1933) 2023-04-20 02:04:55 +00:00
noneflow[bot]
9799809ebd 📝 Update changelog 2023-04-18 10:57:48 +00:00
This-is-XiaoDeng
2a08bc5a14 🍻 publish bot XDbot2 (#1931) 2023-04-18 10:57:00 +00:00
noneflow[bot]
ff1ace7a04 📝 Update changelog 2023-04-16 10:47:18 +00:00
Well404
96f0daf535 📝 Docs: 修正教程中部分 import 缺失的问题 (#1927)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2023-04-16 18:46:29 +08:00
noneflow[bot]
1b2f560ad7 📝 Update changelog 2023-04-15 01:54:44 +00:00
lgc2333
1c033d3a53 🍻 publish plugin Akinator (#1924) 2023-04-15 01:53:52 +00:00
noneflow[bot]
99b26fccb0 📝 Update changelog 2023-04-14 08:27:59 +00:00
Ju4tCode
565aba61dc 🐛 Fix: shell command 包含富文本时报错信息出错 (#1923) 2023-04-14 16:26:54 +08:00
noneflow[bot]
21eb289411 📝 Update changelog 2023-04-13 16:01:18 +00:00
Agnes4m
441e772f48 🍻 publish plugin Bilifan (#1920) 2023-04-13 16:00:22 +00:00
noneflow[bot]
f360e439e9 📝 Update changelog 2023-04-13 14:10:16 +00:00
mas-alone
98b3affe91 🍻 publish plugin osu!入群审批 (#1918) 2023-04-13 14:09:19 +00:00
noneflow[bot]
04be5cb8e8 📝 Update changelog 2023-04-11 17:00:26 +00:00
nikissXI
7f925536b5 🍻 publish plugin 与ChatGpt聊天 (#1916) 2023-04-11 16:59:39 +00:00
noneflow[bot]
73dfcc53e1 📝 Update changelog 2023-04-11 16:43:02 +00:00
aaron-lii
3e543977c9 🍻 publish plugin TataruBot2 (#1914) 2023-04-11 16:42:18 +00:00
noneflow[bot]
97829aa122 📝 Update changelog 2023-04-10 16:38:02 +00:00
IllusiveBull
e42dd109f9 🍻 publish plugin 宝可梦融合 (#1911) 2023-04-10 16:37:16 +00:00
noneflow[bot]
98a6dfc514 📝 Update changelog 2023-04-10 16:17:08 +00:00
lgc2333
d6fd1b8614 🍻 publish plugin FuckYou (#1909) 2023-04-10 16:16:20 +00:00
noneflow[bot]
dd57aabfdc 📝 Update changelog 2023-04-10 08:02:28 +00:00
A60
44c8b4c29d ✏️ Plugin: 更新多功能哔哩哔哩解析工具 (#1913) 2023-04-10 16:01:38 +08:00
noneflow[bot]
1bc3a8eb02 📝 Update changelog 2023-04-09 15:03:56 +00:00
thx114
7371d3e7bb 🍻 publish plugin SDGPT (#1907) 2023-04-09 15:02:56 +00:00
noneflow[bot]
139eeac6ce 📝 Update changelog 2023-04-09 07:27:13 +00:00
Zeta-qixi
d33d2653cf 🍻 publish plugin nonebot clock 群闹钟 (#1861) 2023-04-09 07:26:28 +00:00
noneflow[bot]
ba3fc6abc4 📝 Update changelog 2023-04-08 14:30:44 +00:00
uy/sun
1d60714054 👷 跳过 PR 仓库为 fork 的情况 (#1905) 2023-04-08 22:29:58 +08:00
noneflow[bot]
020705bd4b 📝 Update changelog 2023-04-08 03:29:28 +00:00
Wuyi无疑
1495b34e39 ✏️ Plugin: 移除旧版本的 GenshinUID (#1904) 2023-04-08 11:28:42 +08:00
noneflow[bot]
e0d11226db 📝 Update changelog 2023-04-08 03:16:58 +00:00
zangxx66
8749bc9dc5 🍻 publish plugin B站直播间路灯 (#1900) 2023-04-08 03:16:08 +00:00
noneflow[bot]
716a047aba 📝 Update changelog 2023-04-08 01:04:49 +00:00
KimigaiiWuyi
ed6d436a50 🍻 publish plugin GenshinUID (#1902) 2023-04-08 01:03:55 +00:00
noneflow[bot]
028b51facf 📝 Update changelog 2023-04-07 16:08:37 +00:00
uy/sun
8f28124237 👷 CI: 使用最新的 NoneFlow (#1899) 2023-04-08 00:07:39 +08:00
noneflow[bot]
f3d7a30c66 📝 Update changelog 2023-04-06 09:53:35 +00:00
noneflow[bot]
8f3e9f87cb 🍻 publish plugin 多功能哔哩哔哩解析工具 (#1897)
Co-authored-by: djkcyl <djkcyl@users.noreply.github.com>
2023-04-06 17:52:24 +08:00
noneflow[bot]
36e4c02699 📝 Update changelog 2023-04-04 13:43:12 +00:00
Ju4tCode
1817102a7c Feature: 为消息类添加 has join include exclude 方法 (#1895) 2023-04-04 21:42:01 +08:00
pre-commit-ci[bot]
20820e72ad ⬆️ auto update by pre-commit hooks (#1896)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-04 17:33:00 +08:00
noneflow[bot]
fb4d957025 📝 Update changelog 2023-04-04 03:23:10 +00:00
he0119
fe5635db62 🍻 publish bot CoolQBot (#1893) 2023-04-04 11:22:06 +08:00
noneflow[bot]
30a8230eea 📝 Update changelog 2023-04-04 02:27:57 +00:00
Ju4tCode
908622cf61 👷 use noneflow app (#1892) 2023-04-04 09:48:31 +08:00
github-actions[bot]
8e5ec5c4e7 📝 Update changelog 2023-04-03 17:34:29 +00:00
nek0us
ca071bfc48 🍻 publish plugin Steam游戏状态播报 (#1886) 2023-04-04 01:33:15 +08:00
github-actions[bot]
4e22252c3e 📝 Update changelog 2023-04-03 17:26:30 +00:00
Alpaca4610
c0eee74968 🍻 publish plugin AI生成PPT (#1883) 2023-04-04 01:25:21 +08:00
github-actions[bot]
1e054a4370 📝 Update changelog 2023-04-03 17:16:39 +00:00
canxin121
76ccd241fc 🍻 publish plugin nonebot_paddle_ocr (#1881) 2023-04-04 01:15:30 +08:00
github-actions[bot]
e984b64fe3 📝 Update changelog 2023-04-03 17:01:58 +00:00
canxin121
3256cf7fce 🍻 publish plugin nonebot_api_paddle (#1879) 2023-04-04 01:00:55 +08:00
github-actions[bot]
d9eeb690ac 📝 Update changelog 2023-04-03 13:59:17 +00:00
Ju4tCode
b66f4436bf 📝 add walle-q to readme (#1891) 2023-04-03 21:57:56 +08:00
github-actions[bot]
c11bc7b78f 📝 Update changelog 2023-04-03 13:33:23 +00:00
Ju4tCode
3bbb48dd25 📝 update deploy docs (#1890) 2023-04-03 21:32:12 +08:00
github-actions[bot]
73b92be1e4 📝 Update changelog 2023-04-03 13:27:57 +00:00
abrahum
e977d79ebd 🍻 publish adapter Walle-Q (#1888) 2023-04-03 21:26:50 +08:00
github-actions[bot]
d02896065e 📝 Update changelog 2023-04-02 07:14:23 +00:00
mas-alone
f468aa992d 🍻 publish plugin 来份睡眠套餐 (#1875) 2023-04-02 15:13:21 +08:00
github-actions[bot]
3bfbbcf111 📝 Update changelog 2023-04-02 06:47:44 +00:00
glamorgan9826
e2e8b0a8cd 🍻 publish plugin 今日老婆 (#1873) 2023-04-02 14:46:45 +08:00
github-actions[bot]
c8c5f17fd1 📝 Update changelog 2023-04-01 11:48:37 +00:00
Ju4tCode
7f6fc56bd8 👷 unlock poetry version (#1872) 2023-04-01 19:47:33 +08:00
github-actions[bot]
40855ade01 📝 Update changelog 2023-04-01 09:47:08 +00:00
Umamusume-Agnes-Digital
d116563958 🍻 publish plugin 激战2!!! (#1869) 2023-04-01 17:45:44 +08:00
github-actions[bot]
8f603d3112 📝 Update changelog 2023-04-01 09:06:57 +00:00
mas-alone
998752926f 🍻 publish plugin ROLL (#1867) 2023-04-01 17:05:26 +08:00
605 changed files with 81731 additions and 14061 deletions

View File

@@ -4,16 +4,17 @@
"features": { "features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {} "ghcr.io/devcontainers-contrib/features/poetry:2": {}
}, },
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install -E all && poetry run pre-commit install && yarn install", "postCreateCommand": "./scripts/setup-envs.sh",
"customizations": { "customizations": {
"vscode": { "vscode": {
"settings": { "settings": {
"python.analysis.diagnosticMode": "workspace", "python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "basic", "ruff.organizeImports": false,
"[python]": { "[python]": {
"editor.defaultFormatter": "ms-python.black-formatter", "editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.organizeImports": true "source.fixAll.ruff": "explicit",
"source.organizeImports": "explicit"
} }
}, },
"[javascript]": { "[javascript]": {
@@ -44,6 +45,7 @@
"ms-python.vscode-pylance", "ms-python.vscode-pylance",
"ms-python.isort", "ms-python.isort",
"ms-python.black-formatter", "ms-python.black-formatter",
"charliermarsh.ruff",
"EditorConfig.EditorConfig", "EditorConfig.EditorConfig",
"esbenp.prettier-vscode", "esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss" "bradlc.vscode-tailwindcss"

6
.eslintignore Normal file
View File

@@ -0,0 +1,6 @@
dist
node_modules
.yarn
.history
build
lib

85
.eslintrc.js Normal file
View File

@@ -0,0 +1,85 @@
module.exports = {
root: true,
env: {
browser: true,
commonjs: true,
node: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json", "./website/tsconfig.json"],
},
globals: {
JSX: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:regexp/recommended",
"plugin:prettier/recommended",
],
settings: {
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
typescript: true,
},
react: {
version: "detect",
},
},
overrides: [
{
files: ["*.ts", "*.tsx"],
rules: {
"import/no-unresolved": "off",
},
},
{
files: ["*.js", "*.cjs"],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
],
plugins: ["@typescript-eslint"],
rules: {
"linebreak-style": ["error", "unix"],
quotes: ["error", "double", { avoidEscape: true }],
semi: ["error", "always"],
"@typescript-eslint/no-non-null-assertion": "off",
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
pathGroups: [
{ pattern: "react", group: "builtin", position: "before" },
{ pattern: "fs-extra", group: "builtin" },
{ pattern: "lodash", group: "external", position: "before" },
{ pattern: "clsx", group: "external", position: "before" },
{ pattern: "@theme/**", group: "internal" },
{ pattern: "@site/**", group: "internal" },
{ pattern: "@theme-init/**", group: "internal" },
{ pattern: "@theme-original/**", group: "internal" },
],
pathGroupsExcludedImportTypes: [],
"newlines-between": "always",
alphabetize: {
order: "asc",
},
},
],
},
};

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
website/versioned_*/** linguist-documentation

2
.github/FUNDING.yml vendored
View File

@@ -1,2 +1,2 @@
open_collective: nonebot open_collective: nonebot
custom: ["https://afdian.net/@nonebot"] custom: ["https://afdian.com/@nonebot"]

View File

@@ -0,0 +1,57 @@
name: 发布适配器
title: "Adapter: {name}"
description: 发布适配器到 NoneBot 官方商店
labels: ["Adapter"]
body:
- type: input
id: name
attributes:
label: 适配器名称
description: 适配器名称
validations:
required: true
- type: input
id: description
attributes:
label: 适配器描述
description: 适配器描述
validations:
required: true
- type: input
id: pypi
attributes:
label: PyPI 项目名
description: PyPI 项目名
placeholder: e.g. nonebot-adapter-xxx
validations:
required: true
- type: input
id: module
attributes:
label: 适配器 import 包名
description: 适配器 import 包名
placeholder: e.g. nonebot_adapter_xxx
validations:
required: true
- type: input
id: homepage
attributes:
label: 适配器项目仓库/主页链接
description: 适配器项目仓库/主页链接
placeholder: e.g. https://github.com/xxx/xxx
validations:
required: true
- type: input
id: tags
attributes:
label: 标签
description: 标签
placeholder: 'e.g. [{"label": "标签名", "color": "#ea5252"}]'
value: "[]"
validations:
required: true

37
.github/ISSUE_TEMPLATE/bot_publish.yml vendored Normal file
View File

@@ -0,0 +1,37 @@
name: 发布机器人
title: "Bot: {name}"
description: 发布机器人到 NoneBot 官方商店
labels: ["Bot"]
body:
- type: input
id: name
attributes:
label: 机器人名称
description: 机器人名称
validations:
required: true
- type: input
id: description
attributes:
label: 机器人描述
description: 机器人描述
validations:
required: true
- type: input
id: homepage
attributes:
label: 机器人项目仓库/主页链接
description: 机器人项目仓库/主页链接
placeholder: e.g. https://github.com/xxx/xxx
- type: input
id: tags
attributes:
label: 标签
description: 标签
placeholder: 'e.g. [{"label": "标签名", "color": "#ea5252"}]'
value: "[]"
validations:
required: true

View File

@@ -1,38 +0,0 @@
---
name: Bug report
about: Create a bug report to help us improve
title: 'Bug: Something went wrong'
labels: bug
assignees: ''
---
**描述问题:**
A clear and concise description of what the bug is.
**如何复现?**
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**期望的结果**
A clear and concise description of what you expected to happen.
**环境信息:**
- OS: [e.g. Linux]
- Python Version: [e.g. 3.8]
- Nonebot Version: [e.g. 2.0.0]
**协议端信息:**
- 协议端: [e.g. go-cqhttp]
- 协议端版本: [e.g. 1.0.0]
**截图或日志**
If applicable, add screenshots to help explain your problem.

85
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,85 @@
name: Bug 反馈
title: "Bug: 出现异常"
description: 提交 Bug 反馈以帮助我们改进代码
labels: ["bug"]
body:
- type: dropdown
id: env-os
attributes:
label: 操作系统
description: 选择运行 NoneBot 的系统
options:
- Windows
- MacOS
- Linux
- Other
validations:
required: true
- type: input
id: env-python-ver
attributes:
label: Python 版本
description: 填写运行 NoneBot 的 Python 版本
placeholder: e.g. 3.11.0
validations:
required: true
- type: input
id: env-nb-ver
attributes:
label: NoneBot 版本
description: 填写 NoneBot 版本
placeholder: e.g. 2.0.0
validations:
required: true
- type: input
id: env-adapter
attributes:
label: 适配器
description: 填写使用的适配器以及版本
placeholder: e.g. OneBot v11 2.2.2
validations:
required: true
- type: input
id: env-protocol
attributes:
label: 协议端
description: 填写连接 NoneBot 的协议端及版本
placeholder: e.g. go-cqhttp 1.0.0
validations:
required: true
- type: textarea
id: describe
attributes:
label: 描述问题
description: 清晰简洁地说明问题是什么
validations:
required: true
- type: textarea
id: reproduction
attributes:
label: 复现步骤
description: 提供能复现此问题的详细操作步骤
placeholder: |
1. 首先……
2. 然后……
3. 发生……
validations:
required: true
- type: textarea
id: expected
attributes:
label: 期望的结果
description: 清晰简洁地描述你期望发生的事情
- type: textarea
id: logs
attributes:
label: 截图或日志
description: 提供有助于诊断问题的任何日志和截图

View File

@@ -1,14 +1,5 @@
blank_issues_enabled: false blank_issues_enabled: false
contact_links: contact_links:
- name: Question - name: NoneBot 论坛
url: https://discussions.nonebot.dev/ url: https://discussions.nonebot.dev/
about: Ask questions about nonebot about: 前往 NoneBot 论坛提问
- name: Plugin Publish
url: https://v2.nonebot.dev/store
about: Publish your plugin to nonebot homepage and nb-cli
- name: Adapter Publish
url: https://v2.nonebot.dev/store
about: Publish your adapter to nonebot homepage and nb-cli
- name: Bot Publish
url: https://v2.nonebot.dev/store
about: Publish your bot to nonebot homepage and nb-cli

View File

@@ -1,17 +0,0 @@
---
name: Document improvement
about: Feedback on documentation, including errors and ideas
title: 'Docs: some description'
labels: documentation
assignees: ''
---
**描述问题或主题:**
**需做出的修改:**
* [ ] 一些修改
* [ ] 一些修改
* [ ] 一些修改

18
.github/ISSUE_TEMPLATE/document.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
name: 文档改进
title: "Docs: 描述"
description: 文档错误及改进意见反馈
labels: ["documentation"]
body:
- type: textarea
id: problem
attributes:
label: 描述问题或主题
validations:
required: true
- type: textarea
id: improve
attributes:
label: 需做出的修改
validations:
required: true

View File

@@ -1,16 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'Feature: Something you want'
labels: enhancement
assignees: ''
---
**是否在使用中遇到某些问题而需要新的特性?请描述:**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**描述你所需要的特性:**
A clear and concise description of what you want to happen.

View File

@@ -0,0 +1,20 @@
name: 功能建议
title: "Feature: 功能描述"
description: 提出关于项目新功能的想法
labels: ["enhancement"]
body:
- type: textarea
id: problem
attributes:
label: 希望能解决的问题
description: 在使用中遇到什么问题而需要新的功能?
validations:
required: true
- type: textarea
id: feature
attributes:
label: 描述所需要的功能
description: 请说明需要的功能或解决方法
validations:
required: true

View File

@@ -0,0 +1,43 @@
name: 发布插件
title: "Plugin: {name}"
description: 发布插件到 NoneBot 官方商店
labels: ["Plugin"]
body:
- type: input
id: pypi
attributes:
label: PyPI 项目名
description: PyPI 项目名
placeholder: e.g. nonebot-plugin-xxx
validations:
required: true
- type: input
id: module
attributes:
label: 插件 import 包名
description: 插件 import 包名
placeholder: e.g. nonebot_plugin_xxx
validations:
required: true
- type: input
id: tags
attributes:
label: 标签
description: 标签
placeholder: 'e.g. [{"label": "标签名", "color": "#ea5252"}]'
value: "[]"
validations:
required: true
- type: textarea
id: config
attributes:
label: 插件配置项
description: 插件配置项
render: dotenv
placeholder: |
# e.g.
# KEY=VALUE
# KEY2=VALUE2

View File

@@ -4,18 +4,10 @@ description: Setup Node
runs: runs:
using: "composite" using: "composite"
steps: steps:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v4
with: with:
node-version: "16" node-version: "18"
cache: "yarn"
- id: yarn-cache-dir-path - run: yarn install --frozen-lockfile
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- run: yarn install
shell: bash shell: bash

View File

@@ -6,19 +6,35 @@ inputs:
description: Python version description: Python version
required: false required: false
default: "3.10" default: "3.10"
env-dir:
description: Environment directory
required: false
default: "."
no-root:
description: Do not install package in the environment
required: false
default: "false"
runs: runs:
using: "composite" using: "composite"
steps: steps:
- name: Install poetry - name: Install poetry
run: pipx install poetry==1.3.2 run: pipx install poetry
shell: bash shell: bash
- uses: actions/setup-python@v4 - uses: actions/setup-python@v5
with: with:
python-version: ${{ inputs.python-version }} python-version: ${{ inputs.python-version }}
architecture: "x64"
cache: "poetry" cache: "poetry"
cache-dependency-path: |
./poetry.lock
${{ inputs.env-dir }}/poetry.lock
- run: poetry install -E all - run: |
cd ${{ inputs.env-dir }}
if [ "${{ inputs.no-root }}" = "true" ]; then
poetry install --all-extras --no-root
else
poetry install --all-extras
fi
shell: bash shell: bash

View File

@@ -4,3 +4,43 @@ updates:
directory: "/" directory: "/"
schedule: schedule:
interval: daily interval: daily
groups:
actions:
patterns:
- "*"
- package-ecosystem: github-actions
directory: "/.github/actions/build-api-doc"
schedule:
interval: daily
groups:
actions:
patterns:
- "*"
- package-ecosystem: github-actions
directory: "/.github/actions/setup-node"
schedule:
interval: daily
groups:
actions:
patterns:
- "*"
- package-ecosystem: github-actions
directory: "/.github/actions/setup-python"
schedule:
interval: daily
groups:
actions:
patterns:
- "*"
- package-ecosystem: devcontainers
directory: "/"
schedule:
interval: daily
groups:
devcontainers:
patterns:
- "*"

View File

@@ -6,42 +6,53 @@ on:
- master - master
pull_request: pull_request:
paths: paths:
- "envs/**"
- "nonebot/**" - "nonebot/**"
- "packages/**" - "packages/**"
- "tests/**" - "tests/**"
- ".github/actions/setup-python/**"
- ".github/workflows/codecov.yml"
- "pyproject.toml"
- "poetry.lock"
jobs: jobs:
test: test:
name: Test Coverage name: Test Coverage
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
concurrency: concurrency:
group: test-coverage-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }} group: test-coverage-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.env }}
cancel-in-progress: true cancel-in-progress: true
strategy: strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
env: [pydantic-v1, pydantic-v2]
env: env:
OS: ${{ matrix.os }} OS: ${{ matrix.os }}
PYTHON_VERSION: ${{ matrix.python-version }} PYTHON_VERSION: ${{ matrix.python-version }}
PYDANTIC_VERSION: ${{ matrix.env }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Setup Python environment - name: Setup Python environment
uses: ./.github/actions/setup-python uses: ./.github/actions/setup-python
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
env-dir: ./envs/${{ matrix.env }}
no-root: true
- name: Run Pytest - name: Run Pytest
run: | run: |
cd tests/ cd ./envs/${{ matrix.env }}
poetry run pytest -n auto --cov-report xml poetry run bash "../../scripts/run-tests.sh"
- name: Upload coverage report - name: Upload coverage report
uses: codecov/codecov-action@v3 uses: codecov/codecov-action@v4
with: with:
env_vars: OS,PYTHON_VERSION env_vars: OS,PYTHON_VERSION,PYDANTIC_VERSION
files: ./tests/coverage.xml files: ./tests/coverage.xml
flags: unittests flags: unittests
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

141
.github/workflows/noneflow.yml vendored Normal file
View File

@@ -0,0 +1,141 @@
name: NoneFlow
on:
issues:
types: [opened, reopened, edited]
pull_request_target:
types: [closed]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.run_id }}
cancel-in-progress: false
jobs:
check:
runs-on: ubuntu-latest
name: check
# do not run on forked PRs, do not run on not related issues, do not run on pr comments
if: |
!(
(
github.event.pull_request &&
(
github.event.pull_request.head.repo.fork ||
!(
contains(github.event.pull_request.labels.*.name, 'Plugin') ||
contains(github.event.pull_request.labels.*.name, 'Adapter') ||
contains(github.event.pull_request.labels.*.name, 'Bot')
)
)
) ||
(
github.event_name == 'issue_comment' && github.event.issue.pull_request
)
)
steps:
- run: echo "Check passed"
reaction:
runs-on: ubuntu-latest
name: reaction
needs: check
if: |
(
github.event_name == 'issue_comment' &&
github.event.action == 'created'
) ||
(
github.event_name == 'issues' &&
github.event.action == 'opened'
)
steps:
- name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_KEY }}
- name: Reaction on issue
if: github.event_name == 'issues'
run: |
gh api --method POST /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/reactions -f "content=rocket"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Reaction on issue comment
if: github.event_name == 'issue_comment'
run: |
gh api --method POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f "content=rocket"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
plugin_test:
runs-on: ubuntu-latest
name: nonebot2 plugin test
needs: check
permissions:
issues: read
outputs:
result: ${{ steps.plugin-test.outputs.RESULT }}
output: ${{ steps.plugin-test.outputs.OUTPUT }}
metadata: ${{ steps.plugin-test.outputs.METADATA }}
steps:
- name: Install Poetry
if: ${{ !startsWith(github.event_name, 'pull_request') }}
run: pipx install poetry
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Test Plugin
id: plugin-test
run: |
curl -sSL https://github.com/nonebot/noneflow/releases/latest/download/plugin_test.py | python -
noneflow:
runs-on: ubuntu-latest
name: noneflow
needs: plugin_test
steps:
- name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_KEY }}
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Cache pre-commit hooks
uses: actions/cache@v4
with:
path: .cache/.pre-commit
key: noneflow-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: NoneFlow
uses: docker://ghcr.io/nonebot/noneflow:latest
with:
config: >
{
"base": "master",
"plugin_path": "assets/plugins.json",
"bot_path": "assets/bots.json",
"adapter_path": "assets/adapters.json"
}
env:
PLUGIN_TEST_RESULT: ${{ needs.plugin_test.outputs.result }}
PLUGIN_TEST_OUTPUT: ${{ needs.plugin_test.outputs.output }}
PLUGIN_TEST_METADATA: ${{ needs.plugin_test.outputs.metadata }}
APP_ID: ${{ secrets.APP_ID }}
PRIVATE_KEY: ${{ secrets.APP_KEY }}
PRE_COMMIT_HOME: /github/workspace/.cache/.pre-commit
- name: Fix permission
run: sudo chown -R $(whoami):$(id -ng) .cache/.pre-commit

View File

@@ -1,60 +0,0 @@
name: NoneBot2 Publish Bot
on:
issues:
types: [opened, reopened, edited]
pull_request_target:
types: [closed]
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.run_id }}
cancel-in-progress: true
jobs:
plugin_test:
runs-on: ubuntu-latest
name: nonebot2 plugin test
if: github.event_name != 'issue_comment' || !github.event.issue.pull_request
permissions:
issues: read
outputs:
result: ${{ steps.plugin-test.outputs.RESULT }}
output: ${{ steps.plugin-test.outputs.OUTPUT }}
steps:
- name: Install Poetry
if: ${{ !startsWith(github.event_name, 'pull_request') }}
run: pipx install poetry
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Test Plugin
id: plugin-test
run: |
curl -sSL https://github.com/nonebot/nonebot2-publish-bot/releases/latest/download/plugin_test.py -o plugin_test.py
python plugin_test.py
publish_bot:
runs-on: ubuntu-latest
name: nonebot2 publish bot
needs: plugin_test
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}
- name: NoneBot2 Publish Bot
uses: docker://ghcr.io/nonebot/nonebot2-publish-bot:latest
with:
token: ${{ secrets.GH_TOKEN }}
config: >
{
"base": "master",
"plugin_path": "website/static/plugins.json",
"bot_path": "website/static/bots.json",
"adapter_path": "website/static/adapters.json"
}
env:
PLUGIN_TEST_RESULT: ${{ needs.plugin_test.outputs.result }}
PLUGIN_TEST_OUTPUT: ${{ needs.plugin_test.outputs.output }}

47
.github/workflows/pyright.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: Pyright Lint
on:
push:
branches:
- master
pull_request:
paths:
- "envs/**"
- "nonebot/**"
- "packages/**"
- "tests/**"
- ".github/actions/setup-python/**"
- ".github/workflows/pyright.yml"
- "pyproject.toml"
- "poetry.lock"
jobs:
pyright:
name: Pyright Lint
runs-on: ubuntu-latest
concurrency:
group: pyright-${{ github.ref }}-${{ matrix.env }}
cancel-in-progress: true
strategy:
matrix:
env: [pydantic-v1, pydantic-v2]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Setup Python environment
uses: ./.github/actions/setup-python
with:
env-dir: ./envs/${{ matrix.env }}
no-root: true
- run: |
(cd ./envs/${{ matrix.env }} && echo "$(poetry env info --path)/bin" >> $GITHUB_PATH)
if [ "${{ matrix.env }}" = "pydantic-v1" ]; then
sed -i 's/PYDANTIC_V2 = true/PYDANTIC_V2 = false/g' ./pyproject.toml
fi
shell: bash
- name: Run Pyright
uses: jakebailey/pyright-action@v2

View File

@@ -18,17 +18,24 @@ jobs:
group: pull-request-changelog group: pull-request-changelog
cancel-in-progress: true cancel-in-progress: true
steps: steps:
- uses: actions/checkout@v3 - name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with: with:
token: ${{ secrets.GH_TOKEN }} app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Setup Node Environment - name: Setup Node Environment
uses: ./.github/actions/setup-node uses: ./.github/actions/setup-node
- uses: release-drafter/release-drafter@v5 - uses: release-drafter/release-drafter@v6
id: release-drafter id: release-drafter
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Update Changelog - name: Update Changelog
uses: docker://ghcr.io/nonebot/auto-changelog:master uses: docker://ghcr.io/nonebot/auto-changelog:master
@@ -43,8 +50,8 @@ jobs:
- name: Commit and Push - name: Commit and Push
run: | run: |
yarn prettier yarn prettier
git config user.name github-actions[bot] git config user.name noneflow[bot]
git config user.email github-actions[bot]@users.noreply.github.com git config user.email 129742071+noneflow[bot]@users.noreply.github.com
git add . git add .
git diff-index --quiet HEAD || git commit -m ":memo: Update changelog" git diff-index --quiet HEAD || git commit -m ":memo: Update changelog"
git push git push
@@ -52,8 +59,18 @@ jobs:
release: release:
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps: steps:
- uses: actions/checkout@v3 - name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_KEY }}
- uses: actions/checkout@v4
- name: Setup Python Environment - name: Setup Python Environment
uses: ./.github/actions/setup-python uses: ./.github/actions/setup-python
@@ -64,33 +81,53 @@ jobs:
- name: Build API Doc - name: Build API Doc
uses: ./.github/actions/build-api-doc uses: ./.github/actions/build-api-doc
- run: | - name: Get Version
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV id: version
run: |
echo "VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT
echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- uses: release-drafter/release-drafter@v5 - name: Check Version
if: steps.version.outputs.VERSION != steps.version.outputs.TAG_VERSION
run: exit 1
- uses: release-drafter/release-drafter@v6
with: with:
name: Release ${{ env.TAG_NAME }} 🌈 name: Release ${{ steps.version.outputs.TAG_NAME }} 🌈
tag: ${{ env.TAG_NAME }} tag: ${{ steps.version.outputs.TAG_NAME }}
publish: true publish: true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Build and Publish Package - name: Build Package
run: | run: |
poetry build poetry build
poetry publish -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.PYPI_PASSWORD}}
gh release upload --clobber ${{ env.TAG_NAME }} dist/*.tar.gz dist/*.whl - name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Publish package to GitHub
run: |
gh release upload --clobber ${{ steps.version.outputs.TAG_NAME }} dist/*.tar.gz dist/*.whl
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Build and Publish Doc Package - name: Build and Publish Doc Package
run: | run: |
yarn build:plugin --out-dir ../packages/nonebot-plugin-docs/nonebot_plugin_docs/dist yarn build:plugin --out-dir ../packages/nonebot-plugin-docs/nonebot_plugin_docs/dist
export NONEBOT_VERSION=`poetry version -s`
cd packages/nonebot-plugin-docs/ cd packages/nonebot-plugin-docs/
poetry version $NONEBOT_VERSION poetry version ${{ steps.version.outputs.VERSION }}
poetry build poetry build
poetry publish -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.PYPI_PASSWORD}}
gh release upload --clobber ${{ env.TAG_NAME }} dist/*.tar.gz dist/*.whl - name: Publish Doc Package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: packages/nonebot-plugin-docs/dist/
- name: Publish Doc Package to GitHub
run: |
cd packages/nonebot-plugin-docs/
gh release upload --clobber ${{ steps.version.outputs.TAG_NAME }} dist/*.tar.gz dist/*.whl
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

View File

@@ -6,12 +6,17 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with: with:
ref: master app_id: ${{ secrets.APP_ID }}
token: ${{ secrets.GH_TOKEN }} private_key: ${{ secrets.APP_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Setup Python Environment - name: Setup Python Environment
uses: ./.github/actions/setup-python uses: ./.github/actions/setup-python
@@ -39,8 +44,8 @@ jobs:
- name: Push Tag - name: Push Tag
run: | run: |
git config user.name github-actions[bot] git config user.name noneflow[bot]
git config user.email github-actions[bot]@users.noreply.github.com git config user.email 129742071+noneflow[bot]@users.noreply.github.com
git add . git add .
git commit -m ":bookmark: Release $(poetry version -s)" git commit -m ":bookmark: Release $(poetry version -s)"
git tag ${{ env.TAG_NAME }} git tag ${{ env.TAG_NAME }}

30
.github/workflows/ruff.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Ruff Lint
on:
push:
branches:
- master
pull_request:
paths:
- "envs/**"
- "nonebot/**"
- "packages/**"
- "tests/**"
- ".github/actions/setup-python/**"
- ".github/workflows/ruff.yml"
- "pyproject.toml"
- "poetry.lock"
jobs:
ruff:
name: Ruff Lint
runs-on: ubuntu-latest
concurrency:
group: pyright-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Run Ruff Lint
uses: chartboost/ruff-action@v1

View File

@@ -13,7 +13,9 @@ jobs:
cancel-in-progress: true cancel-in-progress: true
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python Environment - name: Setup Python Environment
uses: ./.github/actions/setup-python uses: ./.github/actions/setup-python
@@ -31,7 +33,7 @@ jobs:
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Deploy to Netlify - name: Deploy to Netlify
uses: nwtgck/actions-netlify@v2 uses: nwtgck/actions-netlify@v3
with: with:
publish-dir: "./website/build" publish-dir: "./website/build"
production-deploy: true production-deploy: true

View File

@@ -0,0 +1,99 @@
name: Site Deploy (Preview CD)
on:
workflow_run:
workflows: ["Site Deploy (Preview CI)"]
types:
- completed
jobs:
preview-cd:
runs-on: ubuntu-latest
concurrency:
group: pull-request-preview-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: pull request
permissions:
actions: read
statuses: write
pull-requests: write
steps:
- name: Set Commit Status
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.workflow_run.head_sha,
context: 'Website Preview',
description: 'Deploying...',
state: 'pending',
})
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: website-preview
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Restore Context
run: |
cat action.env >> $GITHUB_ENV
- name: Set Deploy Name
run: |
echo "DEPLOY_NAME=deploy-preview-${{ env.PR_NUMBER }}" >> $GITHUB_ENV
- name: Deploy to Netlify
id: deploy
uses: nwtgck/actions-netlify@v3
with:
publish-dir: ./website/build
production-deploy: false
deploy-message: "Deploy ${{ env.DEPLOY_NAME }}@${{ github.event.workflow_run.head_sha }}"
alias: ${{ env.DEPLOY_NAME }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.SITE_ID }}
# action netlify has no pull request context, so we need to comment by ourselves
- name: Comment on Pull Request
uses: marocchino/sticky-pull-request-comment@v2
with:
header: website
number: ${{ env.PR_NUMBER }}
message: |
:rocket: Deployed to ${{ steps.deploy.outputs.deploy-url }}
- name: Set Commit Status
uses: actions/github-script@v7
if: always()
with:
script: |
if (`${{ job.status }}` === 'success') {
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.workflow_run.head_sha,
context: 'Website Preview',
description: `Deployed to ${{ steps.deploy.outputs.deploy-url }}`,
state: 'success',
target_url: `${{ steps.deploy.outputs.deploy-url }}`,
})
} else {
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.workflow_run.head_sha,
context: 'Website Preview',
description: `Deploy ${{ job.status }}`,
state: 'failure',
})
}

View File

@@ -0,0 +1,42 @@
name: Site Deploy (Preview CI)
on:
pull_request:
jobs:
preview-ci:
runs-on: ubuntu-latest
concurrency:
group: pull-request-preview-${{ github.event.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Setup Python Environment
uses: ./.github/actions/setup-python
- name: Setup Node Environment
uses: ./.github/actions/setup-node
- name: Build API Doc
uses: ./.github/actions/build-api-doc
- name: Build Doc
run: yarn build
- name: Export Context
run: |
echo "PR_NUMBER=${{ github.event.number }}" >> ./action.env
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: website-preview
path: |
./website/build
./action.env
retention-days: 1

View File

@@ -1,45 +0,0 @@
name: Site Deploy(Preview)
on:
pull_request_target:
jobs:
preview:
runs-on: ubuntu-latest
concurrency:
group: pull-request-preview-${{ github.event.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Python Environment
uses: ./.github/actions/setup-python
- name: Setup Node Environment
uses: ./.github/actions/setup-node
- name: Build API Doc
uses: ./.github/actions/build-api-doc
- name: Build Doc
run: yarn build
- name: Get Deploy Name
run: |
echo "DEPLOY_NAME=deploy-preview-${{ github.event.number }}" >> $GITHUB_ENV
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v2
with:
publish-dir: "./website/build"
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy ${{ env.DEPLOY_NAME }}@${{ github.sha }}"
enable-commit-comment: false
alias: ${{ env.DEPLOY_NAME }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.SITE_ID }}

2
.gitignore vendored
View File

@@ -139,7 +139,7 @@ fabric.properties
.LSOverride .LSOverride
# Icon must end with two \r # Icon must end with two \r
Icon # Icon
# Thumbnails # Thumbnails
._* ._*

View File

@@ -6,33 +6,34 @@ ci:
autoupdate_schedule: monthly autoupdate_schedule: monthly
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks" autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
repos: repos:
- repo: https://github.com/hadialqattan/pycln - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v2.1.3 rev: v0.5.6
hooks: hooks:
- id: pycln - id: ruff
args: [--config, pyproject.toml] args: [--fix, --exit-non-zero-on-fix]
stages: [commit]
- repo: https://github.com/pycqa/isort - repo: https://github.com/pycqa/isort
rev: 5.12.0 rev: 5.13.2
hooks: hooks:
- id: isort - id: isort
stages: [commit] stages: [commit]
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 23.1.0 rev: 24.8.0
hooks: hooks:
- id: black - id: black
stages: [commit] stages: [commit]
- repo: https://github.com/pre-commit/mirrors-prettier - repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6 rev: v4.0.0-alpha.8
hooks: hooks:
- id: prettier - id: prettier
types_or: [javascript, jsx, ts, tsx, markdown, yaml, json] types_or: [javascript, jsx, ts, tsx, markdown, yaml, json]
stages: [commit] stages: [commit]
- repo: https://github.com/nonebot/nonemoji - repo: https://github.com/nonebot/nonemoji
rev: v0.1.3 rev: v0.1.4
hooks: hooks:
- id: nonemoji - id: nonemoji
stages: [prepare-commit-msg] stages: [prepare-commit-msg]

View File

@@ -5,5 +5,17 @@
"arrowParens": "always", "arrowParens": "always",
"singleQuote": false, "singleQuote": false,
"trailingComma": "es5", "trailingComma": "es5",
"semi": true "semi": true,
"overrides": [
{
"files": [
"**/devcontainer.json",
"**/tsconfig.json",
"**/tsconfig.*.json"
],
"options": {
"parser": "json"
}
}
]
} }

31
.stylelintrc.js Normal file
View File

@@ -0,0 +1,31 @@
module.exports = {
extends: ["stylelint-config-standard", "stylelint-prettier/recommended"],
overrides: [
{
files: ["*.css"],
rules: {
"function-no-unknown": [true, { ignoreFunctions: ["theme"] }],
"selector-class-pattern": [
"^([a-z][a-z0-9]*)(-[a-z0-9]+)*$",
{
resolveNestedSelectors: true,
message: (selector) =>
`Expected class selector "${selector}" to be kebab-case`,
},
],
},
},
{
files: ["*.module.css"],
rules: {
"selector-class-pattern": [
"^[a-z][a-zA-Z0-9]+$",
{
message: (selector) =>
`Expected class selector "${selector}" to be lowerCamelCase`,
},
],
},
},
],
};

View File

@@ -1,3 +1,3 @@
# Changelog # Changelog
See [changelog.md](./website/src/pages/changelog.md) or <https://v2.nonebot.dev/changelog> See [changelog.md](./website/src/pages/changelog.md) or <https://nonebot.dev/changelog>

26
CITATION.cff Normal file
View File

@@ -0,0 +1,26 @@
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: NoneBot
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Yongyu
family-names: Yan
email: yyy@nonebot.dev
- name: NoneBot Team
email: contact@nonebot.dev
website: 'https://github.com/nonebot'
repository-code: 'https://github.com/nonebot/nonebot2'
url: 'https://nonebot.dev/'
abstract: >-
NoneBot, an asynchronous multi-platform chatbot framework
written in Python
keywords:
- nonebot
- chatbot
- pydantic
license: MIT

View File

@@ -10,12 +10,10 @@
### 报告问题、故障与漏洞 ### 报告问题、故障与漏洞
NoneBot2 仍然是一个不够稳定的开发中项目,如果你在使用过程中发现问题并确信是由 NoneBot2 引起的,欢迎提交 Issue。 如果你在使用过程中发现问题并确信是由 NoneBot2 引起的,欢迎提交 Issue。
### 建议功能 ### 建议功能
NoneBot2 还未进入正式版,欢迎在 Issue 中提议要加入哪些新功能。
为了让开发者更好地理解你的意图,请认真描述你所需要的特性,可能的话可以提出你认为可行的解决方案。 为了让开发者更好地理解你的意图,请认真描述你所需要的特性,可能的话可以提出你认为可行的解决方案。
## Pull Request ## Pull Request
@@ -84,7 +82,7 @@ NoneBot2 的代码风格遵循 [PEP 8](https://www.python.org/dev/peps/pep-0008/
## 为社区做贡献 ## 为社区做贡献
你可以在 NoneBot 商店上架自己的适配器、插件、机器人,具体步骤可参考 [发布插件](https://v2.nonebot.dev/docs/developer/plugin-publishing) 一节。 你可以在 NoneBot 商店上架自己的适配器、插件、机器人,具体步骤可参考 [发布插件](https://nonebot.dev/docs/developer/plugin-publishing) 一节。
我们仅对插件的兼容性进行简单测试,并会在下一个版本发布前对与该版本不兼容的插件作出处理。 我们仅对插件的兼容性进行简单测试,并会在下一个版本发布前对与该版本不兼容的插件作出处理。

155
README.md
View File

@@ -1,6 +1,6 @@
<!-- markdownlint-disable MD033 MD041 --> <!-- markdownlint-disable MD033 MD041 -->
<p align="center"> <p align="center">
<a href="https://v2.nonebot.dev/"><img src="https://v2.nonebot.dev/logo.png" width="200" height="200" alt="nonebot"></a> <a href="https://nonebot.dev/"><img src="https://nonebot.dev/logo.png" width="200" height="200" alt="nonebot"></a>
</p> </p>
<div align="center"> <div align="center">
@@ -19,9 +19,19 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
<img src="https://img.shields.io/github/license/nonebot/nonebot2" alt="license"> <img src="https://img.shields.io/github/license/nonebot/nonebot2" alt="license">
</a> </a>
<a href="https://pypi.python.org/pypi/nonebot2"> <a href="https://pypi.python.org/pypi/nonebot2">
<img src="https://img.shields.io/pypi/v/nonebot2" alt="pypi"> <img src="https://img.shields.io/pypi/v/nonebot2?logo=python&logoColor=edb641" alt="pypi">
</a> </a>
<img src="https://img.shields.io/badge/python-3.8+-blue" alt="python"> <img src="https://img.shields.io/badge/python-3.9+-blue?logo=python&logoColor=edb641" alt="python">
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&logoColor=edb641" alt="black">
</a>
<a href="https://github.com/Microsoft/pyright">
<img src="https://img.shields.io/badge/types-pyright-797952.svg?logo=python&logoColor=edb641" alt="pyright">
</a>
<a href="https://github.com/astral-sh/ruff">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json" alt="ruff">
</a>
<br />
<a href="https://codecov.io/gh/nonebot/nonebot2"> <a href="https://codecov.io/gh/nonebot/nonebot2">
<img src="https://codecov.io/gh/nonebot/nonebot2/branch/master/graph/badge.svg?token=2P0G0VS7N4" alt="codecov"/> <img src="https://codecov.io/gh/nonebot/nonebot2/branch/master/graph/badge.svg?token=2P0G0VS7N4" alt="codecov"/>
</a> </a>
@@ -31,6 +41,12 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
<a href="https://results.pre-commit.ci/latest/github/nonebot/nonebot2/master"> <a href="https://results.pre-commit.ci/latest/github/nonebot/nonebot2/master">
<img src="https://results.pre-commit.ci/badge/github/nonebot/nonebot2/master.svg" alt="pre-commit" /> <img src="https://results.pre-commit.ci/badge/github/nonebot/nonebot2/master.svg" alt="pre-commit" />
</a> </a>
<a href="https://github.com/nonebot/nonebot2/actions/workflows/pyright.yml">
<img src="https://github.com/nonebot/nonebot2/actions/workflows/pyright.yml/badge.svg?branch=master&event=push" alt="pyright">
</a>
<a href="https://github.com/nonebot/nonebot2/actions/workflows/ruff.yml">
<img src="https://github.com/nonebot/nonebot2/actions/workflows/ruff.yml/badge.svg?branch=master&event=push" alt="ruff">
</a>
<br /> <br />
<a href="https://onebot.dev/"> <a href="https://onebot.dev/">
<img src="https://img.shields.io/badge/OneBot-v11-black?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="onebot"> <img src="https://img.shields.io/badge/OneBot-v11-black?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="onebot">
@@ -38,6 +54,9 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
<a href="https://onebot.dev/"> <a href="https://onebot.dev/">
<img src="https://img.shields.io/badge/OneBot-v12-black?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="onebot"> <img src="https://img.shields.io/badge/OneBot-v12-black?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="onebot">
</a> </a>
<a href="https://bot.q.qq.com/wiki/">
<img src="https://img.shields.io/badge/QQ-Bot-lightgrey?style=social&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTIuODIgMTMwLjg5Ij48ZyBkYXRhLW5hbWU9IuWbvuWxgiAyIj48ZyBkYXRhLW5hbWU9IuWbvuWxgiAxIj48cGF0aCBkPSJNNTUuNjMgMTMwLjhjLTcgMC0xMy45LjA4LTIwLjg2IDAtMTkuMTUtLjI1LTMxLjcxLTExLjQtMzQuMjItMzAuMy00LjA3LTMwLjY2IDE0LjkzLTU5LjIgNDQuODMtNjYuNjQgMi0uNTEgNS4yMS0uMzEgNS4yMS0xLjYzIDAtMi4xMy4xNC0yLjEzLjE0LTUuNTcgMC0uODktMS4zLTEuNDYtMi4yMi0yLjMxLTYuNzMtNi4yMy03LjY3LTEzLjQxLTEtMjAuMTggNS40LTUuNTIgMTEuODctNS40IDE3LjgtLjU5IDYuNDkgNS4yNiA2LjMxIDEzLjA4LS44NiAyMS0uNjguNzQtMS43OCAxLjYtMS43OCAyLjY3djQuMjFjMCAxLjM1IDIuMiAxLjYyIDQuNzkgMi4zNSAzMS4wOSA4LjY1IDQ4LjE3IDM0LjEzIDQ1IDY2LjM3LTEuNzYgMTguMTUtMTQuNTYgMzAuMjMtMzIuNyAzMC42My04LjAyLjE5LTE2LjA3LS4wMS0yNC4xMy0uMDF6IiBmaWxsPSIjMDI5OWZlIi8+PHBhdGggZD0iTTMxLjQ2IDExOC4zOGMtMTAuNS0uNjktMTYuOC02Ljg2LTE4LjM4LTE3LjI3LTMtMTkuNDIgMi43OC0zNS44NiAxOC40Ni00Ny44MyAxNC4xNi0xMC44IDI5Ljg3LTEyIDQ1LjM4LTMuMTkgMTcuMjUgOS44NCAyNC41OSAyNS44MSAyNCA0NS4yOS0uNDkgMTUuOS04LjQyIDIzLjE0LTI0LjM4IDIzLjUtNi41OS4xNC0xMy4xOSAwLTE5Ljc5IDAiIGZpbGw9IiNmZWZlZmUiLz48cGF0aCBkPSJNNDYuMDUgNzkuNThjLjA5IDUgLjIzIDkuODItNyA5Ljc3LTcuODItLjA2LTYuMS01LjY5LTYuMjQtMTAuMTktLjE1LTQuODItLjczLTEwIDYuNzMtOS44NHM2LjM3IDUuNTUgNi41MSAxMC4yNnoiIGZpbGw9IiMxMDlmZmUiLz48cGF0aCBkPSJNODAuMjcgNzkuMjdjLS41MyAzLjkxIDEuNzUgOS42NC01Ljg4IDEwLTcuNDcuMzctNi44MS00LjgyLTYuNjEtOS41LjItNC4zMi0xLjgzLTEwIDUuNzgtMTAuNDJzNi41OSA0Ljg5IDYuNzEgOS45MnoiIGZpbGw9IiMwODljZmUiLz48L2c+PC9nPjwvc3ZnPg==" alt="QQ">
</a>
<a href="https://core.telegram.org/bots/api"> <a href="https://core.telegram.org/bots/api">
<img src="https://img.shields.io/badge/telegram-Bot-lightgrey?style=social&logo=telegram" alt="telegram"> <img src="https://img.shields.io/badge/telegram-Bot-lightgrey?style=social&logo=telegram" alt="telegram">
</a> </a>
@@ -47,11 +66,8 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
<a href="https://docs.github.com/en/developers/apps"> <a href="https://docs.github.com/en/developers/apps">
<img src="https://img.shields.io/badge/GitHub-Bot-181717?style=social&logo=github" alt="github"/> <img src="https://img.shields.io/badge/GitHub-Bot-181717?style=social&logo=github" alt="github"/>
</a> </a>
<a href="https://bot.q.qq.com/wiki/"> <!-- <a href="https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p">
<img src="https://img.shields.io/badge/QQ%E9%A2%91%E9%81%93-Bot-lightgrey?style=social&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTIuODIgMTMwLjg5Ij48ZyBkYXRhLW5hbWU9IuWbvuWxgiAyIj48ZyBkYXRhLW5hbWU9IuWbvuWxgiAxIj48cGF0aCBkPSJNNTUuNjMgMTMwLjhjLTcgMC0xMy45LjA4LTIwLjg2IDAtMTkuMTUtLjI1LTMxLjcxLTExLjQtMzQuMjItMzAuMy00LjA3LTMwLjY2IDE0LjkzLTU5LjIgNDQuODMtNjYuNjQgMi0uNTEgNS4yMS0uMzEgNS4yMS0xLjYzIDAtMi4xMy4xNC0yLjEzLjE0LTUuNTcgMC0uODktMS4zLTEuNDYtMi4yMi0yLjMxLTYuNzMtNi4yMy03LjY3LTEzLjQxLTEtMjAuMTggNS40LTUuNTIgMTEuODctNS40IDE3LjgtLjU5IDYuNDkgNS4yNiA2LjMxIDEzLjA4LS44NiAyMS0uNjguNzQtMS43OCAxLjYtMS43OCAyLjY3djQuMjFjMCAxLjM1IDIuMiAxLjYyIDQuNzkgMi4zNSAzMS4wOSA4LjY1IDQ4LjE3IDM0LjEzIDQ1IDY2LjM3LTEuNzYgMTguMTUtMTQuNTYgMzAuMjMtMzIuNyAzMC42My04LjAyLjE5LTE2LjA3LS4wMS0yNC4xMy0uMDF6IiBmaWxsPSIjMDI5OWZlIi8+PHBhdGggZD0iTTMxLjQ2IDExOC4zOGMtMTAuNS0uNjktMTYuOC02Ljg2LTE4LjM4LTE3LjI3LTMtMTkuNDIgMi43OC0zNS44NiAxOC40Ni00Ny44MyAxNC4xNi0xMC44IDI5Ljg3LTEyIDQ1LjM4LTMuMTkgMTcuMjUgOS44NCAyNC41OSAyNS44MSAyNCA0NS4yOS0uNDkgMTUuOS04LjQyIDIzLjE0LTI0LjM4IDIzLjUtNi41OS4xNC0xMy4xOSAwLTE5Ljc5IDAiIGZpbGw9IiNmZWZlZmUiLz48cGF0aCBkPSJNNDYuMDUgNzkuNThjLjA5IDUgLjIzIDkuODItNyA5Ljc3LTcuODItLjA2LTYuMS01LjY5LTYuMjQtMTAuMTktLjE1LTQuODItLjczLTEwIDYuNzMtOS44NHM2LjM3IDUuNTUgNi41MSAxMC4yNnoiIGZpbGw9IiMxMDlmZmUiLz48cGF0aCBkPSJNODAuMjcgNzkuMjdjLS41MyAzLjkxIDEuNzUgOS42NC01Ljg4IDEwLTcuNDcuMzctNi44MS00LjgyLTYuNjEtOS41LjItNC4zMi0xLjgzLTEwIDUuNzgtMTAuNDJzNi41OSA0Ljg5IDYuNzEgOS45MnoiIGZpbGw9IiMwODljZmUiLz48L2c+PC9nPjwvc3ZnPg==" alt="QQ频道"> <img src="https://img.shields.io/badge/%E9%92%89%E9%92%89-Bot-lightgrey?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAnFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4jUzeAAAAM3RSTlMAQKSRaA+/f0YyFevh29R3cyklIfrlyrGsn41tVUs48c/HqJm9uZdhX1otGwkF9IN8V1CX0Q+IAAABY0lEQVRYw+3V2W7CMBAF0JuNQAhhX9OEfYdu9///rUVWpagE27Ef2gfO+0zGozsKnv6bMGzAhkNytIe5gDdzrwtTCwrbI8x4/NF668NAxgI3Q3UtFi3TyPwNQtPLUUmDd8YfqGLNe4v22XwEYb5zoOuF5baHq2UHtsKe5ivWfGAwrWu2mC34QM0PoCAuqZdOmiwV+5BLyMRtZ7dTSEcs48rzWfzwptMLyzpApka1SJ5FtR4kfCqNIBPEVDmqoqgwUYY5plQOlf6UEjNoOPnuKB6wzDyCrks///TDza8+PnR109WQdxLo8RKWq0PPnuXG0OXKQ6wWLFnCg75uYYbhmMIVVdQ709q33aHbGIj6Duz+2k1HQFX9VwqmY8xYsEJll2ahvhWgsjYLHFRXvIi2Qb0jzMQCzC3FAoydxCma88UCzE3JCWwkjCNYyMUCzHX4DiuTMawEwwhW6hnshPhjZzzJfAH0YacpbmRd7QAAAABJRU5ErkJggg==" alt="dingtalk"> -->
<a href="https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p">
<img src="https://img.shields.io/badge/%E9%92%89%E9%92%89-Bot-lightgrey?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAnFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4jUzeAAAAM3RSTlMAQKSRaA+/f0YyFevh29R3cyklIfrlyrGsn41tVUs48c/HqJm9uZdhX1otGwkF9IN8V1CX0Q+IAAABY0lEQVRYw+3V2W7CMBAF0JuNQAhhX9OEfYdu9///rUVWpagE27Ef2gfO+0zGozsKnv6bMGzAhkNytIe5gDdzrwtTCwrbI8x4/NF668NAxgI3Q3UtFi3TyPwNQtPLUUmDd8YfqGLNe4v22XwEYb5zoOuF5baHq2UHtsKe5ivWfGAwrWu2mC34QM0PoCAuqZdOmiwV+5BLyMRtZ7dTSEcs48rzWfzwptMLyzpApka1SJ5FtR4kfCqNIBPEVDmqoqgwUYY5plQOlf6UEjNoOPnuKB6wzDyCrks///TDza8+PnR109WQdxLo8RKWq0PPnuXG0OXKQ6wWLFnCg75uYYbhmMIVVdQ709q33aHbGIj6Duz+2k1HQFX9VwqmY8xYsEJll2ahvhWgsjYLHFRXvIi2Qb0jzMQCzC3FAoydxCma88UCzE3JCWwkjCNYyMUCzHX4DiuTMawEwwhW6hnshPhjZzzJfAH0YacpbmRd7QAAAABJRU5ErkJggg==" alt="dingtalk">
</a>
</a> </a>
<br /> <br />
<a href="https://jq.qq.com/?_wv=1027&k=5OFifDh"> <a href="https://jq.qq.com/?_wv=1027&k=5OFifDh">
@@ -69,16 +85,16 @@ _✨ 跨平台 Python 异步机器人框架 ✨_
</p> </p>
<p align="center"> <p align="center">
<a href="https://v2.nonebot.dev/">文档</a> <a href="https://nonebot.dev/">文档</a>
· ·
<a href="https://v2.nonebot.dev/docs/quick-start">快速上手</a> <a href="https://nonebot.dev/docs/quick-start">快速上手</a>
· ·
<a href="#插件">文档打不开?</a> <a href="#插件">文档打不开?</a>
</p> </p>
<p align="center"> <p align="center">
<a href="https://asciinema.org/a/569440"> <a href="https://asciinema.org/a/569440">
<img src="https://v2.nonebot.dev/img/setup.svg"> <img src="https://nonebot.dev/img/setup.svg" alt="setup" >
</a> </a>
</p> </p>
@@ -90,36 +106,46 @@ NoneBot2 是一个现代、跨平台、可扩展的 Python 聊天机器人框架
- 异步优先:基于 Python 的异步特性,即使是~~非常~~大量的消息,也能吞吐自如 - 异步优先:基于 Python 的异步特性,即使是~~非常~~大量的消息,也能吞吐自如
- 易于开发:配合 NB-CLI 脚手架,代码编写上手简单,没有过多的冗余代码,可以让开发者专注于业务逻辑 - 易于开发:配合 NB-CLI 脚手架,代码编写上手简单,没有过多的冗余代码,可以让开发者专注于业务逻辑
- 生而可靠100% 类型注解覆盖,配合编辑器的类型推导功能,能将绝大多数的 Bug 杜绝在编辑器中 ([编辑器支持](https://v2.nonebot.dev/docs/editor-support)) - 生而可靠100% 类型注解覆盖,配合编辑器的类型推导功能,能将绝大多数的 Bug 杜绝在编辑器中 ([编辑器支持](https://nonebot.dev/docs/editor-support))
- 社区丰富:社区用户众多,直接和间接用户超过十万人,每天都有大量的活跃用户 ([社区资源](#社区资源)) - 社区丰富:社区用户众多,直接和间接用户超过十万人,每天都有大量的活跃用户 ([社区资源](#社区资源))
- 海纳百川:一个框架,支持多个聊天软件平台,可自定义通信协议 - 海纳百川:一个框架,支持多个聊天软件平台,可自定义通信协议
| 协议名称 | 状态 | 注释 | | 协议名称 | 状态 | 注释 |
| :-----------------------------------------------------------------------: | :--: | :----------------------------------------------------------------: | | :-------------------------------------------------------------------------------------------------------------------: | :--: | :-----------------------------------------------------------------------: |
| [OneBot 协议](https://onebot.dev/) | ✅ | 支持 QQ、TG、微信公众号等[平台](https://onebot.dev/ecosystem.html) | | OneBot[仓库](https://github.com/nonebot/adapter-onebot)[协议](https://onebot.dev/) | ✅ | 支持 QQ、TG、微信公众号、KOOK 等[平台](https://onebot.dev/ecosystem.html) |
| [Telegram](https://core.telegram.org/bots/api) | ✅ | | | Telegram[仓库](https://github.com/nonebot/adapter-telegram)[协议](https://core.telegram.org/bots/api) | ✅ | |
| [飞书](https://open.feishu.cn/document/home/index) | ✅ | | | 飞书[仓库](https://github.com/nonebot/adapter-feishu)[协议](https://open.feishu.cn/document/home/index) | ✅ | |
| [GitHub](https://docs.github.com/en/developers/apps) | ✅ | GitHub APP & OAuth APP | | GitHub[仓库](https://github.com/nonebot/adapter-github)[协议](https://docs.github.com/en/apps) | ✅ | GitHub APP & OAuth APP |
| [QQ 频道](https://bot.q.qq.com/wiki/) | ✅ | 官方接口调整较多 | | QQ[仓库](https://github.com/nonebot/adapter-qq)[协议](https://bot.q.qq.com/wiki/) | ✅ | QQ 官方接口调整较多 |
| [钉钉](https://open.dingtalk.com/document/) | 🤗 | 寻找 Maintainer | | Console[仓库](https://github.com/nonebot/adapter-console) | | 控制台交互 |
| Console | ✅ | 控制台交互 | | Red[仓库](https://github.com/nonebot/adapter-red)[协议](https://chrononeko.github.io/QQNTRedProtocol/) | ✅ | QQ 协议 |
| [开黑啦](https://developer.kookapp.cn/) | ↗️ | 由社区贡献 | | Satori[仓库](https://github.com/nonebot/adapter-satori)[协议](https://satori.js.org/zh-CN) | | 支持 Onebot、TG、飞书、微信公众号、Koishi 等 |
| [Mirai](https://docs.mirai.mamoe.net/mirai-api-http/) | ↗️ | 由社区贡献 | | Discord[仓库](https://github.com/nonebot/adapter-discord)[协议](https://discord.com/developers/docs/intro) | | Discord Bot 协议 |
| [Ntchat](https://github.com/JustUndertaker/adapter-ntchat) | ↗️ | 由社区贡献 | | DoDo[仓库](https://github.com/nonebot/adapter-dodo)[协议](https://open.imdodo.com/) | | DoDo Bot 协议 |
| [MineCraft (Spigot)](https://github.com/17TheWord/nonebot-adapter-spigot) | ↗️ | 由社区贡献 | | Kritor[仓库](https://github.com/nonebot/adapter-kritor)[协议](https://github.com/KarinJS/kritor) | | Kritor (OnebotX) 协议QQ 机器人接口标准 |
| [BiliBili Live](https://github.com/wwweww/adapter-bilibili) | ↗️ | 由社区贡献 | | Mirai[仓库](https://github.com/nonebot/adapter-mirai)[协议](https://docs.mirai.mamoe.net/mirai-api-http/) | | QQ 协议 |
| 钉钉([仓库](https://github.com/nonebot/adapter-ding)[协议](https://open.dingtalk.com/document/) | 🤗 | 寻找 Maintainer暂不可用 |
| 开黑啦([仓库](https://github.com/Tian-que/nonebot-adapter-kaiheila)[协议](https://developer.kookapp.cn/) | ↗️ | 由社区贡献 |
| Mirai[仓库](https://github.com/ieew/nonebot_adapter_mirai2)[协议](https://docs.mirai.mamoe.net/mirai-api-http/) | ↗️ | QQ 协议,由社区贡献 |
| Ntchat[仓库](https://github.com/JustUndertaker/adapter-ntchat) | ↗️ | 微信协议,由社区贡献 |
| MineCraft[仓库](https://github.com/17TheWord/nonebot-adapter-minecraft) | ↗️ | 由社区贡献 |
| BiliBili Live[仓库](https://github.com/wwweww/adapter-bilibili) | ↗️ | 由社区贡献 |
| Walle-Q[仓库](https://github.com/onebot-walle/nonebot_adapter_walleq) | ↗️ | QQ 协议,由社区贡献 |
| Villa[仓库](https://github.com/CMHopeSunshine/nonebot-adapter-villa) | ❌ | 米游社大别野 Bot 协议,官方已下线 |
| Rocket.Chat[仓库](https://github.com/IUnlimit/nonebot-adapter-rocketchat)[协议](https://developer.rocket.chat/) | ↗️ | Rocket.Chat Bot 协议,由社区贡献 |
| Tailchat[仓库](https://github.com/eya46/nonebot-adapter-tailchat)[协议](https://tailchat.msgbyte.com/) | ↗️ | Tailchat 开放平台 Bot 协议,由社区贡献 |
- 坚实后盾:支持多种 web 框架,可自定义替换、组合 - 坚实后盾:支持多种 web 框架,可自定义替换、组合
| 驱动框架 | 类型 | | 驱动框架 | 类型 |
| :--------------------------------------------------------: | :----: | | :-----------------------------------------------------------------: | :----: |
| [FastAPI](https://fastapi.tiangolo.com/) | 服务端 | | [FastAPI](https://fastapi.tiangolo.com/) | 服务端 |
| [Quart](https://pgjones.gitlab.io/quart/) (异步 Flask) | 服务端 | | [Quart](https://quart.palletsprojects.com/en/latest/)异步 Flask | 服务端 |
| [aiohttp](https://docs.aiohttp.org/en/stable/) | 客户端 | | [aiohttp](https://docs.aiohttp.org/en/stable/) | 客户端 |
| [httpx](https://www.python-httpx.org/) | 客户端 | | [httpx](https://www.python-httpx.org/) | 客户端 |
| [websockets](https://websockets.readthedocs.io/en/stable/) | 客户端 | | [websockets](https://websockets.readthedocs.io/en/stable/) | 客户端 |
更多:[概览](https://v2.nonebot.dev/docs/) 更多:[概览](https://nonebot.dev/docs/)
## 什么不是 NoneBot2 ## 什么不是 NoneBot2
@@ -131,7 +157,7 @@ NoneBot2 不是 NoneBot1 的替代品。事实上,它们都在被积极的维
## 即刻开始 ## 即刻开始
~~完整~~文档可以在 [这里](https://v2.nonebot.dev/) 查看。 ~~完整~~文档可以在 [这里](https://nonebot.dev/) 查看。
懒得看文档?下面是快速安装指南: 懒得看文档?下面是快速安装指南:
@@ -186,9 +212,8 @@ NoneBot2 不是 NoneBot1 的替代品。事实上,它们都在被积极的维
或者尝试以下镜像: 或者尝试以下镜像:
- [文档镜像(中国境内)](https://nb2.baka.icu) - [文档镜像(中国境内)](https://nb2.baka.icu)
- [文档镜像(Vercel)](https://nonebot2-vercel-mirror.vercel.app)
- 其他插件请查看 [商店](https://v2.nonebot.dev/store) - 其他插件请查看 [商店](https://nonebot.dev/store/plugins)
## 许可证 ## 许可证
@@ -207,10 +232,62 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
请参考 [贡献指南](./CONTRIBUTING.md) 请参考 [贡献指南](./CONTRIBUTING.md)
### 鸣谢 ## 鸣谢
### 赞助者
感谢以下产品对 NoneBot 项目提供的赞助:
<p align="center">
<a href="https://github.com/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.nonebot.dev/github-dark.png">
<img src="https://assets.nonebot.dev/github-light.png" height="50" alt="GitHub">
</picture>
</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.netlify.com/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.nonebot.dev/netlify-dark.svg">
<img src="https://assets.nonebot.dev/netlify-light.svg" height="50" alt="netlify">
</picture>
</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://sentry.io/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.nonebot.dev/sentry-dark.svg">
<img src="https://assets.nonebot.dev/sentry-light.svg" height="50" alt="sentry">
</picture>
</a>
</p>
<p align="center">
<a href="https://www.docker.com/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.nonebot.dev/docker-dark.svg">
<img src="https://assets.nonebot.dev/docker-light.svg" height="50" alt="docker">
</picture>
</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.algolia.com/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.nonebot.dev/algolia-dark.svg">
<img src="https://assets.nonebot.dev/algolia-light.svg" height="50" alt="algolia">
</picture>
</a>
</p>
<p align="center">
<a href="https://www.jetbrains.com/">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg" height="80" alt="JetBrains" >
</a>
</p>
感谢以下赞助者对 NoneBot 项目提供的资金支持:
<a href="https://assets.nonebot.dev/sponsors.svg">
<img src="https://assets.nonebot.dev/sponsors.svg" alt="sponsors" />
</a>
### 开发者
感谢以下开发者对 NoneBot2 作出的贡献: 感谢以下开发者对 NoneBot2 作出的贡献:
<a href="https://github.com/nonebot/nonebot2/graphs/contributors"> <a href="https://github.com/nonebot/nonebot2/graphs/contributors">
<img src="https://contrib.rocks/image?repo=nonebot/nonebot2&max=1000" /> <img src="https://contrib.rocks/image?repo=nonebot/nonebot2&max=1000" alt="contributors" />
</a> </a>

262
assets/adapters.json Normal file
View File

@@ -0,0 +1,262 @@
[
{
"module_name": "nonebot.adapters.onebot.v11",
"project_link": "nonebot-adapter-onebot",
"name": "OneBot V11",
"desc": "OneBot V11 协议",
"author": "yanyongyu",
"homepage": "https://onebot.adapters.nonebot.dev/",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.ding",
"project_link": "nonebot-adapter-ding",
"name": "钉钉",
"desc": "钉钉协议",
"author": "Artin",
"homepage": "https://github.com/nonebot/adapter-ding",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.feishu",
"project_link": "nonebot-adapter-feishu",
"name": "飞书",
"desc": "飞书协议",
"author": "StarHeartHunt",
"homepage": "https://github.com/nonebot/adapter-feishu",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.telegram",
"project_link": "nonebot-adapter-telegram",
"name": "Telegram",
"desc": "Telegram 协议",
"author": "j1g5awi",
"homepage": "https://github.com/nonebot/adapter-telegram",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.qq",
"project_link": "nonebot-adapter-qq",
"name": "QQ",
"desc": "QQ 官方机器人",
"author": "yanyongyu",
"homepage": "https://github.com/nonebot/adapter-qq",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.kaiheila",
"project_link": "nonebot-adapter-kaiheila",
"name": "开黑啦",
"desc": "开黑啦协议适配",
"author": "Tian-que",
"homepage": "https://github.com/Tian-que/nonebot-adapter-kaiheila",
"tags": [],
"is_official": false
},
{
"module_name": "nonebot.adapters.mirai",
"project_link": "nonebot-adapter-mirai",
"name": "Mirai",
"desc": "mirai-api-http v2 协议适配",
"author": "RF-Tar-Railt",
"homepage": "https://github.com/nonebot/adapter-mirai",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.mirai2",
"project_link": "nonebot_adapter_mirai2",
"name": "mirai2",
"desc": "为 nonebot2 添加 mirai_api_http2.x的兼容适配器",
"author": "ieew",
"homepage": "https://github.com/ieew/nonebot_adapter_mirai2",
"tags": [],
"is_official": false
},
{
"module_name": "nonebot.adapters.onebot.v12",
"project_link": "nonebot-adapter-onebot",
"name": "OneBot V12",
"desc": "OneBot V12 协议",
"author": "yanyongyu",
"homepage": "https://onebot.adapters.nonebot.dev/",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.console",
"project_link": "nonebot-adapter-console",
"name": "Console",
"desc": "基于终端的交互式适配器",
"author": "Melodyknit",
"homepage": "https://github.com/nonebot/adapter-console",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.github",
"project_link": "nonebot-adapter-github",
"name": "GitHub",
"desc": "GitHub APP & OAuth APP integration",
"author": "yanyongyu",
"homepage": "https://github.com/nonebot/adapter-github",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.ntchat",
"project_link": "nonebot-adapter-ntchat",
"name": "Ntchat",
"desc": "pc hook的微信客户端适配",
"author": "JustUndertaker",
"homepage": "https://github.com/JustUndertaker/adapter-ntchat",
"tags": [
{
"label": "微信",
"color": "#ea5252"
}
],
"is_official": false
},
{
"module_name": "nonebot.adapters.minecraft",
"project_link": "nonebot-adapter-minecraft",
"name": "Minecraft",
"desc": "MineCraft通信适配支持Rcon",
"author": "17TheWord",
"homepage": "https://github.com/17TheWord/nonebot-adapter-minecraft",
"tags": [
{
"label": "Minecraft",
"color": "#4ef0ea"
}
],
"is_official": false
},
{
"module_name": "nonebot.adapters.bilibili",
"project_link": "nonebot-adapter-bilibili",
"name": "BilibiliLive",
"desc": "b站直播间ws协议",
"author": "wwweww",
"homepage": "https://github.com/wwweww/adapter-bilibili",
"tags": [],
"is_official": false
},
{
"module_name": "nonebot_adapter_walleq",
"project_link": "nonebot-adapter-walleq",
"name": "Walle-Q",
"desc": "内置 QQ 协议实现",
"author": "abrahum",
"homepage": "https://github.com/onebot-walle/nonebot_adapter_walleq",
"tags": [
{
"label": "QQ",
"color": "#34a9cc"
}
],
"is_official": false
},
{
"module_name": "nonebot.adapters.villa",
"project_link": "nonebot-adapter-villa",
"name": "大别野",
"desc": "米游社大别野官方Bot适配",
"author": "CMHopeSunshine",
"homepage": "https://github.com/CMHopeSunshine/nonebot-adapter-villa",
"tags": [
{
"label": "米哈游",
"color": "#e10909"
}
],
"is_official": false
},
{
"module_name": "nonebot.adapters.red",
"project_link": "nonebot-adapter-red",
"name": "RedProtocol",
"desc": "QQNT RedProtocol 适配",
"author": "zhaomaoniu",
"homepage": "https://github.com/nonebot/adapter-red",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.discord",
"project_link": "nonebot-adapter-discord",
"name": "Discord",
"desc": "Discord 官方 Bot 协议适配",
"author": "CMHopeSunshine",
"homepage": "https://github.com/nonebot/adapter-discord",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.satori",
"project_link": "nonebot-adapter-satori",
"name": "Satori",
"desc": "Satori 协议适配器",
"author": "RF-Tar-Railt",
"homepage": "https://github.com/nonebot/adapter-satori",
"tags": [
{
"label": "跨平台",
"color": "#bf40bf"
}
],
"is_official": true
},
{
"module_name": "nonebot.adapters.dodo",
"project_link": "nonebot-adapter-dodo",
"name": "DoDo",
"desc": "DoDo Bot 协议适配器",
"author": "CMHopeSunshine",
"homepage": "https://github.com/nonebot/adapter-dodo",
"tags": [],
"is_official": true
},
{
"module_name": "nonebot.adapters.rocketchat",
"project_link": "nonebot-adapter-rocketchat",
"name": "RocketChat",
"desc": "RocketChat adapter for nonebot2",
"author": "IllTamer",
"homepage": "https://github.com/IUnlimit/nonebot-adapter-rocketchat",
"tags": [],
"is_official": false
},
{
"module_name": "nonebot.adapters.kritor",
"project_link": "nonebot-adapter-kritor",
"name": "Kritor",
"desc": "Kritor 协议适配",
"author": "RF-Tar-Railt",
"homepage": "https://github.com/nonebot/adapter-kritor",
"tags": [
{
"label": "QQNT",
"color": "#35a7c9"
}
],
"is_official": true
},
{
"module_name": "nonebot_adapter_tailchat",
"project_link": "nonebot-adapter-tailchat",
"name": "Tailchat",
"desc": "Tailchat 适配器",
"author": "eya46",
"homepage": "https://github.com/eya46/nonebot-adapter-tailchat",
"tags": [],
"is_official": false
}
]

View File

@@ -71,14 +71,6 @@
"tags": [], "tags": [],
"is_official": false "is_official": false
}, },
{
"name": "Takker",
"desc": "综合了各种娱乐功能的Bot",
"author": "FYWinds",
"homepage": "https://github.com/FYWinds/takker",
"tags": [],
"is_official": false
},
{ {
"name": "剑网三bot", "name": "剑网三bot",
"desc": "网络游戏《剑侠情缘三》的群聊机器人数据使用www.jx3api.com", "desc": "网络游戏《剑侠情缘三》的群聊机器人数据使用www.jx3api.com",
@@ -163,10 +155,6 @@
{ {
"label": "AI", "label": "AI",
"color": "#ea5252" "color": "#ea5252"
},
{
"label": "a:onebot",
"color": "#000000"
} }
], ],
"is_official": false "is_official": false
@@ -261,12 +249,7 @@
"desc": "🐱🤖 一个以娱乐功能为主的缝合怪划掉QQ机器人包含一定Furry要素但是不会卖萌就是逊啦", "desc": "🐱🤖 一个以娱乐功能为主的缝合怪划掉QQ机器人包含一定Furry要素但是不会卖萌就是逊啦",
"author": "su226", "author": "su226",
"homepage": "https://github.com/su226/IdhagnBot", "homepage": "https://github.com/su226/IdhagnBot",
"tags": [ "tags": [],
{
"label": "a:OneBot",
"color": "#ea5252"
}
],
"is_official": false "is_official": false
}, },
{ {
@@ -339,15 +322,15 @@
"homepage": "https://github.com/Rinfair-CSP-A016/SuzunoBot-AGLAS", "homepage": "https://github.com/Rinfair-CSP-A016/SuzunoBot-AGLAS",
"tags": [ "tags": [
{ {
"label": "t:maimaiDX", "label": "maimaiDX",
"color": "#189ede" "color": "#189ede"
}, },
{ {
"label": "t:Arcaea", "label": "Arcaea",
"color": "#d551ef" "color": "#d551ef"
}, },
{ {
"label": "t:coc", "label": "coc",
"color": "#7fe4d0" "color": "#7fe4d0"
} }
], ],
@@ -434,10 +417,6 @@
{ {
"label": "maimai", "label": "maimai",
"color": "#52eaa5" "color": "#52eaa5"
},
{
"label": "a:onebot",
"color": "#000000"
} }
], ],
"is_official": false "is_official": false
@@ -447,10 +426,209 @@
"desc": "一个会拆家的高性能缝合萝卜子", "desc": "一个会拆家的高性能缝合萝卜子",
"author": "tkgs0", "author": "tkgs0",
"homepage": "https://github.com/tkgs0/Momoko", "homepage": "https://github.com/tkgs0/Momoko",
"tags": [],
"is_official": false
},
{
"name": "CoolQBot",
"desc": "基于 NoneBot2 的聊天机器人",
"author": "he0119",
"homepage": "https://github.com/he0119/CoolQBot",
"tags": [],
"is_official": false
},
{
"name": "XDbot2",
"desc": "简单的QQ功能型机器人",
"author": "This-is-XiaoDeng",
"homepage": "https://github.com/ITCraftDevelopmentTeam/XDbot2",
"tags": [],
"is_official": false
},
{
"name": "March7th",
"desc": "三月七 - 崩坏:星穹铁道机器人",
"author": "mobyw",
"homepage": "https://github.com/Mar-7th/March7th",
"tags": [ "tags": [
{ {
"label": "a:onebot", "label": "StarRail",
"color": "#000000" "color": "#5a8ccc"
},
{
"label": "星穹铁道",
"color": "#6faec6"
}
],
"is_official": false
},
{
"name": "ay机器人",
"desc": "codeforces和洛谷卷王监视、股票监控、ai聊天",
"author": "863109569",
"homepage": "https://github.com/863109569/qqbot",
"tags": [
{
"label": "acm",
"color": "#ea5252"
},
{
"label": "洛谷",
"color": "#81ea52"
},
{
"label": "codeforces",
"color": "#5261ea"
}
],
"is_official": false
},
{
"name": "狐尾",
"desc": "一个整合了兽云祭api的机器人支持账号令牌操作以及上传兽图",
"author": "bingqiu456",
"homepage": "https://github.com/bingqiu456/shouyun",
"tags": [
{
"label": "shouyun",
"color": "#52ea7a"
}
],
"is_official": false
},
{
"name": "ReimeiBot-黎明机器人",
"desc": "流星飞逝,黎明终将到来。",
"author": "ThirdBlood",
"homepage": "https://github.com/3rdBit/ReimeiBot",
"tags": [],
"is_official": false
},
{
"name": "web_bot",
"desc": "把机器人搬到网络上",
"author": "wsdtl",
"homepage": "https://github.com/wsdtl/web_bot",
"tags": [
{
"label": "xiaonan",
"color": "#775151"
}
],
"is_official": false
},
{
"name": "林汐",
"desc": "多平台功能型Bot",
"author": "mute23-code",
"homepage": "https://github.com/netsora/SoraBot",
"tags": [
{
"label": "QQ频道",
"color": "#f47070"
},
{
"label": "OneBot v11",
"color": "#212121"
}
],
"is_official": false
},
{
"name": "米缸",
"desc": "基于nonebot2的米缸Bot",
"author": "LambdaYH",
"homepage": "https://github.com/LambdaYH/MigangBot",
"tags": [],
"is_official": false
},
{
"name": "不正经的妹妹",
"desc": "一款功能丰富、简单易用、自定义性强、扩展性强的可爱的QQ娱乐机器人",
"author": "itsevin",
"homepage": "https://github.com/itsevin/sister_bot",
"tags": [],
"is_official": false
},
{
"name": "星见Kirami",
"desc": "🌟 读作 Kirami写作星见简明轻快的聊天机器人应用。",
"author": "A-kirami",
"homepage": "https://kiramibot.dev/",
"tags": [],
"is_official": false
},
{
"name": "OCNbot",
"desc": "OI Contest Notifier bot一个可以推送洛谷、cf、atcoder、牛客比赛通知的bot",
"author": "ACnoway",
"homepage": "https://github.com/ACnoway/OCNbot",
"tags": [
{
"label": "OI",
"color": "#2fccff"
},
{
"label": "ACM",
"color": "#ff0004"
}
],
"is_official": false
},
{
"name": "妃爱",
"desc": "超可爱的妃爱QQ群聊机器人",
"author": "jiangyuxiaoxiao",
"homepage": "https://github.com/jiangyuxiaoxiao/Hiyori",
"tags": [],
"is_official": false
},
{
"name": "芙芙",
"desc": "供 Mooncell Wiki 协作使用的跨平台机器人",
"author": "StarHeartHunt",
"homepage": "https://github.com/MooncellWiki/BotFooChan",
"tags": [],
"is_official": false
},
{
"name": "Sakiko",
"desc": "基于 LiteLoaderBDS 的 Minecraft 基岩版 Bot",
"author": "zhaomaoniu",
"homepage": "https://github.com/zhaomaoniu/Sakiko",
"tags": [
{
"label": "Minecraft",
"color": "#6cc349"
},
{
"label": "BanGDream",
"color": "#e70050"
}
],
"is_official": false
},
{
"name": "星辰 Bot",
"desc": "欢迎使用 星辰 Bot 项目!这是一款基于 NoneBot2 打造的智能 QQ 机器人旨在为用户提供丰富的功能体验。无论是获取一言的灵感探索历史上的今天还是穿梭60s世界星辰 Bot 为您打开了全新的交流之门。快来尝试吧!",
"author": "StarXinXin",
"homepage": "https://github.com/StarXinXin/StarsBot",
"tags": [],
"is_official": false
},
{
"name": "Minecraft_QQBot",
"desc": "基于 NoneBot2 的 Minecraft 群服互联 QQ 机器人,支持多服务器多种方式连接。",
"author": "Lonely-Sails",
"homepage": "https://github.com/Minecraft-QQBot/BotServer",
"tags": [
{
"label": "Minecraft",
"color": "#ea5252"
},
{
"label": "娱乐",
"color": "#37a7e7"
} }
], ],
"is_official": false "is_official": false

File diff suppressed because it is too large Load Diff

2237
envs/pydantic-v1/poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
[tool.poetry]
name = "nonebot-pydantic-v1"
version = "0.1.0"
description = "Private pydantic v1 test env for nonebot"
authors = ["yanyongyu <yyy@nonebot.dev>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.9"
[tool.poetry.group.dev.dependencies]
pydantic = "^1.0.0"
nonebot-test = { path = "../test/", develop = false }
nonebot2 = { path = "../../", extras = ["all"], develop = true }
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

2312
envs/pydantic-v2/poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
[tool.poetry]
name = "nonebot-pydantic-v2"
version = "0.1.0"
description = "Private pydantic v2 test env for nonebot"
authors = ["yanyongyu <yyy@nonebot.dev>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.9"
[tool.poetry.group.dev.dependencies]
pydantic = "^2.0.0"
nonebot-test = { path = "../test/", develop = false }
nonebot2 = { path = "../../", extras = ["all"], develop = true }
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@@ -0,0 +1 @@
# fake file to make project installable

1059
envs/test/poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

21
envs/test/pyproject.toml Normal file
View File

@@ -0,0 +1,21 @@
[tool.poetry]
name = "nonebot-test"
version = "0.1.0"
description = "Private test env for nonebot"
authors = ["yanyongyu <yyy@nonebot.dev>"]
license = "MIT"
packages = [{ include = "nonebot-test.py" }]
[tool.poetry.dependencies]
python = "^3.9"
nonebug = "^0.3.7"
wsproto = "^1.2.0"
pytest-cov = "^5.0.0"
pytest-xdist = "^3.0.2"
pytest-asyncio = "^0.23.2"
werkzeug = ">=2.3.6,<4.0.0"
coverage-conditional-plugin = "^0.9.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@@ -24,12 +24,18 @@
- `load_all_plugins` => {ref}``load_all_plugins` <nonebot.plugin.load.load_all_plugins>` - `load_all_plugins` => {ref}``load_all_plugins` <nonebot.plugin.load.load_all_plugins>`
- `load_from_json` => {ref}``load_from_json` <nonebot.plugin.load.load_from_json>` - `load_from_json` => {ref}``load_from_json` <nonebot.plugin.load.load_from_json>`
- `load_from_toml` => {ref}``load_from_toml` <nonebot.plugin.load.load_from_toml>` - `load_from_toml` => {ref}``load_from_toml` <nonebot.plugin.load.load_from_toml>`
- `load_builtin_plugin` => {ref}``load_builtin_plugin` <nonebot.plugin.load.load_builtin_plugin>` - `load_builtin_plugin` =>
- `load_builtin_plugins` => {ref}``load_builtin_plugins` <nonebot.plugin.load.load_builtin_plugins>` {ref}``load_builtin_plugin` <nonebot.plugin.load.load_builtin_plugin>`
- `load_builtin_plugins` =>
{ref}``load_builtin_plugins` <nonebot.plugin.load.load_builtin_plugins>`
- `get_plugin` => {ref}``get_plugin` <nonebot.plugin.get_plugin>` - `get_plugin` => {ref}``get_plugin` <nonebot.plugin.get_plugin>`
- `get_plugin_by_module_name` => {ref}``get_plugin_by_module_name` <nonebot.plugin.get_plugin_by_module_name>` - `get_plugin_by_module_name` =>
- `get_loaded_plugins` => {ref}``get_loaded_plugins` <nonebot.plugin.get_loaded_plugins>` {ref}``get_plugin_by_module_name` <nonebot.plugin.get_plugin_by_module_name>`
- `get_available_plugin_names` => {ref}``get_available_plugin_names` <nonebot.plugin.get_available_plugin_names>` - `get_loaded_plugins` =>
{ref}``get_loaded_plugins` <nonebot.plugin.get_loaded_plugins>`
- `get_available_plugin_names` =>
{ref}``get_available_plugin_names` <nonebot.plugin.get_available_plugin_names>`
- `get_plugin_config` => {ref}``get_plugin_config` <nonebot.plugin.get_plugin_config>`
- `require` => {ref}``require` <nonebot.plugin.load.require>` - `require` => {ref}``require` <nonebot.plugin.load.require>`
FrontMatter: FrontMatter:
@@ -39,16 +45,16 @@ FrontMatter:
import os import os
from importlib.metadata import version from importlib.metadata import version
from typing import Any, Dict, Type, Union, TypeVar, Optional, overload from typing import Any, Union, TypeVar, Optional, overload
import loguru import loguru
from pydantic.env_settings import DotenvType
from nonebot.config import Env, Config from nonebot.compat import model_dump
from nonebot.log import logger as logger from nonebot.log import logger as logger
from nonebot.adapters import Bot, Adapter from nonebot.adapters import Bot, Adapter
from nonebot.config import DOTENV_TYPE, Env, Config
from nonebot.utils import escape_tag, resolve_dot_notation from nonebot.utils import escape_tag, resolve_dot_notation
from nonebot.drivers import Driver, ReverseDriver, combine_driver from nonebot.drivers import Driver, ASGIMixin, combine_driver
try: try:
__version__ = version("nonebot2") __version__ = version("nonebot2")
@@ -69,7 +75,8 @@ def get_driver() -> Driver:
全局 {ref}`nonebot.drivers.Driver` 对象 全局 {ref}`nonebot.drivers.Driver` 对象
异常: 异常:
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -83,23 +90,33 @@ def get_driver() -> Driver:
@overload @overload
def get_adapter(name: str) -> Adapter: def get_adapter(name: str) -> Adapter:
... """
参数:
name: 适配器名称
返回:
指定名称的 {ref}`nonebot.adapters.Adapter` 对象
"""
@overload @overload
def get_adapter(name: Type[A]) -> A: def get_adapter(name: type[A]) -> A:
... """
参数:
name: 适配器类型
def get_adapter(name: Union[str, Type[Adapter]]) -> Adapter:
"""获取已注册的 {ref}`nonebot.adapters.Adapter` 实例。
返回: 返回:
指定名称或类型的 {ref}`nonebot.adapters.Adapter` 对象 指定类型的 {ref}`nonebot.adapters.Adapter` 对象
"""
def get_adapter(name: Union[str, type[Adapter]]) -> Adapter:
"""获取已注册的 {ref}`nonebot.adapters.Adapter` 实例。
异常: 异常:
ValueError: 指定的 {ref}`nonebot.adapters.Adapter` 未注册 ValueError: 指定的 {ref}`nonebot.adapters.Adapter` 未注册
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -114,14 +131,15 @@ def get_adapter(name: Union[str, Type[Adapter]]) -> Adapter:
return adapters[target] return adapters[target]
def get_adapters() -> Dict[str, Adapter]: def get_adapters() -> dict[str, Adapter]:
"""获取所有已注册的 {ref}`nonebot.adapters.Adapter` 实例。 """获取所有已注册的 {ref}`nonebot.adapters.Adapter` 实例。
返回: 返回:
所有 {ref}`nonebot.adapters.Adapter` 实例字典 所有 {ref}`nonebot.adapters.Adapter` 实例字典
异常: 异常:
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -132,14 +150,15 @@ def get_adapters() -> Dict[str, Adapter]:
def get_app() -> Any: def get_app() -> Any:
"""获取全局 {ref}`nonebot.drivers.ReverseDriver` 对应的 Server App 对象。 """获取全局 {ref}`nonebot.drivers.ASGIMixin` 对应的 Server App 对象。
返回: 返回:
Server App 对象 Server App 对象
异常: 异常:
AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ReverseDriver` 类型 AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ASGIMixin` 类型
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -147,21 +166,21 @@ def get_app() -> Any:
``` ```
""" """
driver = get_driver() driver = get_driver()
assert isinstance( assert isinstance(driver, ASGIMixin), "app object is only available for asgi driver"
driver, ReverseDriver
), "app object is only available for reverse driver"
return driver.server_app return driver.server_app
def get_asgi() -> Any: def get_asgi() -> Any:
"""获取全局 {ref}`nonebot.drivers.ReverseDriver` 对应 [ASGI](https://asgi.readthedocs.io/) 对象。 """获取全局 {ref}`nonebot.drivers.ASGIMixin` 对应的
[ASGI](https://asgi.readthedocs.io/) 对象。
返回: 返回:
ASGI 对象 ASGI 对象
异常: 异常:
AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ReverseDriver` 类型 AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ASGIMixin` 类型
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -170,8 +189,8 @@ def get_asgi() -> Any:
""" """
driver = get_driver() driver = get_driver()
assert isinstance( assert isinstance(
driver, ReverseDriver driver, ASGIMixin
), "asgi object is only available for reverse driver" ), "asgi object is only available for asgi driver"
return driver.asgi return driver.asgi
@@ -182,7 +201,8 @@ def get_bot(self_id: Optional[str] = None) -> Bot:
当不提供时,返回一个 {ref}`nonebot.adapters.Bot`。 当不提供时,返回一个 {ref}`nonebot.adapters.Bot`。
参数: 参数:
self_id: 用来识别 {ref}`nonebot.adapters.Bot` 的 {ref}`nonebot.adapters.Bot.self_id` 属性 self_id: 用来识别 {ref}`nonebot.adapters.Bot` 的
{ref}`nonebot.adapters.Bot.self_id` 属性
返回: 返回:
{ref}`nonebot.adapters.Bot` 对象 {ref}`nonebot.adapters.Bot` 对象
@@ -190,7 +210,8 @@ def get_bot(self_id: Optional[str] = None) -> Bot:
异常: 异常:
KeyError: 对应 self_id 的 Bot 不存在 KeyError: 对应 self_id 的 Bot 不存在
ValueError: 没有传入 self_id 且没有 Bot 可用 ValueError: 没有传入 self_id 且没有 Bot 可用
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -209,14 +230,16 @@ def get_bot(self_id: Optional[str] = None) -> Bot:
raise ValueError("There are no bots to get.") raise ValueError("There are no bots to get.")
def get_bots() -> Dict[str, Bot]: def get_bots() -> dict[str, Bot]:
"""获取所有连接到 NoneBot 的 {ref}`nonebot.adapters.Bot` 对象。 """获取所有连接到 NoneBot 的 {ref}`nonebot.adapters.Bot` 对象。
返回: 返回:
一个以 {ref}`nonebot.adapters.Bot.self_id` 为键{ref}`nonebot.adapters.Bot` 对象为值的字典 一个以 {ref}`nonebot.adapters.Bot.self_id` 为键
{ref}`nonebot.adapters.Bot` 对象为值的字典
异常: 异常:
ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.init>` 尚未调用) ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
({ref}`nonebot.init <nonebot.init>` 尚未调用)
用法: 用法:
```python ```python
@@ -226,7 +249,7 @@ def get_bots() -> Dict[str, Bot]:
return get_driver().bots return get_driver().bots
def _resolve_combine_expr(obj_str: str) -> Type[Driver]: def _resolve_combine_expr(obj_str: str) -> type[Driver]:
drivers = obj_str.split("+") drivers = obj_str.split("+")
DriverClass = resolve_dot_notation( DriverClass = resolve_dot_notation(
drivers[0], "Driver", default_prefix="nonebot.drivers." drivers[0], "Driver", default_prefix="nonebot.drivers."
@@ -243,15 +266,16 @@ def _resolve_combine_expr(obj_str: str) -> Type[Driver]:
def _log_patcher(record: "loguru.Record"): def _log_patcher(record: "loguru.Record"):
"""使用插件标识优化日志展示"""
record["name"] = ( record["name"] = (
plugin.name plugin.id_
if (module_name := record["name"]) if (module_name := record["name"])
and (plugin := get_plugin_by_module_name(module_name)) and (plugin := get_plugin_by_module_name(module_name))
else (module_name and module_name.split(".")[0]) else (module_name and module_name.split(".", maxsplit=1)[0])
) )
def init(*, _env_file: Optional[DotenvType] = None, **kwargs: Any) -> None: def init(*, _env_file: Optional[DOTENV_TYPE] = None, **kwargs: Any) -> None:
"""初始化 NoneBot 以及 全局 {ref}`nonebot.drivers.Driver` 对象。 """初始化 NoneBot 以及 全局 {ref}`nonebot.drivers.Driver` 对象。
NoneBot 将会从 .env 文件中读取环境信息,并使用相应的 env 文件配置。 NoneBot 将会从 .env 文件中读取环境信息,并使用相应的 env 文件配置。
@@ -274,9 +298,11 @@ def init(*, _env_file: Optional[DotenvType] = None, **kwargs: Any) -> None:
_env_file = _env_file or f".env.{env.environment}" _env_file = _env_file or f".env.{env.environment}"
config = Config( config = Config(
**kwargs, **kwargs,
_env_file=(".env", _env_file) _env_file=(
if isinstance(_env_file, (str, os.PathLike)) (".env", _env_file)
else _env_file, if isinstance(_env_file, (str, os.PathLike))
else _env_file
),
) )
logger.configure( logger.configure(
@@ -286,7 +312,7 @@ def init(*, _env_file: Optional[DotenvType] = None, **kwargs: Any) -> None:
f"Current <y><b>Env: {escape_tag(env.environment)}</b></y>" f"Current <y><b>Env: {escape_tag(env.environment)}</b></y>"
) )
logger.opt(colors=True).debug( logger.opt(colors=True).debug(
f"Loaded <y><b>Config</b></y>: {escape_tag(str(config.dict()))}" f"Loaded <y><b>Config</b></y>: {escape_tag(str(model_dump(config)))}"
) )
DriverClass = _resolve_combine_expr(config.driver) DriverClass = _resolve_combine_expr(config.driver)
@@ -331,10 +357,9 @@ from nonebot.plugin import load_from_json as load_from_json
from nonebot.plugin import load_from_toml as load_from_toml from nonebot.plugin import load_from_toml as load_from_toml
from nonebot.plugin import load_all_plugins as load_all_plugins from nonebot.plugin import load_all_plugins as load_all_plugins
from nonebot.plugin import on_shell_command as on_shell_command from nonebot.plugin import on_shell_command as on_shell_command
from nonebot.plugin import get_plugin_config as get_plugin_config
from nonebot.plugin import get_loaded_plugins as get_loaded_plugins from nonebot.plugin import get_loaded_plugins as get_loaded_plugins
from nonebot.plugin import load_builtin_plugin as load_builtin_plugin from nonebot.plugin import load_builtin_plugin as load_builtin_plugin
from nonebot.plugin import load_builtin_plugins as load_builtin_plugins from nonebot.plugin import load_builtin_plugins as load_builtin_plugins
from nonebot.plugin import get_plugin_by_module_name as get_plugin_by_module_name from nonebot.plugin import get_plugin_by_module_name as get_plugin_by_module_name
from nonebot.plugin import get_available_plugin_names as get_available_plugin_names from nonebot.plugin import get_available_plugin_names as get_available_plugin_names
__autodoc__ = {"internal": False}

View File

@@ -19,6 +19,11 @@ __autodoc__ = {
"Event": True, "Event": True,
"Adapter": True, "Adapter": True,
"Message": True, "Message": True,
"Message.__getitem__": True,
"Message.__contains__": True,
"Message._construct": True,
"MessageSegment": True, "MessageSegment": True,
"MessageSegment.__str__": True,
"MessageSegment.__add__": True,
"MessageTemplate": True, "MessageTemplate": True,
} }

416
nonebot/compat.py Normal file
View File

@@ -0,0 +1,416 @@
"""本模块为 Pydantic 版本兼容层模块
为兼容 Pydantic V1 与 V2 版本,定义了一系列兼容函数与类供使用。
FrontMatter:
sidebar_position: 16
description: nonebot.compat 模块
"""
from collections.abc import Generator
from functools import cached_property
from dataclasses import dataclass, is_dataclass
from typing_extensions import Self, get_args, get_origin, is_typeddict
from typing import (
TYPE_CHECKING,
Any,
Union,
Generic,
TypeVar,
Callable,
Optional,
Protocol,
Annotated,
overload,
)
from pydantic import VERSION, BaseModel
from nonebot.typing import origin_is_annotated
T = TypeVar("T")
PYDANTIC_V2 = int(VERSION.split(".", 1)[0]) == 2
if TYPE_CHECKING:
class _CustomValidationClass(Protocol):
@classmethod
def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]: ...
CVC = TypeVar("CVC", bound=_CustomValidationClass)
__all__ = (
"Required",
"PydanticUndefined",
"PydanticUndefinedType",
"ConfigDict",
"DEFAULT_CONFIG",
"FieldInfo",
"ModelField",
"TypeAdapter",
"extract_field_info",
"model_fields",
"model_config",
"model_dump",
"type_validate_python",
"type_validate_json",
"custom_validation",
)
__autodoc__ = {
"PydanticUndefined": "Pydantic Undefined object",
"PydanticUndefinedType": "Pydantic Undefined type",
}
if PYDANTIC_V2: # pragma: pydantic-v2
from pydantic import GetCoreSchemaHandler
from pydantic import TypeAdapter as TypeAdapter
from pydantic_core import CoreSchema, core_schema
from pydantic._internal._repr import display_as_type
from pydantic.fields import FieldInfo as BaseFieldInfo
Required = Ellipsis
"""Alias of Ellipsis for compatibility with pydantic v1"""
# Export undefined type
from pydantic_core import PydanticUndefined as PydanticUndefined
from pydantic_core import PydanticUndefinedType as PydanticUndefinedType
# isort: split
# Export model config dict
from pydantic import ConfigDict as ConfigDict
DEFAULT_CONFIG = ConfigDict(extra="allow", arbitrary_types_allowed=True)
"""Default config for validations"""
class FieldInfo(BaseFieldInfo):
"""FieldInfo class with extra property for compatibility with pydantic v1"""
# make default can be positional argument
def __init__(self, default: Any = PydanticUndefined, **kwargs: Any) -> None:
super().__init__(default=default, **kwargs)
@property
def extra(self) -> dict[str, Any]:
"""Extra data that is not part of the standard pydantic fields.
For compatibility with pydantic v1.
"""
# extract extra data from attributes set except used slots
# we need to call super in advance due to
# comprehension not inlined in cpython < 3.12
# https://peps.python.org/pep-0709/
slots = super().__slots__
return {k: v for k, v in self._attributes_set.items() if k not in slots}
@dataclass
class ModelField:
"""ModelField class for compatibility with pydantic v1"""
name: str
"""The name of the field."""
annotation: Any
"""The annotation of the field."""
field_info: FieldInfo
"""The FieldInfo of the field."""
@classmethod
def _construct(cls, name: str, annotation: Any, field_info: FieldInfo) -> Self:
return cls(name, annotation, field_info)
@classmethod
def construct(
cls, name: str, annotation: Any, field_info: Optional[FieldInfo] = None
) -> Self:
"""Construct a ModelField from given infos."""
return cls._construct(name, annotation, field_info or FieldInfo())
def __hash__(self) -> int:
# Each ModelField is unique for our purposes,
# to allow store them in a set.
return id(self)
@cached_property
def type_adapter(self) -> TypeAdapter:
"""TypeAdapter of the field.
Cache the TypeAdapter to avoid creating it multiple times.
Pydantic v2 uses too much cpu time to create TypeAdapter.
See: https://github.com/pydantic/pydantic/issues/9834
"""
return TypeAdapter(
Annotated[self.annotation, self.field_info],
config=None if self._annotation_has_config() else DEFAULT_CONFIG,
)
def _annotation_has_config(self) -> bool:
"""Check if the annotation has config.
TypeAdapter raise error when annotation has config
and given config is not None.
"""
type_is_annotated = origin_is_annotated(get_origin(self.annotation))
inner_type = (
get_args(self.annotation)[0] if type_is_annotated else self.annotation
)
try:
return (
issubclass(inner_type, BaseModel)
or is_dataclass(inner_type)
or is_typeddict(inner_type)
)
except TypeError:
return False
def get_default(self) -> Any:
"""Get the default value of the field."""
return self.field_info.get_default(call_default_factory=True)
def _type_display(self):
"""Get the display of the type of the field."""
return display_as_type(self.annotation)
def validate_value(self, value: Any) -> Any:
"""Validate the value pass to the field."""
return self.type_adapter.validate_python(value)
def extract_field_info(field_info: BaseFieldInfo) -> dict[str, Any]:
"""Get FieldInfo init kwargs from a FieldInfo instance."""
kwargs = field_info._attributes_set.copy()
kwargs["annotation"] = field_info.rebuild_annotation()
return kwargs
def model_fields(model: type[BaseModel]) -> list[ModelField]:
"""Get field list of a model."""
return [
ModelField._construct(
name=name,
annotation=field_info.rebuild_annotation(),
field_info=FieldInfo(**extract_field_info(field_info)),
)
for name, field_info in model.model_fields.items()
]
def model_config(model: type[BaseModel]) -> Any:
"""Get config of a model."""
return model.model_config
def model_dump(
model: BaseModel,
include: Optional[set[str]] = None,
exclude: Optional[set[str]] = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
) -> dict[str, Any]:
return model.model_dump(
include=include,
exclude=exclude,
by_alias=by_alias,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
)
def type_validate_python(type_: type[T], data: Any) -> T:
"""Validate data with given type."""
return TypeAdapter(type_).validate_python(data)
def type_validate_json(type_: type[T], data: Union[str, bytes]) -> T:
"""Validate JSON with given type."""
return TypeAdapter(type_).validate_json(data)
def __get_pydantic_core_schema__(
cls: type["_CustomValidationClass"],
source_type: Any,
handler: GetCoreSchemaHandler,
) -> CoreSchema:
validators = list(cls.__get_validators__())
if len(validators) == 1:
return core_schema.no_info_plain_validator_function(validators[0])
return core_schema.chain_schema(
[core_schema.no_info_plain_validator_function(func) for func in validators]
)
def custom_validation(class_: type["CVC"]) -> type["CVC"]:
"""Use pydantic v1 like validator generator in pydantic v2"""
setattr(
class_,
"__get_pydantic_core_schema__",
classmethod(__get_pydantic_core_schema__),
)
return class_
else: # pragma: pydantic-v1
from pydantic import Extra
from pydantic import parse_obj_as, parse_raw_as
from pydantic import BaseConfig as PydanticConfig
from pydantic.fields import FieldInfo as BaseFieldInfo
from pydantic.fields import ModelField as BaseModelField
from pydantic.schema import get_annotation_from_field_info
# isort: split
from pydantic.fields import Required as Required
# isort: split
from pydantic.fields import Undefined as PydanticUndefined
from pydantic.fields import UndefinedType as PydanticUndefinedType
class ConfigDict(PydanticConfig):
"""Config class that allow get value with default value."""
@classmethod
def get(cls, field: str, default: Any = None) -> Any:
"""Get a config value."""
return getattr(cls, field, default)
class DEFAULT_CONFIG(ConfigDict):
extra = Extra.allow
arbitrary_types_allowed = True
class FieldInfo(BaseFieldInfo):
def __init__(self, default: Any = PydanticUndefined, **kwargs: Any):
# preprocess default value to make it compatible with pydantic v2
# when default is Required, set it to PydanticUndefined
if default is Required:
default = PydanticUndefined
super().__init__(default, **kwargs)
class ModelField(BaseModelField):
@classmethod
def _construct(cls, name: str, annotation: Any, field_info: FieldInfo) -> Self:
return cls(
name=name,
type_=annotation,
class_validators=None,
model_config=DEFAULT_CONFIG,
default=field_info.default,
default_factory=field_info.default_factory,
required=(
field_info.default is PydanticUndefined
and field_info.default_factory is None
),
field_info=field_info,
)
@classmethod
def construct(
cls, name: str, annotation: Any, field_info: Optional[FieldInfo] = None
) -> Self:
"""Construct a ModelField from given infos.
Field annotation is preprocessed with field_info.
"""
if field_info is not None:
annotation = get_annotation_from_field_info(
annotation, field_info, name
)
return cls._construct(name, annotation, field_info or FieldInfo())
def validate_value(self, value: Any) -> Any:
"""Validate the value pass to the field."""
v, errs_ = self.validate(value, {}, loc=())
if errs_:
raise ValueError(value, self)
return v
class TypeAdapter(Generic[T]):
@overload
def __init__(
self,
type: type[T],
*,
config: Optional[ConfigDict] = ...,
) -> None: ...
@overload
def __init__(
self,
type: Any,
*,
config: Optional[ConfigDict] = ...,
) -> None: ...
def __init__(
self,
type: Any,
*,
config: Optional[ConfigDict] = None,
) -> None:
self.type = type
self.config = config
def validate_python(self, value: Any) -> T:
return type_validate_python(self.type, value)
def validate_json(self, value: Union[str, bytes]) -> T:
return type_validate_json(self.type, value)
def extract_field_info(field_info: BaseFieldInfo) -> dict[str, Any]:
"""Get FieldInfo init kwargs from a FieldInfo instance."""
kwargs = {
s: getattr(field_info, s) for s in field_info.__slots__ if s != "extra"
}
kwargs.update(field_info.extra)
return kwargs
def model_fields(model: type[BaseModel]) -> list[ModelField]:
"""Get field list of a model."""
# construct the model field without preprocess to avoid error
return [
ModelField._construct(
name=model_field.name,
annotation=model_field.annotation,
field_info=FieldInfo(
**extract_field_info(model_field.field_info),
),
)
for model_field in model.__fields__.values()
]
def model_config(model: type[BaseModel]) -> Any:
"""Get config of a model."""
return model.__config__
def model_dump(
model: BaseModel,
include: Optional[set[str]] = None,
exclude: Optional[set[str]] = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
) -> dict[str, Any]:
return model.dict(
include=include,
exclude=exclude,
by_alias=by_alias,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
)
def type_validate_python(type_: type[T], data: Any) -> T:
"""Validate data with given type."""
return parse_obj_as(type_, data)
def type_validate_json(type_: type[T], data: Union[str, bytes]) -> T:
"""Validate JSON with given type."""
return parse_raw_as(type_, data)
def custom_validation(class_: type["CVC"]) -> type["CVC"]:
"""Do nothing in pydantic v1"""
return class_

View File

@@ -1,79 +1,257 @@
"""本模块定义了 NoneBot 本身运行所需的配置项。 """本模块定义了 NoneBot 本身运行所需的配置项。
NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及 [`python-dotenv`](https://saurabh-kumar.com/python-dotenv/) 来读取配置。 NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及
[`python-dotenv`](https://saurabh-kumar.com/python-dotenv/) 来读取配置。
配置项需符合特殊格式或 json 序列化格式。详情见 [`pydantic Field Type`](https://pydantic-docs.helpmanual.io/usage/types/) 文档。 配置项需符合特殊格式或 json 序列化格式
详情见 [`pydantic Field Type`](https://pydantic-docs.helpmanual.io/usage/types/) 文档。
FrontMatter: FrontMatter:
sidebar_position: 1 sidebar_position: 1
description: nonebot.config 模块 description: nonebot.config 模块
""" """
import os import os
import abc
import json
from pathlib import Path
from datetime import timedelta from datetime import timedelta
from ipaddress import IPv4Address from ipaddress import IPv4Address
from typing import TYPE_CHECKING, Any, Set, Dict, Tuple, Union, Mapping, Optional from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, Union, Optional
from typing_extensions import TypeAlias, get_args, get_origin
from pydantic.utils import deep_update from dotenv import dotenv_values
from pydantic import Extra, Field, BaseSettings, IPvAnyAddress from pydantic import Field, BaseModel
from pydantic.env_settings import ( from pydantic.networks import IPvAnyAddress
DotenvType,
SettingsError,
EnvSettingsSource,
InitSettingsSource,
SettingsSourceCallable,
)
from nonebot.log import logger from nonebot.log import logger
from nonebot.typing import origin_is_union
from nonebot.utils import deep_update, type_is_complex, lenient_issubclass
from nonebot.compat import (
PYDANTIC_V2,
ConfigDict,
ModelField,
PydanticUndefined,
PydanticUndefinedType,
model_config,
model_fields,
)
DOTENV_TYPE: TypeAlias = Union[
Path, str, list[Union[Path, str]], tuple[Union[Path, str], ...]
]
ENV_FILE_SENTINEL = Path("")
class CustomEnvSettings(EnvSettingsSource): class SettingsError(ValueError): ...
def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
"""
Build environment variables suitable for passing to the Model.
"""
d: Dict[str, Any] = {}
if settings.__config__.case_sensitive:
env_vars: Mapping[str, Optional[str]] = os.environ # pragma: no cover
else:
env_vars = {k.lower(): v for k, v in os.environ.items()}
env_file_vars = self._read_env_files(settings.__config__.case_sensitive) class BaseSettingsSource(abc.ABC):
env_vars = {**env_file_vars, **env_vars} def __init__(self, settings_cls: type["BaseSettings"]) -> None:
self.settings_cls = settings_cls
for field in settings.__fields__.values(): @property
env_val: Optional[str] = None def config(self) -> "SettingsConfig":
for env_name in field.field_info.extra["env_names"]: return model_config(self.settings_cls)
env_val = env_vars.get(env_name)
if env_name in env_file_vars:
del env_file_vars[env_name]
if env_val is not None:
break
is_complex, allow_parse_failure = self.field_is_complex(field) @abc.abstractmethod
if is_complex: def __call__(self) -> dict[str, Any]:
if env_val is None: raise NotImplementedError
if env_val_built := self.explode_env_vars(field, env_vars):
d[field.alias] = env_val_built
else: class InitSettingsSource(BaseSettingsSource):
# field is complex and there's a value, decode that as JSON, then add explode_env_vars __slots__ = ("init_kwargs",)
def __init__(
self, settings_cls: type["BaseSettings"], init_kwargs: dict[str, Any]
) -> None:
self.init_kwargs = init_kwargs
super().__init__(settings_cls)
def __call__(self) -> dict[str, Any]:
return self.init_kwargs
def __repr__(self) -> str:
return f"InitSettingsSource(init_kwargs={self.init_kwargs!r})"
class DotEnvSettingsSource(BaseSettingsSource):
def __init__(
self,
settings_cls: type["BaseSettings"],
env_file: Optional[DOTENV_TYPE] = ENV_FILE_SENTINEL,
env_file_encoding: Optional[str] = None,
case_sensitive: Optional[bool] = None,
env_nested_delimiter: Optional[str] = None,
) -> None:
super().__init__(settings_cls)
self.env_file = (
env_file
if env_file is not ENV_FILE_SENTINEL
else self.config.get("env_file", (".env",))
)
self.env_file_encoding = (
env_file_encoding
if env_file_encoding is not None
else self.config.get("env_file_encoding", "utf-8")
)
self.case_sensitive = (
case_sensitive
if case_sensitive is not None
else self.config.get("case_sensitive", False)
)
self.env_nested_delimiter = (
env_nested_delimiter
if env_nested_delimiter is not None
else self.config.get("env_nested_delimiter", None)
)
def _apply_case_sensitive(self, var_name: str) -> str:
return var_name if self.case_sensitive else var_name.lower()
def _field_is_complex(self, field: ModelField) -> tuple[bool, bool]:
if type_is_complex(field.annotation):
return True, False
elif origin_is_union(get_origin(field.annotation)) and any(
type_is_complex(arg) for arg in get_args(field.annotation)
):
return True, True
return False, False
def _parse_env_vars(
self, env_vars: Mapping[str, Optional[str]]
) -> dict[str, Optional[str]]:
return {
self._apply_case_sensitive(key): value for key, value in env_vars.items()
}
def _read_env_file(self, file_path: Path) -> dict[str, Optional[str]]:
file_vars = dotenv_values(file_path, encoding=self.env_file_encoding)
return self._parse_env_vars(file_vars)
def _read_env_files(self) -> dict[str, Optional[str]]:
env_files = self.env_file
if env_files is None:
return {}
if isinstance(env_files, (str, os.PathLike)):
env_files = [env_files]
dotenv_vars: dict[str, Optional[str]] = {}
for env_file in env_files:
env_path = Path(env_file).expanduser()
if env_path.is_file():
dotenv_vars.update(self._read_env_file(env_path))
return dotenv_vars
def _next_field(
self, field: Optional[ModelField], key: str
) -> Optional[ModelField]:
if not field or origin_is_union(get_origin(field.annotation)):
return None
elif field.annotation and lenient_issubclass(field.annotation, BaseModel):
for field in model_fields(field.annotation):
if field.name == key:
return field
return None
def _explode_env_vars(
self,
field: ModelField,
env_vars: dict[str, Optional[str]],
env_file_vars: dict[str, Optional[str]],
) -> dict[str, Any]:
if self.env_nested_delimiter is None:
return {}
prefix = f"{field.name}{self.env_nested_delimiter}"
result: dict[str, Any] = {}
for env_name, env_val in env_vars.items():
if not env_name.startswith(prefix):
continue
# delete from file vars when used
if env_name in env_file_vars:
del env_file_vars[env_name]
_, *keys, last_key = env_name.split(self.env_nested_delimiter)
env_var = result
target_field: Optional[ModelField] = field
for key in keys:
target_field = self._next_field(target_field, key)
env_var = env_var.setdefault(key, {})
target_field = self._next_field(target_field, last_key)
if target_field and env_val:
is_complex, allow_parse_failure = self._field_is_complex(target_field)
if is_complex:
try: try:
env_val = settings.__config__.parse_env_var(field.name, env_val) env_val = json.loads(env_val)
except ValueError as e: except ValueError as e:
if not allow_parse_failure: if not allow_parse_failure:
raise SettingsError( raise SettingsError(
f'error parsing env var "{env_name}"' # type: ignore f'error parsing env var "{env_name}"'
) from e
env_var[last_key] = env_val
return result
def __call__(self) -> dict[str, Any]:
"""从环境变量和 dotenv 配置文件中读取配置项。"""
d: dict[str, Any] = {}
env_vars = self._parse_env_vars(os.environ)
env_file_vars = self._read_env_files()
env_vars = {**env_file_vars, **env_vars}
for field in model_fields(self.settings_cls):
field_name = field.name
env_name = self._apply_case_sensitive(field_name)
# try get values from env vars
env_val = env_vars.get(env_name, PydanticUndefined)
# delete from file vars when used
if env_name in env_file_vars:
del env_file_vars[env_name]
is_complex, allow_parse_failure = self._field_is_complex(field)
if is_complex:
if isinstance(env_val, PydanticUndefinedType):
# field is complex but no value found so far, try explode_env_vars
if env_val_built := self._explode_env_vars(
field, env_vars, env_file_vars
):
d[field_name] = env_val_built
elif env_val is None:
d[field_name] = env_val
else:
# field is complex and there's a value
# decode that as JSON, then add explode_env_vars
try:
env_val = json.loads(env_val)
except ValueError as e:
if not allow_parse_failure:
raise SettingsError(
f'error parsing env var "{env_name}"'
) from e ) from e
if isinstance(env_val, dict): if isinstance(env_val, dict):
d[field.alias] = deep_update( # field value is a dict
env_val, self.explode_env_vars(field, env_vars) # try explode_env_vars to find more sub-values
d[field_name] = deep_update(
env_val,
self._explode_env_vars(field, env_vars, env_file_vars),
) )
else: else:
d[field.alias] = env_val d[field_name] = env_val
elif env_val is not None: elif env_val is not PydanticUndefined:
# simplest case, field is not complex, we only need to add the value if it was found # simplest case, field is not complex
d[field.alias] = env_val # we only need to add the value if it was found
d[field_name] = env_val
# remain user custom config # remain user custom config
for env_name in env_file_vars: for env_name in env_file_vars:
@@ -81,8 +259,8 @@ class CustomEnvSettings(EnvSettingsSource):
if env_val and (val_striped := env_val.strip()): if env_val and (val_striped := env_val.strip()):
# there's a value, decode that as JSON # there's a value, decode that as JSON
try: try:
env_val = settings.__config__.parse_env_var(env_name, val_striped) env_val = json.loads(val_striped)
except ValueError as e: except ValueError:
logger.trace( logger.trace(
"Error while parsing JSON for " "Error while parsing JSON for "
f"{env_name!r}={val_striped!r}. " f"{env_name!r}={val_striped!r}. "
@@ -105,41 +283,83 @@ class CustomEnvSettings(EnvSettingsSource):
return d return d
class BaseConfig(BaseSettings): if PYDANTIC_V2: # pragma: pydantic-v2
class SettingsConfig(ConfigDict, total=False):
env_file: Optional[DOTENV_TYPE]
env_file_encoding: str
case_sensitive: bool
env_nested_delimiter: Optional[str]
else: # pragma: pydantic-v1
class SettingsConfig(ConfigDict):
env_file: Optional[DOTENV_TYPE]
env_file_encoding: str
case_sensitive: bool
env_nested_delimiter: Optional[str]
class BaseSettings(BaseModel):
if TYPE_CHECKING: if TYPE_CHECKING:
# dummy getattr for pylance checking, actually not used # dummy getattr for pylance checking, actually not used
def __getattr__(self, name: str) -> Any: # pragma: no cover def __getattr__(self, name: str) -> Any: # pragma: no cover
return self.__dict__.get(name) return self.__dict__.get(name)
class Config: if PYDANTIC_V2: # pragma: pydantic-v2
extra = Extra.allow model_config = SettingsConfig(
env_nested_delimiter = "__" extra="allow",
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
env_nested_delimiter="__",
)
else: # pragma: pydantic-v1
@classmethod class Config(SettingsConfig):
def customise_sources( extra = "allow" # type: ignore
cls, env_file = ".env"
init_settings: InitSettingsSource, env_file_encoding = "utf-8"
env_settings: EnvSettingsSource, case_sensitive = False
file_secret_settings: SettingsSourceCallable, env_nested_delimiter = "__"
) -> Tuple[SettingsSourceCallable, ...]:
common_config = init_settings.init_kwargs.pop("_common_config", {}) def __init__(
return ( __settings_self__, # pyright: ignore[reportSelfClsParameterName]
init_settings, _env_file: Optional[DOTENV_TYPE] = ENV_FILE_SENTINEL,
CustomEnvSettings( _env_file_encoding: Optional[str] = None,
env_settings.env_file, _env_nested_delimiter: Optional[str] = None,
env_settings.env_file_encoding, **values: Any,
env_settings.env_nested_delimiter, ) -> None:
env_settings.env_prefix_len, super().__init__(
), **__settings_self__._settings_build_values(
InitSettingsSource(common_config), values,
file_secret_settings, env_file=_env_file,
env_file_encoding=_env_file_encoding,
env_nested_delimiter=_env_nested_delimiter,
) )
)
def _settings_build_values(
self,
init_kwargs: dict[str, Any],
env_file: Optional[DOTENV_TYPE] = None,
env_file_encoding: Optional[str] = None,
env_nested_delimiter: Optional[str] = None,
) -> dict[str, Any]:
init_settings = InitSettingsSource(self.__class__, init_kwargs=init_kwargs)
env_settings = DotEnvSettingsSource(
self.__class__,
env_file=env_file,
env_file_encoding=env_file_encoding,
env_nested_delimiter=env_nested_delimiter,
)
return deep_update(env_settings(), init_settings())
class Env(BaseConfig): class Env(BaseSettings):
"""运行环境配置。大小写不敏感。 """运行环境配置。大小写不敏感。
将会从 `环境变量` > `.env 环境配置文件` 的优先级读取环境信息。 将会从 **环境变量** > **dotenv 配置文件** 的优先级读取环境信息。
""" """
environment: str = "prod" environment: str = "prod"
@@ -148,20 +368,18 @@ class Env(BaseConfig):
NoneBot 将从 `.env.{environment}` 文件中加载配置。 NoneBot 将从 `.env.{environment}` 文件中加载配置。
""" """
class Config:
env_file = ".env"
class Config(BaseSettings):
class Config(BaseConfig):
"""NoneBot 主要配置。大小写不敏感。 """NoneBot 主要配置。大小写不敏感。
除了 NoneBot 的配置项外,还可以自行添加配置项到 `.env.{environment}` 文件中。 除了 NoneBot 的配置项外,还可以自行添加配置项到 `.env.{environment}` 文件中。
这些配置将会在 json 反序列化后一起带入 `Config` 类中。 这些配置将会在 json 反序列化后一起带入 `Config` 类中。
配置方法参考: [配置](https://v2.nonebot.dev/docs/appendices/config) 配置方法参考: [配置](https://nonebot.dev/docs/appendices/config)
""" """
_env_file: DotenvType = ".env", ".env.prod" if TYPE_CHECKING:
_env_file: Optional[DOTENV_TYPE] = ".env", ".env.prod"
# nonebot configs # nonebot configs
driver: str = "~fastapi" driver: str = "~fastapi"
@@ -170,15 +388,17 @@ class Config(BaseConfig):
配置格式为 `<module>[:<Driver>][+<module>[:<Mixin>]]*`。 配置格式为 `<module>[:<Driver>][+<module>[:<Mixin>]]*`。
`~` 为 `nonebot.drivers.` 的缩写。 `~` 为 `nonebot.drivers.` 的缩写。
配置方法参考: [配置驱动器](https://nonebot.dev/docs/advanced/driver#%E9%85%8D%E7%BD%AE%E9%A9%B1%E5%8A%A8%E5%99%A8)
""" """
host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore
"""NoneBot {ref}`nonebot.drivers.ReverseDriver` 服务端监听的 IP/主机名。""" """NoneBot {ref}`nonebot.drivers.ReverseDriver` 服务端监听的 IP/主机名。"""
port: int = Field(default=8080, ge=1, le=65535) port: int = Field(default=8080, ge=1, le=65535)
"""NoneBot {ref}`nonebot.drivers.ReverseDriver` 服务端监听的端口。""" """NoneBot {ref}`nonebot.drivers.ReverseDriver` 服务端监听的端口。"""
log_level: Union[int, str] = "INFO" log_level: Union[int, str] = "INFO"
"""NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称 """NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称
参考 [`loguru 日志等级`](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。 参考 [记录日志](https://nonebot.dev/docs/appendices/log)[loguru 日志等级](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。
:::tip 提示 :::tip 提示
日志等级名称应为大写,如 `INFO`。 日志等级名称应为大写,如 `INFO`。
@@ -196,7 +416,7 @@ class Config(BaseConfig):
"""API 请求超时时间,单位: 秒。""" """API 请求超时时间,单位: 秒。"""
# bot runtime configs # bot runtime configs
superusers: Set[str] = set() superusers: set[str] = set()
"""机器人超级用户。 """机器人超级用户。
用法: 用法:
@@ -204,19 +424,23 @@ class Config(BaseConfig):
SUPERUSERS=["12345789"] SUPERUSERS=["12345789"]
``` ```
""" """
nickname: Set[str] = set() nickname: set[str] = set()
"""机器人昵称。""" """机器人昵称。"""
command_start: Set[str] = {"/"} command_start: set[str] = {"/"}
"""命令的起始标记,用于判断一条消息是不是命令。 """命令的起始标记,用于判断一条消息是不是命令。
参考[命令响应规则](https://nonebot.dev/docs/advanced/matcher#command)。
用法: 用法:
```conf ```conf
COMMAND_START=["/", ""] COMMAND_START=["/", ""]
``` ```
""" """
command_sep: Set[str] = {"."} command_sep: set[str] = {"."}
"""命令的分隔标记,用于将文本形式的命令切分为元组(实际的命令名)。 """命令的分隔标记,用于将文本形式的命令切分为元组(实际的命令名)。
参考[命令响应规则](https://nonebot.dev/docs/advanced/matcher#command)。
用法: 用法:
```conf ```conf
COMMAND_SEP=["."] COMMAND_SEP=["."]
@@ -227,9 +451,8 @@ class Config(BaseConfig):
用法: 用法:
```conf ```conf
SESSION_EXPIRE_TIMEOUT=120 # 单位: 秒 SESSION_EXPIRE_TIMEOUT=[-][DD]D[,][HH:MM:]SS[.ffffff]
SESSION_EXPIRE_TIMEOUT=[DD ][HH:MM]SS[.ffffff] SESSION_EXPIRE_TIMEOUT=[±]P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
SESSION_EXPIRE_TIMEOUT=P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
``` ```
""" """
@@ -240,11 +463,21 @@ class Config(BaseConfig):
# custom configs can be assigned during nonebot.init # custom configs can be assigned during nonebot.init
# or from env file using json loads # or from env file using json loads
class Config: if PYDANTIC_V2: # pragma: pydantic-v2
env_file = ".env", ".env.prod" model_config = SettingsConfig(env_file=(".env", ".env.prod"))
else: # pragma: pydantic-v1
class Config( # pyright: ignore[reportIncompatibleVariableOverride]
SettingsConfig
):
env_file = ".env", ".env.prod"
__autodoc__ = { __autodoc__ = {
"CustomEnvSettings": False, "SettingsError": False,
"BaseConfig": False, "BaseSettingsSource": False,
"InitSettingsSource": False,
"DotEnvSettingsSource": False,
"SettingsConfig": False,
"BaseSettings": False,
} }

View File

@@ -4,6 +4,7 @@ FrontMatter:
sidebar_position: 9 sidebar_position: 9
description: nonebot.consts 模块 description: nonebot.consts 模块
""" """
import os import os
import sys import sys
from typing import Literal from typing import Literal
@@ -42,12 +43,6 @@ SHELL_ARGV: Literal["_argv"] = "_argv"
REGEX_MATCHED: Literal["_matched"] = "_matched" REGEX_MATCHED: Literal["_matched"] = "_matched"
"""正则匹配结果存储 key""" """正则匹配结果存储 key"""
REGEX_STR: Literal["_matched_str"] = "_matched_str"
"""正则匹配文本存储 key"""
REGEX_GROUP: Literal["_matched_groups"] = "_matched_groups"
"""正则匹配 group 元组存储 key"""
REGEX_DICT: Literal["_matched_dict"] = "_matched_dict"
"""正则匹配 group 字典存储 key"""
STARTSWITH_KEY: Literal["_startswith"] = "_startswith" STARTSWITH_KEY: Literal["_startswith"] = "_startswith"
"""响应触发前缀 key""" """响应触发前缀 key"""
ENDSWITH_KEY: Literal["_endswith"] = "_endswith" ENDSWITH_KEY: Literal["_endswith"] = "_endswith"

View File

@@ -9,29 +9,14 @@ import abc
import asyncio import asyncio
import inspect import inspect
from dataclasses import field, dataclass from dataclasses import field, dataclass
from typing import ( from collections.abc import Iterable, Awaitable
Any, from typing import Any, Generic, TypeVar, Callable, Optional, cast
Dict,
List,
Type,
Tuple,
Generic,
TypeVar,
Callable,
Iterable,
Optional,
Awaitable,
cast,
)
from pydantic import BaseConfig
from pydantic.schema import get_annotation_from_field_info
from pydantic.fields import Required, FieldInfo, Undefined, ModelField
from nonebot.log import logger from nonebot.log import logger
from nonebot.typing import _DependentCallable from nonebot.typing import _DependentCallable
from nonebot.exception import SkippedException from nonebot.exception import SkippedException
from nonebot.utils import run_sync, is_coroutine_callable from nonebot.utils import run_sync, is_coroutine_callable
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
from .utils import check_field_type, get_typed_signature from .utils import check_field_type, get_typed_signature
@@ -45,15 +30,19 @@ class Param(abc.ABC, FieldInfo):
继承自 `pydantic.fields.FieldInfo`,用于描述参数信息(不包括参数名)。 继承自 `pydantic.fields.FieldInfo`,用于描述参数信息(不包括参数名)。
""" """
def __init__(self, *args, validate: bool = False, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.validate = validate
@classmethod @classmethod
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type["Param"], ...] cls, param: inspect.Parameter, allow_types: tuple[type["Param"], ...]
) -> Optional["Param"]: ) -> Optional["Param"]:
return return
@classmethod @classmethod
def _check_parameterless( def _check_parameterless(
cls, value: Any, allow_types: Tuple[Type["Param"], ...] cls, value: Any, allow_types: tuple[type["Param"], ...]
) -> Optional["Param"]: ) -> Optional["Param"]:
return return
@@ -65,10 +54,6 @@ class Param(abc.ABC, FieldInfo):
return return
class CustomConfig(BaseConfig):
arbitrary_types_allowed = True
@dataclass(frozen=True) @dataclass(frozen=True)
class Dependent(Generic[R]): class Dependent(Generic[R]):
"""依赖注入容器 """依赖注入容器
@@ -82,8 +67,8 @@ class Dependent(Generic[R]):
""" """
call: _DependentCallable[R] call: _DependentCallable[R]
params: Tuple[ModelField] = field(default_factory=tuple) params: tuple[ModelField, ...] = field(default_factory=tuple)
parameterless: Tuple[Param] = field(default_factory=tuple) parameterless: tuple[Param, ...] = field(default_factory=tuple)
def __repr__(self) -> str: def __repr__(self) -> str:
if inspect.isfunction(self.call) or inspect.isclass(self.call): if inspect.isfunction(self.call) or inspect.isclass(self.call):
@@ -97,60 +82,49 @@ class Dependent(Generic[R]):
) )
async def __call__(self, **kwargs: Any) -> R: async def __call__(self, **kwargs: Any) -> R:
# do pre-check try:
await self.check(**kwargs) # do pre-check
await self.check(**kwargs)
# solve param values # solve param values
values = await self.solve(**kwargs) values = await self.solve(**kwargs)
# call function # call function
if is_coroutine_callable(self.call): if is_coroutine_callable(self.call):
return await cast(Callable[..., Awaitable[R]], self.call)(**values) return await cast(Callable[..., Awaitable[R]], self.call)(**values)
else: else:
return await run_sync(cast(Callable[..., R], self.call))(**values) return await run_sync(cast(Callable[..., R], self.call))(**values)
except SkippedException as e:
logger.trace(f"{self} skipped due to {e}")
raise
@staticmethod @staticmethod
def parse_params( def parse_params(
call: _DependentCallable[R], allow_types: Tuple[Type[Param], ...] call: _DependentCallable[R], allow_types: tuple[type[Param], ...]
) -> Tuple[ModelField]: ) -> tuple[ModelField, ...]:
fields: List[ModelField] = [] fields: list[ModelField] = []
params = get_typed_signature(call).parameters.values() params = get_typed_signature(call).parameters.values()
for param in params: for param in params:
default_value = Required if isinstance(param.default, Param):
if param.default != param.empty: field_info = param.default
default_value = param.default
if isinstance(default_value, Param):
field_info = default_value
else: else:
for allow_type in allow_types: for allow_type in allow_types:
if field_info := allow_type._check_param(param, allow_types): if field_info := allow_type._check_param(param, allow_types):
break break
else: else:
raise ValueError( raise ValueError(
f"Unknown parameter {param.name} for function {call} with type {param.annotation}" f"Unknown parameter {param.name} "
f"for function {call} with type {param.annotation}"
) )
default_value = field_info.default
annotation: Any = Any annotation: Any = Any
required = default_value == Required if param.annotation is not param.empty:
if param.annotation != param.empty:
annotation = param.annotation annotation = param.annotation
annotation = get_annotation_from_field_info(
annotation, field_info, param.name
)
fields.append( fields.append(
ModelField( ModelField.construct(
name=param.name, name=param.name, annotation=annotation, field_info=field_info
type_=annotation,
class_validators=None,
model_config=CustomConfig,
default=None if required else default_value,
required=required,
field_info=field_info,
) )
) )
@@ -158,9 +132,9 @@ class Dependent(Generic[R]):
@staticmethod @staticmethod
def parse_parameterless( def parse_parameterless(
parameterless: Tuple[Any, ...], allow_types: Tuple[Type[Param], ...] parameterless: tuple[Any, ...], allow_types: tuple[type[Param], ...]
) -> Tuple[Param, ...]: ) -> tuple[Param, ...]:
parameterless_params: List[Param] = [] parameterless_params: list[Param] = []
for value in parameterless: for value in parameterless:
for allow_type in allow_types: for allow_type in allow_types:
if param := allow_type._check_parameterless(value, allow_types): if param := allow_type._check_parameterless(value, allow_types):
@@ -176,13 +150,13 @@ class Dependent(Generic[R]):
*, *,
call: _DependentCallable[R], call: _DependentCallable[R],
parameterless: Optional[Iterable[Any]] = None, parameterless: Optional[Iterable[Any]] = None,
allow_types: Iterable[Type[Param]], allow_types: Iterable[type[Param]],
) -> "Dependent[R]": ) -> "Dependent[R]":
allow_types = tuple(allow_types) allow_types = tuple(allow_types)
params = cls.parse_params(call, allow_types) params = cls.parse_params(call, allow_types)
parameterless_params = ( parameterless_params = (
tuple() ()
if parameterless is None if parameterless is None
else cls.parse_parameterless(tuple(parameterless), allow_types) else cls.parse_parameterless(tuple(parameterless), allow_types)
) )
@@ -190,27 +164,20 @@ class Dependent(Generic[R]):
return cls(call, params, parameterless_params) return cls(call, params, parameterless_params)
async def check(self, **params: Any) -> None: async def check(self, **params: Any) -> None:
try: await asyncio.gather(*(param._check(**params) for param in self.parameterless))
await asyncio.gather( await asyncio.gather(
*(param._check(**params) for param in self.parameterless) *(cast(Param, param.field_info)._check(**params) for param in self.params)
) )
await asyncio.gather(
*(
cast(Param, param.field_info)._check(**params)
for param in self.params
)
)
except SkippedException as e:
logger.trace(f"{self} skipped due to {e}")
raise
async def _solve_field(self, field: ModelField, params: Dict[str, Any]) -> Any: async def _solve_field(self, field: ModelField, params: dict[str, Any]) -> Any:
value = await cast(Param, field.field_info)._solve(**params) param = cast(Param, field.field_info)
if value is Undefined: value = await param._solve(**params)
if value is PydanticUndefined:
value = field.get_default() value = field.get_default()
return check_field_type(field, value) v = check_field_type(field, value)
return v if param.validate else value
async def solve(self, **params: Any) -> Dict[str, Any]: async def solve(self, **params: Any) -> dict[str, Any]:
# solve parameterless # solve parameterless
for param in self.parameterless: for param in self.parameterless:
await param._solve(**params) await param._solve(**params)

View File

@@ -3,20 +3,20 @@ FrontMatter:
sidebar_position: 1 sidebar_position: 1
description: nonebot.dependencies.utils 模块 description: nonebot.dependencies.utils 模块
""" """
import inspect import inspect
from typing import Any, Dict, TypeVar, Callable, ForwardRef from typing import Any, Callable, ForwardRef
from loguru import logger from loguru import logger
from pydantic.fields import ModelField
from pydantic.typing import evaluate_forwardref
from nonebot.compat import ModelField
from nonebot.exception import TypeMisMatch from nonebot.exception import TypeMisMatch
from nonebot.typing import evaluate_forwardref
V = TypeVar("V")
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature: def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
"""获取可调用对象签名""" """获取可调用对象签名"""
signature = inspect.signature(call) signature = inspect.signature(call)
globalns = getattr(call, "__globals__", {}) globalns = getattr(call, "__globals__", {})
typed_params = [ typed_params = [
@@ -31,8 +31,9 @@ def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
return inspect.Signature(typed_params) return inspect.Signature(typed_params)
def get_typed_annotation(param: inspect.Parameter, globalns: Dict[str, Any]) -> Any: def get_typed_annotation(param: inspect.Parameter, globalns: dict[str, Any]) -> Any:
"""获取参数的类型注解""" """获取参数的类型注解"""
annotation = param.annotation annotation = param.annotation
if isinstance(annotation, str): if isinstance(annotation, str):
annotation = ForwardRef(annotation) annotation = ForwardRef(annotation)
@@ -46,8 +47,10 @@ def get_typed_annotation(param: inspect.Parameter, globalns: Dict[str, Any]) ->
return annotation return annotation
def check_field_type(field: ModelField, value: V) -> V: def check_field_type(field: ModelField, value: Any) -> Any:
_, errs_ = field.validate(value, {}, loc=()) """检查字段类型是否匹配"""
if errs_:
try:
return field.validate_value(value)
except ValueError:
raise TypeMisMatch(field, value) raise TypeMisMatch(field, value)
return value

View File

@@ -8,30 +8,41 @@ FrontMatter:
""" """
from nonebot.internal.driver import URL as URL from nonebot.internal.driver import URL as URL
from nonebot.internal.driver import Mixin as Mixin
from nonebot.internal.driver import Driver as Driver from nonebot.internal.driver import Driver as Driver
from nonebot.internal.driver import Cookies as Cookies from nonebot.internal.driver import Cookies as Cookies
from nonebot.internal.driver import Request as Request from nonebot.internal.driver import Request as Request
from nonebot.internal.driver import Response as Response from nonebot.internal.driver import Response as Response
from nonebot.internal.driver import ASGIMixin as ASGIMixin
from nonebot.internal.driver import WebSocket as WebSocket from nonebot.internal.driver import WebSocket as WebSocket
from nonebot.internal.driver import HTTPVersion as HTTPVersion from nonebot.internal.driver import HTTPVersion as HTTPVersion
from nonebot.internal.driver import ForwardMixin as ForwardMixin from nonebot.internal.driver import ForwardMixin as ForwardMixin
from nonebot.internal.driver import ReverseMixin as ReverseMixin
from nonebot.internal.driver import ForwardDriver as ForwardDriver from nonebot.internal.driver import ForwardDriver as ForwardDriver
from nonebot.internal.driver import ReverseDriver as ReverseDriver from nonebot.internal.driver import ReverseDriver as ReverseDriver
from nonebot.internal.driver import combine_driver as combine_driver from nonebot.internal.driver import combine_driver as combine_driver
from nonebot.internal.driver import HTTPClientMixin as HTTPClientMixin
from nonebot.internal.driver import HTTPServerSetup as HTTPServerSetup from nonebot.internal.driver import HTTPServerSetup as HTTPServerSetup
from nonebot.internal.driver import HTTPClientSession as HTTPClientSession
from nonebot.internal.driver import WebSocketClientMixin as WebSocketClientMixin
from nonebot.internal.driver import WebSocketServerSetup as WebSocketServerSetup from nonebot.internal.driver import WebSocketServerSetup as WebSocketServerSetup
__autodoc__ = { __autodoc__ = {
"URL": True, "URL": True,
"Driver": True,
"Cookies": True, "Cookies": True,
"Request": True, "Request": True,
"Response": True, "Response": True,
"WebSocket": True, "WebSocket": True,
"HTTPVersion": True, "HTTPVersion": True,
"Driver": True,
"Mixin": True,
"ForwardMixin": True, "ForwardMixin": True,
"ForwardDriver": True, "ForwardDriver": True,
"HTTPClientMixin": True,
"WebSocketClientMixin": True,
"ReverseMixin": True,
"ReverseDriver": True, "ReverseDriver": True,
"ASGIMixin": True,
"combine_driver": True, "combine_driver": True,
"HTTPServerSetup": True, "HTTPServerSetup": True,
"WebSocketServerSetup": True, "WebSocketServerSetup": True,

View File

@@ -15,71 +15,150 @@ FrontMatter:
description: nonebot.drivers.aiohttp 模块 description: nonebot.drivers.aiohttp 模块
""" """
from typing import Type, AsyncGenerator from typing_extensions import override
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from typing import TYPE_CHECKING, Union, Optional
from multidict import CIMultiDict
from nonebot.typing import overrides
from nonebot.drivers import Request, Response
from nonebot.exception import WebSocketClosed from nonebot.exception import WebSocketClosed
from nonebot.drivers import URL, Request, Response
from nonebot.drivers.none import Driver as NoneDriver from nonebot.drivers.none import Driver as NoneDriver
from nonebot.drivers import WebSocket as BaseWebSocket from nonebot.drivers import WebSocket as BaseWebSocket
from nonebot.drivers import HTTPVersion, ForwardMixin, ForwardDriver, combine_driver from nonebot.internal.driver import Cookies, QueryTypes, CookieTypes, HeaderTypes
from nonebot.drivers import (
HTTPVersion,
HTTPClientMixin,
HTTPClientSession,
WebSocketClientMixin,
combine_driver,
)
try: try:
import aiohttp import aiohttp
except ModuleNotFoundError as e: # pragma: no cover except ModuleNotFoundError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install aiohttp first to use this driver. `pip install nonebot2[aiohttp]`" "Please install aiohttp first to use this driver. "
"Install with pip: `pip install nonebot2[aiohttp]`"
) from e ) from e
class Mixin(ForwardMixin): class Session(HTTPClientSession):
@override
def __init__(
self,
params: QueryTypes = None,
headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: Union[str, HTTPVersion] = HTTPVersion.H11,
timeout: Optional[float] = None,
proxy: Optional[str] = None,
):
self._client: Optional[aiohttp.ClientSession] = None
self._params = URL.build(query=params).query if params is not None else None
self._headers = CIMultiDict(headers) if headers is not None else None
self._cookies = tuple(
(cookie.name, cookie.value)
for cookie in Cookies(cookies)
if cookie.value is not None
)
version = HTTPVersion(version)
if version == HTTPVersion.H10:
self._version = aiohttp.HttpVersion10
elif version == HTTPVersion.H11:
self._version = aiohttp.HttpVersion11
else:
raise RuntimeError(f"Unsupported HTTP version: {version}")
self._timeout = timeout
self._proxy = proxy
@property
def client(self) -> aiohttp.ClientSession:
if self._client is None:
raise RuntimeError("Session is not initialized")
return self._client
@override
async def request(self, setup: Request) -> Response:
if self._params:
params = self._params.copy()
params.update(setup.url.query)
url = setup.url.with_query(params)
else:
url = setup.url
data = setup.data
if setup.files:
data = aiohttp.FormData(data or {}, quote_fields=False)
for name, file in setup.files:
data.add_field(name, file[1], content_type=file[2], filename=file[0])
cookies = (
(cookie.name, cookie.value)
for cookie in setup.cookies
if cookie.value is not None
)
timeout = aiohttp.ClientTimeout(setup.timeout)
async with await self.client.request(
setup.method,
url,
data=setup.content or data,
json=setup.json,
cookies=cookies,
headers=setup.headers,
proxy=setup.proxy or self._proxy,
timeout=timeout,
) as response:
return Response(
response.status,
headers=response.headers.copy(),
content=await response.read(),
request=setup,
)
@override
async def setup(self) -> None:
if self._client is not None:
raise RuntimeError("Session has already been initialized")
self._client = aiohttp.ClientSession(
cookies=self._cookies,
headers=self._headers,
version=self._version,
timeout=self._timeout,
trust_env=True,
)
await self._client.__aenter__()
@override
async def close(self) -> None:
try:
if self._client is not None:
await self._client.close()
finally:
self._client = None
class Mixin(HTTPClientMixin, WebSocketClientMixin):
"""AIOHTTP Mixin""" """AIOHTTP Mixin"""
@property @property
@overrides(ForwardMixin) @override
def type(self) -> str: def type(self) -> str:
return "aiohttp" return "aiohttp"
@overrides(ForwardMixin) @override
async def request(self, setup: Request) -> Response: async def request(self, setup: Request) -> Response:
if setup.version == HTTPVersion.H10: async with self.get_session() as session:
version = aiohttp.HttpVersion10 return await session.request(setup)
elif setup.version == HTTPVersion.H11:
version = aiohttp.HttpVersion11
else:
raise RuntimeError(f"Unsupported HTTP version: {setup.version}")
timeout = aiohttp.ClientTimeout(setup.timeout) @override
files = None
if setup.files:
files = aiohttp.FormData()
for name, file in setup.files:
files.add_field(name, file[1], content_type=file[2], filename=file[0])
cookies = {
cookie.name: cookie.value for cookie in setup.cookies if cookie.value
}
async with aiohttp.ClientSession(
cookies=cookies, version=version, trust_env=True
) as session:
async with session.request(
setup.method,
setup.url,
data=setup.content or setup.data or files,
json=setup.json,
headers=setup.headers,
timeout=timeout,
proxy=setup.proxy,
) as response:
return Response(
response.status,
headers=response.headers.copy(),
content=await response.read(),
request=setup,
)
@overrides(ForwardMixin)
@asynccontextmanager @asynccontextmanager
async def websocket(self, setup: Request) -> AsyncGenerator["WebSocket", None]: async def websocket(self, setup: Request) -> AsyncGenerator["WebSocket", None]:
if setup.version == HTTPVersion.H10: if setup.version == HTTPVersion.H10:
@@ -99,6 +178,25 @@ class Mixin(ForwardMixin):
) as ws: ) as ws:
yield WebSocket(request=setup, session=session, websocket=ws) yield WebSocket(request=setup, session=session, websocket=ws)
@override
def get_session(
self,
params: QueryTypes = None,
headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: Union[str, HTTPVersion] = HTTPVersion.H11,
timeout: Optional[float] = None,
proxy: Optional[str] = None,
) -> Session:
return Session(
params=params,
headers=headers,
cookies=cookies,
version=version,
timeout=timeout,
proxy=proxy,
)
class WebSocket(BaseWebSocket): class WebSocket(BaseWebSocket):
"""AIOHTTP Websocket Wrapper""" """AIOHTTP Websocket Wrapper"""
@@ -115,17 +213,17 @@ class WebSocket(BaseWebSocket):
self.websocket = websocket self.websocket = websocket
@property @property
@overrides(BaseWebSocket) @override
def closed(self): def closed(self):
return self.websocket.closed return self.websocket.closed
@overrides(BaseWebSocket) @override
async def accept(self): async def accept(self):
raise NotImplementedError raise NotImplementedError
@overrides(BaseWebSocket) @override
async def close(self, code: int = 1000): async def close(self, code: int = 1000, reason: str = ""):
await self.websocket.close(code=code) await self.websocket.close(code=code, message=reason.encode("utf-8"))
await self.session.close() await self.session.close()
async def _receive(self) -> aiohttp.WSMessage: async def _receive(self) -> aiohttp.WSMessage:
@@ -134,7 +232,7 @@ class WebSocket(BaseWebSocket):
raise WebSocketClosed(self.websocket.close_code or 1006) raise WebSocketClosed(self.websocket.close_code or 1006)
return msg return msg
@overrides(BaseWebSocket) @override
async def receive(self) -> str: async def receive(self) -> str:
msg = await self._receive() msg = await self._receive()
if msg.type not in (aiohttp.WSMsgType.TEXT, aiohttp.WSMsgType.BINARY): if msg.type not in (aiohttp.WSMsgType.TEXT, aiohttp.WSMsgType.BINARY):
@@ -143,7 +241,7 @@ class WebSocket(BaseWebSocket):
) )
return msg.data return msg.data
@overrides(BaseWebSocket) @override
async def receive_text(self) -> str: async def receive_text(self) -> str:
msg = await self._receive() msg = await self._receive()
if msg.type != aiohttp.WSMsgType.TEXT: if msg.type != aiohttp.WSMsgType.TEXT:
@@ -152,7 +250,7 @@ class WebSocket(BaseWebSocket):
) )
return msg.data return msg.data
@overrides(BaseWebSocket) @override
async def receive_bytes(self) -> bytes: async def receive_bytes(self) -> bytes:
msg = await self._receive() msg = await self._receive()
if msg.type != aiohttp.WSMsgType.BINARY: if msg.type != aiohttp.WSMsgType.BINARY:
@@ -161,14 +259,19 @@ class WebSocket(BaseWebSocket):
) )
return msg.data return msg.data
@overrides(BaseWebSocket) @override
async def send_text(self, data: str) -> None: async def send_text(self, data: str) -> None:
await self.websocket.send_str(data) await self.websocket.send_str(data)
@overrides(BaseWebSocket) @override
async def send_bytes(self, data: bytes) -> None: async def send_bytes(self, data: bytes) -> None:
await self.websocket.send_bytes(data) await self.websocket.send_bytes(data)
Driver: Type[ForwardDriver] = combine_driver(NoneDriver, Mixin) # type: ignore if TYPE_CHECKING:
"""AIOHTTP Driver"""
class Driver(Mixin, NoneDriver): ...
else:
Driver = combine_driver(NoneDriver, Mixin)
"""AIOHTTP Driver"""

View File

@@ -15,24 +15,24 @@ FrontMatter:
description: nonebot.drivers.fastapi 模块 description: nonebot.drivers.fastapi 模块
""" """
import logging import logging
import contextlib import contextlib
from functools import wraps from functools import wraps
from typing import Any, Dict, List, Tuple, Union, Optional from typing_extensions import override
from typing import Any, Union, Optional
from pydantic import BaseSettings from pydantic import BaseModel
from nonebot.config import Env from nonebot.config import Env
from nonebot.typing import overrides from nonebot.drivers import ASGIMixin
from nonebot.exception import WebSocketClosed from nonebot.exception import WebSocketClosed
from nonebot.internal.driver import FileTypes from nonebot.internal.driver import FileTypes
from nonebot.drivers import Driver as BaseDriver
from nonebot.config import Config as NoneBotConfig from nonebot.config import Config as NoneBotConfig
from nonebot.drivers import Request as BaseRequest from nonebot.drivers import Request as BaseRequest
from nonebot.drivers import WebSocket as BaseWebSocket from nonebot.drivers import WebSocket as BaseWebSocket
from nonebot.drivers import ReverseDriver, HTTPServerSetup, WebSocketServerSetup from nonebot.compat import model_dump, type_validate_python
from nonebot.drivers import HTTPServerSetup, WebSocketServerSetup
from ._lifespan import LIFESPAN_FUNC, Lifespan
try: try:
import uvicorn import uvicorn
@@ -41,7 +41,8 @@ try:
from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
except ModuleNotFoundError as e: # pragma: no cover except ModuleNotFoundError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install FastAPI by using `pip install nonebot2[fastapi]`" "Please install FastAPI first to use this driver. "
"Install with pip: `pip install nonebot2[fastapi]`"
) from e ) from e
@@ -58,7 +59,7 @@ def catch_closed(func):
return decorator return decorator
class Config(BaseSettings): class Config(BaseModel):
"""FastAPI 驱动框架设置,详情参考 FastAPI 文档""" """FastAPI 驱动框架设置,详情参考 FastAPI 文档"""
fastapi_openapi_url: Optional[str] = None fastapi_openapi_url: Optional[str] = None
@@ -71,30 +72,25 @@ class Config(BaseSettings):
"""是否包含适配器路由的 schema默认为 `True`""" """是否包含适配器路由的 schema默认为 `True`"""
fastapi_reload: bool = False fastapi_reload: bool = False
"""开启/关闭冷重载""" """开启/关闭冷重载"""
fastapi_reload_dirs: Optional[List[str]] = None fastapi_reload_dirs: Optional[list[str]] = None
"""重载监控文件夹列表,默认为 uvicorn 默认值""" """重载监控文件夹列表,默认为 uvicorn 默认值"""
fastapi_reload_delay: float = 0.25 fastapi_reload_delay: float = 0.25
"""重载延迟,默认为 uvicorn 默认值""" """重载延迟,默认为 uvicorn 默认值"""
fastapi_reload_includes: Optional[List[str]] = None fastapi_reload_includes: Optional[list[str]] = None
"""要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值""" """要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值"""
fastapi_reload_excludes: Optional[List[str]] = None fastapi_reload_excludes: Optional[list[str]] = None
"""不要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值""" """不要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值"""
fastapi_extra: Dict[str, Any] = {} fastapi_extra: dict[str, Any] = {}
"""传递给 `FastAPI` 的其他参数。""" """传递给 `FastAPI` 的其他参数。"""
class Config:
extra = "ignore"
class Driver(BaseDriver, ASGIMixin):
class Driver(ReverseDriver):
"""FastAPI 驱动框架。""" """FastAPI 驱动框架。"""
def __init__(self, env: Env, config: NoneBotConfig): def __init__(self, env: Env, config: NoneBotConfig):
super(Driver, self).__init__(env, config) super().__init__(env, config)
self.fastapi_config: Config = Config(**config.dict()) self.fastapi_config: Config = type_validate_python(Config, model_dump(config))
self._lifespan = Lifespan()
self._server_app = FastAPI( self._server_app = FastAPI(
lifespan=self._lifespan_manager, lifespan=self._lifespan_manager,
@@ -105,30 +101,30 @@ class Driver(ReverseDriver):
) )
@property @property
@overrides(ReverseDriver) @override
def type(self) -> str: def type(self) -> str:
"""驱动名称: `fastapi`""" """驱动名称: `fastapi`"""
return "fastapi" return "fastapi"
@property @property
@overrides(ReverseDriver) @override
def server_app(self) -> FastAPI: def server_app(self) -> FastAPI:
"""`FastAPI APP` 对象""" """`FastAPI APP` 对象"""
return self._server_app return self._server_app
@property @property
@overrides(ReverseDriver) @override
def asgi(self) -> FastAPI: def asgi(self) -> FastAPI:
"""`FastAPI APP` 对象""" """`FastAPI APP` 对象"""
return self._server_app return self._server_app
@property @property
@overrides(ReverseDriver) @override
def logger(self) -> logging.Logger: def logger(self) -> logging.Logger:
"""fastapi 使用的 logger""" """fastapi 使用的 logger"""
return logging.getLogger("fastapi") return logging.getLogger("fastapi")
@overrides(ReverseDriver) @override
def setup_http_server(self, setup: HTTPServerSetup): def setup_http_server(self, setup: HTTPServerSetup):
async def _handle(request: Request) -> Response: async def _handle(request: Request) -> Response:
return await self._handle_http(request, setup) return await self._handle_http(request, setup)
@@ -141,7 +137,7 @@ class Driver(ReverseDriver):
include_in_schema=self.fastapi_config.fastapi_include_adapter_schema, include_in_schema=self.fastapi_config.fastapi_include_adapter_schema,
) )
@overrides(ReverseDriver) @override
def setup_websocket_server(self, setup: WebSocketServerSetup) -> None: def setup_websocket_server(self, setup: WebSocketServerSetup) -> None:
async def _handle(websocket: WebSocket) -> None: async def _handle(websocket: WebSocket) -> None:
await self._handle_ws(websocket, setup) await self._handle_ws(websocket, setup)
@@ -152,14 +148,6 @@ class Driver(ReverseDriver):
name=setup.name, name=setup.name,
) )
@overrides(ReverseDriver)
def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
return self._lifespan.on_startup(func)
@overrides(ReverseDriver)
def on_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
return self._lifespan.on_shutdown(func)
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def _lifespan_manager(self, app: FastAPI): async def _lifespan_manager(self, app: FastAPI):
await self._lifespan.startup() await self._lifespan.startup()
@@ -168,17 +156,17 @@ class Driver(ReverseDriver):
finally: finally:
await self._lifespan.shutdown() await self._lifespan.shutdown()
@overrides(ReverseDriver) @override
def run( def run(
self, self,
host: Optional[str] = None, host: Optional[str] = None,
port: Optional[int] = None, port: Optional[int] = None,
*, *args,
app: Optional[str] = None, app: Optional[str] = None,
**kwargs, **kwargs,
): ):
"""使用 `uvicorn` 启动 FastAPI""" """使用 `uvicorn` 启动 FastAPI"""
super().run(host, port, app, **kwargs) super().run(host, port, app=app, **kwargs)
LOGGING_CONFIG = { LOGGING_CONFIG = {
"version": 1, "version": 1,
"disable_existing_loggers": False, "disable_existing_loggers": False,
@@ -218,7 +206,7 @@ class Driver(ReverseDriver):
json = await request.json() json = await request.json()
data: Optional[dict] = None data: Optional[dict] = None
files: Optional[List[Tuple[str, FileTypes]]] = None files: Optional[list[tuple[str, FileTypes]]] = None
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
form = await request.form() form = await request.form()
data = {} data = {}
@@ -267,30 +255,30 @@ class Driver(ReverseDriver):
class FastAPIWebSocket(BaseWebSocket): class FastAPIWebSocket(BaseWebSocket):
"""FastAPI WebSocket Wrapper""" """FastAPI WebSocket Wrapper"""
@overrides(BaseWebSocket) @override
def __init__(self, *, request: BaseRequest, websocket: WebSocket): def __init__(self, *, request: BaseRequest, websocket: WebSocket):
super().__init__(request=request) super().__init__(request=request)
self.websocket = websocket self.websocket = websocket
@property @property
@overrides(BaseWebSocket) @override
def closed(self) -> bool: def closed(self) -> bool:
return ( return (
self.websocket.client_state == WebSocketState.DISCONNECTED self.websocket.client_state == WebSocketState.DISCONNECTED
or self.websocket.application_state == WebSocketState.DISCONNECTED or self.websocket.application_state == WebSocketState.DISCONNECTED
) )
@overrides(BaseWebSocket) @override
async def accept(self) -> None: async def accept(self) -> None:
await self.websocket.accept() await self.websocket.accept()
@overrides(BaseWebSocket) @override
async def close( async def close(
self, code: int = status.WS_1000_NORMAL_CLOSURE, reason: str = "" self, code: int = status.WS_1000_NORMAL_CLOSURE, reason: str = ""
) -> None: ) -> None:
await self.websocket.close(code, reason) await self.websocket.close(code, reason)
@overrides(BaseWebSocket) @override
async def receive(self) -> Union[str, bytes]: async def receive(self) -> Union[str, bytes]:
# assert self.websocket.application_state == WebSocketState.CONNECTED # assert self.websocket.application_state == WebSocketState.CONNECTED
msg = await self.websocket.receive() msg = await self.websocket.receive()
@@ -298,21 +286,21 @@ class FastAPIWebSocket(BaseWebSocket):
raise WebSocketClosed(msg["code"]) raise WebSocketClosed(msg["code"])
return msg["text"] if "text" in msg else msg["bytes"] return msg["text"] if "text" in msg else msg["bytes"]
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive_text(self) -> str: async def receive_text(self) -> str:
return await self.websocket.receive_text() return await self.websocket.receive_text()
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive_bytes(self) -> bytes: async def receive_bytes(self) -> bytes:
return await self.websocket.receive_bytes() return await self.websocket.receive_bytes()
@overrides(BaseWebSocket) @override
async def send_text(self, data: str) -> None: async def send_text(self, data: str) -> None:
await self.websocket.send({"type": "websocket.send", "text": data}) await self.websocket.send({"type": "websocket.send", "text": data})
@overrides(BaseWebSocket) @override
async def send_bytes(self, data: bytes) -> None: async def send_bytes(self, data: bytes) -> None:
await self.websocket.send({"type": "websocket.send", "bytes": data}) await self.websocket.send({"type": "websocket.send", "bytes": data})

View File

@@ -14,18 +14,21 @@ FrontMatter:
sidebar_position: 3 sidebar_position: 3
description: nonebot.drivers.httpx 模块 description: nonebot.drivers.httpx 模块
""" """
from typing import Type, AsyncGenerator
from contextlib import asynccontextmanager
from nonebot.typing import overrides from typing_extensions import override
from typing import TYPE_CHECKING, Union, Optional
from multidict import CIMultiDict
from nonebot.drivers.none import Driver as NoneDriver from nonebot.drivers.none import Driver as NoneDriver
from nonebot.internal.driver import Cookies, QueryTypes, CookieTypes, HeaderTypes
from nonebot.drivers import ( from nonebot.drivers import (
URL,
Request, Request,
Response, Response,
WebSocket,
HTTPVersion, HTTPVersion,
ForwardMixin, HTTPClientMixin,
ForwardDriver, HTTPClientSession,
combine_driver, combine_driver,
) )
@@ -33,49 +36,123 @@ try:
import httpx import httpx
except ModuleNotFoundError as e: # pragma: no cover except ModuleNotFoundError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install httpx by using `pip install nonebot2[httpx]`" "Please install httpx first to use this driver. "
"Install with pip: `pip install nonebot2[httpx]`"
) from e ) from e
class Mixin(ForwardMixin): class Session(HTTPClientSession):
@override
def __init__(
self,
params: QueryTypes = None,
headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: Union[str, HTTPVersion] = HTTPVersion.H11,
timeout: Optional[float] = None,
proxy: Optional[str] = None,
):
self._client: Optional[httpx.AsyncClient] = None
self._params = (
tuple(URL.build(query=params).query.items()) if params is not None else None
)
self._headers = (
tuple(CIMultiDict(headers).items()) if headers is not None else None
)
self._cookies = Cookies(cookies)
self._version = HTTPVersion(version)
self._timeout = timeout
self._proxy = proxy
@property
def client(self) -> httpx.AsyncClient:
if self._client is None:
raise RuntimeError("Session is not initialized")
return self._client
@override
async def request(self, setup: Request) -> Response:
response = await self.client.request(
setup.method,
str(setup.url),
content=setup.content,
data=setup.data,
files=setup.files,
json=setup.json,
headers=tuple(setup.headers.items()),
cookies=setup.cookies.jar,
timeout=setup.timeout,
)
return Response(
response.status_code,
headers=response.headers.multi_items(),
content=response.content,
request=setup,
)
@override
async def setup(self) -> None:
if self._client is not None:
raise RuntimeError("Session has already been initialized")
self._client = httpx.AsyncClient(
params=self._params,
headers=self._headers,
cookies=self._cookies.jar,
http2=self._version == HTTPVersion.H2,
proxies=self._proxy,
follow_redirects=True,
)
await self._client.__aenter__()
@override
async def close(self) -> None:
try:
if self._client is not None:
await self._client.aclose()
finally:
self._client = None
class Mixin(HTTPClientMixin):
"""HTTPX Mixin""" """HTTPX Mixin"""
@property @property
@overrides(ForwardMixin) @override
def type(self) -> str: def type(self) -> str:
return "httpx" return "httpx"
@overrides(ForwardMixin) @override
async def request(self, setup: Request) -> Response: async def request(self, setup: Request) -> Response:
async with httpx.AsyncClient( async with self.get_session(
cookies=setup.cookies.jar, version=setup.version, proxy=setup.proxy
http2=setup.version == HTTPVersion.H2, ) as session:
proxies=setup.proxy, return await session.request(setup)
follow_redirects=True,
) as client:
response = await client.request(
setup.method,
str(setup.url),
content=setup.content,
data=setup.data,
json=setup.json,
files=setup.files,
headers=tuple(setup.headers.items()),
timeout=setup.timeout,
)
return Response(
response.status_code,
headers=response.headers.multi_items(),
content=response.content,
request=setup,
)
@overrides(ForwardMixin) @override
@asynccontextmanager def get_session(
async def websocket(self, setup: Request) -> AsyncGenerator[WebSocket, None]: self,
async with super(Mixin, self).websocket(setup) as ws: params: QueryTypes = None,
yield ws headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: Union[str, HTTPVersion] = HTTPVersion.H11,
timeout: Optional[float] = None,
proxy: Optional[str] = None,
) -> Session:
return Session(
params=params,
headers=headers,
cookies=cookies,
version=version,
timeout=timeout,
proxy=proxy,
)
Driver: Type[ForwardDriver] = combine_driver(NoneDriver, Mixin) # type: ignore if TYPE_CHECKING:
"""HTTPX Driver"""
class Driver(Mixin, NoneDriver): ...
else:
Driver = combine_driver(NoneDriver, Mixin)
"""HTTPX Driver"""

View File

@@ -9,19 +9,16 @@ FrontMatter:
description: nonebot.drivers.none 模块 description: nonebot.drivers.none 模块
""" """
import signal import signal
import asyncio import asyncio
import threading import threading
from typing_extensions import override
from nonebot.log import logger from nonebot.log import logger
from nonebot.consts import WINDOWS from nonebot.consts import WINDOWS
from nonebot.typing import overrides
from nonebot.config import Env, Config from nonebot.config import Env, Config
from nonebot.drivers import Driver as BaseDriver from nonebot.drivers import Driver as BaseDriver
from ._lifespan import LIFESPAN_FUNC, Lifespan
HANDLED_SIGNALS = ( HANDLED_SIGNALS = (
signal.SIGINT, # Unix signal 2. Sent by Ctrl+C. signal.SIGINT, # Unix signal 2. Sent by Ctrl+C.
signal.SIGTERM, # Unix signal 15. Sent by `kill <pid>`. signal.SIGTERM, # Unix signal 15. Sent by `kill <pid>`.
@@ -36,38 +33,22 @@ class Driver(BaseDriver):
def __init__(self, env: Env, config: Config): def __init__(self, env: Env, config: Config):
super().__init__(env, config) super().__init__(env, config)
self._lifespan = Lifespan()
self.should_exit: asyncio.Event = asyncio.Event() self.should_exit: asyncio.Event = asyncio.Event()
self.force_exit: bool = False self.force_exit: bool = False
@property @property
@overrides(BaseDriver) @override
def type(self) -> str: def type(self) -> str:
"""驱动名称: `none`""" """驱动名称: `none`"""
return "none" return "none"
@property @property
@overrides(BaseDriver) @override
def logger(self): def logger(self):
"""none driver 使用的 logger""" """none driver 使用的 logger"""
return logger return logger
@overrides(BaseDriver) @override
def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
"""
注册一个启动时执行的函数
"""
return self._lifespan.on_startup(func)
@overrides(BaseDriver)
def on_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
"""
注册一个停止时执行的函数
"""
return self._lifespan.on_shutdown(func)
@overrides(BaseDriver)
def run(self, *args, **kwargs): def run(self, *args, **kwargs):
"""启动 none driver""" """启动 none driver"""
super().run(*args, **kwargs) super().run(*args, **kwargs)
@@ -87,9 +68,11 @@ class Driver(BaseDriver):
await self._lifespan.startup() await self._lifespan.startup()
except Exception as e: except Exception as e:
logger.opt(colors=True, exception=e).error( logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running startup function. " "<r><bg #f8bbd0>Application startup failed. "
"Ignored!</bg #f8bbd0></r>" "Exiting.</bg #f8bbd0></r>"
) )
self.should_exit.set()
return
logger.info("Application startup completed.") logger.info("Application startup completed.")
@@ -146,7 +129,15 @@ class Driver(BaseDriver):
signal.signal(sig, self._handle_exit) signal.signal(sig, self._handle_exit)
def _handle_exit(self, sig, frame): def _handle_exit(self, sig, frame):
if self.should_exit.is_set(): self.exit(force=self.should_exit.is_set())
self.force_exit = True
else: def exit(self, force: bool = False):
"""退出 none driver
参数:
force: 强制退出
"""
if not self.should_exit.is_set():
self.should_exit.set() self.should_exit.set()
if force:
self.force_exit = True

View File

@@ -17,33 +17,36 @@ FrontMatter:
import asyncio import asyncio
from functools import wraps from functools import wraps
from typing import Any, Dict, List, Tuple, Union, TypeVar, Callable, Optional, Coroutine from typing_extensions import override
from typing import Any, Union, Optional, cast
from pydantic import BaseSettings from pydantic import BaseModel
from nonebot.config import Env from nonebot.config import Env
from nonebot.typing import overrides from nonebot.drivers import ASGIMixin
from nonebot.exception import WebSocketClosed from nonebot.exception import WebSocketClosed
from nonebot.internal.driver import FileTypes from nonebot.internal.driver import FileTypes
from nonebot.drivers import Driver as BaseDriver
from nonebot.config import Config as NoneBotConfig from nonebot.config import Config as NoneBotConfig
from nonebot.drivers import Request as BaseRequest from nonebot.drivers import Request as BaseRequest
from nonebot.drivers import WebSocket as BaseWebSocket from nonebot.drivers import WebSocket as BaseWebSocket
from nonebot.drivers import ReverseDriver, HTTPServerSetup, WebSocketServerSetup from nonebot.compat import model_dump, type_validate_python
from nonebot.drivers import HTTPServerSetup, WebSocketServerSetup
try: try:
import uvicorn import uvicorn
from quart import request as _request from quart import request as _request
from quart import websocket as _websocket from quart.ctx import WebsocketContext
from quart.globals import websocket_ctx
from quart import Quart, Request, Response from quart import Quart, Request, Response
from quart.datastructures import FileStorage from quart.datastructures import FileStorage
from quart import Websocket as QuartWebSocket from quart import Websocket as QuartWebSocket
except ModuleNotFoundError as e: # pragma: no cover except ModuleNotFoundError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install Quart by using `pip install nonebot2[quart]`" "Please install Quart first to use this driver. "
"Install with pip: `pip install nonebot2[quart]`"
) from e ) from e
_AsyncCallable = TypeVar("_AsyncCallable", bound=Callable[..., Coroutine])
def catch_closed(func): def catch_closed(func):
@wraps(func) @wraps(func)
@@ -56,63 +59,62 @@ def catch_closed(func):
return decorator return decorator
class Config(BaseSettings): class Config(BaseModel):
"""Quart 驱动框架设置""" """Quart 驱动框架设置"""
quart_reload: bool = False quart_reload: bool = False
"""开启/关闭冷重载""" """开启/关闭冷重载"""
quart_reload_dirs: Optional[List[str]] = None quart_reload_dirs: Optional[list[str]] = None
"""重载监控文件夹列表,默认为 uvicorn 默认值""" """重载监控文件夹列表,默认为 uvicorn 默认值"""
quart_reload_delay: float = 0.25 quart_reload_delay: float = 0.25
"""重载延迟,默认为 uvicorn 默认值""" """重载延迟,默认为 uvicorn 默认值"""
quart_reload_includes: Optional[List[str]] = None quart_reload_includes: Optional[list[str]] = None
"""要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值""" """要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值"""
quart_reload_excludes: Optional[List[str]] = None quart_reload_excludes: Optional[list[str]] = None
"""不要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值""" """不要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值"""
quart_extra: Dict[str, Any] = {} quart_extra: dict[str, Any] = {}
"""传递给 `Quart` 的其他参数。""" """传递给 `Quart` 的其他参数。"""
class Config:
extra = "ignore"
class Driver(BaseDriver, ASGIMixin):
class Driver(ReverseDriver):
"""Quart 驱动框架""" """Quart 驱动框架"""
def __init__(self, env: Env, config: NoneBotConfig): def __init__(self, env: Env, config: NoneBotConfig):
super().__init__(env, config) super().__init__(env, config)
self.quart_config = Config(**config.dict()) self.quart_config = type_validate_python(Config, model_dump(config))
self._server_app = Quart( self._server_app = Quart(
self.__class__.__qualname__, **self.quart_config.quart_extra self.__class__.__qualname__, **self.quart_config.quart_extra
) )
self._server_app.before_serving(self._lifespan.startup)
self._server_app.after_serving(self._lifespan.shutdown)
@property @property
@overrides(ReverseDriver) @override
def type(self) -> str: def type(self) -> str:
"""驱动名称: `quart`""" """驱动名称: `quart`"""
return "quart" return "quart"
@property @property
@overrides(ReverseDriver) @override
def server_app(self) -> Quart: def server_app(self) -> Quart:
"""`Quart` 对象""" """`Quart` 对象"""
return self._server_app return self._server_app
@property @property
@overrides(ReverseDriver) @override
def asgi(self): def asgi(self):
"""`Quart` 对象""" """`Quart` 对象"""
return self._server_app return self._server_app
@property @property
@overrides(ReverseDriver) @override
def logger(self): def logger(self):
"""Quart 使用的 logger""" """Quart 使用的 logger"""
return self._server_app.logger return self._server_app.logger
@overrides(ReverseDriver) @override
def setup_http_server(self, setup: HTTPServerSetup): def setup_http_server(self, setup: HTTPServerSetup):
async def _handle() -> Response: async def _handle() -> Response:
return await self._handle_http(setup) return await self._handle_http(setup)
@@ -124,7 +126,7 @@ class Driver(ReverseDriver):
view_func=_handle, view_func=_handle,
) )
@overrides(ReverseDriver) @override
def setup_websocket_server(self, setup: WebSocketServerSetup) -> None: def setup_websocket_server(self, setup: WebSocketServerSetup) -> None:
async def _handle() -> None: async def _handle() -> None:
return await self._handle_ws(setup) return await self._handle_ws(setup)
@@ -135,22 +137,12 @@ class Driver(ReverseDriver):
view_func=_handle, view_func=_handle,
) )
@overrides(ReverseDriver) @override
def on_startup(self, func: _AsyncCallable) -> _AsyncCallable:
"""参考文档: [`Startup and Shutdown`](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)"""
return self.server_app.before_serving(func) # type: ignore
@overrides(ReverseDriver)
def on_shutdown(self, func: _AsyncCallable) -> _AsyncCallable:
"""参考文档: [`Startup and Shutdown`](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)"""
return self.server_app.after_serving(func) # type: ignore
@overrides(ReverseDriver)
def run( def run(
self, self,
host: Optional[str] = None, host: Optional[str] = None,
port: Optional[int] = None, port: Optional[int] = None,
*, *args,
app: Optional[str] = None, app: Optional[str] = None,
**kwargs, **kwargs,
): ):
@@ -188,13 +180,11 @@ class Driver(ReverseDriver):
async def _handle_http(self, setup: HTTPServerSetup) -> Response: async def _handle_http(self, setup: HTTPServerSetup) -> Response:
request: Request = _request request: Request = _request
json = None json = await request.get_json() if request.is_json else None
if request.is_json:
json = await request.get_json()
data = await request.form data = await request.form
files_dict = await request.files files_dict = await request.files
files: List[Tuple[str, FileTypes]] = [] files: list[tuple[str, FileTypes]] = []
key: str key: str
value: FileStorage value: FileStorage
for key, value in files_dict.items(): for key, value in files_dict.items():
@@ -223,7 +213,8 @@ class Driver(ReverseDriver):
) )
async def _handle_ws(self, setup: WebSocketServerSetup) -> None: async def _handle_ws(self, setup: WebSocketServerSetup) -> None:
websocket: QuartWebSocket = _websocket ctx = cast(WebsocketContext, websocket_ctx.copy())
websocket = websocket_ctx.websocket
http_request = BaseRequest( http_request = BaseRequest(
websocket.method, websocket.method,
@@ -233,7 +224,7 @@ class Driver(ReverseDriver):
version=websocket.http_version, version=websocket.http_version,
) )
ws = WebSocket(request=http_request, websocket=websocket) ws = WebSocket(request=http_request, websocket_ctx=ctx)
await setup.handle_func(ws) await setup.handle_func(ws)
@@ -241,30 +232,34 @@ class Driver(ReverseDriver):
class WebSocket(BaseWebSocket): class WebSocket(BaseWebSocket):
"""Quart WebSocket Wrapper""" """Quart WebSocket Wrapper"""
def __init__(self, *, request: BaseRequest, websocket: QuartWebSocket): def __init__(self, *, request: BaseRequest, websocket_ctx: WebsocketContext):
super().__init__(request=request) super().__init__(request=request)
self.websocket = websocket self.websocket_ctx = websocket_ctx
@property @property
@overrides(BaseWebSocket) def websocket(self) -> QuartWebSocket:
return self.websocket_ctx.websocket
@property
@override
def closed(self): def closed(self):
# FIXME # FIXME
return True return True
@overrides(BaseWebSocket) @override
async def accept(self): async def accept(self):
await self.websocket.accept() await self.websocket.accept()
@overrides(BaseWebSocket) @override
async def close(self, code: int = 1000, reason: str = ""): async def close(self, code: int = 1000, reason: str = ""):
await self.websocket.close(code, reason) await self.websocket.close(code, reason)
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive(self) -> Union[str, bytes]: async def receive(self) -> Union[str, bytes]:
return await self.websocket.receive() return await self.websocket.receive()
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive_text(self) -> str: async def receive_text(self) -> str:
msg = await self.websocket.receive() msg = await self.websocket.receive()
@@ -272,7 +267,7 @@ class WebSocket(BaseWebSocket):
raise TypeError("WebSocket received unexpected frame type: bytes") raise TypeError("WebSocket received unexpected frame type: bytes")
return msg return msg
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive_bytes(self) -> bytes: async def receive_bytes(self) -> bytes:
msg = await self.websocket.receive() msg = await self.websocket.receive()
@@ -280,11 +275,11 @@ class WebSocket(BaseWebSocket):
raise TypeError("WebSocket received unexpected frame type: str") raise TypeError("WebSocket received unexpected frame type: str")
return msg return msg
@overrides(BaseWebSocket) @override
async def send_text(self, data: str): async def send_text(self, data: str):
await self.websocket.send(data) await self.websocket.send(data)
@overrides(BaseWebSocket) @override
async def send_bytes(self, data: bytes): async def send_bytes(self, data: bytes):
await self.websocket.send(data) await self.websocket.send(data)

View File

@@ -14,58 +14,59 @@ FrontMatter:
sidebar_position: 4 sidebar_position: 4
description: nonebot.drivers.websockets 模块 description: nonebot.drivers.websockets 模块
""" """
import logging import logging
from functools import wraps from functools import wraps
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from typing import Type, Union, AsyncGenerator from typing_extensions import ParamSpec, override
from collections.abc import Coroutine, AsyncGenerator
from typing import TYPE_CHECKING, Any, Union, TypeVar, Callable
from nonebot.typing import overrides from nonebot.drivers import Request
from nonebot.log import LoguruHandler from nonebot.log import LoguruHandler
from nonebot.drivers import Request, Response
from nonebot.exception import WebSocketClosed from nonebot.exception import WebSocketClosed
from nonebot.drivers.none import Driver as NoneDriver from nonebot.drivers.none import Driver as NoneDriver
from nonebot.drivers import WebSocket as BaseWebSocket from nonebot.drivers import WebSocket as BaseWebSocket
from nonebot.drivers import ForwardMixin, ForwardDriver, combine_driver from nonebot.drivers import WebSocketClientMixin, combine_driver
try: try:
from websockets.exceptions import ConnectionClosed from websockets.exceptions import ConnectionClosed
from websockets.legacy.client import Connect, WebSocketClientProtocol from websockets.legacy.client import Connect, WebSocketClientProtocol
except ModuleNotFoundError as e: # pragma: no cover except ModuleNotFoundError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install websockets by using `pip install nonebot2[websockets]`" "Please install websockets first to use this driver. "
"Install with pip: `pip install nonebot2[websockets]`"
) from e ) from e
T = TypeVar("T")
P = ParamSpec("P")
logger = logging.Logger("websockets.client", "INFO") logger = logging.Logger("websockets.client", "INFO")
logger.addHandler(LoguruHandler()) logger.addHandler(LoguruHandler())
def catch_closed(func): def catch_closed(
func: Callable[P, Coroutine[Any, Any, T]]
) -> Callable[P, Coroutine[Any, Any, T]]:
@wraps(func) @wraps(func)
async def decorator(*args, **kwargs): async def decorator(*args: P.args, **kwargs: P.kwargs) -> T:
try: try:
return await func(*args, **kwargs) return await func(*args, **kwargs)
except ConnectionClosed as e: except ConnectionClosed as e:
if e.rcvd_then_sent: raise WebSocketClosed(e.code, e.reason)
raise WebSocketClosed(e.rcvd.code, e.rcvd.reason) # type: ignore
else:
raise WebSocketClosed(e.sent.code, e.sent.reason) # type: ignore
return decorator return decorator
class Mixin(ForwardMixin): class Mixin(WebSocketClientMixin):
"""Websockets Mixin""" """Websockets Mixin"""
@property @property
@overrides(ForwardMixin) @override
def type(self) -> str: def type(self) -> str:
return "websockets" return "websockets"
@overrides(ForwardMixin) @override
async def request(self, setup: Request) -> Response:
return await super(Mixin, self).request(setup)
@overrides(ForwardMixin)
@asynccontextmanager @asynccontextmanager
async def websocket(self, setup: Request) -> AsyncGenerator["WebSocket", None]: async def websocket(self, setup: Request) -> AsyncGenerator["WebSocket", None]:
connection = Connect( connection = Connect(
@@ -80,30 +81,30 @@ class Mixin(ForwardMixin):
class WebSocket(BaseWebSocket): class WebSocket(BaseWebSocket):
"""Websockets WebSocket Wrapper""" """Websockets WebSocket Wrapper"""
@overrides(BaseWebSocket) @override
def __init__(self, *, request: Request, websocket: WebSocketClientProtocol): def __init__(self, *, request: Request, websocket: WebSocketClientProtocol):
super().__init__(request=request) super().__init__(request=request)
self.websocket = websocket self.websocket = websocket
@property @property
@overrides(BaseWebSocket) @override
def closed(self) -> bool: def closed(self) -> bool:
return self.websocket.closed return self.websocket.closed
@overrides(BaseWebSocket) @override
async def accept(self): async def accept(self):
raise NotImplementedError raise NotImplementedError
@overrides(BaseWebSocket) @override
async def close(self, code: int = 1000, reason: str = ""): async def close(self, code: int = 1000, reason: str = ""):
await self.websocket.close(code, reason) await self.websocket.close(code, reason)
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive(self) -> Union[str, bytes]: async def receive(self) -> Union[str, bytes]:
return await self.websocket.recv() return await self.websocket.recv()
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive_text(self) -> str: async def receive_text(self) -> str:
msg = await self.websocket.recv() msg = await self.websocket.recv()
@@ -111,7 +112,7 @@ class WebSocket(BaseWebSocket):
raise TypeError("WebSocket received unexpected frame type: bytes") raise TypeError("WebSocket received unexpected frame type: bytes")
return msg return msg
@overrides(BaseWebSocket) @override
@catch_closed @catch_closed
async def receive_bytes(self) -> bytes: async def receive_bytes(self) -> bytes:
msg = await self.websocket.recv() msg = await self.websocket.recv()
@@ -119,14 +120,19 @@ class WebSocket(BaseWebSocket):
raise TypeError("WebSocket received unexpected frame type: str") raise TypeError("WebSocket received unexpected frame type: str")
return msg return msg
@overrides(BaseWebSocket) @override
async def send_text(self, data: str) -> None: async def send_text(self, data: str) -> None:
await self.websocket.send(data) await self.websocket.send(data)
@overrides(BaseWebSocket) @override
async def send_bytes(self, data: bytes) -> None: async def send_bytes(self, data: bytes) -> None:
await self.websocket.send(data) await self.websocket.send(data)
Driver: Type[ForwardDriver] = combine_driver(NoneDriver, Mixin) # type: ignore if TYPE_CHECKING:
"""Websockets Driver"""
class Driver(Mixin, NoneDriver): ...
else:
Driver = combine_driver(NoneDriver, Mixin)
"""Websockets Driver"""

View File

@@ -31,7 +31,7 @@ FrontMatter:
from typing import Any, Optional from typing import Any, Optional
from pydantic.fields import ModelField from nonebot.compat import ModelField
class NoneBotException(Exception): class NoneBotException(Exception):
@@ -43,9 +43,9 @@ class NoneBotException(Exception):
# Rule Exception # Rule Exception
class ParserExit(NoneBotException): class ParserExit(NoneBotException):
"""{ref}`nonebot.rule.shell_command` 处理消息失败时返回的异常""" """{ref}`nonebot.rule.shell_command` 处理消息失败时返回的异常"""
def __init__(self, status: int = 0, message: Optional[str] = None): def __init__(self, status: int = 0, message: Optional[str] = None) -> None:
self.status = status self.status = status
self.message = message self.message = message
@@ -69,7 +69,7 @@ class IgnoredException(ProcessException):
reason: 忽略事件的原因 reason: 忽略事件的原因
""" """
def __init__(self, reason: Any): def __init__(self, reason: Any) -> None:
self.reason: Any = reason self.reason: Any = reason
def __repr__(self) -> str: def __repr__(self) -> str:
@@ -96,7 +96,7 @@ class SkippedException(ProcessException):
class TypeMisMatch(SkippedException): class TypeMisMatch(SkippedException):
"""当前 `Handler` 的参数类型不匹配。""" """当前 `Handler` 的参数类型不匹配。"""
def __init__(self, param: ModelField, value: Any): def __init__(self, param: ModelField, value: Any) -> None:
self.param: ModelField = param self.param: ModelField = param
self.value: Any = value self.value: Any = value
@@ -108,7 +108,8 @@ class TypeMisMatch(SkippedException):
class MockApiException(ProcessException): class MockApiException(ProcessException):
"""指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。可由 api hook 抛出。 """指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。
可由 api hook 抛出。
参数: 参数:
result: 返回的内容 result: 返回的内容
@@ -144,7 +145,8 @@ class MatcherException(NoneBotException):
class PausedException(MatcherException): class PausedException(MatcherException):
"""指示 NoneBot 结束当前 `Handler` 并等待下一条消息后继续下一个 `Handler`。可用于用户输入新信息。 """指示 NoneBot 结束当前 `Handler` 并等待下一条消息后继续下一个 `Handler`。
可用于用户输入新信息。
可以在 `Handler` 中通过 {ref}`nonebot.matcher.Matcher.pause` 抛出。 可以在 `Handler` 中通过 {ref}`nonebot.matcher.Matcher.pause` 抛出。
@@ -158,7 +160,8 @@ class PausedException(MatcherException):
class RejectedException(MatcherException): class RejectedException(MatcherException):
"""指示 NoneBot 结束当前 `Handler` 并等待下一条消息后重新运行当前 `Handler`。可用于用户重新输入。 """指示 NoneBot 结束当前 `Handler` 并等待下一条消息后重新运行当前 `Handler`。
可用于用户重新输入。
可以在 `Handler` 中通过 {ref}`nonebot.matcher.Matcher.reject` 抛出。 可以在 `Handler` 中通过 {ref}`nonebot.matcher.Matcher.reject` 抛出。
@@ -187,7 +190,7 @@ class FinishedException(MatcherException):
# Adapter Exceptions # Adapter Exceptions
class AdapterException(NoneBotException): class AdapterException(NoneBotException):
"""代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception` """代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception`
参数: 参数:
adapter_name: 标识 adapter adapter_name: 标识 adapter
@@ -210,7 +213,9 @@ class ApiNotAvailable(AdapterException):
class NetworkError(AdapterException): class NetworkError(AdapterException):
"""在网络出现问题时抛出,如: API 请求地址不正确, API 请求无返回或返回状态非正常等。""" """在网络出现问题时抛出,
如: API 请求地址不正确, API 请求无返回或返回状态非正常等。
"""
class ActionFailed(AdapterException): class ActionFailed(AdapterException):
@@ -219,13 +224,13 @@ class ActionFailed(AdapterException):
# Driver Exceptions # Driver Exceptions
class DriverException(NoneBotException): class DriverException(NoneBotException):
"""`Driver` 抛出的异常基类""" """`Driver` 抛出的异常基类"""
class WebSocketClosed(DriverException): class WebSocketClosed(DriverException):
"""WebSocket 连接已关闭""" """WebSocket 连接已关闭"""
def __init__(self, code: int, reason: Optional[str] = None): def __init__(self, code: int, reason: Optional[str] = None) -> None:
self.code = code self.code = code
self.reason = reason self.reason = reason

View File

@@ -1,16 +1,19 @@
import abc import abc
from typing import Any
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from typing import Any, Dict, AsyncGenerator
from nonebot.config import Config from nonebot.config import Config
from nonebot.internal.driver._lifespan import LIFESPAN_FUNC
from nonebot.internal.driver import ( from nonebot.internal.driver import (
Driver, Driver,
Request, Request,
Response, Response,
ASGIMixin,
WebSocket, WebSocket,
ForwardDriver, HTTPClientMixin,
ReverseDriver,
HTTPServerSetup, HTTPServerSetup,
WebSocketClientMixin,
WebSocketServerSetup, WebSocketServerSetup,
) )
@@ -30,7 +33,7 @@ class Adapter(abc.ABC):
def __init__(self, driver: Driver, **kwargs: Any): def __init__(self, driver: Driver, **kwargs: Any):
self.driver: Driver = driver self.driver: Driver = driver
"""{ref}`nonebot.drivers.Driver` 实例""" """{ref}`nonebot.drivers.Driver` 实例"""
self.bots: Dict[str, Bot] = {} self.bots: dict[str, Bot] = {}
"""本协议适配器已建立连接的 {ref}`nonebot.adapters.Bot` 实例""" """本协议适配器已建立连接的 {ref}`nonebot.adapters.Bot` 实例"""
def __repr__(self) -> str: def __repr__(self) -> str:
@@ -72,30 +75,33 @@ class Adapter(abc.ABC):
def setup_http_server(self, setup: HTTPServerSetup): def setup_http_server(self, setup: HTTPServerSetup):
"""设置一个 HTTP 服务器路由配置""" """设置一个 HTTP 服务器路由配置"""
if not isinstance(self.driver, ReverseDriver): if not isinstance(self.driver, ASGIMixin):
raise TypeError("Current driver does not support http server") raise TypeError("Current driver does not support http server")
self.driver.setup_http_server(setup) self.driver.setup_http_server(setup)
def setup_websocket_server(self, setup: WebSocketServerSetup): def setup_websocket_server(self, setup: WebSocketServerSetup):
"""设置一个 WebSocket 服务器路由配置""" """设置一个 WebSocket 服务器路由配置"""
if not isinstance(self.driver, ReverseDriver): if not isinstance(self.driver, ASGIMixin):
raise TypeError("Current driver does not support websocket server") raise TypeError("Current driver does not support websocket server")
self.driver.setup_websocket_server(setup) self.driver.setup_websocket_server(setup)
async def request(self, setup: Request) -> Response: async def request(self, setup: Request) -> Response:
"""进行一个 HTTP 客户端请求""" """进行一个 HTTP 客户端请求"""
if not isinstance(self.driver, ForwardDriver): if not isinstance(self.driver, HTTPClientMixin):
raise TypeError("Current driver does not support http client") raise TypeError("Current driver does not support http client")
return await self.driver.request(setup) return await self.driver.request(setup)
@asynccontextmanager @asynccontextmanager
async def websocket(self, setup: Request) -> AsyncGenerator[WebSocket, None]: async def websocket(self, setup: Request) -> AsyncGenerator[WebSocket, None]:
"""建立一个 WebSocket 客户端连接请求""" """建立一个 WebSocket 客户端连接请求"""
if not isinstance(self.driver, ForwardDriver): if not isinstance(self.driver, WebSocketClientMixin):
raise TypeError("Current driver does not support websocket client") raise TypeError("Current driver does not support websocket client")
async with self.driver.websocket(setup) as ws: async with self.driver.websocket(setup) as ws:
yield ws yield ws
def on_ready(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
return self.driver._lifespan.on_ready(func)
@abc.abstractmethod @abc.abstractmethod
async def _call_api(self, bot: Bot, api: str, **data: Any) -> Any: async def _call_api(self, bot: Bot, api: str, **data: Any) -> Any:
"""`Adapter` 实际调用 api 的逻辑实现函数,实现该方法以调用 api。 """`Adapter` 实际调用 api 的逻辑实现函数,实现该方法以调用 api。

View File

@@ -1,7 +1,7 @@
import abc import abc
import asyncio import asyncio
from functools import partial from functools import partial
from typing import TYPE_CHECKING, Any, Set, Union, Optional, Protocol from typing import TYPE_CHECKING, Any, Union, ClassVar, Optional, Protocol
from nonebot.log import logger from nonebot.log import logger
from nonebot.config import Config from nonebot.config import Config
@@ -14,8 +14,7 @@ if TYPE_CHECKING:
from .message import Message, MessageSegment from .message import Message, MessageSegment
class _ApiCall(Protocol): class _ApiCall(Protocol):
async def __call__(self, **kwargs: Any) -> Any: async def __call__(self, **kwargs: Any) -> Any: ...
...
class Bot(abc.ABC): class Bot(abc.ABC):
@@ -28,9 +27,9 @@ class Bot(abc.ABC):
self_id: 机器人 ID self_id: 机器人 ID
""" """
_calling_api_hook: Set[T_CallingAPIHook] = set() _calling_api_hook: ClassVar[set[T_CallingAPIHook]] = set()
"""call_api 时执行的函数""" """call_api 时执行的函数"""
_called_api_hook: Set[T_CalledAPIHook] = set() _called_api_hook: ClassVar[set[T_CalledAPIHook]] = set()
"""call_api 后执行的函数""" """call_api 后执行的函数"""
def __init__(self, adapter: "Adapter", self_id: str): def __init__(self, adapter: "Adapter", self_id: str):
@@ -106,7 +105,10 @@ class Bot(abc.ABC):
logger.debug("Running CalledAPI hooks...") logger.debug("Running CalledAPI hooks...")
await asyncio.gather(*coros) await asyncio.gather(*coros)
except MockApiException as e: except MockApiException as e:
# mock api result
result = e.result result = e.result
# ignore exception
exception = None
logger.debug( logger.debug(
f"Calling API {api} result is mocked. Return {result} instead." f"Calling API {api} result is mocked. Return {result} instead."
) )

View File

@@ -1,9 +1,10 @@
import abc import abc
from typing import Any, Type, TypeVar from typing import Any, TypeVar
from pydantic import BaseModel from pydantic import BaseModel
from nonebot.utils import DataclassEncoder from nonebot.utils import DataclassEncoder
from nonebot.compat import PYDANTIC_V2, ConfigDict
from .message import Message from .message import Message
@@ -13,15 +14,21 @@ E = TypeVar("E", bound="Event")
class Event(abc.ABC, BaseModel): class Event(abc.ABC, BaseModel):
"""Event 基类。提供获取关键信息的方法,其余信息可直接获取。""" """Event 基类。提供获取关键信息的方法,其余信息可直接获取。"""
class Config: if PYDANTIC_V2: # pragma: pydantic-v2
extra = "allow" model_config = ConfigDict(extra="allow")
json_encoders = {Message: DataclassEncoder} else: # pragma: pydantic-v1
@classmethod class Config(ConfigDict):
def validate(cls: Type["E"], value: Any) -> "E": extra = "allow" # type: ignore
if isinstance(value, Event) and not isinstance(value, cls): json_encoders = {Message: DataclassEncoder} # noqa: RUF012
raise TypeError(f"{value} is incompatible with Event type {cls}")
return super().validate(value) if not PYDANTIC_V2: # pragma: pydantic-v1
@classmethod
def validate(cls: type["E"], value: Any) -> "E":
if isinstance(value, Event) and not isinstance(value, cls):
raise TypeError(f"{value} is incompatible with Event type {cls}")
return super().validate(value)
@abc.abstractmethod @abc.abstractmethod
def get_type(self) -> str: def get_type(self) -> str:
@@ -44,10 +51,11 @@ class Event(abc.ABC, BaseModel):
def get_log_string(self) -> str: def get_log_string(self) -> str:
"""获取事件日志信息的方法。 """获取事件日志信息的方法。
通常你不需要修改这个方法,只有当希望 NoneBot 隐藏该事件日志时,可以抛出 `NoLogException` 异常。 通常你不需要修改这个方法,只有当希望 NoneBot 隐藏该事件日志时,
可以抛出 `NoLogException` 异常。
异常: 异常:
NoLogException: NoLogException: 希望 NoneBot 隐藏该事件日志
""" """
return f"[{self.get_event_name()}]: {self.get_event_description()}" return f"[{self.get_event_name()}]: {self.get_event_description()}"
@@ -58,7 +66,9 @@ class Event(abc.ABC, BaseModel):
@abc.abstractmethod @abc.abstractmethod
def get_session_id(self) -> str: def get_session_id(self) -> str:
"""获取会话 id 的方法,用于判断当前事件属于哪一个会话,通常是用户 id、群组 id 组合。""" """获取会话 id 的方法,用于判断当前事件属于哪一个会话,
通常是用户 id、群组 id 组合。
"""
raise NotImplementedError raise NotImplementedError
@abc.abstractmethod @abc.abstractmethod

View File

@@ -1,41 +1,40 @@
import abc import abc
from copy import deepcopy from copy import deepcopy
from typing_extensions import Self
from collections.abc import Iterable
from dataclasses import field, asdict, dataclass from dataclasses import field, asdict, dataclass
from typing import ( from typing import ( # noqa: UP035
Any, Any,
Dict,
List,
Type, Type,
Tuple,
Union, Union,
Generic, Generic,
TypeVar, TypeVar,
Iterable,
Optional, Optional,
SupportsIndex,
overload, overload,
) )
from pydantic import parse_obj_as from nonebot.compat import custom_validation, type_validate_python
from .template import MessageTemplate from .template import MessageTemplate
T = TypeVar("T")
TMS = TypeVar("TMS", bound="MessageSegment") TMS = TypeVar("TMS", bound="MessageSegment")
TM = TypeVar("TM", bound="Message") TM = TypeVar("TM", bound="Message")
@custom_validation
@dataclass @dataclass
class MessageSegment(abc.ABC, Generic[TM]): class MessageSegment(abc.ABC, Generic[TM]):
"""消息段基类""" """消息段基类"""
type: str type: str
"""消息段类型""" """消息段类型"""
data: Dict[str, Any] = field(default_factory=dict) data: dict[str, Any] = field(default_factory=dict)
"""消息段数据""" """消息段数据"""
@classmethod @classmethod
@abc.abstractmethod @abc.abstractmethod
def get_message_class(cls) -> Type[TM]: def get_message_class(cls) -> Type[TM]: # noqa: UP006
"""获取消息数组类型""" """获取消息数组类型"""
raise NotImplementedError raise NotImplementedError
@@ -47,7 +46,9 @@ class MessageSegment(abc.ABC, Generic[TM]):
def __len__(self) -> int: def __len__(self) -> int:
return len(str(self)) return len(str(self))
def __ne__(self: T, other: T) -> bool: def __ne__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: Self
) -> bool:
return not self == other return not self == other
def __add__(self: TMS, other: Union[str, TMS, Iterable[TMS]]) -> TM: def __add__(self: TMS, other: Union[str, TMS, Iterable[TMS]]) -> TM:
@@ -61,9 +62,11 @@ class MessageSegment(abc.ABC, Generic[TM]):
yield cls._validate yield cls._validate
@classmethod @classmethod
def _validate(cls, value): def _validate(cls, value) -> Self:
if isinstance(value, cls): if isinstance(value, cls):
return value return value
if isinstance(value, MessageSegment):
raise ValueError(f"Type {type(value)} can not be converted to {cls}")
if not isinstance(value, dict): if not isinstance(value, dict):
raise ValueError(f"Expected dict for MessageSegment, got {type(value)}") raise ValueError(f"Expected dict for MessageSegment, got {type(value)}")
if "type" not in value: if "type" not in value:
@@ -84,7 +87,10 @@ class MessageSegment(abc.ABC, Generic[TM]):
def items(self): def items(self):
return asdict(self).items() return asdict(self).items()
def copy(self: T) -> T: def join(self: TMS, iterable: Iterable[Union[TMS, TM]]) -> TM:
return self.get_message_class()(self).join(iterable)
def copy(self) -> Self:
return deepcopy(self) return deepcopy(self)
@abc.abstractmethod @abc.abstractmethod
@@ -93,8 +99,9 @@ class MessageSegment(abc.ABC, Generic[TM]):
raise NotImplementedError raise NotImplementedError
class Message(List[TMS], abc.ABC): @custom_validation
"""消息数组 class Message(list[TMS], abc.ABC):
"""消息序列
参数: 参数:
message: 消息内容 message: 消息内容
@@ -117,12 +124,12 @@ class Message(List[TMS], abc.ABC):
self.extend(self._construct(message)) # pragma: no cover self.extend(self._construct(message)) # pragma: no cover
@classmethod @classmethod
def template(cls: Type[TM], format_string: Union[str, TM]) -> MessageTemplate[TM]: def template(cls, format_string: Union[str, TM]) -> MessageTemplate[Self]:
"""创建消息模板。 """创建消息模板。
用法和 `str.format` 大致相同, 但是可以输出消息对象, 并且支持以 `Message` 对象作为消息模板 用法和 `str.format` 大致相同支持以 `Message` 对象作为消息模板并输出消息对象。
并且提供了拓展的格式化控制符,
并且提供了拓展的格式化控制符, 可以用适用于该消息类型的 `MessageSegment` 工厂方法创建消息 可以通过该消息类型的 `MessageSegment` 工厂方法创建消息
参数: 参数:
format_string: 格式化模板 format_string: 格式化模板
@@ -134,7 +141,7 @@ class Message(List[TMS], abc.ABC):
@classmethod @classmethod
@abc.abstractmethod @abc.abstractmethod
def get_segment_class(cls) -> Type[TMS]: def get_segment_class(cls) -> type[TMS]:
"""获取消息段类型""" """获取消息段类型"""
raise NotImplementedError raise NotImplementedError
@@ -146,7 +153,7 @@ class Message(List[TMS], abc.ABC):
yield cls._validate yield cls._validate
@classmethod @classmethod
def _validate(cls, value): def _validate(cls, value) -> Self:
if isinstance(value, cls): if isinstance(value, cls):
return value return value
elif isinstance(value, Message): elif isinstance(value, Message):
@@ -154,9 +161,9 @@ class Message(List[TMS], abc.ABC):
elif isinstance(value, str): elif isinstance(value, str):
pass pass
elif isinstance(value, dict): elif isinstance(value, dict):
value = parse_obj_as(cls.get_segment_class(), value) value = type_validate_python(cls.get_segment_class(), value)
elif isinstance(value, Iterable): elif isinstance(value, Iterable):
value = [parse_obj_as(cls.get_segment_class(), v) for v in value] value = [type_validate_python(cls.get_segment_class(), v) for v in value]
else: else:
raise ValueError( raise ValueError(
f"Expected str, dict or iterable for Message, got {type(value)}" f"Expected str, dict or iterable for Message, got {type(value)}"
@@ -169,16 +176,18 @@ class Message(List[TMS], abc.ABC):
"""构造消息数组""" """构造消息数组"""
raise NotImplementedError raise NotImplementedError
def __add__(self: TM, other: Union[str, TMS, Iterable[TMS]]) -> TM: def __add__( # pyright: ignore[reportIncompatibleMethodOverride]
self, other: Union[str, TMS, Iterable[TMS]]
) -> Self:
result = self.copy() result = self.copy()
result += other result += other
return result return result
def __radd__(self: TM, other: Union[str, TMS, Iterable[TMS]]) -> TM: def __radd__(self, other: Union[str, TMS, Iterable[TMS]]) -> Self:
result = self.__class__(other) result = self.__class__(other)
return result + self return result + self
def __iadd__(self: TM, other: Union[str, TMS, Iterable[TMS]]) -> TM: def __iadd__(self, other: Union[str, TMS, Iterable[TMS]]) -> Self:
if isinstance(other, str): if isinstance(other, str):
self.extend(self._construct(other)) self.extend(self._construct(other))
elif isinstance(other, MessageSegment): elif isinstance(other, MessageSegment):
@@ -190,65 +199,70 @@ class Message(List[TMS], abc.ABC):
return self return self
@overload @overload
def __getitem__(self: TM, __args: str) -> TM: def __getitem__(self, args: str) -> Self:
""" """获取仅包含指定消息段类型的消息
参数: 参数:
__args: 消息段类型 args: 消息段类型
返回: 返回:
所有类型为 `__args` 的消息段 所有类型为 `args` 的消息段
""" """
@overload @overload
def __getitem__(self, __args: Tuple[str, int]) -> TMS: def __getitem__(self, args: tuple[str, int]) -> TMS:
""" """索引指定类型的消息段
参数: 参数:
__args: 消息段类型和索引 args: 消息段类型和索引
返回: 返回:
类型为 `__args[0]` 的消息段第 `__args[1]` 个 类型为 `args[0]` 的消息段第 `args[1]` 个
""" """
@overload @overload
def __getitem__(self: TM, __args: Tuple[str, slice]) -> TM: def __getitem__(self, args: tuple[str, slice]) -> Self:
""" """切片指定类型的消息段
参数: 参数:
__args: 消息段类型和切片 args: 消息段类型和切片
返回: 返回:
类型为 `__args[0]` 的消息段切片 `__args[1]` 类型为 `args[0]` 的消息段切片 `args[1]`
""" """
@overload @overload
def __getitem__(self, __args: int) -> TMS: def __getitem__(self, args: int) -> TMS:
""" """索引消息段
参数: 参数:
__args: 索引 args: 索引
返回: 返回:
第 `__args` 个消息段 第 `args` 个消息段
""" """
@overload @overload
def __getitem__(self: TM, __args: slice) -> TM: def __getitem__(self, args: slice) -> Self:
""" """切片消息段
参数: 参数:
__args: 切片 args: 切片
返回: 返回:
消息切片 `__args` 消息切片 `args`
""" """
def __getitem__( def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride]
self: TM, self,
args: Union[ args: Union[
str, str,
Tuple[str, int], tuple[str, int],
Tuple[str, slice], tuple[str, slice],
int, int,
slice, slice,
], ],
) -> Union[TMS, TM]: ) -> Union[TMS, Self]:
arg1, arg2 = args if isinstance(args, tuple) else (args, None) arg1, arg2 = args if isinstance(args, tuple) else (args, None)
if isinstance(arg1, int) and arg2 is None: if isinstance(arg1, int) and arg2 is None:
return super().__getitem__(arg1) return super().__getitem__(arg1)
@@ -263,15 +277,54 @@ class Message(List[TMS], abc.ABC):
else: else:
raise ValueError("Incorrect arguments to slice") # pragma: no cover raise ValueError("Incorrect arguments to slice") # pragma: no cover
def index(self, value: Union[TMS, str], *args) -> int: def __contains__( # pyright: ignore[reportIncompatibleMethodOverride]
self, value: Union[TMS, str]
) -> bool:
"""检查消息段是否存在
参数:
value: 消息段或消息段类型
返回:
消息内是否存在给定消息段或给定类型的消息段
"""
if isinstance(value, str):
return next((seg for seg in self if seg.type == value), None) is not None
return super().__contains__(value)
def has(self, value: Union[TMS, str]) -> bool:
"""{ref}``__contains__` <nonebot.adapters.Message.__contains__>` 相同"""
return value in self
def index(self, value: Union[TMS, str], *args: SupportsIndex) -> int:
"""索引消息段
参数:
value: 消息段或者消息段类型
arg: start 与 end
返回:
索引 index
异常:
ValueError: 消息段不存在
"""
if isinstance(value, str): if isinstance(value, str):
first_segment = next((seg for seg in self if seg.type == value), None) first_segment = next((seg for seg in self if seg.type == value), None)
if first_segment is None: if first_segment is None:
raise ValueError(f"Segment with type {value} is not in message") raise ValueError(f"Segment with type {value!r} is not in message")
return super().index(first_segment, *args) return super().index(first_segment, *args)
return super().index(value, *args) return super().index(value, *args)
def get(self: TM, type_: str, count: Optional[int] = None) -> TM: def get(self, type_: str, count: Optional[int] = None) -> Self:
"""获取指定类型的消息段
参数:
type_: 消息段类型
count: 获取个数
返回:
构建的新消息
"""
if count is None: if count is None:
return self[type_] return self[type_]
@@ -286,9 +339,32 @@ class Message(List[TMS], abc.ABC):
return filtered return filtered
def count(self, value: Union[TMS, str]) -> int: def count(self, value: Union[TMS, str]) -> int:
"""计算指定消息段的个数
参数:
value: 消息段或消息段类型
返回:
个数
"""
return len(self[value]) if isinstance(value, str) else super().count(value) return len(self[value]) if isinstance(value, str) else super().count(value)
def append(self: TM, obj: Union[str, TMS]) -> TM: def only(self, value: Union[TMS, str]) -> bool:
"""检查消息中是否仅包含指定消息段
参数:
value: 指定消息段或消息段类型
返回:
是否仅包含指定消息段
"""
if isinstance(value, str):
return all(seg.type == value for seg in self)
return all(seg == value for seg in self)
def append( # pyright: ignore[reportIncompatibleMethodOverride]
self, obj: Union[str, TMS]
) -> Self:
"""添加一个消息段到消息数组末尾。 """添加一个消息段到消息数组末尾。
参数: 参数:
@@ -302,7 +378,9 @@ class Message(List[TMS], abc.ABC):
raise ValueError(f"Unexpected type: {type(obj)} {obj}") # pragma: no cover raise ValueError(f"Unexpected type: {type(obj)} {obj}") # pragma: no cover
return self return self
def extend(self: TM, obj: Union[TM, Iterable[TMS]]) -> TM: def extend( # pyright: ignore[reportIncompatibleMethodOverride]
self, obj: Union[Self, Iterable[TMS]]
) -> Self:
"""拼接一个消息数组或多个消息段到消息数组末尾。 """拼接一个消息数组或多个消息段到消息数组末尾。
参数: 参数:
@@ -312,18 +390,52 @@ class Message(List[TMS], abc.ABC):
self.append(segment) self.append(segment)
return self return self
def copy(self: TM) -> TM: def join(self, iterable: Iterable[Union[TMS, Self]]) -> Self:
"""将多个消息连接并将自身作为分割
参数:
iterable: 要连接的消息
返回:
连接后的消息
"""
ret = self.__class__()
for index, msg in enumerate(iterable):
if index != 0:
ret.extend(self)
if isinstance(msg, MessageSegment):
ret.append(msg.copy())
else:
ret.extend(msg.copy())
return ret
def copy(self) -> Self:
"""深拷贝消息"""
return deepcopy(self) return deepcopy(self)
def include(self, *types: str) -> Self:
"""过滤消息
参数:
types: 包含的消息段类型
返回:
新构造的消息
"""
return self.__class__(seg for seg in self if seg.type in types)
def exclude(self, *types: str) -> Self:
"""过滤消息
参数:
types: 不包含的消息段类型
返回:
新构造的消息
"""
return self.__class__(seg for seg in self if seg.type not in types)
def extract_plain_text(self) -> str: def extract_plain_text(self) -> str:
"""提取消息内纯文本消息""" """提取消息内纯文本消息"""
return "".join(str(seg) for seg in self if seg.is_text()) return "".join(str(seg) for seg in self if seg.is_text())
__autodoc__ = {
"MessageSegment.__str__": True,
"MessageSegment.__add__": True,
"Message.__getitem__": True,
"Message._construct": True,
}

View File

@@ -1,31 +1,33 @@
import functools import functools
from string import Formatter from string import Formatter
from typing_extensions import TypeAlias
from collections.abc import Mapping, Sequence
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
Set,
Dict,
List,
Type,
Tuple,
Union, Union,
Generic, Generic,
Mapping,
TypeVar, TypeVar,
Callable, Callable,
Optional, Optional,
Sequence,
cast, cast,
overload, overload,
) )
from _string import formatter_field_name_split # type: ignore
if TYPE_CHECKING: if TYPE_CHECKING:
from .message import Message, MessageSegment from .message import Message, MessageSegment
def formatter_field_name_split(
field_name: str,
) -> tuple[str, list[tuple[bool, str]]]: ...
TM = TypeVar("TM", bound="Message") TM = TypeVar("TM", bound="Message")
TF = TypeVar("TF", str, "Message") TF = TypeVar("TF", str, "Message")
FormatSpecFunc = Callable[[Any], str] FormatSpecFunc: TypeAlias = Callable[[Any], str]
FormatSpecFunc_T = TypeVar("FormatSpecFunc_T", bound=FormatSpecFunc) FormatSpecFunc_T = TypeVar("FormatSpecFunc_T", bound=FormatSpecFunc)
@@ -35,26 +37,35 @@ class MessageTemplate(Formatter, Generic[TF]):
参数: 参数:
template: 模板 template: 模板
factory: 消息类型工厂,默认为 `str` factory: 消息类型工厂,默认为 `str`
private_getattr: 是否允许在模板中访问私有属性,默认为 `False`
""" """
@overload @overload
def __init__( def __init__(
self: "MessageTemplate[str]", template: str, factory: Type[str] = str self: "MessageTemplate[str]",
) -> None: template: str,
... factory: type[str] = str,
private_getattr: bool = False,
) -> None: ...
@overload @overload
def __init__( def __init__(
self: "MessageTemplate[TM]", template: Union[str, TM], factory: Type[TM] self: "MessageTemplate[TM]",
) -> None: template: Union[str, TM],
... factory: type[TM],
private_getattr: bool = False,
) -> None: ...
def __init__( def __init__(
self, template: Union[str, TM], factory: Union[Type[str], Type[TM]] = str self,
template: Union[str, TM],
factory: Union[type[str], type[TM]] = str,
private_getattr: bool = False,
) -> None: ) -> None:
self.template: TF = template # type: ignore self.template: TF = template # type: ignore
self.factory: Type[TF] = factory # type: ignore self.factory: type[TF] = factory # type: ignore
self.format_specs: Dict[str, FormatSpecFunc] = {} self.format_specs: dict[str, FormatSpecFunc] = {}
self.private_getattr = private_getattr
def __repr__(self) -> str: def __repr__(self) -> str:
return f"MessageTemplate({self.template!r}, factory={self.factory!r})" return f"MessageTemplate({self.template!r}, factory={self.factory!r})"
@@ -68,7 +79,9 @@ class MessageTemplate(Formatter, Generic[TF]):
self.format_specs[name] = spec self.format_specs[name] = spec
return spec return spec
def format(self, *args, **kwargs): def format( # pyright: ignore[reportIncompatibleMethodOverride]
self, *args, **kwargs
) -> TF:
"""根据传入参数和模板生成消息对象""" """根据传入参数和模板生成消息对象"""
return self._format(args, kwargs) return self._format(args, kwargs)
@@ -101,7 +114,7 @@ class MessageTemplate(Formatter, Generic[TF]):
self.check_unused_args(used_args, args, kwargs) self.check_unused_args(used_args, args, kwargs)
return cast(TF, full_message) return cast(TF, full_message)
def vformat( def vformat( # pyright: ignore[reportIncompatibleMethodOverride]
self, self,
format_string: str, format_string: str,
args: Sequence[Any], args: Sequence[Any],
@@ -109,15 +122,15 @@ class MessageTemplate(Formatter, Generic[TF]):
) -> TF: ) -> TF:
raise NotImplementedError("`vformat` has merged into `_format`") raise NotImplementedError("`vformat` has merged into `_format`")
def _vformat( def _vformat( # pyright: ignore[reportIncompatibleMethodOverride]
self, self,
format_string: str, format_string: str,
args: Sequence[Any], args: Sequence[Any],
kwargs: Mapping[str, Any], kwargs: Mapping[str, Any],
used_args: Set[Union[int, str]], used_args: set[Union[int, str]],
auto_arg_index: int = 0, auto_arg_index: int = 0,
) -> Tuple[TF, int]: ) -> tuple[TF, int]:
results: List[Any] = [self.factory()] results: list[Any] = [self.factory()]
for literal_text, field_name, format_spec, conversion in self.parse( for literal_text, field_name, format_spec, conversion in self.parse(
format_string format_string
@@ -166,10 +179,23 @@ class MessageTemplate(Formatter, Generic[TF]):
return functools.reduce(self._add, results), auto_arg_index return functools.reduce(self._add, results), auto_arg_index
def get_field(
self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]
) -> tuple[Any, Union[int, str]]:
first, rest = formatter_field_name_split(field_name)
obj = self.get_value(first, args, kwargs)
for is_attr, value in rest:
if not self.private_getattr and value.startswith("_"):
raise ValueError("Cannot access private attribute")
obj = getattr(obj, value) if is_attr else obj[value]
return obj, first
def format_field(self, value: Any, format_spec: str) -> Any: def format_field(self, value: Any, format_spec: str) -> Any:
formatter: Optional[FormatSpecFunc] = self.format_specs.get(format_spec) formatter: Optional[FormatSpecFunc] = self.format_specs.get(format_spec)
if formatter is None and not issubclass(self.factory, str): if formatter is None and not issubclass(self.factory, str):
segment_class: Type["MessageSegment"] = self.factory.get_segment_class() segment_class: type["MessageSegment"] = self.factory.get_segment_class()
method = getattr(segment_class, format_spec, None) method = getattr(segment_class, format_spec, None)
if callable(method) and not cast(str, method.__name__).startswith("_"): if callable(method) and not cast(str, method.__name__).startswith("_"):
formatter = getattr(segment_class, format_spec) formatter = getattr(segment_class, format_spec)

View File

@@ -1,8 +1,9 @@
from .model import URL as URL from .model import URL as URL
from .model import RawURL as RawURL from .model import RawURL as RawURL
from .driver import Driver as Driver from .abstract import Mixin as Mixin
from .model import Cookies as Cookies from .model import Cookies as Cookies
from .model import Request as Request from .model import Request as Request
from .abstract import Driver as Driver
from .model import FileType as FileType from .model import FileType as FileType
from .model import Response as Response from .model import Response as Response
from .model import DataTypes as DataTypes from .model import DataTypes as DataTypes
@@ -10,16 +11,21 @@ from .model import FileTypes as FileTypes
from .model import WebSocket as WebSocket from .model import WebSocket as WebSocket
from .model import FilesTypes as FilesTypes from .model import FilesTypes as FilesTypes
from .model import QueryTypes as QueryTypes from .model import QueryTypes as QueryTypes
from .abstract import ASGIMixin as ASGIMixin
from .model import CookieTypes as CookieTypes from .model import CookieTypes as CookieTypes
from .model import FileContent as FileContent from .model import FileContent as FileContent
from .model import HTTPVersion as HTTPVersion from .model import HTTPVersion as HTTPVersion
from .model import HeaderTypes as HeaderTypes from .model import HeaderTypes as HeaderTypes
from .model import SimpleQuery as SimpleQuery from .model import SimpleQuery as SimpleQuery
from .model import ContentTypes as ContentTypes from .model import ContentTypes as ContentTypes
from .driver import ForwardMixin as ForwardMixin
from .model import QueryVariable as QueryVariable from .model import QueryVariable as QueryVariable
from .driver import ForwardDriver as ForwardDriver from .abstract import ForwardMixin as ForwardMixin
from .driver import ReverseDriver as ReverseDriver from .abstract import ReverseMixin as ReverseMixin
from .driver import combine_driver as combine_driver from .abstract import ForwardDriver as ForwardDriver
from .abstract import ReverseDriver as ReverseDriver
from .combine import combine_driver as combine_driver
from .model import HTTPServerSetup as HTTPServerSetup from .model import HTTPServerSetup as HTTPServerSetup
from .abstract import HTTPClientMixin as HTTPClientMixin
from .abstract import HTTPClientSession as HTTPClientSession
from .model import WebSocketServerSetup as WebSocketServerSetup from .model import WebSocketServerSetup as WebSocketServerSetup
from .abstract import WebSocketClientMixin as WebSocketClientMixin

View File

@@ -1,16 +1,19 @@
from typing import Any, List, Union, Callable, Awaitable, cast from collections.abc import Awaitable
from typing_extensions import TypeAlias
from typing import Any, Union, Callable, cast
from nonebot.utils import run_sync, is_coroutine_callable from nonebot.utils import run_sync, is_coroutine_callable
SYNC_LIFESPAN_FUNC = Callable[[], Any] SYNC_LIFESPAN_FUNC: TypeAlias = Callable[[], Any]
ASYNC_LIFESPAN_FUNC = Callable[[], Awaitable[Any]] ASYNC_LIFESPAN_FUNC: TypeAlias = Callable[[], Awaitable[Any]]
LIFESPAN_FUNC = Union[SYNC_LIFESPAN_FUNC, ASYNC_LIFESPAN_FUNC] LIFESPAN_FUNC: TypeAlias = Union[SYNC_LIFESPAN_FUNC, ASYNC_LIFESPAN_FUNC]
class Lifespan: class Lifespan:
def __init__(self) -> None: def __init__(self) -> None:
self._startup_funcs: List[LIFESPAN_FUNC] = [] self._startup_funcs: list[LIFESPAN_FUNC] = []
self._shutdown_funcs: List[LIFESPAN_FUNC] = [] self._ready_funcs: list[LIFESPAN_FUNC] = []
self._shutdown_funcs: list[LIFESPAN_FUNC] = []
def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC: def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
self._startup_funcs.append(func) self._startup_funcs.append(func)
@@ -20,9 +23,13 @@ class Lifespan:
self._shutdown_funcs.append(func) self._shutdown_funcs.append(func)
return func return func
def on_ready(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
self._ready_funcs.append(func)
return func
@staticmethod @staticmethod
async def _run_lifespan_func( async def _run_lifespan_func(
funcs: List[LIFESPAN_FUNC], funcs: list[LIFESPAN_FUNC],
) -> None: ) -> None:
for func in funcs: for func in funcs:
if is_coroutine_callable(func): if is_coroutine_callable(func):
@@ -34,6 +41,9 @@ class Lifespan:
if self._startup_funcs: if self._startup_funcs:
await self._run_lifespan_func(self._startup_funcs) await self._run_lifespan_func(self._startup_funcs)
if self._ready_funcs:
await self._run_lifespan_func(self._ready_funcs)
async def shutdown(self) -> None: async def shutdown(self) -> None:
if self._shutdown_funcs: if self._shutdown_funcs:
await self._run_lifespan_func(self._shutdown_funcs) await self._run_lifespan_func(self._shutdown_funcs)

View File

@@ -1,7 +1,10 @@
import abc import abc
import asyncio import asyncio
from types import TracebackType
from collections.abc import AsyncGenerator
from typing_extensions import Self, TypeAlias
from contextlib import AsyncExitStack, asynccontextmanager from contextlib import AsyncExitStack, asynccontextmanager
from typing import TYPE_CHECKING, Any, Set, Dict, Type, Callable, AsyncGenerator from typing import TYPE_CHECKING, Any, Union, ClassVar, Optional
from nonebot.log import logger from nonebot.log import logger
from nonebot.config import Env, Config from nonebot.config import Env, Config
@@ -15,7 +18,18 @@ from nonebot.typing import (
T_BotDisconnectionHook, T_BotDisconnectionHook,
) )
from .model import Request, Response, WebSocket, HTTPServerSetup, WebSocketServerSetup from ._lifespan import LIFESPAN_FUNC, Lifespan
from .model import (
Request,
Response,
WebSocket,
QueryTypes,
CookieTypes,
HeaderTypes,
HTTPVersion,
HTTPServerSetup,
WebSocketServerSetup,
)
if TYPE_CHECKING: if TYPE_CHECKING:
from nonebot.internal.adapter import Bot, Adapter from nonebot.internal.adapter import Bot, Adapter
@@ -25,18 +39,20 @@ BOT_HOOK_PARAMS = [DependParam, BotParam, DefaultParam]
class Driver(abc.ABC): class Driver(abc.ABC):
"""Driver 基类。 """驱动器基类。
驱动器控制框架的启动和停止适配器的注册以及机器人生命周期管理
参数: 参数:
env: 包含环境信息的 Env 对象 env: 包含环境信息的 Env 对象
config: 包含配置信息的 Config 对象 config: 包含配置信息的 Config 对象
""" """
_adapters: Dict[str, "Adapter"] = {} _adapters: ClassVar[dict[str, "Adapter"]] = {}
"""已注册的适配器列表""" """已注册的适配器列表"""
_bot_connection_hook: Set[Dependent[Any]] = set() _bot_connection_hook: ClassVar[set[Dependent[Any]]] = set()
"""Bot 连接建立时执行的函数""" """Bot 连接建立时执行的函数"""
_bot_disconnection_hook: Set[Dependent[Any]] = set() _bot_disconnection_hook: ClassVar[set[Dependent[Any]]] = set()
"""Bot 连接断开时执行的函数""" """Bot 连接断开时执行的函数"""
def __init__(self, env: Env, config: Config): def __init__(self, env: Env, config: Config):
@@ -44,7 +60,9 @@ class Driver(abc.ABC):
"""环境名称""" """环境名称"""
self.config: Config = config self.config: Config = config
"""全局配置对象""" """全局配置对象"""
self._bots: Dict[str, "Bot"] = {} self._bots: dict[str, "Bot"] = {}
self._bot_tasks: set[asyncio.Task] = set()
self._lifespan = Lifespan()
def __repr__(self) -> str: def __repr__(self) -> str:
return ( return (
@@ -53,11 +71,11 @@ class Driver(abc.ABC):
) )
@property @property
def bots(self) -> Dict[str, "Bot"]: def bots(self) -> dict[str, "Bot"]:
"""获取当前所有已连接的 Bot""" """获取当前所有已连接的 Bot"""
return self._bots return self._bots
def register_adapter(self, adapter: Type["Adapter"], **kwargs) -> None: def register_adapter(self, adapter: type["Adapter"], **kwargs) -> None:
"""注册一个协议适配器 """注册一个协议适配器
参数: 参数:
@@ -89,22 +107,20 @@ class Driver(abc.ABC):
@abc.abstractmethod @abc.abstractmethod
def run(self, *args, **kwargs): def run(self, *args, **kwargs):
""" """启动驱动框架"""
启动驱动框架
"""
logger.opt(colors=True).debug( logger.opt(colors=True).debug(
f"<g>Loaded adapters: {escape_tag(', '.join(self._adapters))}</g>" f"<g>Loaded adapters: {escape_tag(', '.join(self._adapters))}</g>"
) )
@abc.abstractmethod self.on_shutdown(self._cleanup)
def on_startup(self, func: Callable) -> Callable:
"""注册一个在驱动器启动时执行的函数"""
raise NotImplementedError
@abc.abstractmethod def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
def on_shutdown(self, func: Callable) -> Callable: """注册一个启动时执行的函数"""
"""注册一个在驱动器停止时执行的函数""" return self._lifespan.on_startup(func)
raise NotImplementedError
def on_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
"""注册一个停止时执行的函数"""
return self._lifespan.on_shutdown(func)
@classmethod @classmethod
def on_bot_connect(cls, func: T_BotConnectionHook) -> T_BotConnectionHook: def on_bot_connect(cls, func: T_BotConnectionHook) -> T_BotConnectionHook:
@@ -152,11 +168,15 @@ class Driver(abc.ABC):
await asyncio.gather(*coros) await asyncio.gather(*coros)
except Exception as e: except Exception as e:
logger.opt(colors=True, exception=e).error( logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running WebSocketConnection hook. " "<r><bg #f8bbd0>"
"Running cancelled!</bg #f8bbd0></r>" "Error when running WebSocketConnection hook. "
"Running cancelled!"
"</bg #f8bbd0></r>"
) )
asyncio.create_task(_run_hook(bot)) task = asyncio.create_task(_run_hook(bot))
task.add_done_callback(self._bot_tasks.discard)
self._bot_tasks.add(task)
def _bot_disconnect(self, bot: "Bot") -> None: def _bot_disconnect(self, bot: "Bot") -> None:
"""在连接断开后,调用该函数来注销 bot 对象""" """在连接断开后,调用该函数来注销 bot 对象"""
@@ -177,20 +197,56 @@ class Driver(abc.ABC):
await asyncio.gather(*coros) await asyncio.gather(*coros)
except Exception as e: except Exception as e:
logger.opt(colors=True, exception=e).error( logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running WebSocketDisConnection hook. " "<r><bg #f8bbd0>"
"Running cancelled!</bg #f8bbd0></r>" "Error when running WebSocketDisConnection hook. "
"Running cancelled!"
"</bg #f8bbd0></r>"
) )
asyncio.create_task(_run_hook(bot)) task = asyncio.create_task(_run_hook(bot))
task.add_done_callback(self._bot_tasks.discard)
self._bot_tasks.add(task)
async def _cleanup(self) -> None:
"""清理驱动器资源"""
if self._bot_tasks:
logger.opt(colors=True).debug(
"<y>Waiting for running bot connection hooks...</y>"
)
await asyncio.gather(*self._bot_tasks, return_exceptions=True)
class ForwardMixin(abc.ABC): class Mixin(abc.ABC):
"""客户端混入基类。""" """可与其他驱动器共用的混入基类。"""
@property @property
@abc.abstractmethod @abc.abstractmethod
def type(self) -> str: def type(self) -> str:
"""客户端驱动类型名称""" """混入驱动类型名称"""
raise NotImplementedError
class ForwardMixin(Mixin):
"""客户端混入基类。"""
class ReverseMixin(Mixin):
"""服务端混入基类。"""
class HTTPClientSession(abc.ABC):
"""HTTP 客户端会话基类。"""
@abc.abstractmethod
def __init__(
self,
params: QueryTypes = None,
headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: Union[str, HTTPVersion] = HTTPVersion.H11,
timeout: Optional[float] = None,
proxy: Optional[str] = None,
):
raise NotImplementedError raise NotImplementedError
@abc.abstractmethod @abc.abstractmethod
@@ -198,6 +254,54 @@ class ForwardMixin(abc.ABC):
"""发送一个 HTTP 请求""" """发送一个 HTTP 请求"""
raise NotImplementedError raise NotImplementedError
@abc.abstractmethod
async def setup(self) -> None:
"""初始化会话"""
raise NotImplementedError
@abc.abstractmethod
async def close(self) -> None:
"""关闭会话"""
raise NotImplementedError
async def __aenter__(self) -> Self:
await self.setup()
return self
async def __aexit__(
self,
exc_type: Optional[type[BaseException]],
exc: Optional[BaseException],
tb: Optional[TracebackType],
) -> None:
await self.close()
class HTTPClientMixin(ForwardMixin):
"""HTTP 客户端混入基类。"""
@abc.abstractmethod
async def request(self, setup: Request) -> Response:
"""发送一个 HTTP 请求"""
raise NotImplementedError
@abc.abstractmethod
def get_session(
self,
params: QueryTypes = None,
headers: HeaderTypes = None,
cookies: CookieTypes = None,
version: Union[str, HTTPVersion] = HTTPVersion.H11,
timeout: Optional[float] = None,
proxy: Optional[str] = None,
) -> HTTPClientSession:
"""获取一个 HTTP 会话"""
raise NotImplementedError
class WebSocketClientMixin(ForwardMixin):
"""WebSocket 客户端混入基类。"""
@abc.abstractmethod @abc.abstractmethod
@asynccontextmanager @asynccontextmanager
async def websocket(self, setup: Request) -> AsyncGenerator[WebSocket, None]: async def websocket(self, setup: Request) -> AsyncGenerator[WebSocket, None]:
@@ -206,12 +310,11 @@ class ForwardMixin(abc.ABC):
yield # used for static type checking's generator detection yield # used for static type checking's generator detection
class ForwardDriver(Driver, ForwardMixin): class ASGIMixin(ReverseMixin):
"""客户端基类。将客户端框架封装,以满足适配器使用。""" """ASGI 服务端基类。
将后端框架封装以满足适配器使用
class ReverseDriver(Driver): """
"""服务端基类。将后端框架封装,以满足适配器使用。"""
@property @property
@abc.abstractmethod @abc.abstractmethod
@@ -236,22 +339,14 @@ class ReverseDriver(Driver):
raise NotImplementedError raise NotImplementedError
def combine_driver(driver: Type[Driver], *mixins: Type[ForwardMixin]) -> Type[Driver]: ForwardDriver: TypeAlias = ForwardMixin
"""将一个驱动器和多个混入类合并。""" """支持客户端请求的驱动器。
# check first
assert issubclass(driver, Driver), "`driver` must be subclass of Driver"
assert all(
map(lambda m: issubclass(m, ForwardMixin), mixins)
), "`mixins` must be subclass of ForwardMixin"
if not mixins: **Deprecated**请使用 {ref}`nonebot.drivers.ForwardMixin` 或其子类代替
return driver """
def type_(self: ForwardDriver) -> str: ReverseDriver: TypeAlias = ReverseMixin
return ( """支持服务端请求的驱动器。
driver.type.__get__(self)
+ "+"
+ "+".join(map(lambda x: x.type.__get__(self), mixins))
)
return type("CombinedDriver", (*mixins, driver, ForwardDriver), {"type": property(type_)}) # type: ignore **Deprecated**请使用 {ref}`nonebot.drivers.ReverseMixin` 或其子类代替
"""

View File

@@ -0,0 +1,44 @@
from typing import TYPE_CHECKING, Union, TypeVar, overload
from .abstract import Mixin, Driver
D = TypeVar("D", bound="Driver")
if TYPE_CHECKING:
class CombinedDriver(Driver, Mixin): ...
@overload
def combine_driver(driver: type[D]) -> type[D]: ...
@overload
def combine_driver(
driver: type[D], __m: type[Mixin], /, *mixins: type[Mixin]
) -> type["CombinedDriver"]: ...
def combine_driver(
driver: type[D], *mixins: type[Mixin]
) -> Union[type[D], type["CombinedDriver"]]:
"""将一个驱动器和多个混入类合并。"""
# check first
if not issubclass(driver, Driver):
raise TypeError("`driver` must be subclass of Driver")
if not all(issubclass(m, Mixin) for m in mixins):
raise TypeError("`mixins` must be subclass of Mixin")
if not mixins:
return driver
def type_(self: "CombinedDriver") -> str:
return (
driver.type.__get__(self) # type: ignore
+ "+"
+ "+".join(x.type.__get__(self) for x in mixins) # type: ignore
)
return type(
"CombinedDriver", (*mixins, driver), {"type": property(type_)}
) # type: ignore

View File

@@ -2,55 +2,46 @@ import abc
import urllib.request import urllib.request
from enum import Enum from enum import Enum
from dataclasses import dataclass from dataclasses import dataclass
from typing_extensions import TypeAlias
from http.cookiejar import Cookie, CookieJar from http.cookiejar import Cookie, CookieJar
from typing import ( from typing import IO, Any, Union, Callable, Optional
IO, from collections.abc import Mapping, Iterator, Awaitable, MutableMapping
Any,
Dict,
List,
Tuple,
Union,
Mapping,
Callable,
Iterator,
Optional,
Awaitable,
MutableMapping,
)
from yarl import URL as URL from yarl import URL as URL
from multidict import CIMultiDict from multidict import CIMultiDict
RawURL = Tuple[bytes, bytes, Optional[int], bytes] RawURL: TypeAlias = tuple[bytes, bytes, Optional[int], bytes]
SimpleQuery = Union[str, int, float] SimpleQuery: TypeAlias = Union[str, int, float]
QueryVariable = Union[SimpleQuery, List[SimpleQuery]] QueryVariable: TypeAlias = Union[SimpleQuery, list[SimpleQuery]]
QueryTypes = Union[ QueryTypes: TypeAlias = Union[
None, str, Mapping[str, QueryVariable], List[Tuple[str, QueryVariable]] None, str, Mapping[str, QueryVariable], list[tuple[str, SimpleQuery]]
] ]
HeaderTypes = Union[ HeaderTypes: TypeAlias = Union[
None, None,
CIMultiDict[str], CIMultiDict[str],
Dict[str, str], dict[str, str],
List[Tuple[str, str]], list[tuple[str, str]],
] ]
CookieTypes = Union[None, "Cookies", CookieJar, Dict[str, str], List[Tuple[str, str]]] CookieTypes: TypeAlias = Union[
None, "Cookies", CookieJar, dict[str, str], list[tuple[str, str]]
]
ContentTypes = Union[str, bytes, None] ContentTypes: TypeAlias = Union[str, bytes, None]
DataTypes = Union[dict, None] DataTypes: TypeAlias = Union[dict, None]
FileContent = Union[IO[bytes], bytes] FileContent: TypeAlias = Union[IO[bytes], bytes]
FileType = Tuple[Optional[str], FileContent, Optional[str]] FileType: TypeAlias = tuple[Optional[str], FileContent, Optional[str]]
FileTypes = Union[ FileTypes: TypeAlias = Union[
# file (or bytes) # file (or bytes)
FileContent, FileContent,
# (filename, file (or bytes)) # (filename, file (or bytes))
Tuple[Optional[str], FileContent], tuple[Optional[str], FileContent],
# (filename, file (or bytes), content_type) # (filename, file (or bytes), content_type)
FileType, FileType,
] ]
FilesTypes = Union[Dict[str, FileTypes], List[Tuple[str, FileTypes]], None] FilesTypes: TypeAlias = Union[dict[str, FileTypes], list[tuple[str, FileTypes]], None]
class HTTPVersion(Enum): class HTTPVersion(Enum):
@@ -116,13 +107,13 @@ class Request:
self.content: ContentTypes = content self.content: ContentTypes = content
self.data: DataTypes = data self.data: DataTypes = data
self.json: Any = json self.json: Any = json
self.files: Optional[List[Tuple[str, FileType]]] = None self.files: Optional[list[tuple[str, FileType]]] = None
if files: if files:
self.files = [] self.files = []
files_ = files.items() if isinstance(files, dict) else files files_ = files.items() if isinstance(files, dict) else files
for name, file_info in files_: for name, file_info in files_:
if not isinstance(file_info, tuple): if not isinstance(file_info, tuple):
self.files.append((name, (None, file_info, None))) self.files.append((name, (name, file_info, None)))
elif len(file_info) == 2: elif len(file_info) == 2:
self.files.append((name, (file_info[0], file_info[1], None))) self.files.append((name, (file_info[0], file_info[1], None)))
else: else:
@@ -160,7 +151,6 @@ class Response:
class WebSocket(abc.ABC): class WebSocket(abc.ABC):
def __init__(self, *, request: Request): def __init__(self, *, request: Request):
# request
self.request: Request = request self.request: Request = request
def __repr__(self) -> str: def __repr__(self) -> str:
@@ -169,9 +159,7 @@ class WebSocket(abc.ABC):
@property @property
@abc.abstractmethod @abc.abstractmethod
def closed(self) -> bool: def closed(self) -> bool:
""" """连接是否已经关闭"""
连接是否已经关闭
"""
raise NotImplementedError raise NotImplementedError
@abc.abstractmethod @abc.abstractmethod
@@ -257,7 +245,7 @@ class Cookies(MutableMapping):
) )
self.jar.set_cookie(cookie) self.jar.set_cookie(cookie)
def get( def get( # pyright: ignore[reportIncompatibleMethodOverride]
self, self,
name: str, name: str,
default: Optional[str] = None, default: Optional[str] = None,
@@ -298,12 +286,14 @@ class Cookies(MutableMapping):
def clear(self, domain: Optional[str] = None, path: Optional[str] = None) -> None: def clear(self, domain: Optional[str] = None, path: Optional[str] = None) -> None:
self.jar.clear(domain, path) self.jar.clear(domain, path)
def update(self, cookies: CookieTypes = None) -> None: def update( # pyright: ignore[reportIncompatibleMethodOverride]
self, cookies: CookieTypes = None
) -> None:
cookies = Cookies(cookies) cookies = Cookies(cookies)
for cookie in cookies.jar: for cookie in cookies.jar:
self.jar.set_cookie(cookie) self.jar.set_cookie(cookie)
def as_header(self, request: Request) -> Dict[str, str]: def as_header(self, request: Request) -> dict[str, str]:
urllib_request = self._CookieCompatRequest(request) urllib_request = self._CookieCompatRequest(request)
self.jar.add_cookie_header(urllib_request) self.jar.add_cookie_header(urllib_request)
return urllib_request.added_headers return urllib_request.added_headers
@@ -341,9 +331,11 @@ class Cookies(MutableMapping):
method=request.method, method=request.method,
) )
self.request = request self.request = request
self.added_headers: Dict[str, str] = {} self.added_headers: dict[str, str] = {}
def add_unredirected_header(self, key: str, value: str) -> None: def add_unredirected_header( # pyright: ignore[reportIncompatibleMethodOverride]
self, key: str, value: str
) -> None:
super().add_unredirected_header(key, value) super().add_unredirected_header(key, value)
self.added_headers[key] = value self.added_headers[key] = value

View File

@@ -6,6 +6,7 @@ matchers = MatcherManager()
from .matcher import Matcher as Matcher from .matcher import Matcher as Matcher
from .matcher import current_bot as current_bot from .matcher import current_bot as current_bot
from .matcher import MatcherSource as MatcherSource
from .matcher import current_event as current_event from .matcher import current_event as current_event
from .matcher import current_handler as current_handler from .matcher import current_handler as current_handler
from .matcher import current_matcher as current_matcher from .matcher import current_matcher as current_matcher

View File

@@ -1,19 +1,5 @@
from typing import ( from typing import TYPE_CHECKING, Union, TypeVar, Optional, overload
TYPE_CHECKING, from collections.abc import Iterator, KeysView, ItemsView, ValuesView, MutableMapping
Any,
List,
Type,
Tuple,
Union,
TypeVar,
Iterator,
KeysView,
Optional,
ItemsView,
ValuesView,
MutableMapping,
overload,
)
from .provider import DEFAULT_PROVIDER_CLASS, MatcherProvider from .provider import DEFAULT_PROVIDER_CLASS, MatcherProvider
@@ -23,7 +9,7 @@ if TYPE_CHECKING:
T = TypeVar("T") T = TypeVar("T")
class MatcherManager(MutableMapping[int, List[Type["Matcher"]]]): class MatcherManager(MutableMapping[int, list[type["Matcher"]]]):
"""事件响应器管理器 """事件响应器管理器
实现了常用字典操作,用于管理事件响应器。 实现了常用字典操作,用于管理事件响应器。
@@ -44,58 +30,60 @@ class MatcherManager(MutableMapping[int, List[Type["Matcher"]]]):
def __len__(self) -> int: def __len__(self) -> int:
return len(self.provider) return len(self.provider)
def __getitem__(self, key: int) -> List[Type["Matcher"]]: def __getitem__(self, key: int) -> list[type["Matcher"]]:
return self.provider[key] return self.provider[key]
def __setitem__(self, key: int, value: List[Type["Matcher"]]) -> None: def __setitem__(self, key: int, value: list[type["Matcher"]]) -> None:
self.provider[key] = value self.provider[key] = value
def __delitem__(self, key: int) -> None: def __delitem__(self, key: int) -> None:
del self.provider[key] del self.provider[key]
def __eq__(self, other: Any) -> bool: def __eq__(self, other: object) -> bool:
return isinstance(other, MatcherManager) and self.provider == other.provider return isinstance(other, MatcherManager) and self.provider == other.provider
def keys(self) -> KeysView[int]: def keys(self) -> KeysView[int]:
return self.provider.keys() return self.provider.keys()
def values(self) -> ValuesView[List[Type["Matcher"]]]: def values(self) -> ValuesView[list[type["Matcher"]]]:
return self.provider.values() return self.provider.values()
def items(self) -> ItemsView[int, List[Type["Matcher"]]]: def items(self) -> ItemsView[int, list[type["Matcher"]]]:
return self.provider.items() return self.provider.items()
@overload @overload
def get(self, key: int) -> Optional[List[Type["Matcher"]]]: def get(self, key: int) -> Optional[list[type["Matcher"]]]: ...
...
@overload @overload
def get(self, key: int, default: T) -> Union[List[Type["Matcher"]], T]: def get(self, key: int, default: T) -> Union[list[type["Matcher"]], T]: ...
...
def get( def get(
self, key: int, default: Optional[T] = None self, key: int, default: Optional[T] = None
) -> Optional[Union[List[Type["Matcher"]], T]]: ) -> Optional[Union[list[type["Matcher"]], T]]:
return self.provider.get(key, default) return self.provider.get(key, default)
def pop(self, key: int) -> List[Type["Matcher"]]: def pop( # pyright: ignore[reportIncompatibleMethodOverride]
self, key: int
) -> list[type["Matcher"]]:
return self.provider.pop(key) return self.provider.pop(key)
def popitem(self) -> Tuple[int, List[Type["Matcher"]]]: def popitem(self) -> tuple[int, list[type["Matcher"]]]:
return self.provider.popitem() return self.provider.popitem()
def clear(self) -> None: def clear(self) -> None:
self.provider.clear() self.provider.clear()
def update(self, __m: MutableMapping[int, List[Type["Matcher"]]]) -> None: def update( # pyright: ignore[reportIncompatibleMethodOverride]
self, __m: MutableMapping[int, list[type["Matcher"]]]
) -> None:
self.provider.update(__m) self.provider.update(__m)
def setdefault( def setdefault(
self, key: int, default: List[Type["Matcher"]] self, key: int, default: list[type["Matcher"]]
) -> List[Type["Matcher"]]: ) -> list[type["Matcher"]]:
return self.provider.setdefault(key, default) return self.provider.setdefault(key, default)
def set_provider(self, provider_class: Type[MatcherProvider]) -> None: def set_provider(self, provider_class: type[MatcherProvider]) -> None:
"""设置事件响应器存储器 """设置事件响应器存储器
参数: 参数:

View File

@@ -1,18 +1,22 @@
import sys
import inspect
import warnings
from pathlib import Path
from types import ModuleType from types import ModuleType
from dataclasses import dataclass
from contextvars import ContextVar from contextvars import ContextVar
from typing_extensions import Self from typing_extensions import Self
from collections.abc import Iterable
from datetime import datetime, timedelta from datetime import datetime, timedelta
from contextlib import AsyncExitStack, contextmanager from contextlib import AsyncExitStack, contextmanager
from typing import ( from typing import ( # noqa: UP035
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
List,
Type, Type,
Union, Union,
TypeVar, TypeVar,
Callable, Callable,
ClassVar, ClassVar,
Iterable,
NoReturn, NoReturn,
Optional, Optional,
overload, overload,
@@ -20,7 +24,8 @@ from typing import (
from nonebot.log import logger from nonebot.log import logger
from nonebot.internal.rule import Rule from nonebot.internal.rule import Rule
from nonebot.dependencies import Dependent from nonebot.utils import classproperty
from nonebot.dependencies import Param, Dependent
from nonebot.internal.permission import User, Permission from nonebot.internal.permission import User, Permission
from nonebot.internal.adapter import ( from nonebot.internal.adapter import (
Bot, Bot,
@@ -29,6 +34,13 @@ from nonebot.internal.adapter import (
MessageSegment, MessageSegment,
MessageTemplate, MessageTemplate,
) )
from nonebot.typing import (
T_State,
T_Handler,
T_TypeUpdater,
T_DependencyCache,
T_PermissionUpdater,
)
from nonebot.consts import ( from nonebot.consts import (
ARG_KEY, ARG_KEY,
RECEIVE_KEY, RECEIVE_KEY,
@@ -36,14 +48,6 @@ from nonebot.consts import (
LAST_RECEIVE_KEY, LAST_RECEIVE_KEY,
REJECT_CACHE_TARGET, REJECT_CACHE_TARGET,
) )
from nonebot.typing import (
Any,
T_State,
T_Handler,
T_TypeUpdater,
T_DependencyCache,
T_PermissionUpdater,
)
from nonebot.exception import ( from nonebot.exception import (
PausedException, PausedException,
StopPropagation, StopPropagation,
@@ -72,18 +76,59 @@ T = TypeVar("T")
current_bot: ContextVar[Bot] = ContextVar("current_bot") current_bot: ContextVar[Bot] = ContextVar("current_bot")
current_event: ContextVar[Event] = ContextVar("current_event") current_event: ContextVar[Event] = ContextVar("current_event")
current_matcher: ContextVar["Matcher"] = ContextVar("current_matcher") current_matcher: ContextVar["Matcher"] = ContextVar("current_matcher")
current_handler: ContextVar[Dependent] = ContextVar("current_handler") current_handler: ContextVar[Dependent[Any]] = ContextVar("current_handler")
@dataclass
class MatcherSource:
"""Matcher 源代码上下文信息"""
plugin_id: Optional[str] = None
"""事件响应器所在插件标识符"""
module_name: Optional[str] = None
"""事件响应器所在插件模块的路径名"""
lineno: Optional[int] = None
"""事件响应器所在行号"""
@property
def plugin(self) -> Optional["Plugin"]:
"""事件响应器所在插件"""
from nonebot.plugin import get_plugin
if self.plugin_id is not None:
return get_plugin(self.plugin_id)
@property
def plugin_name(self) -> Optional[str]:
"""事件响应器所在插件名"""
return self.plugin and self.plugin.name
@property
def module(self) -> Optional[ModuleType]:
if self.module_name is not None:
return sys.modules.get(self.module_name)
@property
def file(self) -> Optional[Path]:
if self.module is not None and (file := inspect.getsourcefile(self.module)):
return Path(file).absolute()
class MatcherMeta(type): class MatcherMeta(type):
if TYPE_CHECKING: if TYPE_CHECKING:
module_name: Optional[str]
type: str type: str
_source: Optional[MatcherSource]
module_name: Optional[str]
def __repr__(self) -> str: def __repr__(self) -> str:
return ( return (
f"{self.__name__}(type={self.type!r}" f"{self.__name__}(type={self.type!r}"
+ (f", module={self.module_name}" if self.module_name else "") + (f", module={self.module_name}" if self.module_name else "")
+ (
f", lineno={self._source.lineno}"
if self._source and self._source.lineno is not None
else ""
)
+ ")" + ")"
) )
@@ -91,14 +136,7 @@ class MatcherMeta(type):
class Matcher(metaclass=MatcherMeta): class Matcher(metaclass=MatcherMeta):
"""事件响应器类""" """事件响应器类"""
plugin: ClassVar[Optional["Plugin"]] = None _source: ClassVar[Optional[MatcherSource]] = None
"""事件响应器所在插件"""
module: ClassVar[Optional[ModuleType]] = None
"""事件响应器所在插件模块"""
plugin_name: ClassVar[Optional[str]] = None
"""事件响应器所在插件名"""
module_name: ClassVar[Optional[str]] = None
"""事件响应器所在点分割插件模块路径"""
type: ClassVar[str] = "" type: ClassVar[str] = ""
"""事件响应器类型""" """事件响应器类型"""
@@ -106,7 +144,7 @@ class Matcher(metaclass=MatcherMeta):
"""事件响应器匹配规则""" """事件响应器匹配规则"""
permission: ClassVar[Permission] = Permission() permission: ClassVar[Permission] = Permission()
"""事件响应器触发权限""" """事件响应器触发权限"""
handlers: List[Dependent[Any]] = [] handlers: ClassVar[list[Dependent[Any]]] = []
"""事件响应器拥有的事件处理函数列表""" """事件响应器拥有的事件处理函数列表"""
priority: ClassVar[int] = 1 priority: ClassVar[int] = 1
"""事件响应器优先级""" """事件响应器优先级"""
@@ -125,7 +163,7 @@ class Matcher(metaclass=MatcherMeta):
_default_permission_updater: ClassVar[Optional[Dependent[Permission]]] = None _default_permission_updater: ClassVar[Optional[Dependent[Permission]]] = None
"""事件响应器权限更新函数""" """事件响应器权限更新函数"""
HANDLER_PARAM_TYPES = ( HANDLER_PARAM_TYPES: ClassVar[tuple[Type[Param], ...]] = ( # noqa: UP006
DependParam, DependParam,
BotParam, BotParam,
EventParam, EventParam,
@@ -136,13 +174,18 @@ class Matcher(metaclass=MatcherMeta):
) )
def __init__(self): def __init__(self):
self.handlers = self.handlers.copy() self.remain_handlers: list[Dependent[Any]] = self.handlers.copy()
self.state = self._default_state.copy() self.state = self._default_state.copy()
def __repr__(self) -> str: def __repr__(self) -> str:
return ( return (
f"{self.__class__.__name__}(type={self.type!r}" f"{self.__class__.__name__}(type={self.type!r}"
+ (f", module={self.module_name}" if self.module_name else "") + (f", module={self.module_name}" if self.module_name else "")
+ (
f", lineno={self._source.lineno}"
if self._source and self._source.lineno is not None
else ""
)
+ ")" + ")"
) )
@@ -152,20 +195,21 @@ class Matcher(metaclass=MatcherMeta):
type_: str = "", type_: str = "",
rule: Optional[Rule] = None, rule: Optional[Rule] = None,
permission: Optional[Permission] = None, permission: Optional[Permission] = None,
handlers: Optional[List[Union[T_Handler, Dependent[Any]]]] = None, handlers: Optional[list[Union[T_Handler, Dependent[Any]]]] = None,
temp: bool = False, temp: bool = False,
priority: int = 1, priority: int = 1,
block: bool = False, block: bool = False,
*, *,
plugin: Optional["Plugin"] = None, plugin: Optional["Plugin"] = None,
module: Optional[ModuleType] = None, module: Optional[ModuleType] = None,
source: Optional[MatcherSource] = None,
expire_time: Optional[Union[datetime, timedelta]] = None, expire_time: Optional[Union[datetime, timedelta]] = None,
default_state: Optional[T_State] = None, default_state: Optional[T_State] = None,
default_type_updater: Optional[Union[T_TypeUpdater, Dependent[str]]] = None, default_type_updater: Optional[Union[T_TypeUpdater, Dependent[str]]] = None,
default_permission_updater: Optional[ default_permission_updater: Optional[
Union[T_PermissionUpdater, Dependent[Permission]] Union[T_PermissionUpdater, Dependent[Permission]]
] = None, ] = None,
) -> Type[Self]: ) -> Type[Self]: # noqa: UP006
""" """
创建一个新的事件响应器,并存储至 `matchers <#matchers>`_ 创建一个新的事件响应器,并存储至 `matchers <#matchers>`_
@@ -177,35 +221,64 @@ class Matcher(metaclass=MatcherMeta):
temp: 是否为临时事件响应器,即触发一次后删除 temp: 是否为临时事件响应器,即触发一次后删除
priority: 响应优先级 priority: 响应优先级
block: 是否阻止事件向更低优先级的响应器传播 block: 是否阻止事件向更低优先级的响应器传播
plugin: 事件响应器所在插件 plugin: **Deprecated.** 事件响应器所在插件
module: 事件响应器所在模块 module: **Deprecated.** 事件响应器所在模块
default_state: 默认状态 `state` source: 事件响应器源代码上下文信息
expire_time: 事件响应器最终有效时间点,过时即被删除 expire_time: 事件响应器最终有效时间点,过时即被删除
default_state: 默认状态 `state`
default_type_updater: 默认事件类型更新函数
default_permission_updater: 默认会话权限更新函数
返回: 返回:
Type[Matcher]: 新的事件响应器类 Type[Matcher]: 新的事件响应器类
""" """
if plugin is not None:
warnings.warn(
(
"Pass `plugin` context info to create Matcher is deprecated. "
"Use `source` instead."
),
DeprecationWarning,
)
if module is not None:
warnings.warn(
(
"Pass `module` context info to create Matcher is deprecated. "
"Use `source` instead."
),
DeprecationWarning,
)
source = source or (
MatcherSource(
plugin_id=plugin and plugin.id_,
module_name=module and module.__name__,
)
if plugin is not None or module is not None
else None
)
NewMatcher = type( NewMatcher = type(
cls.__name__, cls.__name__,
(cls,), (cls,),
{ {
"plugin": plugin, "_source": source,
"module": module,
"plugin_name": plugin and plugin.name,
"module_name": module and module.__name__,
"type": type_, "type": type_,
"rule": rule or Rule(), "rule": rule or Rule(),
"permission": permission or Permission(), "permission": permission or Permission(),
"handlers": [ "handlers": (
handler [
if isinstance(handler, Dependent) (
else Dependent[Any].parse( handler
call=handler, allow_types=cls.HANDLER_PARAM_TYPES if isinstance(handler, Dependent)
) else Dependent[Any].parse(
for handler in handlers call=handler, allow_types=cls.HANDLER_PARAM_TYPES
] )
if handlers )
else [], for handler in handlers
]
if handlers
else []
),
"temp": temp, "temp": temp,
"expire_time": ( "expire_time": (
expire_time expire_time
@@ -247,13 +320,38 @@ class Matcher(metaclass=MatcherMeta):
matchers[priority].append(NewMatcher) matchers[priority].append(NewMatcher)
return NewMatcher return NewMatcher # type: ignore
@classmethod @classmethod
def destroy(cls) -> None: def destroy(cls) -> None:
"""销毁当前的事件响应器""" """销毁当前的事件响应器"""
matchers[cls.priority].remove(cls) matchers[cls.priority].remove(cls)
@classproperty
def plugin(cls) -> Optional["Plugin"]:
"""事件响应器所在插件"""
return cls._source and cls._source.plugin
@classproperty
def plugin_id(cls) -> Optional[str]:
"""事件响应器所在插件标识符"""
return cls._source and cls._source.plugin_id
@classproperty
def plugin_name(cls) -> Optional[str]:
"""事件响应器所在插件名"""
return cls._source and cls._source.plugin_name
@classproperty
def module(cls) -> Optional[ModuleType]:
"""事件响应器所在插件模块"""
return cls._source and cls._source.module
@classproperty
def module_name(cls) -> Optional[str]:
"""事件响应器所在插件模块路径"""
return cls._source and cls._source.module_name
@classmethod @classmethod
async def check_perm( async def check_perm(
cls, cls,
@@ -367,7 +465,7 @@ class Matcher(metaclass=MatcherMeta):
parameterless: 非参数类型依赖列表 parameterless: 非参数类型依赖列表
""" """
async def _receive(event: Event, matcher: "Matcher") -> Union[None, NoReturn]: async def _receive(event: Event, matcher: "Matcher") -> None:
matcher.set_target(RECEIVE_KEY.format(id=id)) matcher.set_target(RECEIVE_KEY.format(id=id))
if matcher.get_target() == RECEIVE_KEY.format(id=id): if matcher.get_target() == RECEIVE_KEY.format(id=id):
matcher.set_receive(id, event) matcher.set_receive(id, event)
@@ -376,7 +474,7 @@ class Matcher(metaclass=MatcherMeta):
return return
await matcher.reject() await matcher.reject()
_parameterless = (Depends(_receive), *(parameterless or tuple())) _parameterless = (Depends(_receive), *(parameterless or ()))
def _decorator(func: T_Handler) -> T_Handler: def _decorator(func: T_Handler) -> T_Handler:
if cls.handlers and cls.handlers[-1].call is func: if cls.handlers and cls.handlers[-1].call is func:
@@ -406,7 +504,8 @@ class Matcher(metaclass=MatcherMeta):
) -> Callable[[T_Handler], T_Handler]: ) -> Callable[[T_Handler], T_Handler]:
"""装饰一个函数来指示 NoneBot 获取一个参数 `key` """装饰一个函数来指示 NoneBot 获取一个参数 `key`
当要获取的 `key` 不存在时接收用户新的一条消息再运行该函数,如果 `key` 已存在则直接继续运行 当要获取的 `key` 不存在时接收用户新的一条消息再运行该函数,
如果 `key` 已存在则直接继续运行
参数: 参数:
key: 参数名 key: 参数名
@@ -423,7 +522,7 @@ class Matcher(metaclass=MatcherMeta):
return return
await matcher.reject(prompt) await matcher.reject(prompt)
_parameterless = (Depends(_key_getter), *(parameterless or tuple())) _parameterless = (Depends(_key_getter), *(parameterless or ()))
def _decorator(func: T_Handler) -> T_Handler: def _decorator(func: T_Handler) -> T_Handler:
if cls.handlers and cls.handlers[-1].call is func: if cls.handlers and cls.handlers[-1].call is func:
@@ -454,7 +553,8 @@ class Matcher(metaclass=MatcherMeta):
参数: 参数:
message: 消息内容 message: 消息内容
kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,请参考对应 adapter 的 bot 对象 api kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,
请参考对应 adapter 的 bot 对象 api
""" """
bot = current_bot.get() bot = current_bot.get()
event = current_event.get() event = current_event.get()
@@ -475,7 +575,8 @@ class Matcher(metaclass=MatcherMeta):
参数: 参数:
message: 消息内容 message: 消息内容
kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,请参考对应 adapter 的 bot 对象 api kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,
请参考对应 adapter 的 bot 对象 api
""" """
if message is not None: if message is not None:
await cls.send(message, **kwargs) await cls.send(message, **kwargs)
@@ -491,7 +592,8 @@ class Matcher(metaclass=MatcherMeta):
参数: 参数:
prompt: 消息内容 prompt: 消息内容
kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,请参考对应 adapter 的 bot 对象 api kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,
请参考对应 adapter 的 bot 对象 api
""" """
if prompt is not None: if prompt is not None:
await cls.send(prompt, **kwargs) await cls.send(prompt, **kwargs)
@@ -508,7 +610,8 @@ class Matcher(metaclass=MatcherMeta):
参数: 参数:
prompt: 消息内容 prompt: 消息内容
kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,请参考对应 adapter 的 bot 对象 api kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,
请参考对应 adapter 的 bot 对象 api
""" """
if prompt is not None: if prompt is not None:
await cls.send(prompt, **kwargs) await cls.send(prompt, **kwargs)
@@ -527,7 +630,8 @@ class Matcher(metaclass=MatcherMeta):
参数: 参数:
key: 参数名 key: 参数名
prompt: 消息内容 prompt: 消息内容
kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,请参考对应 adapter 的 bot 对象 api kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,
请参考对应 adapter 的 bot 对象 api
""" """
matcher = current_matcher.get() matcher = current_matcher.get()
matcher.set_target(ARG_KEY.format(key=key)) matcher.set_target(ARG_KEY.format(key=key))
@@ -548,7 +652,8 @@ class Matcher(metaclass=MatcherMeta):
参数: 参数:
id: 消息 id id: 消息 id
prompt: 消息内容 prompt: 消息内容
kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,请参考对应 adapter 的 bot 对象 api kwargs: {ref}`nonebot.adapters.Bot.send` 的参数,
请参考对应 adapter 的 bot 对象 api
""" """
matcher = current_matcher.get() matcher = current_matcher.get()
matcher.set_target(RECEIVE_KEY.format(id=id)) matcher.set_target(RECEIVE_KEY.format(id=id))
@@ -565,12 +670,10 @@ class Matcher(metaclass=MatcherMeta):
raise SkippedException raise SkippedException
@overload @overload
def get_receive(self, id: str) -> Union[Event, None]: def get_receive(self, id: str) -> Union[Event, None]: ...
...
@overload @overload
def get_receive(self, id: str, default: T) -> Union[Event, T]: def get_receive(self, id: str, default: T) -> Union[Event, T]: ...
...
def get_receive( def get_receive(
self, id: str, default: Optional[T] = None self, id: str, default: Optional[T] = None
@@ -587,12 +690,10 @@ class Matcher(metaclass=MatcherMeta):
self.state[LAST_RECEIVE_KEY] = event self.state[LAST_RECEIVE_KEY] = event
@overload @overload
def get_last_receive(self) -> Union[Event, None]: def get_last_receive(self) -> Union[Event, None]: ...
...
@overload @overload
def get_last_receive(self, default: T) -> Union[Event, T]: def get_last_receive(self, default: T) -> Union[Event, T]: ...
...
def get_last_receive( def get_last_receive(
self, default: Optional[T] = None self, default: Optional[T] = None
@@ -604,12 +705,10 @@ class Matcher(metaclass=MatcherMeta):
return self.state.get(LAST_RECEIVE_KEY, default) return self.state.get(LAST_RECEIVE_KEY, default)
@overload @overload
def get_arg(self, key: str) -> Union[Message, None]: def get_arg(self, key: str) -> Union[Message, None]: ...
...
@overload @overload
def get_arg(self, key: str, default: T) -> Union[Message, T]: def get_arg(self, key: str, default: T) -> Union[Message, T]: ...
...
def get_arg( def get_arg(
self, key: str, default: Optional[T] = None self, key: str, default: Optional[T] = None
@@ -631,12 +730,10 @@ class Matcher(metaclass=MatcherMeta):
self.state[REJECT_TARGET] = target self.state[REJECT_TARGET] = target
@overload @overload
def get_target(self) -> Union[str, None]: def get_target(self) -> Union[str, None]: ...
...
@overload @overload
def get_target(self, default: T) -> Union[str, T]: def get_target(self, default: T) -> Union[str, T]: ...
...
def get_target(self, default: Optional[T] = None) -> Optional[Union[str, T]]: def get_target(self, default: Optional[T] = None) -> Optional[Union[str, T]]:
return self.state.get(REJECT_TARGET, default) return self.state.get(REJECT_TARGET, default)
@@ -686,7 +783,7 @@ class Matcher(metaclass=MatcherMeta):
async def resolve_reject(self): async def resolve_reject(self):
handler = current_handler.get() handler = current_handler.get()
self.handlers.insert(0, handler) self.remain_handlers.insert(0, handler)
if REJECT_CACHE_TARGET in self.state: if REJECT_CACHE_TARGET in self.state:
self.state[REJECT_TARGET] = self.state[REJECT_CACHE_TARGET] self.state[REJECT_TARGET] = self.state[REJECT_CACHE_TARGET]
@@ -720,8 +817,8 @@ class Matcher(metaclass=MatcherMeta):
# Refresh preprocess state # Refresh preprocess state
self.state.update(state) self.state.update(state)
while self.handlers: while self.remain_handlers:
handler = self.handlers.pop(0) handler = self.remain_handlers.pop(0)
current_handler.set(handler) current_handler.set(handler)
logger.debug(f"Running handler {handler}") logger.debug(f"Running handler {handler}")
try: try:
@@ -763,12 +860,11 @@ class Matcher(metaclass=MatcherMeta):
type_, type_,
Rule(), Rule(),
permission, permission,
self.handlers, self.remain_handlers,
temp=True, temp=True,
priority=0, priority=0,
block=True, block=True,
plugin=self.plugin, source=self.__class__._source,
module=self.module,
expire_time=bot.config.session_expire_timeout, expire_time=bot.config.session_expire_timeout,
default_state=self.state, default_state=self.state,
default_type_updater=self.__class__._default_type_updater, default_type_updater=self.__class__._default_type_updater,
@@ -784,12 +880,11 @@ class Matcher(metaclass=MatcherMeta):
type_, type_,
Rule(), Rule(),
permission, permission,
self.handlers, self.remain_handlers,
temp=True, temp=True,
priority=0, priority=0,
block=True, block=True,
plugin=self.plugin, source=self.__class__._source,
module=self.module,
expire_time=bot.config.session_expire_timeout, expire_time=bot.config.session_expire_timeout,
default_state=self.state, default_state=self.state,
default_type_updater=self.__class__._default_type_updater, default_type_updater=self.__class__._default_type_updater,

View File

@@ -1,12 +1,13 @@
import abc import abc
from typing import TYPE_CHECKING
from collections import defaultdict from collections import defaultdict
from typing import TYPE_CHECKING, List, Type, Mapping, MutableMapping from collections.abc import Mapping, MutableMapping
if TYPE_CHECKING: if TYPE_CHECKING:
from .matcher import Matcher from .matcher import Matcher
class MatcherProvider(abc.ABC, MutableMapping[int, List[Type["Matcher"]]]): class MatcherProvider(abc.ABC, MutableMapping[int, list[type["Matcher"]]]):
"""事件响应器存储器基类 """事件响应器存储器基类
参数: 参数:
@@ -14,12 +15,12 @@ class MatcherProvider(abc.ABC, MutableMapping[int, List[Type["Matcher"]]]):
""" """
@abc.abstractmethod @abc.abstractmethod
def __init__(self, matchers: Mapping[int, List[Type["Matcher"]]]): def __init__(self, matchers: Mapping[int, list[type["Matcher"]]]):
raise NotImplementedError raise NotImplementedError
class _DictProvider(defaultdict, MatcherProvider): class _DictProvider(defaultdict, MatcherProvider):
def __init__(self, matchers: Mapping[int, List[Type["Matcher"]]]): def __init__(self, matchers: Mapping[int, list[type["Matcher"]]]):
super().__init__(list, matchers) super().__init__(list, matchers)

View File

@@ -1,15 +1,30 @@
import asyncio import asyncio
import inspect import inspect
from typing_extensions import Annotated from typing_extensions import Self, get_args, override, get_origin
from contextlib import AsyncExitStack, contextmanager, asynccontextmanager from contextlib import AsyncExitStack, contextmanager, asynccontextmanager
from typing import TYPE_CHECKING, Any, Type, Tuple, Literal, Callable, Optional, cast from typing import (
TYPE_CHECKING,
Any,
Union,
Literal,
Callable,
Optional,
Annotated,
cast,
)
from pydantic.typing import get_args, get_origin from pydantic.fields import FieldInfo as PydanticFieldInfo
from pydantic.fields import Required, Undefined, ModelField
from nonebot.dependencies import Param, Dependent
from nonebot.dependencies.utils import check_field_type from nonebot.dependencies.utils import check_field_type
from nonebot.dependencies import Param, Dependent, CustomConfig from nonebot.compat import FieldInfo, ModelField, PydanticUndefined, extract_field_info
from nonebot.typing import T_State, T_Handler, T_DependencyCache from nonebot.typing import (
_STATE_FLAG,
T_State,
T_Handler,
T_DependencyCache,
origin_is_annotated,
)
from nonebot.utils import ( from nonebot.utils import (
get_name, get_name,
run_sync, run_sync,
@@ -31,26 +46,31 @@ class DependsInner:
dependency: Optional[T_Handler] = None, dependency: Optional[T_Handler] = None,
*, *,
use_cache: bool = True, use_cache: bool = True,
validate: Union[bool, PydanticFieldInfo] = False,
) -> None: ) -> None:
self.dependency = dependency self.dependency = dependency
self.use_cache = use_cache self.use_cache = use_cache
self.validate = validate
def __repr__(self) -> str: def __repr__(self) -> str:
dep = get_name(self.dependency) dep = get_name(self.dependency)
cache = "" if self.use_cache else ", use_cache=False" cache = "" if self.use_cache else ", use_cache=False"
return f"DependsInner({dep}{cache})" validate = f", validate={self.validate}" if self.validate else ""
return f"DependsInner({dep}{cache}{validate})"
def Depends( def Depends(
dependency: Optional[T_Handler] = None, dependency: Optional[T_Handler] = None,
*, *,
use_cache: bool = True, use_cache: bool = True,
validate: Union[bool, PydanticFieldInfo] = False,
) -> Any: ) -> Any:
"""子依赖装饰器 """子依赖装饰器
参数: 参数:
dependency: 依赖函数。默认为参数的类型注释。 dependency: 依赖函数。默认为参数的类型注释。
use_cache: 是否使用缓存。默认为 `True`。 use_cache: 是否使用缓存。默认为 `True`。
validate: 是否使用 Pydantic 类型校验。默认为 `False`。
用法: 用法:
```python ```python
@@ -63,37 +83,74 @@ def Depends(
finally: finally:
... ...
async def handler(param_name: Any = Depends(depend_func), gen: Any = Depends(depend_gen_func)): async def handler(
param_name: Any = Depends(depend_func),
gen: Any = Depends(depend_gen_func),
):
... ...
``` ```
""" """
return DependsInner(dependency, use_cache=use_cache) return DependsInner(dependency, use_cache=use_cache, validate=validate)
class DependParam(Param): class DependParam(Param):
"""子依赖参数""" """子依赖注入参数
本注入解析所有子依赖注入,然后将它们的返回值作为参数值传递给父依赖。
本注入应该具有最高优先级,因此应该在其他参数之前检查。
"""
def __init__(
self, *args, dependent: Dependent[Any], use_cache: bool, **kwargs: Any
) -> None:
super().__init__(*args, **kwargs)
self.dependent = dependent
self.use_cache = use_cache
def __repr__(self) -> str: def __repr__(self) -> str:
return f"Depends({self.extra['dependent']})" return f"Depends({self.dependent}, use_cache={self.use_cache})"
@classmethod @classmethod
def _from_field(
cls,
sub_dependent: Dependent[Any],
use_cache: bool,
validate: Union[bool, PydanticFieldInfo],
) -> Self:
kwargs = {}
if isinstance(validate, PydanticFieldInfo):
kwargs.update(extract_field_info(validate))
kwargs["validate"] = bool(validate)
kwargs["dependent"] = sub_dependent
kwargs["use_cache"] = use_cache
return cls(**kwargs)
@classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["DependParam"]: ) -> Optional[Self]:
type_annotation, depends_inner = param.annotation, None type_annotation, depends_inner = param.annotation, None
# extract type annotation and dependency from Annotated
if get_origin(param.annotation) is Annotated: if get_origin(param.annotation) is Annotated:
type_annotation, *extra_args = get_args(param.annotation) type_annotation, *extra_args = get_args(param.annotation)
depends_inner = next( depends_inner = next(
(x for x in extra_args if isinstance(x, DependsInner)), None (x for x in reversed(extra_args) if isinstance(x, DependsInner)), None
) )
# param default value takes higher priority
depends_inner = ( depends_inner = (
param.default if isinstance(param.default, DependsInner) else depends_inner param.default if isinstance(param.default, DependsInner) else depends_inner
) )
# not a dependent
if depends_inner is None: if depends_inner is None:
return return
dependency: T_Handler dependency: T_Handler
# sub dependency is not specified, use type annotation
if depends_inner.dependency is None: if depends_inner.dependency is None:
assert ( assert (
type_annotation is not inspect.Signature.empty type_annotation is not inspect.Signature.empty
@@ -101,33 +158,39 @@ class DependParam(Param):
dependency = type_annotation dependency = type_annotation
else: else:
dependency = depends_inner.dependency dependency = depends_inner.dependency
# parse sub dependency
sub_dependent = Dependent[Any].parse( sub_dependent = Dependent[Any].parse(
call=dependency, call=dependency,
allow_types=allow_types, allow_types=allow_types,
) )
return cls(Required, use_cache=depends_inner.use_cache, dependent=sub_dependent)
return cls._from_field(
sub_dependent, depends_inner.use_cache, depends_inner.validate
)
@classmethod @classmethod
@override
def _check_parameterless( def _check_parameterless(
cls, value: Any, allow_types: Tuple[Type[Param], ...] cls, value: Any, allow_types: tuple[type[Param], ...]
) -> Optional["Param"]: ) -> Optional["Param"]:
if isinstance(value, DependsInner): if isinstance(value, DependsInner):
assert value.dependency, "Dependency cannot be empty" assert value.dependency, "Dependency cannot be empty"
dependent = Dependent[Any].parse( dependent = Dependent[Any].parse(
call=value.dependency, allow_types=allow_types call=value.dependency, allow_types=allow_types
) )
return cls(Required, use_cache=value.use_cache, dependent=dependent) return cls._from_field(dependent, value.use_cache, value.validate)
@override
async def _solve( async def _solve(
self, self,
stack: Optional[AsyncExitStack] = None, stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None, dependency_cache: Optional[T_DependencyCache] = None,
**kwargs: Any, **kwargs: Any,
) -> Any: ) -> Any:
use_cache: bool = self.extra["use_cache"] use_cache: bool = self.use_cache
dependency_cache = {} if dependency_cache is None else dependency_cache dependency_cache = {} if dependency_cache is None else dependency_cache
sub_dependent: Dependent = self.extra["dependent"] sub_dependent = self.dependent
call = cast(Callable[..., Any], sub_dependent.call) call = cast(Callable[..., Any], sub_dependent.call)
# solve sub dependency with current cache # solve sub dependency with current cache
@@ -161,228 +224,331 @@ class DependParam(Param):
dependency_cache[call] = task dependency_cache[call] = task
return await task return await task
@override
async def _check(self, **kwargs: Any) -> None: async def _check(self, **kwargs: Any) -> None:
# run sub dependent pre-checkers # run sub dependent pre-checkers
sub_dependent: Dependent = self.extra["dependent"] await self.dependent.check(**kwargs)
await sub_dependent.check(**kwargs)
class BotParam(Param): class BotParam(Param):
"""{ref}`nonebot.adapters.Bot` 参数""" """{ref}`nonebot.adapters.Bot` 注入参数
本注入解析所有类型为且仅为 {ref}`nonebot.adapters.Bot` 及其子类或 `None` 的参数。
为保证兼容性,本注入还会解析名为 `bot` 且没有类型注解的参数。
"""
def __init__(
self, *args, checker: Optional[ModelField] = None, **kwargs: Any
) -> None:
super().__init__(*args, **kwargs)
self.checker = checker
def __repr__(self) -> str: def __repr__(self) -> str:
return ( return (
"BotParam(" "BotParam("
+ ( + (repr(self.checker.annotation) if self.checker is not None else "")
repr(cast(ModelField, checker).type_)
if (checker := self.extra.get("checker"))
else ""
)
+ ")" + ")"
) )
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["BotParam"]: ) -> Optional[Self]:
from nonebot.adapters import Bot from nonebot.adapters import Bot
if param.default == param.empty: # param type is Bot(s) or subclass(es) of Bot or None
if generic_check_issubclass(param.annotation, Bot): if generic_check_issubclass(param.annotation, Bot):
checker: Optional[ModelField] = None checker: Optional[ModelField] = None
if param.annotation is not Bot: if param.annotation is not Bot:
checker = ModelField( checker = ModelField.construct(
name=param.name, name=param.name, annotation=param.annotation, field_info=FieldInfo()
type_=param.annotation, )
class_validators=None, return cls(checker=checker)
model_config=CustomConfig, # legacy: param is named "bot" and has no type annotation
default=None, elif param.annotation == param.empty and param.name == "bot":
required=True, return cls()
)
return cls(Required, checker=checker)
elif param.annotation == param.empty and param.name == "bot":
return cls(Required)
async def _solve(self, bot: "Bot", **kwargs: Any) -> Any: @override
async def _solve( # pyright: ignore[reportIncompatibleMethodOverride]
self, bot: "Bot", **kwargs: Any
) -> Any:
return bot return bot
async def _check(self, bot: "Bot", **kwargs: Any) -> None: @override
if checker := self.extra.get("checker"): async def _check( # pyright: ignore[reportIncompatibleMethodOverride]
check_field_type(checker, bot) self, bot: "Bot", **kwargs: Any
) -> None:
if self.checker is not None:
check_field_type(self.checker, bot)
class EventParam(Param): class EventParam(Param):
"""{ref}`nonebot.adapters.Event` 参数""" """{ref}`nonebot.adapters.Event` 注入参数
本注入解析所有类型为且仅为 {ref}`nonebot.adapters.Event` 及其子类或 `None` 的参数。
为保证兼容性,本注入还会解析名为 `event` 且没有类型注解的参数。
"""
def __init__(
self, *args, checker: Optional[ModelField] = None, **kwargs: Any
) -> None:
super().__init__(*args, **kwargs)
self.checker = checker
def __repr__(self) -> str: def __repr__(self) -> str:
return ( return (
"EventParam(" "EventParam("
+ ( + (repr(self.checker.annotation) if self.checker is not None else "")
repr(cast(ModelField, checker).type_)
if (checker := self.extra.get("checker"))
else ""
)
+ ")" + ")"
) )
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["EventParam"]: ) -> Optional[Self]:
from nonebot.adapters import Event from nonebot.adapters import Event
if param.default == param.empty: # param type is Event(s) or subclass(es) of Event or None
if generic_check_issubclass(param.annotation, Event): if generic_check_issubclass(param.annotation, Event):
checker: Optional[ModelField] = None checker: Optional[ModelField] = None
if param.annotation is not Event: if param.annotation is not Event:
checker = ModelField( checker = ModelField.construct(
name=param.name, name=param.name, annotation=param.annotation, field_info=FieldInfo()
type_=param.annotation, )
class_validators=None, return cls(checker=checker)
model_config=CustomConfig, # legacy: param is named "event" and has no type annotation
default=None, elif param.annotation == param.empty and param.name == "event":
required=True, return cls()
)
return cls(Required, checker=checker)
elif param.annotation == param.empty and param.name == "event":
return cls(Required)
async def _solve(self, event: "Event", **kwargs: Any) -> Any: @override
async def _solve( # pyright: ignore[reportIncompatibleMethodOverride]
self, event: "Event", **kwargs: Any
) -> Any:
return event return event
async def _check(self, event: "Event", **kwargs: Any) -> Any: @override
if checker := self.extra.get("checker", None): async def _check( # pyright: ignore[reportIncompatibleMethodOverride]
check_field_type(checker, event) self, event: "Event", **kwargs: Any
) -> Any:
if self.checker is not None:
check_field_type(self.checker, event)
class StateParam(Param): class StateParam(Param):
"""事件处理状态参数""" """事件处理状态注入参数
本注入解析所有类型为 `T_State` 的参数。
为保证兼容性,本注入还会解析名为 `state` 且没有类型注解的参数。
"""
def __repr__(self) -> str: def __repr__(self) -> str:
return "StateParam()" return "StateParam()"
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["StateParam"]: ) -> Optional[Self]:
if param.default == param.empty: # param type is T_State
if param.annotation is T_State: if origin_is_annotated(
return cls(Required) get_origin(param.annotation)
elif param.annotation == param.empty and param.name == "state": ) and _STATE_FLAG in get_args(param.annotation):
return cls(Required) return cls()
# legacy: param is named "state" and has no type annotation
elif param.annotation == param.empty and param.name == "state":
return cls()
async def _solve(self, state: T_State, **kwargs: Any) -> Any: @override
async def _solve( # pyright: ignore[reportIncompatibleMethodOverride]
self, state: T_State, **kwargs: Any
) -> Any:
return state return state
class MatcherParam(Param): class MatcherParam(Param):
"""事件响应器实例参数""" """事件响应器实例注入参数
本注入解析所有类型为且仅为 {ref}`nonebot.matcher.Matcher` 及其子类或 `None` 的参数。
为保证兼容性,本注入还会解析名为 `matcher` 且没有类型注解的参数。
"""
def __init__(
self, *args, checker: Optional[ModelField] = None, **kwargs: Any
) -> None:
super().__init__(*args, **kwargs)
self.checker = checker
def __repr__(self) -> str: def __repr__(self) -> str:
return "MatcherParam()" return (
"MatcherParam("
+ (repr(self.checker.annotation) if self.checker is not None else "")
+ ")"
)
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["MatcherParam"]: ) -> Optional[Self]:
from nonebot.matcher import Matcher from nonebot.matcher import Matcher
if generic_check_issubclass(param.annotation, Matcher) or ( # param type is Matcher(s) or subclass(es) of Matcher or None
param.annotation == param.empty and param.name == "matcher" if generic_check_issubclass(param.annotation, Matcher):
): checker: Optional[ModelField] = None
return cls(Required) if param.annotation is not Matcher:
checker = ModelField.construct(
name=param.name, annotation=param.annotation, field_info=FieldInfo()
)
return cls(checker=checker)
# legacy: param is named "matcher" and has no type annotation
elif param.annotation == param.empty and param.name == "matcher":
return cls()
async def _solve(self, matcher: "Matcher", **kwargs: Any) -> Any: @override
async def _solve( # pyright: ignore[reportIncompatibleMethodOverride]
self, matcher: "Matcher", **kwargs: Any
) -> Any:
return matcher return matcher
@override
async def _check( # pyright: ignore[reportIncompatibleMethodOverride]
self, matcher: "Matcher", **kwargs: Any
) -> Any:
if self.checker is not None:
check_field_type(self.checker, matcher)
class ArgInner: class ArgInner:
def __init__( def __init__(
self, key: Optional[str], type: Literal["message", "str", "plaintext"] self, key: Optional[str], type: Literal["message", "str", "plaintext"]
) -> None: ) -> None:
self.key = key self.key: Optional[str] = key
self.type = type self.type: Literal["message", "str", "plaintext"] = type
def __repr__(self) -> str: def __repr__(self) -> str:
return f"ArgInner(key={self.key!r}, type={self.type!r})" return f"ArgInner(key={self.key!r}, type={self.type!r})"
def Arg(key: Optional[str] = None) -> Any: def Arg(key: Optional[str] = None) -> Any:
"""`got` 的 Arg 参数消息""" """Arg 参数消息"""
return ArgInner(key, "message") return ArgInner(key, "message")
def ArgStr(key: Optional[str] = None) -> str: def ArgStr(key: Optional[str] = None) -> str:
"""`got` 的 Arg 参数消息文本""" """Arg 参数消息文本"""
return ArgInner(key, "str") # type: ignore return ArgInner(key, "str") # type: ignore
def ArgPlainText(key: Optional[str] = None) -> str: def ArgPlainText(key: Optional[str] = None) -> str:
"""`got` 的 Arg 参数消息纯文本""" """Arg 参数消息纯文本"""
return ArgInner(key, "plaintext") # type: ignore return ArgInner(key, "plaintext") # type: ignore
class ArgParam(Param): class ArgParam(Param):
"""`got` 的 Arg 参数""" """Arg 注入参数
本注入解析事件响应器操作 `got` 所获取的参数。
可以通过 `Arg`、`ArgStr`、`ArgPlainText` 等函数参数 `key` 指定获取的参数,
留空则会根据参数名称获取。
"""
def __init__(
self,
*args,
key: str,
type: Literal["message", "str", "plaintext"],
**kwargs: Any,
) -> None:
super().__init__(*args, **kwargs)
self.key = key
self.type = type
def __repr__(self) -> str: def __repr__(self) -> str:
return f"ArgParam(key={self.extra['key']!r}, type={self.extra['type']!r})" return f"ArgParam(key={self.key!r}, type={self.type!r})"
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["ArgParam"]: ) -> Optional[Self]:
if isinstance(param.default, ArgInner): if isinstance(param.default, ArgInner):
return cls( return cls(key=param.default.key or param.name, type=param.default.type)
Required, key=param.default.key or param.name, type=param.default.type elif get_origin(param.annotation) is Annotated:
) for arg in get_args(param.annotation)[:0:-1]:
if isinstance(arg, ArgInner):
return cls(key=arg.key or param.name, type=arg.type)
async def _solve(self, matcher: "Matcher", **kwargs: Any) -> Any: async def _solve( # pyright: ignore[reportIncompatibleMethodOverride]
message = matcher.get_arg(self.extra["key"]) self, matcher: "Matcher", **kwargs: Any
) -> Any:
message = matcher.get_arg(self.key)
if message is None: if message is None:
return message return message
if self.extra["type"] == "message": if self.type == "message":
return message return message
elif self.extra["type"] == "str": elif self.type == "str":
return str(message) return str(message)
else: else:
return message.extract_plain_text() return message.extract_plain_text()
class ExceptionParam(Param): class ExceptionParam(Param):
"""`run_postprocessor` 的异常参数""" """{ref}`nonebot.message.run_postprocessor` 的异常注入参数
本注入解析所有类型为 `Exception` 或 `None` 的参数。
为保证兼容性,本注入还会解析名为 `exception` 且没有类型注解的参数。
"""
def __repr__(self) -> str: def __repr__(self) -> str:
return "ExceptionParam()" return "ExceptionParam()"
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["ExceptionParam"]: ) -> Optional[Self]:
if generic_check_issubclass(param.annotation, Exception) or ( # param type is Exception(s) or subclass(es) of Exception or None
param.annotation == param.empty and param.name == "exception" if generic_check_issubclass(param.annotation, Exception):
): return cls()
return cls(Required) # legacy: param is named "exception" and has no type annotation
elif param.annotation == param.empty and param.name == "exception":
return cls()
@override
async def _solve(self, exception: Optional[Exception] = None, **kwargs: Any) -> Any: async def _solve(self, exception: Optional[Exception] = None, **kwargs: Any) -> Any:
return exception return exception
class DefaultParam(Param): class DefaultParam(Param):
"""默认值参数""" """默认值注入参数
本注入解析所有剩余未能解析且具有默认值的参数。
本注入参数应该具有最低优先级,因此应该在所有其他注入参数之后使用。
"""
def __repr__(self) -> str: def __repr__(self) -> str:
return f"DefaultParam(default={self.default!r})" return f"DefaultParam(default={self.default!r})"
@classmethod @classmethod
@override
def _check_param( def _check_param(
cls, param: inspect.Parameter, allow_types: Tuple[Type[Param], ...] cls, param: inspect.Parameter, allow_types: tuple[type[Param], ...]
) -> Optional["DefaultParam"]: ) -> Optional[Self]:
if param.default != param.empty: if param.default != param.empty:
return cls(param.default) return cls(default=param.default)
@override
async def _solve(self, **kwargs: Any) -> Any: async def _solve(self, **kwargs: Any) -> Any:
return Undefined return PydanticUndefined
__autodoc__ = { __autodoc__ = {

View File

@@ -1,7 +1,7 @@
import asyncio import asyncio
from typing_extensions import Self from typing_extensions import Self
from contextlib import AsyncExitStack from contextlib import AsyncExitStack
from typing import Set, Tuple, Union, NoReturn, Optional from typing import Union, ClassVar, NoReturn, Optional
from nonebot.dependencies import Dependent from nonebot.dependencies import Dependent
from nonebot.utils import run_coro_with_catch from nonebot.utils import run_coro_with_catch
@@ -9,7 +9,7 @@ from nonebot.exception import SkippedException
from nonebot.typing import T_DependencyCache, T_PermissionChecker from nonebot.typing import T_DependencyCache, T_PermissionChecker
from .adapter import Bot, Event from .adapter import Bot, Event
from .params import BotParam, EventParam, DependParam, DefaultParam from .params import Param, BotParam, EventParam, DependParam, DefaultParam
class Permission: class Permission:
@@ -30,7 +30,7 @@ class Permission:
__slots__ = ("checkers",) __slots__ = ("checkers",)
HANDLER_PARAM_TYPES = [ HANDLER_PARAM_TYPES: ClassVar[list[type[Param]]] = [
DependParam, DependParam,
BotParam, BotParam,
EventParam, EventParam,
@@ -38,11 +38,13 @@ class Permission:
] ]
def __init__(self, *checkers: Union[T_PermissionChecker, Dependent[bool]]) -> None: def __init__(self, *checkers: Union[T_PermissionChecker, Dependent[bool]]) -> None:
self.checkers: Set[Dependent[bool]] = { self.checkers: set[Dependent[bool]] = {
checker (
if isinstance(checker, Dependent) checker
else Dependent[bool].parse( if isinstance(checker, Dependent)
call=checker, allow_types=self.HANDLER_PARAM_TYPES else Dependent[bool].parse(
call=checker, allow_types=self.HANDLER_PARAM_TYPES
)
) )
for checker in checkers for checker in checkers
} }
@@ -120,7 +122,7 @@ class User:
__slots__ = ("users", "perm") __slots__ = ("users", "perm")
def __init__( def __init__(
self, users: Tuple[str, ...], perm: Optional[Permission] = None self, users: tuple[str, ...], perm: Optional[Permission] = None
) -> None: ) -> None:
self.users = users self.users = users
self.perm = perm self.perm = perm
@@ -144,7 +146,7 @@ class User:
@classmethod @classmethod
def _clean_permission(cls, perm: Permission) -> Optional[Permission]: def _clean_permission(cls, perm: Permission) -> Optional[Permission]:
if len(perm.checkers) == 1 and isinstance( if len(perm.checkers) == 1 and isinstance(
user_perm := tuple(perm.checkers)[0].call, cls user_perm := next(iter(perm.checkers)).call, cls
): ):
return user_perm.perm return user_perm.perm
return perm return perm

View File

@@ -1,13 +1,13 @@
import asyncio import asyncio
from contextlib import AsyncExitStack from contextlib import AsyncExitStack
from typing import Set, Union, NoReturn, Optional from typing import Union, ClassVar, NoReturn, Optional
from nonebot.dependencies import Dependent from nonebot.dependencies import Dependent
from nonebot.exception import SkippedException from nonebot.exception import SkippedException
from nonebot.typing import T_State, T_RuleChecker, T_DependencyCache from nonebot.typing import T_State, T_RuleChecker, T_DependencyCache
from .adapter import Bot, Event from .adapter import Bot, Event
from .params import BotParam, EventParam, StateParam, DependParam, DefaultParam from .params import Param, BotParam, EventParam, StateParam, DependParam, DefaultParam
class Rule: class Rule:
@@ -28,7 +28,7 @@ class Rule:
__slots__ = ("checkers",) __slots__ = ("checkers",)
HANDLER_PARAM_TYPES = [ HANDLER_PARAM_TYPES: ClassVar[list[type[Param]]] = [
DependParam, DependParam,
BotParam, BotParam,
EventParam, EventParam,
@@ -37,11 +37,13 @@ class Rule:
] ]
def __init__(self, *checkers: Union[T_RuleChecker, Dependent[bool]]) -> None: def __init__(self, *checkers: Union[T_RuleChecker, Dependent[bool]]) -> None:
self.checkers: Set[Dependent[bool]] = { self.checkers: set[Dependent[bool]] = {
checker (
if isinstance(checker, Dependent) checker
else Dependent[bool].parse( if isinstance(checker, Dependent)
call=checker, allow_types=self.HANDLER_PARAM_TYPES else Dependent[bool].parse(
call=checker, allow_types=self.HANDLER_PARAM_TYPES
)
) )
for checker in checkers for checker in checkers
} }

View File

@@ -2,7 +2,7 @@
NoneBot 使用 [`loguru`][loguru] 来记录日志信息。 NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
自定义 logger 请参考 [自定义日志](https://v2.nonebot.dev/docs/appendices/log) 自定义 logger 请参考 [自定义日志](https://nonebot.dev/docs/appendices/log)
以及 [`loguru`][loguru] 文档。 以及 [`loguru`][loguru] 文档。
[loguru]: https://github.com/Delgan/loguru [loguru]: https://github.com/Delgan/loguru
@@ -13,6 +13,7 @@ FrontMatter:
""" """
import sys import sys
import inspect
import logging import logging
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
@@ -45,6 +46,7 @@ logger: "Logger" = loguru.logger
# logger.addHandler(default_handler) # logger.addHandler(default_handler)
# https://loguru.readthedocs.io/en/stable/overview.html#entirely-compatible-with-standard-logging
class LoguruHandler(logging.Handler): # pragma: no cover class LoguruHandler(logging.Handler): # pragma: no cover
"""logging 与 loguru 之间的桥梁,将 logging 的日志转发到 loguru。""" """logging 与 loguru 之间的桥梁,将 logging 的日志转发到 loguru。"""
@@ -54,8 +56,8 @@ class LoguruHandler(logging.Handler): # pragma: no cover
except ValueError: except ValueError:
level = record.levelno level = record.levelno
frame, depth = logging.currentframe(), 2 frame, depth = inspect.currentframe(), 0
while frame and frame.f_code.co_filename == logging.__file__: while frame and (depth == 0 or frame.f_code.co_filename == logging.__file__):
frame = frame.f_back frame = frame.f_back
depth += 1 depth += 1
@@ -88,5 +90,6 @@ logger_id = logger.add(
filter=default_filter, filter=default_filter,
format=default_format, format=default_format,
) )
"""默认日志处理器 id"""
__autodoc__ = {"logger_id": False} __autodoc__ = {"logger_id": False}

View File

@@ -8,6 +8,7 @@ FrontMatter:
from nonebot.internal.matcher import Matcher as Matcher from nonebot.internal.matcher import Matcher as Matcher
from nonebot.internal.matcher import matchers as matchers from nonebot.internal.matcher import matchers as matchers
from nonebot.internal.matcher import current_bot as current_bot from nonebot.internal.matcher import current_bot as current_bot
from nonebot.internal.matcher import MatcherSource as MatcherSource
from nonebot.internal.matcher import current_event as current_event from nonebot.internal.matcher import current_event as current_event
from nonebot.internal.matcher import MatcherManager as MatcherManager from nonebot.internal.matcher import MatcherManager as MatcherManager
from nonebot.internal.matcher import MatcherProvider as MatcherProvider from nonebot.internal.matcher import MatcherProvider as MatcherProvider

View File

@@ -11,7 +11,7 @@ import asyncio
import contextlib import contextlib
from datetime import datetime from datetime import datetime
from contextlib import AsyncExitStack from contextlib import AsyncExitStack
from typing import TYPE_CHECKING, Any, Set, Dict, Type, Optional from typing import TYPE_CHECKING, Any, Optional
from nonebot.log import logger from nonebot.log import logger
from nonebot.rule import TrieRule from nonebot.rule import TrieRule
@@ -46,10 +46,10 @@ from nonebot.internal.params import (
if TYPE_CHECKING: if TYPE_CHECKING:
from nonebot.adapters import Bot, Event from nonebot.adapters import Bot, Event
_event_preprocessors: Set[Dependent[Any]] = set() _event_preprocessors: set[Dependent[Any]] = set()
_event_postprocessors: Set[Dependent[Any]] = set() _event_postprocessors: set[Dependent[Any]] = set()
_run_preprocessors: Set[Dependent[Any]] = set() _run_preprocessors: set[Dependent[Any]] = set()
_run_postprocessors: Set[Dependent[Any]] = set() _run_postprocessors: set[Dependent[Any]] = set()
EVENT_PCS_PARAMS = ( EVENT_PCS_PARAMS = (
DependParam, DependParam,
@@ -80,7 +80,10 @@ RUN_POSTPCS_PARAMS = (
def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor: def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
"""事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。""" """事件预处理。
装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
"""
_event_preprocessors.add( _event_preprocessors.add(
Dependent[Any].parse(call=func, allow_types=EVENT_PCS_PARAMS) Dependent[Any].parse(call=func, allow_types=EVENT_PCS_PARAMS)
) )
@@ -88,7 +91,10 @@ def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor: def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
"""事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。""" """事件后处理。
装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
"""
_event_postprocessors.add( _event_postprocessors.add(
Dependent[Any].parse(call=func, allow_types=EVENT_PCS_PARAMS) Dependent[Any].parse(call=func, allow_types=EVENT_PCS_PARAMS)
) )
@@ -96,7 +102,10 @@ def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor: def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
"""运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。""" """运行预处理。
装饰一个函数,使它在每次事件响应器运行前执行。
"""
_run_preprocessors.add( _run_preprocessors.add(
Dependent[Any].parse(call=func, allow_types=RUN_PREPCS_PARAMS) Dependent[Any].parse(call=func, allow_types=RUN_PREPCS_PARAMS)
) )
@@ -104,81 +113,313 @@ def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor: def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:
"""运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。""" """运行后处理。
装饰一个函数,使它在每次事件响应器运行后执行。
"""
_run_postprocessors.add( _run_postprocessors.add(
Dependent[Any].parse(call=func, allow_types=RUN_POSTPCS_PARAMS) Dependent[Any].parse(call=func, allow_types=RUN_POSTPCS_PARAMS)
) )
return func return func
async def _check_matcher( async def _apply_event_preprocessors(
Matcher: Type[Matcher],
bot: "Bot", bot: "Bot",
event: "Event", event: "Event",
state: T_State, state: T_State,
stack: Optional[AsyncExitStack] = None, stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None, dependency_cache: Optional[T_DependencyCache] = None,
show_log: bool = True,
) -> bool:
"""运行事件预处理。
参数:
bot: Bot 对象
event: Event 对象
state: 会话状态
stack: 异步上下文栈
dependency_cache: 依赖缓存
show_log: 是否显示日志
返回:
是否继续处理事件
"""
if not _event_preprocessors:
return True
if show_log:
logger.debug("Running PreProcessors...")
try:
await asyncio.gather(
*(
run_coro_with_catch(
proc(
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _event_preprocessors
)
)
except IgnoredException:
logger.opt(colors=True).info(
f"Event {escape_tag(event.get_event_name())} is <b>ignored</b>"
)
return False
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running EventPreProcessors. "
"Event ignored!</bg #f8bbd0></r>"
)
return False
return True
async def _apply_event_postprocessors(
bot: "Bot",
event: "Event",
state: T_State,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
show_log: bool = True,
) -> None: ) -> None:
"""运行事件后处理。
参数:
bot: Bot 对象
event: Event 对象
state: 会话状态
stack: 异步上下文栈
dependency_cache: 依赖缓存
show_log: 是否显示日志
"""
if not _event_postprocessors:
return
if show_log:
logger.debug("Running PostProcessors...")
try:
await asyncio.gather(
*(
run_coro_with_catch(
proc(
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _event_postprocessors
)
)
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>"
)
async def _apply_run_preprocessors(
bot: "Bot",
event: "Event",
state: T_State,
matcher: Matcher,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
) -> bool:
"""运行事件响应器运行前处理。
参数:
bot: Bot 对象
event: Event 对象
state: 会话状态
matcher: 事件响应器
stack: 异步上下文栈
dependency_cache: 依赖缓存
返回:
是否继续处理事件
"""
if not _run_preprocessors:
return True
# ensure matcher function can be correctly called
with matcher.ensure_context(bot, event):
try:
await asyncio.gather(
*(
run_coro_with_catch(
proc(
matcher=matcher,
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _run_preprocessors
)
)
except IgnoredException:
logger.opt(colors=True).info(f"{matcher} running is <b>cancelled</b>")
return False
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running RunPreProcessors. "
"Running cancelled!</bg #f8bbd0></r>"
)
return False
return True
async def _apply_run_postprocessors(
bot: "Bot",
event: "Event",
matcher: Matcher,
exception: Optional[Exception] = None,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
) -> None:
"""运行事件响应器运行后处理。
参数:
bot: Bot 对象
event: Event 对象
matcher: 事件响应器
exception: 事件响应器运行异常
stack: 异步上下文栈
dependency_cache: 依赖缓存
"""
if not _run_postprocessors:
return
with matcher.ensure_context(bot, event):
try:
await asyncio.gather(
*(
run_coro_with_catch(
proc(
matcher=matcher,
exception=exception,
bot=bot,
event=event,
state=matcher.state,
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _run_postprocessors
)
)
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running RunPostProcessors</bg #f8bbd0></r>"
)
async def _check_matcher(
Matcher: type[Matcher],
bot: "Bot",
event: "Event",
state: T_State,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
) -> bool:
"""检查事件响应器是否符合运行条件。
请注意,过时的事件响应器将被**销毁**。对于未过时的事件响应器,将会一次检查其响应类型、权限和规则。
参数:
Matcher: 要检查的事件响应器
bot: Bot 对象
event: Event 对象
state: 会话状态
stack: 异步上下文栈
dependency_cache: 依赖缓存
返回:
bool: 是否符合运行条件
"""
if Matcher.expire_time and datetime.now() > Matcher.expire_time: if Matcher.expire_time and datetime.now() > Matcher.expire_time:
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
Matcher.destroy() Matcher.destroy()
return return False
try: try:
if not await Matcher.check_perm( if not await Matcher.check_perm(bot, event, stack, dependency_cache):
bot, event, stack, dependency_cache logger.trace(f"Permission conditions not met for {Matcher}")
) or not await Matcher.check_rule(bot, event, state, stack, dependency_cache): return False
return except Exception as e:
logger.opt(colors=True, exception=e).error(
f"<r><bg #f8bbd0>Permission check failed for {Matcher}.</bg #f8bbd0></r>"
)
return False
try:
if not await Matcher.check_rule(bot, event, state, stack, dependency_cache):
logger.trace(f"Rule conditions not met for {Matcher}")
return False
except Exception as e: except Exception as e:
logger.opt(colors=True, exception=e).error( logger.opt(colors=True, exception=e).error(
f"<r><bg #f8bbd0>Rule check failed for {Matcher}.</bg #f8bbd0></r>" f"<r><bg #f8bbd0>Rule check failed for {Matcher}.</bg #f8bbd0></r>"
) )
return return False
if Matcher.temp: return True
with contextlib.suppress(Exception):
Matcher.destroy()
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
async def _run_matcher( async def _run_matcher(
Matcher: Type[Matcher], Matcher: type[Matcher],
bot: "Bot", bot: "Bot",
event: "Event", event: "Event",
state: T_State, state: T_State,
stack: Optional[AsyncExitStack] = None, stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None, dependency_cache: Optional[T_DependencyCache] = None,
) -> None: ) -> None:
"""运行事件响应器。
临时事件响应器将在运行前被**销毁**。
参数:
Matcher: 事件响应器
bot: Bot 对象
event: Event 对象
state: 会话状态
stack: 异步上下文栈
dependency_cache: 依赖缓存
异常:
StopPropagation: 阻止事件继续传播
"""
logger.info(f"Event will be handled by {Matcher}") logger.info(f"Event will be handled by {Matcher}")
matcher = Matcher() if Matcher.temp:
if coros := [ with contextlib.suppress(Exception):
run_coro_with_catch( Matcher.destroy()
proc(
matcher=matcher,
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _run_preprocessors
]:
# ensure matcher function can be correctly called
with matcher.ensure_context(bot, event):
try:
await asyncio.gather(*coros)
except IgnoredException:
logger.opt(colors=True).info(f"{matcher} running is <b>cancelled</b>")
return
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running RunPreProcessors. Running cancelled!</bg #f8bbd0></r>"
)
return matcher = Matcher()
if not await _apply_run_preprocessors(
bot=bot,
event=event,
state=state,
matcher=matcher,
stack=stack,
dependency_cache=dependency_cache,
):
return
exception = None exception = None
@@ -191,33 +432,55 @@ async def _run_matcher(
) )
exception = e exception = e
if coros := [ await _apply_run_postprocessors(
run_coro_with_catch( bot=bot,
proc( event=event,
matcher=matcher, matcher=matcher,
exception=exception, exception=exception,
bot=bot, stack=stack,
event=event, dependency_cache=dependency_cache,
state=matcher.state, )
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _run_postprocessors
]:
# ensure matcher function can be correctly called
with matcher.ensure_context(bot, event):
try:
await asyncio.gather(*coros)
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running RunPostProcessors</bg #f8bbd0></r>"
)
if matcher.block: if matcher.block:
raise StopPropagation raise StopPropagation
return
async def check_and_run_matcher(
Matcher: type[Matcher],
bot: "Bot",
event: "Event",
state: T_State,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
) -> None:
"""检查并运行事件响应器。
参数:
Matcher: 事件响应器
bot: Bot 对象
event: Event 对象
state: 会话状态
stack: 异步上下文栈
dependency_cache: 依赖缓存
"""
if not await _check_matcher(
Matcher=Matcher,
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
):
return
await _run_matcher(
Matcher=Matcher,
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
)
async def handle_event(bot: "Bot", event: "Event") -> None: async def handle_event(bot: "Bot", event: "Event") -> None:
@@ -242,38 +505,19 @@ async def handle_event(bot: "Bot", event: "Event") -> None:
if show_log: if show_log:
logger.opt(colors=True).success(log_msg) logger.opt(colors=True).success(log_msg)
state: Dict[Any, Any] = {} state: dict[Any, Any] = {}
dependency_cache: T_DependencyCache = {} dependency_cache: T_DependencyCache = {}
# create event scope context
async with AsyncExitStack() as stack: async with AsyncExitStack() as stack:
if coros := [ if not await _apply_event_preprocessors(
run_coro_with_catch( bot=bot,
proc( event=event,
bot=bot, state=state,
event=event, stack=stack,
state=state, dependency_cache=dependency_cache,
stack=stack, ):
dependency_cache=dependency_cache, return
),
(SkippedException,),
)
for proc in _event_preprocessors
]:
try:
if show_log:
logger.debug("Running PreProcessors...")
await asyncio.gather(*coros)
except IgnoredException as e:
logger.opt(colors=True).info(
f"Event {escape_tag(event.get_event_name())} is <b>ignored</b>"
)
return
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running EventPreProcessors. "
"Event ignored!</bg #f8bbd0></r>"
)
return
# Trie Match # Trie Match
try: try:
@@ -284,6 +528,7 @@ async def handle_event(bot: "Bot", event: "Event") -> None:
) )
break_flag = False break_flag = False
# iterate through all priority until stop propagation
for priority in sorted(matchers.keys()): for priority in sorted(matchers.keys()):
if break_flag: if break_flag:
break break
@@ -292,14 +537,12 @@ async def handle_event(bot: "Bot", event: "Event") -> None:
logger.debug(f"Checking for matchers in priority {priority}...") logger.debug(f"Checking for matchers in priority {priority}...")
pending_tasks = [ pending_tasks = [
_check_matcher( check_and_run_matcher(
matcher, bot, event, state.copy(), stack, dependency_cache matcher, bot, event, state.copy(), stack, dependency_cache
) )
for matcher in matchers[priority] for matcher in matchers[priority]
] ]
results = await asyncio.gather(*pending_tasks, return_exceptions=True) results = await asyncio.gather(*pending_tasks, return_exceptions=True)
for result in results: for result in results:
if not isinstance(result, Exception): if not isinstance(result, Exception):
continue continue
@@ -314,24 +557,4 @@ async def handle_event(bot: "Bot", event: "Event") -> None:
if show_log: if show_log:
logger.debug("Checking for matchers completed") logger.debug("Checking for matchers completed")
if coros := [ await _apply_event_postprocessors(bot, event, state, stack, dependency_cache)
run_coro_with_catch(
proc(
bot=bot,
event=event,
state=state,
stack=stack,
dependency_cache=dependency_cache,
),
(SkippedException,),
)
for proc in _event_postprocessors
]:
try:
if show_log:
logger.debug("Running PostProcessors...")
await asyncio.gather(*coros)
except Exception as e:
logger.opt(colors=True, exception=e).error(
"<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>"
)

View File

@@ -5,8 +5,8 @@ FrontMatter:
description: nonebot.params 模块 description: nonebot.params 模块
""" """
import warnings from re import Match
from typing import Any, Dict, List, Tuple, Union, Optional from typing import Any, Union, Literal, Callable, Optional, overload
from nonebot.typing import T_State from nonebot.typing import T_State
from nonebot.matcher import Matcher from nonebot.matcher import Matcher
@@ -25,15 +25,12 @@ from nonebot.internal.params import MatcherParam as MatcherParam
from nonebot.internal.params import ExceptionParam as ExceptionParam from nonebot.internal.params import ExceptionParam as ExceptionParam
from nonebot.consts import ( from nonebot.consts import (
CMD_KEY, CMD_KEY,
REGEX_STR,
PREFIX_KEY, PREFIX_KEY,
REGEX_DICT,
SHELL_ARGS, SHELL_ARGS,
SHELL_ARGV, SHELL_ARGV,
CMD_ARG_KEY, CMD_ARG_KEY,
KEYWORD_KEY, KEYWORD_KEY,
RAW_CMD_KEY, RAW_CMD_KEY,
REGEX_GROUP,
ENDSWITH_KEY, ENDSWITH_KEY,
CMD_START_KEY, CMD_START_KEY,
FULLMATCH_KEY, FULLMATCH_KEY,
@@ -83,7 +80,7 @@ def _command(state: T_State) -> Message:
return state[PREFIX_KEY][CMD_KEY] return state[PREFIX_KEY][CMD_KEY]
def Command() -> Tuple[str, ...]: def Command() -> tuple[str, ...]:
"""消息命令元组""" """消息命令元组"""
return Depends(_command) return Depends(_command)
@@ -133,7 +130,7 @@ def ShellCommandArgs() -> Any:
return Depends(_shell_command_args, use_cache=False) return Depends(_shell_command_args, use_cache=False)
def _shell_command_argv(state: T_State) -> List[Union[str, MessageSegment]]: def _shell_command_argv(state: T_State) -> list[Union[str, MessageSegment]]:
return state[SHELL_ARGV] return state[SHELL_ARGV]
@@ -142,44 +139,59 @@ def ShellCommandArgv() -> Any:
return Depends(_shell_command_argv, use_cache=False) return Depends(_shell_command_argv, use_cache=False)
def _regex_matched(state: T_State) -> str: def _regex_matched(state: T_State) -> Match[str]:
return state[REGEX_MATCHED] return state[REGEX_MATCHED]
def RegexMatched() -> str: def RegexMatched() -> Match[str]:
"""正则匹配结果""" """正则匹配结果"""
warnings.warn(
'"RegexMatched()" will be changed to "re.Match" object, '
'use "RegexStr()" instead. '
"See https://github.com/nonebot/nonebot2/pull/1453 .",
DeprecationWarning,
)
return Depends(_regex_matched, use_cache=False) return Depends(_regex_matched, use_cache=False)
def _regex_str(state: T_State) -> str: def _regex_str(
return state[REGEX_STR] groups: tuple[Union[str, int], ...]
) -> Callable[[T_State], Union[str, tuple[Union[str, Any], ...], Any]]:
def _regex_str_dependency(
state: T_State,
) -> Union[str, tuple[Union[str, Any], ...], Any]:
return _regex_matched(state).group(*groups)
return _regex_str_dependency
def RegexStr() -> str: @overload
def RegexStr(__group: Literal[0] = 0) -> str: ...
@overload
def RegexStr(__group: Union[str, int]) -> Union[str, Any]: ...
@overload
def RegexStr(
__group1: Union[str, int], __group2: Union[str, int], *groups: Union[str, int]
) -> tuple[Union[str, Any], ...]: ...
def RegexStr(*groups: Union[str, int]) -> Union[str, tuple[Union[str, Any], ...], Any]:
"""正则匹配结果文本""" """正则匹配结果文本"""
return Depends(_regex_str, use_cache=False) return Depends(_regex_str(groups), use_cache=False)
def _regex_group(state: T_State) -> Tuple[Any, ...]: def _regex_group(state: T_State) -> tuple[Any, ...]:
return state[REGEX_GROUP] return _regex_matched(state).groups()
def RegexGroup() -> Tuple[Any, ...]: def RegexGroup() -> tuple[Any, ...]:
"""正则匹配结果 group 元组""" """正则匹配结果 group 元组"""
return Depends(_regex_group, use_cache=False) return Depends(_regex_group, use_cache=False)
def _regex_dict(state: T_State) -> Dict[str, Any]: def _regex_dict(state: T_State) -> dict[str, Any]:
return state[REGEX_DICT] return _regex_matched(state).groupdict()
def RegexDict() -> Dict[str, Any]: def RegexDict() -> dict[str, Any]:
"""正则匹配结果 group 字典""" """正则匹配结果 group 字典"""
return Depends(_regex_dict, use_cache=False) return Depends(_regex_dict, use_cache=False)

View File

@@ -1,7 +1,8 @@
"""本模块是 {ref}`nonebot.matcher.Matcher.permission` 的类型定义。 """本模块是 {ref}`nonebot.matcher.Matcher.permission` 的类型定义。
每个 {ref}`nonebot.matcher.Matcher` 拥有一个 {ref}`nonebot.permission.Permission` 每个{ref}`事件响应器 <nonebot.matcher.Matcher>`
其中是 `PermissionChecker` 的集合,只要有一个 `PermissionChecker` 检查结果为 `True` 时就会继续运行 拥有一个 {ref}`nonebot.permission.Permission`,其中是 `PermissionChecker` 的集合
只要有一个 `PermissionChecker` 检查结果为 `True` 时就会继续运行。
FrontMatter: FrontMatter:
sidebar_position: 6 sidebar_position: 6

View File

@@ -24,10 +24,12 @@
- `load_all_plugins` => {ref}``load_all_plugins` <nonebot.plugin.load.load_all_plugins>` - `load_all_plugins` => {ref}``load_all_plugins` <nonebot.plugin.load.load_all_plugins>`
- `load_from_json` => {ref}``load_from_json` <nonebot.plugin.load.load_from_json>` - `load_from_json` => {ref}``load_from_json` <nonebot.plugin.load.load_from_json>`
- `load_from_toml` => {ref}``load_from_toml` <nonebot.plugin.load.load_from_toml>` - `load_from_toml` => {ref}``load_from_toml` <nonebot.plugin.load.load_from_toml>`
- `load_builtin_plugin` => {ref}``load_builtin_plugin` <nonebot.plugin.load.load_builtin_plugin>` - `load_builtin_plugin` =>
- `load_builtin_plugins` => {ref}``load_builtin_plugins` <nonebot.plugin.load.load_builtin_plugins>` {ref}``load_builtin_plugin` <nonebot.plugin.load.load_builtin_plugin>`
- `load_builtin_plugins` =>
{ref}``load_builtin_plugins` <nonebot.plugin.load.load_builtin_plugins>`
- `require` => {ref}``require` <nonebot.plugin.load.require>` - `require` => {ref}``require` <nonebot.plugin.load.require>`
- `PluginMetadata` => {ref}``PluginMetadata` <nonebot.plugin.plugin.PluginMetadata>` - `PluginMetadata` => {ref}``PluginMetadata` <nonebot.plugin.model.PluginMetadata>`
FrontMatter: FrontMatter:
sidebar_position: 0 sidebar_position: 0
@@ -37,12 +39,19 @@ FrontMatter:
from itertools import chain from itertools import chain
from types import ModuleType from types import ModuleType
from contextvars import ContextVar from contextvars import ContextVar
from typing import Set, Dict, List, Tuple, Optional from typing import TypeVar, Optional
_plugins: Dict[str, "Plugin"] = {} from pydantic import BaseModel
_managers: List["PluginManager"] = []
_current_plugin_chain: ContextVar[Tuple["Plugin", ...]] = ContextVar( from nonebot import get_driver
"_current_plugin_chain", default=tuple() from nonebot.compat import model_dump, type_validate_python
C = TypeVar("C", bound=BaseModel)
_plugins: dict[str, "Plugin"] = {}
_managers: list["PluginManager"] = []
_current_plugin: ContextVar[Optional["Plugin"]] = ContextVar(
"_current_plugin", default=None
) )
@@ -50,34 +59,87 @@ def _module_name_to_plugin_name(module_name: str) -> str:
return module_name.rsplit(".", 1)[-1] return module_name.rsplit(".", 1)[-1]
def _controlled_modules() -> dict[str, str]:
return {
plugin_id: module_name
for manager in _managers
for plugin_id, module_name in manager.controlled_modules.items()
}
def _find_parent_plugin_id(
module_name: str, controlled_modules: Optional[dict[str, str]] = None
) -> Optional[str]:
if controlled_modules is None:
controlled_modules = _controlled_modules()
available = {
module_name: plugin_id for plugin_id, module_name in controlled_modules.items()
}
while "." in module_name:
module_name, _ = module_name.rsplit(".", 1)
if module_name in available:
return available[module_name]
def _module_name_to_plugin_id(
module_name: str, controlled_modules: Optional[dict[str, str]] = None
) -> str:
plugin_name = _module_name_to_plugin_name(module_name)
if parent_plugin_id := _find_parent_plugin_id(module_name, controlled_modules):
return f"{parent_plugin_id}:{plugin_name}"
return plugin_name
def _new_plugin( def _new_plugin(
module_name: str, module: ModuleType, manager: "PluginManager" module_name: str, module: ModuleType, manager: "PluginManager"
) -> "Plugin": ) -> "Plugin":
plugin_name = _module_name_to_plugin_name(module_name) plugin_id = _module_name_to_plugin_id(module_name)
if plugin_name in _plugins: if plugin_id in _plugins:
raise RuntimeError("Plugin already exists! Check your plugin name.") raise RuntimeError(
plugin = Plugin(plugin_name, module, module_name, manager) f"Plugin {plugin_id} already exists! Check your plugin name."
_plugins[plugin_name] = plugin )
parent_plugin_id = _find_parent_plugin_id(module_name)
if parent_plugin_id is not None and parent_plugin_id not in _plugins:
raise RuntimeError(
f"Parent plugin {parent_plugin_id} must "
f"be loaded before loading {plugin_id}."
)
parent_plugin = _plugins[parent_plugin_id] if parent_plugin_id is not None else None
plugin = Plugin(
name=_module_name_to_plugin_name(module_name),
module=module,
module_name=module_name,
manager=manager,
parent_plugin=parent_plugin,
)
if parent_plugin:
parent_plugin.sub_plugins.add(plugin)
_plugins[plugin_id] = plugin
return plugin return plugin
def _revert_plugin(plugin: "Plugin") -> None: def _revert_plugin(plugin: "Plugin") -> None:
if plugin.name not in _plugins: if plugin.id_ not in _plugins:
raise RuntimeError("Plugin not found!") raise RuntimeError("Plugin not found!")
del _plugins[plugin.name] del _plugins[plugin.id_]
if parent_plugin := plugin.parent_plugin: if parent_plugin := plugin.parent_plugin:
parent_plugin.sub_plugins.remove(plugin) parent_plugin.sub_plugins.discard(plugin)
def get_plugin(name: str) -> Optional["Plugin"]: def get_plugin(plugin_id: str) -> Optional["Plugin"]:
"""获取已经导入的某个插件。 """获取已经导入的某个插件。
如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。 如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。
如果为嵌套的子插件,标识符为 `父插件标识符:子插件文件(夹)名`。
参数: 参数:
name: 插件,即 {ref}`nonebot.plugin.plugin.Plugin.name`。 plugin_id: 插件标识符,即 {ref}`nonebot.plugin.model.Plugin.id_`。
""" """
return _plugins.get(name) return _plugins.get(plugin_id)
def get_plugin_by_module_name(module_name: str) -> Optional["Plugin"]: def get_plugin_by_module_name(module_name: str) -> Optional["Plugin"]:
@@ -86,7 +148,7 @@ def get_plugin_by_module_name(module_name: str) -> Optional["Plugin"]:
如果提供的模块名为某个插件的子模块,同样会返回该插件。 如果提供的模块名为某个插件的子模块,同样会返回该插件。
参数: 参数:
module_name: 模块名,即 {ref}`nonebot.plugin.plugin.Plugin.module_name`。 module_name: 模块名,即 {ref}`nonebot.plugin.model.Plugin.module_name`。
""" """
loaded = {plugin.module_name: plugin for plugin in _plugins.values()} loaded = {plugin.module_name: plugin for plugin in _plugins.values()}
has_parent = True has_parent = True
@@ -96,22 +158,27 @@ def get_plugin_by_module_name(module_name: str) -> Optional["Plugin"]:
module_name, *has_parent = module_name.rsplit(".", 1) module_name, *has_parent = module_name.rsplit(".", 1)
def get_loaded_plugins() -> Set["Plugin"]: def get_loaded_plugins() -> set["Plugin"]:
"""获取当前已导入的所有插件。""" """获取当前已导入的所有插件。"""
return set(_plugins.values()) return set(_plugins.values())
def get_available_plugin_names() -> Set[str]: def get_available_plugin_names() -> set[str]:
"""获取当前所有可用的插件(包含尚未加载的插件)。""" """获取当前所有可用的插件标识符(包含尚未加载的插件)。"""
return {*chain.from_iterable(manager.available_plugins for manager in _managers)} return {*chain.from_iterable(manager.available_plugins for manager in _managers)}
def get_plugin_config(config: type[C]) -> C:
"""从全局配置获取当前插件需要的配置项。"""
return type_validate_python(config, model_dump(get_driver().config))
from .on import on as on from .on import on as on
from .manager import PluginManager from .manager import PluginManager
from .on import on_type as on_type from .on import on_type as on_type
from .model import Plugin as Plugin
from .load import require as require from .load import require as require
from .on import on_regex as on_regex from .on import on_regex as on_regex
from .plugin import Plugin as Plugin
from .on import on_notice as on_notice from .on import on_notice as on_notice
from .on import on_command as on_command from .on import on_command as on_command
from .on import on_keyword as on_keyword from .on import on_keyword as on_keyword
@@ -127,8 +194,9 @@ from .load import load_plugins as load_plugins
from .on import on_startswith as on_startswith from .on import on_startswith as on_startswith
from .load import load_from_json as load_from_json from .load import load_from_json as load_from_json
from .load import load_from_toml as load_from_toml from .load import load_from_toml as load_from_toml
from .model import PluginMetadata as PluginMetadata
from .on import on_shell_command as on_shell_command from .on import on_shell_command as on_shell_command
from .plugin import PluginMetadata as PluginMetadata
from .load import load_all_plugins as load_all_plugins from .load import load_all_plugins as load_all_plugins
from .load import load_builtin_plugin as load_builtin_plugin from .load import load_builtin_plugin as load_builtin_plugin
from .load import load_builtin_plugins as load_builtin_plugins from .load import load_builtin_plugins as load_builtin_plugins
from .load import inherit_supported_adapters as inherit_supported_adapters

View File

@@ -4,19 +4,21 @@ FrontMatter:
sidebar_position: 1 sidebar_position: 1
description: nonebot.plugin.load 模块 description: nonebot.plugin.load 模块
""" """
import json import json
from pathlib import Path from pathlib import Path
from types import ModuleType from types import ModuleType
from typing import Set, Union, Iterable, Optional from typing import Union, Optional
from collections.abc import Iterable
from nonebot.utils import path_to_module_name from nonebot.utils import path_to_module_name
from .plugin import Plugin from .model import Plugin
from .manager import PluginManager from .manager import PluginManager
from . import _managers, get_plugin, _module_name_to_plugin_name from . import _managers, get_plugin, _module_name_to_plugin_id
try: # pragma: py-gte-311 try: # pragma: py-gte-311
import tomllib # pyright: reportMissingImports=false import tomllib # pyright: ignore[reportMissingImports]
except ModuleNotFoundError: # pragma: py-lt-311 except ModuleNotFoundError: # pragma: py-lt-311
import tomli as tomllib import tomli as tomllib
@@ -25,7 +27,8 @@ def load_plugin(module_path: Union[str, Path]) -> Optional[Plugin]:
"""加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。 """加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。
参数: 参数:
module_path: 插件名称 `path.to.your.plugin` 或插件路径 `pathlib.Path(path/to/your/plugin)` module_path: 插件名称 `path.to.your.plugin`
或插件路径 `pathlib.Path(path/to/your/plugin)`
""" """
module_path = ( module_path = (
path_to_module_name(module_path) path_to_module_name(module_path)
@@ -37,7 +40,7 @@ def load_plugin(module_path: Union[str, Path]) -> Optional[Plugin]:
return manager.load_plugin(module_path) return manager.load_plugin(module_path)
def load_plugins(*plugin_dir: str) -> Set[Plugin]: def load_plugins(*plugin_dir: str) -> set[Plugin]:
"""导入文件夹下多个插件,以 `_` 开头的插件不会被导入! """导入文件夹下多个插件,以 `_` 开头的插件不会被导入!
参数: 参数:
@@ -50,7 +53,7 @@ def load_plugins(*plugin_dir: str) -> Set[Plugin]:
def load_all_plugins( def load_all_plugins(
module_path: Iterable[str], plugin_dir: Iterable[str] module_path: Iterable[str], plugin_dir: Iterable[str]
) -> Set[Plugin]: ) -> set[Plugin]:
"""导入指定列表中的插件以及指定目录下多个插件,以 `_` 开头的插件不会被导入! """导入指定列表中的插件以及指定目录下多个插件,以 `_` 开头的插件不会被导入!
参数: 参数:
@@ -62,8 +65,9 @@ def load_all_plugins(
return manager.load_all_plugins() return manager.load_all_plugins()
def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]: def load_from_json(file_path: str, encoding: str = "utf-8") -> set[Plugin]:
"""导入指定 json 文件中的 `plugins` 以及 `plugin_dirs` 下多个插件,以 `_` 开头的插件不会被导入! """导入指定 json 文件中的 `plugins` 以及 `plugin_dirs` 下多个插件
以 `_` 开头的插件不会被导入!
参数: 参数:
file_path: 指定 json 文件路径 file_path: 指定 json 文件路径
@@ -81,7 +85,7 @@ def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
nonebot.load_from_json("plugins.json") nonebot.load_from_json("plugins.json")
``` ```
""" """
with open(file_path, "r", encoding=encoding) as f: with open(file_path, encoding=encoding) as f:
data = json.load(f) data = json.load(f)
if not isinstance(data, dict): if not isinstance(data, dict):
raise TypeError("json file must contains a dict!") raise TypeError("json file must contains a dict!")
@@ -92,8 +96,10 @@ def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
return load_all_plugins(set(plugins), set(plugin_dirs)) return load_all_plugins(set(plugins), set(plugin_dirs))
def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]: def load_from_toml(file_path: str, encoding: str = "utf-8") -> set[Plugin]:
"""导入指定 toml 文件 `[tool.nonebot]` 中的 `plugins` 以及 `plugin_dirs` 下多个插件,以 `_` 开头的插件不会被导入! """导入指定 toml 文件 `[tool.nonebot]` 中的
`plugins` 以及 `plugin_dirs` 下多个插件。
以 `_` 开头的插件不会被导入!
参数: 参数:
file_path: 指定 toml 文件路径 file_path: 指定 toml 文件路径
@@ -110,7 +116,7 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
nonebot.load_from_toml("pyproject.toml") nonebot.load_from_toml("pyproject.toml")
``` ```
""" """
with open(file_path, "r", encoding=encoding) as f: with open(file_path, encoding=encoding) as f:
data = tomllib.loads(f.read()) data = tomllib.loads(f.read())
nonebot_data = data.get("tool", {}).get("nonebot") nonebot_data = data.get("tool", {}).get("nonebot")
@@ -134,7 +140,7 @@ def load_builtin_plugin(name: str) -> Optional[Plugin]:
return load_plugin(f"nonebot.plugins.{name}") return load_plugin(f"nonebot.plugins.{name}")
def load_builtin_plugins(*plugins: str) -> Set[Plugin]: def load_builtin_plugins(*plugins: str) -> set[Plugin]:
"""导入多个 NoneBot 内置插件。 """导入多个 NoneBot 内置插件。
参数: 参数:
@@ -145,27 +151,78 @@ def load_builtin_plugins(*plugins: str) -> Set[Plugin]:
def _find_manager_by_name(name: str) -> Optional[PluginManager]: def _find_manager_by_name(name: str) -> Optional[PluginManager]:
for manager in reversed(_managers): for manager in reversed(_managers):
if name in manager.plugins or name in manager.searched_plugins: if (
name in manager.controlled_modules
or name in manager.controlled_modules.values()
):
return manager return manager
def require(name: str) -> ModuleType: def require(name: str) -> ModuleType:
"""获取一个插件的导出内容 """声明依赖插件
如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。
参数: 参数:
name: 插件名,即 {ref}`nonebot.plugin.plugin.Plugin.name` name: 插件模块名或插件标识符,仅在已声明插件的情况下可使用标识符
异常: 异常:
RuntimeError: 插件无法加载 RuntimeError: 插件无法加载
""" """
plugin = get_plugin(_module_name_to_plugin_name(name)) if "." in name:
if not plugin: # name is a module name
plugin = get_plugin(_module_name_to_plugin_id(name))
else:
# name is a plugin id or simple module name (equals to plugin id)
plugin = get_plugin(name)
# if plugin not loaded
if plugin is None:
# plugin already declared, module name / plugin id
if manager := _find_manager_by_name(name): if manager := _find_manager_by_name(name):
plugin = manager.load_plugin(name) plugin = manager.load_plugin(name)
# plugin not declared, try to declare and load it
else: else:
plugin = load_plugin(name) plugin = load_plugin(name)
if not plugin:
if plugin is None:
raise RuntimeError(f'Cannot load plugin "{name}"!') raise RuntimeError(f'Cannot load plugin "{name}"!')
return plugin.module return plugin.module
def inherit_supported_adapters(*names: str) -> Optional[set[str]]:
"""获取已加载插件的适配器支持状态集合。
如果传入了多个插件名称,返回值会自动取交集。
参数:
names: 插件名称列表。
异常:
RuntimeError: 插件未加载
ValueError: 插件缺少元数据
"""
final_supported: Optional[set[str]] = None
for name in names:
plugin = get_plugin(_module_name_to_plugin_id(name))
if plugin is None:
raise RuntimeError(
f'Plugin "{name}" is not loaded! You should require it first.'
)
meta = plugin.metadata
if meta is None:
raise ValueError(f'Plugin "{name}" has no metadata!')
if (raw := meta.supported_adapters) is None:
continue
support = {
f"nonebot.adapters.{adapter[1:]}" if adapter.startswith("~") else adapter
for adapter in raw
}
final_supported = (
support if final_supported is None else (final_supported & support)
)
return final_supported

View File

@@ -6,26 +6,28 @@ FrontMatter:
sidebar_position: 5 sidebar_position: 5
description: nonebot.plugin.manager 模块 description: nonebot.plugin.manager 模块
""" """
import sys import sys
import pkgutil import pkgutil
import importlib import importlib
from pathlib import Path from pathlib import Path
from itertools import chain from itertools import chain
from typing import Optional
from types import ModuleType from types import ModuleType
from importlib.abc import MetaPathFinder from importlib.abc import MetaPathFinder
from collections.abc import Iterable, Sequence
from importlib.machinery import PathFinder, SourceFileLoader from importlib.machinery import PathFinder, SourceFileLoader
from typing import Set, Dict, List, Iterable, Optional, Sequence
from nonebot.log import logger from nonebot.log import logger
from nonebot.utils import escape_tag, path_to_module_name from nonebot.utils import escape_tag, path_to_module_name
from .plugin import Plugin, PluginMetadata from .model import Plugin, PluginMetadata
from . import ( from . import (
_managers, _managers,
_new_plugin, _new_plugin,
_revert_plugin, _revert_plugin,
_current_plugin_chain, _current_plugin,
_module_name_to_plugin_name, _module_name_to_plugin_id,
) )
@@ -34,7 +36,7 @@ class PluginManager:
参数: 参数:
plugins: 独立插件模块名集合。 plugins: 独立插件模块名集合。
search_path: 插件搜索路径(文件夹)。 search_path: 插件搜索路径(文件夹),相对于当前工作目录
""" """
def __init__( def __init__(
@@ -43,60 +45,78 @@ class PluginManager:
search_path: Optional[Iterable[str]] = None, search_path: Optional[Iterable[str]] = None,
): ):
# simple plugin not in search path # simple plugin not in search path
self.plugins: Set[str] = set(plugins or []) self.plugins: set[str] = set(plugins or [])
self.search_path: Set[str] = set(search_path or []) self.search_path: set[str] = set(search_path or [])
# cache plugins # cache plugins
self._third_party_plugin_names: Dict[str, str] = {} self._third_party_plugin_ids: dict[str, str] = {}
self._searched_plugin_names: Dict[str, Path] = {} self._searched_plugin_ids: dict[str, str] = {}
self.prepare_plugins() self._prepare_plugins()
def __repr__(self) -> str: def __repr__(self) -> str:
return f"PluginManager(plugins={self.plugins}, search_path={self.search_path})" return f"PluginManager(available_plugins={self.controlled_modules})"
@property @property
def third_party_plugins(self) -> Set[str]: def third_party_plugins(self) -> set[str]:
"""返回所有独立插件名称""" """返回所有独立插件标识符"""
return set(self._third_party_plugin_names.keys()) return set(self._third_party_plugin_ids.keys())
@property @property
def searched_plugins(self) -> Set[str]: def searched_plugins(self) -> set[str]:
"""返回已搜索到的插件名称""" """返回已搜索到的插件标识符"""
return set(self._searched_plugin_names.keys()) return set(self._searched_plugin_ids.keys())
@property @property
def available_plugins(self) -> Set[str]: def available_plugins(self) -> set[str]:
"""返回当前插件管理器中可用的插件名称""" """返回当前插件管理器中可用的插件标识符"""
return self.third_party_plugins | self.searched_plugins return self.third_party_plugins | self.searched_plugins
def _previous_plugins(self) -> Set[str]: @property
_pre_managers: List[PluginManager] def controlled_modules(self) -> dict[str, str]:
"""返回当前插件管理器中控制的插件标识符与模块路径映射字典。"""
return dict(
chain(
self._third_party_plugin_ids.items(), self._searched_plugin_ids.items()
)
)
def _previous_controlled_modules(self) -> dict[str, str]:
_pre_managers: list[PluginManager]
if self in _managers: if self in _managers:
_pre_managers = _managers[: _managers.index(self)] _pre_managers = _managers[: _managers.index(self)]
else: else:
_pre_managers = _managers[:] _pre_managers = _managers[:]
return { return {
*chain.from_iterable(manager.available_plugins for manager in _pre_managers) plugin_id: module_name
for manager in _pre_managers
for plugin_id, module_name in manager.controlled_modules.items()
} }
def prepare_plugins(self) -> Set[str]: def _prepare_plugins(self) -> set[str]:
"""搜索插件并缓存插件名称。""" """搜索插件并缓存插件名称。"""
# get all previous ready to load plugins # get all previous ready to load plugins
previous_plugins = self._previous_plugins() previous_plugin_ids = self._previous_controlled_modules()
searched_plugins: Dict[str, Path] = {}
third_party_plugins: Dict[str, str] = {} # if self not in global managers, merge self's controlled modules
def get_controlled_modules():
return (
previous_plugin_ids
if self in _managers
else {**previous_plugin_ids, **self.controlled_modules}
)
# check third party plugins # check third party plugins
for plugin in self.plugins: for plugin in self.plugins:
name = _module_name_to_plugin_name(plugin) plugin_id = _module_name_to_plugin_id(plugin, get_controlled_modules())
if name in third_party_plugins or name in previous_plugins: if (
plugin_id in self._third_party_plugin_ids
or plugin_id in previous_plugin_ids
):
raise RuntimeError( raise RuntimeError(
f"Plugin already exists: {name}! Check your plugin name" f"Plugin already exists: {plugin_id}! Check your plugin name"
) )
third_party_plugins[name] = plugin self._third_party_plugin_ids[plugin_id] = plugin
self._third_party_plugin_names = third_party_plugins
# check plugins in search path # check plugins in search path
for module_info in pkgutil.iter_modules(self.search_path): for module_info in pkgutil.iter_modules(self.search_path):
@@ -104,47 +124,55 @@ class PluginManager:
if module_info.name.startswith("_"): if module_info.name.startswith("_"):
continue continue
if (
module_info.name in searched_plugins
or module_info.name in previous_plugins
or module_info.name in third_party_plugins
):
raise RuntimeError(
f"Plugin already exists: {module_info.name}! Check your plugin name"
)
if not ( if not (
module_spec := module_info.module_finder.find_spec( module_spec := module_info.module_finder.find_spec(
module_info.name, None module_info.name, None
) )
): ):
continue continue
if not (module_path := module_spec.origin):
continue
searched_plugins[module_info.name] = Path(module_path).resolve()
self._searched_plugin_names = searched_plugins if not module_spec.origin:
continue
# get module name from path, pkgutil does not return the actual module name
module_path = Path(module_spec.origin).resolve()
module_name = path_to_module_name(module_path)
plugin_id = _module_name_to_plugin_id(module_name, get_controlled_modules())
if (
plugin_id in previous_plugin_ids
or plugin_id in self._third_party_plugin_ids
or plugin_id in self._searched_plugin_ids
):
raise RuntimeError(
f"Plugin already exists: {plugin_id}! Check your plugin name"
)
self._searched_plugin_ids[plugin_id] = module_name
return self.available_plugins return self.available_plugins
def load_plugin(self, name: str) -> Optional[Plugin]: def load_plugin(self, name: str) -> Optional[Plugin]:
"""加载指定插件。 """加载指定插件。
对于独立插件,可以使用完整插件模块名或者插件名称 可以使用完整插件模块名或者插件标识符加载
参数: 参数:
name: 插件名称。 name: 插件名称或插件标识符
""" """
try: try:
if name in self.plugins: # load using plugin id
if name in self._third_party_plugin_ids:
module = importlib.import_module(self._third_party_plugin_ids[name])
elif name in self._searched_plugin_ids:
module = importlib.import_module(self._searched_plugin_ids[name])
# load using module name
elif (
name in self._third_party_plugin_ids.values()
or name in self._searched_plugin_ids.values()
):
module = importlib.import_module(name) module = importlib.import_module(name)
elif name in self._third_party_plugin_names:
module = importlib.import_module(self._third_party_plugin_names[name])
elif name in self._searched_plugin_names:
module = importlib.import_module(
path_to_module_name(self._searched_plugin_names[name])
)
else: else:
raise RuntimeError(f"Plugin not found: {name}! Check your plugin name") raise RuntimeError(f"Plugin not found: {name}! Check your plugin name")
@@ -153,13 +181,13 @@ class PluginManager:
) is None or not isinstance(plugin, Plugin): ) is None or not isinstance(plugin, Plugin):
raise RuntimeError( raise RuntimeError(
f"Module {module.__name__} is not loaded as a plugin! " f"Module {module.__name__} is not loaded as a plugin! "
"Make sure not to import it before loading." f"Make sure not to import it before loading."
) )
logger.opt(colors=True).success( logger.opt(colors=True).success(
f'Succeeded to load plugin "<y>{escape_tag(plugin.name)}</y>"' f'Succeeded to load plugin "<y>{escape_tag(plugin.id_)}</y>"'
+ ( + (
f' from "<m>{escape_tag(plugin.module_name)}</m>"' f' from "<m>{escape_tag(plugin.module_name)}</m>"'
if plugin.module_name != plugin.name if plugin.module_name != plugin.id_
else "" else ""
) )
) )
@@ -169,7 +197,7 @@ class PluginManager:
f'<r><bg #f8bbd0>Failed to import "{escape_tag(name)}"</bg #f8bbd0></r>' f'<r><bg #f8bbd0>Failed to import "{escape_tag(name)}"</bg #f8bbd0></r>'
) )
def load_all_plugins(self) -> Set[Plugin]: def load_all_plugins(self) -> set[Plugin]:
"""加载所有可用插件。""" """加载所有可用插件。"""
return set( return set(
@@ -191,21 +219,16 @@ class PluginFinder(MetaPathFinder):
module_origin = module_spec.origin module_origin = module_spec.origin
if not module_origin: if not module_origin:
return return
module_path = Path(module_origin).resolve()
for manager in reversed(_managers): for manager in reversed(_managers):
# use path instead of name in case of submodule name conflict if fullname in manager.controlled_modules.values():
if (
fullname in manager.plugins
or module_path in manager._searched_plugin_names.values()
):
module_spec.loader = PluginLoader(manager, fullname, module_origin) module_spec.loader = PluginLoader(manager, fullname, module_origin)
return module_spec return module_spec
return return
class PluginLoader(SourceFileLoader): class PluginLoader(SourceFileLoader):
def __init__(self, manager: PluginManager, fullname: str, path) -> None: def __init__(self, manager: PluginManager, fullname: str, path: str) -> None:
self.manager = manager self.manager = manager
self.loaded = False self.loaded = False
super().__init__(fullname, path) super().__init__(fullname, path)
@@ -225,16 +248,8 @@ class PluginLoader(SourceFileLoader):
plugin = _new_plugin(self.name, module, self.manager) plugin = _new_plugin(self.name, module, self.manager)
setattr(module, "__plugin__", plugin) setattr(module, "__plugin__", plugin)
# detect parent plugin before entering current plugin context
parent_plugins = _current_plugin_chain.get()
for pre_plugin in reversed(parent_plugins):
if _managers.index(pre_plugin.manager) < _managers.index(self.manager):
plugin.parent_plugin = pre_plugin
pre_plugin.sub_plugins.add(plugin)
break
# enter plugin context # enter plugin context
_plugin_token = _current_plugin_chain.set(parent_plugins + (plugin,)) _plugin_token = _current_plugin.set(plugin)
try: try:
super().exec_module(module) super().exec_module(module)
@@ -243,7 +258,7 @@ class PluginLoader(SourceFileLoader):
raise raise
finally: finally:
# leave plugin context # leave plugin context
_current_plugin_chain.reset(_plugin_token) _current_plugin.reset(_plugin_token)
# get plugin metadata # get plugin metadata
metadata: Optional[PluginMetadata] = getattr(module, "__plugin_meta__", None) metadata: Optional[PluginMetadata] = getattr(module, "__plugin_meta__", None)

89
nonebot/plugin/model.py Normal file
View File

@@ -0,0 +1,89 @@
"""本模块定义插件相关信息。
FrontMatter:
sidebar_position: 3
description: nonebot.plugin.model 模块
"""
import contextlib
from types import ModuleType
from dataclasses import field, dataclass
from typing import TYPE_CHECKING, Any, Type, Optional # noqa: UP035
from pydantic import BaseModel
from nonebot.matcher import Matcher
from nonebot.utils import resolve_dot_notation
if TYPE_CHECKING:
from nonebot.adapters import Adapter
from .manager import PluginManager
@dataclass(eq=False)
class PluginMetadata:
"""插件元信息,由插件编写者提供"""
name: str
"""插件名称"""
description: str
"""插件功能介绍"""
usage: str
"""插件使用方法"""
type: Optional[str] = None
"""插件类型,用于商店分类"""
homepage: Optional[str] = None
"""插件主页"""
config: Optional[Type[BaseModel]] = None # noqa: UP006
"""插件配置项"""
supported_adapters: Optional[set[str]] = None
"""插件支持的适配器模块路径
格式为 `<module>[:<Adapter>]``~` 为 `nonebot.adapters.` 的缩写。
`None` 表示支持**所有适配器**。
"""
extra: dict[Any, Any] = field(default_factory=dict)
"""插件额外信息,可由插件编写者自由扩展定义"""
def get_supported_adapters(self) -> Optional[set[Type["Adapter"]]]: # noqa: UP006
"""获取当前已安装的插件支持适配器类列表"""
if self.supported_adapters is None:
return None
adapters = set()
for adapter in self.supported_adapters:
with contextlib.suppress(ModuleNotFoundError, AttributeError):
adapters.add(
resolve_dot_notation(adapter, "Adapter", "nonebot.adapters.")
)
return adapters
@dataclass(eq=False)
class Plugin:
"""存储插件信息"""
name: str
"""插件名称NoneBot 使用 文件/文件夹 名称作为插件名称"""
module: ModuleType
"""插件模块对象"""
module_name: str
"""点分割模块路径"""
manager: "PluginManager"
"""导入该插件的插件管理器"""
matcher: set[type[Matcher]] = field(default_factory=set)
"""插件加载时定义的 `Matcher`"""
parent_plugin: Optional["Plugin"] = None
"""父插件"""
sub_plugins: set["Plugin"] = field(default_factory=set)
"""子插件集合"""
metadata: Optional[PluginMetadata] = None
@property
def id_(self) -> str:
"""插件索引标识"""
return (
f"{self.parent_plugin.id_}:{self.name}" if self.parent_plugin else self.name
)

View File

@@ -4,16 +4,18 @@ FrontMatter:
sidebar_position: 2 sidebar_position: 2
description: nonebot.plugin.on 模块 description: nonebot.plugin.on 模块
""" """
import re import re
import inspect import inspect
import warnings
from types import ModuleType from types import ModuleType
from typing import Any, Union, Optional
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Any, Set, Dict, List, Type, Tuple, Union, Optional
from nonebot.adapters import Event from nonebot.adapters import Event
from nonebot.matcher import Matcher
from nonebot.permission import Permission from nonebot.permission import Permission
from nonebot.dependencies import Dependent from nonebot.dependencies import Dependent
from nonebot.matcher import Matcher, MatcherSource
from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_PermissionChecker from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_PermissionChecker
from nonebot.rule import ( from nonebot.rule import (
Rule, Rule,
@@ -28,49 +30,83 @@ from nonebot.rule import (
shell_command, shell_command,
) )
from .plugin import Plugin from .model import Plugin
from .manager import _current_plugin
from . import get_plugin_by_module_name from . import get_plugin_by_module_name
from .manager import _current_plugin_chain
def store_matcher(matcher: Type[Matcher]) -> None: def store_matcher(matcher: type[Matcher]) -> None:
"""存储一个事件响应器到插件。 """存储一个事件响应器到插件。
参数: 参数:
matcher: 事件响应器 matcher: 事件响应器
""" """
# only store the matcher defined when plugin loading # only store the matcher defined when plugin loading
if plugin_chain := _current_plugin_chain.get(): if plugin := _current_plugin.get():
plugin_chain[-1].matcher.add(matcher) plugin.matcher.add(matcher)
def get_matcher_plugin(depth: int = 1) -> Optional[Plugin]: def get_matcher_plugin(depth: int = 1) -> Optional[Plugin]: # pragma: no cover
"""获取事件响应器定义所在插件。 """获取事件响应器定义所在插件。
**Deprecated**, 请使用 {ref}`nonebot.plugin.on.get_matcher_source` 获取信息。
参数: 参数:
depth: 调用栈深度 depth: 调用栈深度
""" """
# matcher defined when plugin loading warnings.warn(
if plugin_chain := _current_plugin_chain.get(): "`get_matcher_plugin` is deprecated, please use `get_matcher_source` instead",
return plugin_chain[-1] DeprecationWarning,
)
# matcher defined when plugin running return (source := get_matcher_source(depth + 1)) and source.plugin
if module := get_matcher_module(depth + 1):
if plugin := get_plugin_by_module_name(module.__name__):
return plugin
def get_matcher_module(depth: int = 1) -> Optional[ModuleType]: def get_matcher_module(depth: int = 1) -> Optional[ModuleType]: # pragma: no cover
"""获取事件响应器定义所在模块。 """获取事件响应器定义所在模块。
**Deprecated**, 请使用 {ref}`nonebot.plugin.on.get_matcher_source` 获取信息。
参数:
depth: 调用栈深度
"""
warnings.warn(
"`get_matcher_module` is deprecated, please use `get_matcher_source` instead",
DeprecationWarning,
)
return (source := get_matcher_source(depth + 1)) and source.module
def get_matcher_source(depth: int = 0) -> Optional[MatcherSource]:
"""获取事件响应器定义所在源码信息。
参数: 参数:
depth: 调用栈深度 depth: 调用栈深度
""" """
current_frame = inspect.currentframe() current_frame = inspect.currentframe()
if current_frame is None: if current_frame is None:
return None return None
frame = inspect.getouterframes(current_frame)[depth + 1].frame
return inspect.getmodule(frame) frame = current_frame
d = depth + 1
while d > 0:
frame = frame.f_back
if frame is None:
raise ValueError("Depth out of range")
d -= 1
module_name = (module := inspect.getmodule(frame)) and module.__name__
# matcher defined when plugin loading
plugin: Optional["Plugin"] = _current_plugin.get()
# matcher defined when plugin running
if plugin is None and module_name:
plugin = get_plugin_by_module_name(module_name)
return MatcherSource(
plugin_id=plugin and plugin.id_,
module_name=module_name,
lineno=frame.f_lineno,
)
def on( def on(
@@ -78,14 +114,14 @@ def on(
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
permission: Optional[Union[Permission, T_PermissionChecker]] = None, permission: Optional[Union[Permission, T_PermissionChecker]] = None,
*, *,
handlers: Optional[List[Union[T_Handler, Dependent]]] = None, handlers: Optional[list[Union[T_Handler, Dependent[Any]]]] = None,
temp: bool = False, temp: bool = False,
expire_time: Optional[Union[datetime, timedelta]] = None, expire_time: Optional[Union[datetime, timedelta]] = None,
priority: int = 1, priority: int = 1,
block: bool = False, block: bool = False,
state: Optional[T_State] = None, state: Optional[T_State] = None,
_depth: int = 0, _depth: int = 0,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个基础事件响应器,可自定义类型。 """注册一个基础事件响应器,可自定义类型。
参数: 参数:
@@ -108,15 +144,14 @@ def on(
priority=priority, priority=priority,
block=block, block=block,
handlers=handlers, handlers=handlers,
plugin=get_matcher_plugin(_depth + 1), source=get_matcher_source(_depth + 1),
module=get_matcher_module(_depth + 1),
default_state=state, default_state=state,
) )
store_matcher(matcher) store_matcher(matcher)
return matcher return matcher
def on_metaevent(*args, _depth: int = 0, **kwargs) -> Type[Matcher]: def on_metaevent(*args, _depth: int = 0, **kwargs) -> type[Matcher]:
"""注册一个元事件响应器。 """注册一个元事件响应器。
参数: 参数:
@@ -132,7 +167,7 @@ def on_metaevent(*args, _depth: int = 0, **kwargs) -> Type[Matcher]:
return on("meta_event", *args, **kwargs, _depth=_depth + 1) return on("meta_event", *args, **kwargs, _depth=_depth + 1)
def on_message(*args, _depth: int = 0, **kwargs) -> Type[Matcher]: def on_message(*args, _depth: int = 0, **kwargs) -> type[Matcher]:
"""注册一个消息事件响应器。 """注册一个消息事件响应器。
参数: 参数:
@@ -149,7 +184,7 @@ def on_message(*args, _depth: int = 0, **kwargs) -> Type[Matcher]:
return on("message", *args, **kwargs, _depth=_depth + 1) return on("message", *args, **kwargs, _depth=_depth + 1)
def on_notice(*args, _depth: int = 0, **kwargs) -> Type[Matcher]: def on_notice(*args, _depth: int = 0, **kwargs) -> type[Matcher]:
"""注册一个通知事件响应器。 """注册一个通知事件响应器。
参数: 参数:
@@ -165,7 +200,7 @@ def on_notice(*args, _depth: int = 0, **kwargs) -> Type[Matcher]:
return on("notice", *args, **kwargs, _depth=_depth + 1) return on("notice", *args, **kwargs, _depth=_depth + 1)
def on_request(*args, _depth: int = 0, **kwargs) -> Type[Matcher]: def on_request(*args, _depth: int = 0, **kwargs) -> type[Matcher]:
"""注册一个请求事件响应器。 """注册一个请求事件响应器。
参数: 参数:
@@ -182,12 +217,12 @@ def on_request(*args, _depth: int = 0, **kwargs) -> Type[Matcher]:
def on_startswith( def on_startswith(
msg: Union[str, Tuple[str, ...]], msg: Union[str, tuple[str, ...]],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
ignorecase: bool = False, ignorecase: bool = False,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。 """注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
参数: 参数:
@@ -206,12 +241,12 @@ def on_startswith(
def on_endswith( def on_endswith(
msg: Union[str, Tuple[str, ...]], msg: Union[str, tuple[str, ...]],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
ignorecase: bool = False, ignorecase: bool = False,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。 """注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
参数: 参数:
@@ -230,12 +265,12 @@ def on_endswith(
def on_fullmatch( def on_fullmatch(
msg: Union[str, Tuple[str, ...]], msg: Union[str, tuple[str, ...]],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
ignorecase: bool = False, ignorecase: bool = False,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。 """注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。
参数: 参数:
@@ -254,11 +289,11 @@ def on_fullmatch(
def on_keyword( def on_keyword(
keywords: Set[str], keywords: set[str],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。 """注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
参数: 参数:
@@ -276,13 +311,13 @@ def on_keyword(
def on_command( def on_command(
cmd: Union[str, Tuple[str, ...]], cmd: Union[str, tuple[str, ...]],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None, aliases: Optional[set[Union[str, tuple[str, ...]]]] = None,
force_whitespace: Optional[Union[str, bool]] = None, force_whitespace: Optional[Union[str, bool]] = None,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息以指定命令开头时响应。 """注册一个消息事件响应器,并且当消息以指定命令开头时响应。
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`_ 命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`_
@@ -311,18 +346,19 @@ def on_command(
def on_shell_command( def on_shell_command(
cmd: Union[str, Tuple[str, ...]], cmd: Union[str, tuple[str, ...]],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None, aliases: Optional[set[Union[str, tuple[str, ...]]]] = None,
parser: Optional[ArgumentParser] = None, parser: Optional[ArgumentParser] = None,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个支持 `shell_like` 解析参数的命令消息事件响应器。 """注册一个支持 `shell_like` 解析参数的命令消息事件响应器。
与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。 与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。
并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中 可以通过 {ref}`nonebot.params.ShellCommandArgv` 获取原始参数列表,
通过 {ref}`nonebot.params.ShellCommandArgs` 获取解析后的参数字典。
参数: 参数:
cmd: 指定命令内容 cmd: 指定命令内容
@@ -352,7 +388,7 @@ def on_regex(
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息匹配正则表达式时响应。 """注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`_ 命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`_
@@ -373,12 +409,12 @@ def on_regex(
def on_type( def on_type(
types: Union[Type[Event], Tuple[Type[Event], ...]], types: Union[type[Event], tuple[type[Event], ...]],
rule: Optional[Union[Rule, T_RuleChecker]] = None, rule: Optional[Union[Rule, T_RuleChecker]] = None,
*, *,
_depth: int = 0, _depth: int = 0,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个事件响应器,并且当事件为指定类型时响应。 """注册一个事件响应器,并且当事件为指定类型时响应。
参数: 参数:
@@ -399,14 +435,14 @@ def on_type(
class _Group: class _Group:
def __init__(self, **kwargs): def __init__(self, **kwargs):
"""创建一个事件响应器组合,参数为默认值,与 `on` 一致""" """创建一个事件响应器组合,参数为默认值,与 `on` 一致"""
self.matchers: List[Type[Matcher]] = [] self.matchers: list[type[Matcher]] = []
"""组内事件响应器列表""" """组内事件响应器列表"""
self.base_kwargs: Dict[str, Any] = kwargs self.base_kwargs: dict[str, Any] = kwargs
"""其他传递给 `on` 的参数默认值""" """其他传递给 `on` 的参数默认值"""
def _get_final_kwargs( def _get_final_kwargs(
self, update: Dict[str, Any], *, exclude: Optional[Set[str]] = None self, update: dict[str, Any], *, exclude: Optional[set[str]] = None
) -> Dict[str, Any]: ) -> dict[str, Any]:
"""获取最终传递给 `on` 的参数 """获取最终传递给 `on` 的参数
参数: 参数:
@@ -427,6 +463,7 @@ class CommandGroup(_Group):
参数: 参数:
cmd: 指定命令内容 cmd: 指定命令内容
prefix_aliases: 是否影响命令别名,给命令别名加前缀
rule: 事件响应规则 rule: 事件响应规则
permission: 事件响应权限 permission: 事件响应权限
handlers: 事件处理函数列表 handlers: 事件处理函数列表
@@ -437,16 +474,19 @@ class CommandGroup(_Group):
state: 默认 state state: 默认 state
""" """
def __init__(self, cmd: Union[str, Tuple[str, ...]], **kwargs): def __init__(
self, cmd: Union[str, tuple[str, ...]], prefix_aliases: bool = False, **kwargs
):
"""命令前缀""" """命令前缀"""
super().__init__(**kwargs) super().__init__(**kwargs)
self.basecmd: Tuple[str, ...] = (cmd,) if isinstance(cmd, str) else cmd self.basecmd: tuple[str, ...] = (cmd,) if isinstance(cmd, str) else cmd
self.base_kwargs.pop("aliases", None) self.base_kwargs.pop("aliases", None)
self.prefix_aliases = prefix_aliases
def __repr__(self) -> str: def __repr__(self) -> str:
return f"CommandGroup(cmd={self.basecmd}, matchers={len(self.matchers)})" return f"CommandGroup(cmd={self.basecmd}, matchers={len(self.matchers)})"
def command(self, cmd: Union[str, Tuple[str, ...]], **kwargs) -> Type[Matcher]: def command(self, cmd: Union[str, tuple[str, ...]], **kwargs) -> type[Matcher]:
"""注册一个新的命令。新参数将会覆盖命令组默认值 """注册一个新的命令。新参数将会覆盖命令组默认值
参数: 参数:
@@ -464,13 +504,18 @@ class CommandGroup(_Group):
""" """
sub_cmd = (cmd,) if isinstance(cmd, str) else cmd sub_cmd = (cmd,) if isinstance(cmd, str) else cmd
cmd = self.basecmd + sub_cmd cmd = self.basecmd + sub_cmd
if self.prefix_aliases and (aliases := kwargs.get("aliases")):
kwargs["aliases"] = {
self.basecmd + ((alias,) if isinstance(alias, str) else alias)
for alias in aliases
}
matcher = on_command(cmd, **self._get_final_kwargs(kwargs)) matcher = on_command(cmd, **self._get_final_kwargs(kwargs))
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def shell_command( def shell_command(
self, cmd: Union[str, Tuple[str, ...]], **kwargs self, cmd: Union[str, tuple[str, ...]], **kwargs
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个新的 `shell_like` 命令。新参数将会覆盖命令组默认值 """注册一个新的 `shell_like` 命令。新参数将会覆盖命令组默认值
参数: 参数:
@@ -488,6 +533,11 @@ class CommandGroup(_Group):
""" """
sub_cmd = (cmd,) if isinstance(cmd, str) else cmd sub_cmd = (cmd,) if isinstance(cmd, str) else cmd
cmd = self.basecmd + sub_cmd cmd = self.basecmd + sub_cmd
if self.prefix_aliases and (aliases := kwargs.get("aliases")):
kwargs["aliases"] = {
self.basecmd + ((alias,) if isinstance(alias, str) else alias)
for alias in aliases
}
matcher = on_shell_command(cmd, **self._get_final_kwargs(kwargs)) matcher = on_shell_command(cmd, **self._get_final_kwargs(kwargs))
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
@@ -499,7 +549,7 @@ class MatcherGroup(_Group):
def __repr__(self) -> str: def __repr__(self) -> str:
return f"MatcherGroup(matchers={len(self.matchers)})" return f"MatcherGroup(matchers={len(self.matchers)})"
def on(self, **kwargs) -> Type[Matcher]: def on(self, **kwargs) -> type[Matcher]:
"""注册一个基础事件响应器,可自定义类型。 """注册一个基础事件响应器,可自定义类型。
参数: 参数:
@@ -517,7 +567,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_metaevent(self, **kwargs) -> Type[Matcher]: def on_metaevent(self, **kwargs) -> type[Matcher]:
"""注册一个元事件响应器。 """注册一个元事件响应器。
参数: 参数:
@@ -535,7 +585,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_message(self, **kwargs) -> Type[Matcher]: def on_message(self, **kwargs) -> type[Matcher]:
"""注册一个消息事件响应器。 """注册一个消息事件响应器。
参数: 参数:
@@ -553,7 +603,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_notice(self, **kwargs) -> Type[Matcher]: def on_notice(self, **kwargs) -> type[Matcher]:
"""注册一个通知事件响应器。 """注册一个通知事件响应器。
参数: 参数:
@@ -571,7 +621,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_request(self, **kwargs) -> Type[Matcher]: def on_request(self, **kwargs) -> type[Matcher]:
"""注册一个请求事件响应器。 """注册一个请求事件响应器。
参数: 参数:
@@ -590,8 +640,8 @@ class MatcherGroup(_Group):
return matcher return matcher
def on_startswith( def on_startswith(
self, msg: Union[str, Tuple[str, ...]], **kwargs self, msg: Union[str, tuple[str, ...]], **kwargs
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。 """注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
参数: 参数:
@@ -611,7 +661,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_endswith(self, msg: Union[str, Tuple[str, ...]], **kwargs) -> Type[Matcher]: def on_endswith(self, msg: Union[str, tuple[str, ...]], **kwargs) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。 """注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
参数: 参数:
@@ -631,7 +681,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_fullmatch(self, msg: Union[str, Tuple[str, ...]], **kwargs) -> Type[Matcher]: def on_fullmatch(self, msg: Union[str, tuple[str, ...]], **kwargs) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。 """注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。
参数: 参数:
@@ -651,7 +701,7 @@ class MatcherGroup(_Group):
self.matchers.append(matcher) self.matchers.append(matcher)
return matcher return matcher
def on_keyword(self, keywords: Set[str], **kwargs) -> Type[Matcher]: def on_keyword(self, keywords: set[str], **kwargs) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。 """注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
参数: 参数:
@@ -672,11 +722,11 @@ class MatcherGroup(_Group):
def on_command( def on_command(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: Union[str, tuple[str, ...]],
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None, aliases: Optional[set[Union[str, tuple[str, ...]]]] = None,
force_whitespace: Optional[Union[str, bool]] = None, force_whitespace: Optional[Union[str, bool]] = None,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息以指定命令开头时响应。 """注册一个消息事件响应器,并且当消息以指定命令开头时响应。
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`_ 命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`_
@@ -703,16 +753,17 @@ class MatcherGroup(_Group):
def on_shell_command( def on_shell_command(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: Union[str, tuple[str, ...]],
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None, aliases: Optional[set[Union[str, tuple[str, ...]]]] = None,
parser: Optional[ArgumentParser] = None, parser: Optional[ArgumentParser] = None,
**kwargs, **kwargs,
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个支持 `shell_like` 解析参数的命令消息事件响应器。 """注册一个支持 `shell_like` 解析参数的命令消息事件响应器。
与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。 与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。
并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中 可以通过 {ref}`nonebot.params.ShellCommandArgv` 获取原始参数列表,
通过 {ref}`nonebot.params.ShellCommandArgs` 获取解析后的参数字典。
参数: 参数:
cmd: 指定命令内容 cmd: 指定命令内容
@@ -734,7 +785,7 @@ class MatcherGroup(_Group):
def on_regex( def on_regex(
self, pattern: str, flags: Union[int, re.RegexFlag] = 0, **kwargs self, pattern: str, flags: Union[int, re.RegexFlag] = 0, **kwargs
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个消息事件响应器,并且当消息匹配正则表达式时响应。 """注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`_ 命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`_
@@ -757,8 +808,8 @@ class MatcherGroup(_Group):
return matcher return matcher
def on_type( def on_type(
self, types: Union[Type[Event], Tuple[Type[Event]]], **kwargs self, types: Union[type[Event], tuple[type[Event]]], **kwargs
) -> Type[Matcher]: ) -> type[Matcher]:
"""注册一个事件响应器,并且当事件为指定类型时响应。 """注册一个事件响应器,并且当事件为指定类型时响应。
参数: 参数:

View File

@@ -1,410 +1,421 @@
import re import re
from typing import Any
from types import ModuleType from types import ModuleType
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Set, List, Type, Tuple, Union, Optional
from nonebot.adapters import Event from nonebot.adapters import Event
from nonebot.matcher import Matcher
from nonebot.permission import Permission from nonebot.permission import Permission
from nonebot.dependencies import Dependent from nonebot.dependencies import Dependent
from nonebot.rule import Rule, ArgumentParser from nonebot.rule import Rule, ArgumentParser
from nonebot.matcher import Matcher, MatcherSource
from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_PermissionChecker from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_PermissionChecker
from .plugin import Plugin from .model import Plugin
def store_matcher(matcher: Type[Matcher]) -> None: ... def store_matcher(matcher: type[Matcher]) -> None: ...
def get_matcher_plugin(depth: int = ...) -> Optional[Plugin]: ... def get_matcher_plugin(depth: int = ...) -> Plugin | None: ...
def get_matcher_module(depth: int = ...) -> Optional[ModuleType]: ... def get_matcher_module(depth: int = ...) -> ModuleType | None: ...
def get_matcher_source(depth: int = ...) -> MatcherSource | None: ...
def on( def on(
type: str = "", type: str = "",
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
*, *,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_metaevent( def on_metaevent(
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
*, *,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_message( def on_message(
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
*, *,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_notice( def on_notice(
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
*, *,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_request( def on_request(
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
*, *,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_startswith( def on_startswith(
msg: Union[str, Tuple[str, ...]], msg: str | tuple[str, ...],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
ignorecase: bool = ..., ignorecase: bool = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_endswith( def on_endswith(
msg: Union[str, Tuple[str, ...]], msg: str | tuple[str, ...],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
ignorecase: bool = ..., ignorecase: bool = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_fullmatch( def on_fullmatch(
msg: Union[str, Tuple[str, ...]], msg: str | tuple[str, ...],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
ignorecase: bool = ..., ignorecase: bool = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_keyword( def on_keyword(
keywords: Set[str], keywords: set[str],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_command( def on_command(
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., aliases: set[str | tuple[str, ...]] | None = ...,
force_whitespace: Optional[Union[str, bool]] = ..., force_whitespace: str | bool | None = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_shell_command( def on_shell_command(
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., aliases: set[str | tuple[str, ...]] | None = ...,
parser: Optional[ArgumentParser] = ..., parser: ArgumentParser | None = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_regex( def on_regex(
pattern: str, pattern: str,
flags: Union[int, re.RegexFlag] = ..., flags: int | re.RegexFlag = ...,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_type( def on_type(
types: Union[Type[Event], Tuple[Type[Event], ...]], types: type[Event] | tuple[type[Event], ...],
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
*, *,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
class CommandGroup: class _Group:
matchers: list[type[Matcher]] = ...
base_kwargs: dict[str, Any] = ...
def _get_final_kwargs(
self, update: dict[str, Any], *, exclude: set[str] | None = None
) -> dict[str, Any]: ...
class CommandGroup(_Group):
basecmd: tuple[str, ...] = ...
prefix_aliases: bool = ...
def __init__( def __init__(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
prefix_aliases: bool = ...,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
): ... ): ...
def command( def command(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., aliases: set[str | tuple[str, ...]] | None = ...,
force_whitespace: Optional[Union[str, bool]] = ..., force_whitespace: str | bool | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def shell_command( def shell_command(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., aliases: set[str | tuple[str, ...]] | None = ...,
parser: Optional[ArgumentParser] = ..., parser: ArgumentParser | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
class MatcherGroup: class MatcherGroup(_Group):
def __init__( def __init__(
self, self,
*, *,
type: str = ..., type: str = ...,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
): ... ): ...
def on( def on(
self, self,
*, *,
type: str = ..., type: str = ...,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_metaevent( def on_metaevent(
self, self,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_message( def on_message(
self, self,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_notice( def on_notice(
self, self,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_request( def on_request(
self, self,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_startswith( def on_startswith(
self, self,
msg: Union[str, Tuple[str, ...]], msg: str | tuple[str, ...],
*, *,
ignorecase: bool = ..., ignorecase: bool = ...,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_endswith( def on_endswith(
self, self,
msg: Union[str, Tuple[str, ...]], msg: str | tuple[str, ...],
*, *,
ignorecase: bool = ..., ignorecase: bool = ...,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_fullmatch( def on_fullmatch(
self, self,
msg: Union[str, Tuple[str, ...]], msg: str | tuple[str, ...],
*, *,
ignorecase: bool = ..., ignorecase: bool = ...,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_keyword( def on_keyword(
self, self,
keywords: Set[str], keywords: set[str],
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_command( def on_command(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., aliases: set[str | tuple[str, ...]] | None = ...,
force_whitespace: Optional[Union[str, bool]] = ..., force_whitespace: str | bool | None = ...,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_shell_command( def on_shell_command(
self, self,
cmd: Union[str, Tuple[str, ...]], cmd: str | tuple[str, ...],
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., aliases: set[str | tuple[str, ...]] | None = ...,
parser: Optional[ArgumentParser] = ..., parser: ArgumentParser | None = ...,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_regex( def on_regex(
self, self,
pattern: str, pattern: str,
flags: Union[int, re.RegexFlag] = ..., flags: int | re.RegexFlag = ...,
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...
def on_type( def on_type(
self, self,
types: Union[Type[Event], Tuple[Type[Event]]], types: type[Event] | tuple[type[Event]],
*, *,
rule: Optional[Union[Rule, T_RuleChecker]] = ..., rule: Rule | T_RuleChecker | None = ...,
permission: Optional[Union[Permission, T_PermissionChecker]] = ..., permission: Permission | T_PermissionChecker | None = ...,
handlers: Optional[List[Union[T_Handler, Dependent]]] = ..., handlers: list[T_Handler | Dependent[Any]] | None = ...,
temp: bool = ..., temp: bool = ...,
expire_time: Optional[Union[datetime, timedelta]] = ..., expire_time: datetime | timedelta | None = ...,
priority: int = ..., priority: int = ...,
block: bool = ..., block: bool = ...,
state: Optional[T_State] = ..., state: T_State | None = ...,
) -> Type[Matcher]: ... ) -> type[Matcher]: ...

View File

@@ -1,55 +0,0 @@
"""本模块定义插件对象。
FrontMatter:
sidebar_position: 3
description: nonebot.plugin.plugin 模块
"""
from types import ModuleType
from dataclasses import field, dataclass
from typing import TYPE_CHECKING, Any, Set, Dict, Type, Optional
from pydantic import BaseModel
from nonebot.matcher import Matcher
# FIXME: backport for nonebug
from . import _plugins as plugins # nopycln: import
if TYPE_CHECKING:
from .manager import PluginManager
@dataclass(eq=False)
class PluginMetadata:
"""插件元信息,由插件编写者提供"""
name: str
"""插件可阅读名称"""
description: str
"""插件功能介绍"""
usage: str
"""插件使用方法"""
config: Optional[Type[BaseModel]] = None
"""插件配置项"""
extra: Dict[Any, Any] = field(default_factory=dict)
@dataclass(eq=False)
class Plugin:
"""存储插件信息"""
name: str
"""插件索引标识NoneBot 使用 文件/文件夹 名称作为标识符"""
module: ModuleType
"""插件模块对象"""
module_name: str
"""点分割模块路径"""
manager: "PluginManager"
"""导入该插件的插件管理器"""
matcher: Set[Type[Matcher]] = field(default_factory=set)
"""插件加载时定义的 `Matcher`"""
parent_plugin: Optional["Plugin"] = None
"""父插件"""
sub_plugins: Set["Plugin"] = field(default_factory=set)
"""子插件集合"""
metadata: Optional[PluginMetadata] = None

View File

@@ -1,11 +1,23 @@
from nonebot import on_command
from nonebot.rule import to_me from nonebot.rule import to_me
from nonebot.adapters import Message from nonebot.adapters import Message
from nonebot.params import CommandArg from nonebot.params import CommandArg
from nonebot.plugin import on_command from nonebot.plugin import PluginMetadata
__plugin_meta__ = PluginMetadata(
name="echo",
description="重复你说的话",
usage="/echo [text]",
type="application",
homepage="https://github.com/nonebot/nonebot2/blob/master/nonebot/plugins/echo.py",
config=None,
supported_adapters=None,
)
echo = on_command("echo", to_me()) echo = on_command("echo", to_me())
@echo.handle() @echo.handle()
async def handle_echo(message: Message = CommandArg()): async def handle_echo(message: Message = CommandArg()):
await echo.send(message=message) if any((not seg.is_text()) or str(seg) for seg in message):
await echo.send(message=message)

View File

@@ -1,10 +1,21 @@
from typing import Dict, AsyncGenerator from collections.abc import AsyncGenerator
from nonebot.adapters import Event from nonebot.adapters import Event
from nonebot.params import Depends from nonebot.params import Depends
from nonebot.plugin import PluginMetadata
from nonebot.message import IgnoredException, event_preprocessor from nonebot.message import IgnoredException, event_preprocessor
_running_matcher: Dict[str, int] = {} __plugin_meta__ = PluginMetadata(
name="唯一会话",
description="限制同一会话内同时只能运行一个响应器",
usage="加载插件后自动生效",
type="application",
homepage="https://github.com/nonebot/nonebot2/blob/master/nonebot/plugins/single_session.py",
config=None,
supported_adapters=None,
)
_running_matcher: dict[str, int] = {}
async def matcher_mutex(event: Event) -> AsyncGenerator[bool, None]: async def matcher_mutex(event: Event) -> AsyncGenerator[bool, None]:
@@ -15,7 +26,7 @@ async def matcher_mutex(event: Event) -> AsyncGenerator[bool, None]:
yield result yield result
else: else:
current_event_id = id(event) current_event_id = id(event)
if event_id := _running_matcher.get(session_id, None): if event_id := _running_matcher.get(session_id):
result = event_id != current_event_id result = event_id != current_event_id
else: else:
_running_matcher[session_id] = current_event_id _running_matcher[session_id] = current_event_id

View File

@@ -1,7 +1,8 @@
"""本模块是 {ref}`nonebot.matcher.Matcher.rule` 的类型定义。 """本模块是 {ref}`nonebot.matcher.Matcher.rule` 的类型定义。
每个事件响应器 {ref}`nonebot.matcher.Matcher` 拥有一个匹配规则 {ref}`nonebot.rule.Rule` 每个{ref}`事件响应器 <nonebot.matcher.Matcher>`拥有一个
其中是 `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行 {ref}`nonebot.rule.Rule`,其中是 `RuleChecker` 的集合
只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
FrontMatter: FrontMatter:
sidebar_position: 5 sidebar_position: 5
@@ -11,21 +12,19 @@ FrontMatter:
import re import re
import shlex import shlex
from argparse import Action from argparse import Action
from gettext import gettext
from argparse import ArgumentError from argparse import ArgumentError
from contextvars import ContextVar from contextvars import ContextVar
from collections.abc import Sequence
from itertools import chain, product from itertools import chain, product
from argparse import Namespace as Namespace from argparse import Namespace as Namespace
from argparse import ArgumentParser as ArgParser from argparse import ArgumentParser as ArgParser
from typing import ( from typing import (
IO, IO,
TYPE_CHECKING, TYPE_CHECKING,
List,
Type,
Tuple,
Union, Union,
TypeVar, TypeVar,
Optional, Optional,
Sequence,
TypedDict, TypedDict,
NamedTuple, NamedTuple,
cast, cast,
@@ -43,15 +42,12 @@ from nonebot.adapters import Bot, Event, Message, MessageSegment
from nonebot.params import Command, EventToMe, CommandArg, CommandWhitespace from nonebot.params import Command, EventToMe, CommandArg, CommandWhitespace
from nonebot.consts import ( from nonebot.consts import (
CMD_KEY, CMD_KEY,
REGEX_STR,
PREFIX_KEY, PREFIX_KEY,
REGEX_DICT,
SHELL_ARGS, SHELL_ARGS,
SHELL_ARGV, SHELL_ARGV,
CMD_ARG_KEY, CMD_ARG_KEY,
KEYWORD_KEY, KEYWORD_KEY,
RAW_CMD_KEY, RAW_CMD_KEY,
REGEX_GROUP,
ENDSWITH_KEY, ENDSWITH_KEY,
CMD_START_KEY, CMD_START_KEY,
FULLMATCH_KEY, FULLMATCH_KEY,
@@ -62,20 +58,19 @@ from nonebot.consts import (
T = TypeVar("T") T = TypeVar("T")
CMD_RESULT = TypedDict(
"CMD_RESULT",
{
"command": Optional[Tuple[str, ...]],
"raw_command": Optional[str],
"command_arg": Optional[Message[MessageSegment]],
"command_start": Optional[str],
"command_whitespace": Optional[str],
},
)
TRIE_VALUE = NamedTuple( class CMD_RESULT(TypedDict):
"TRIE_VALUE", [("command_start", str), ("command", Tuple[str, ...])] command: Optional[tuple[str, ...]]
) raw_command: Optional[str]
command_arg: Optional[Message]
command_start: Optional[str]
command_whitespace: Optional[str]
class TRIE_VALUE(NamedTuple):
command_start: str
command: tuple[str, ...]
parser_message: ContextVar[str] = ContextVar("parser_message") parser_message: ContextVar[str] = ContextVar("parser_message")
@@ -119,6 +114,11 @@ class TrieRule:
# check whitespace # check whitespace
arg_str = segment_text[len(pf.key) :] arg_str = segment_text[len(pf.key) :]
arg_str_stripped = arg_str.lstrip() arg_str_stripped = arg_str.lstrip()
# check next segment until arg detected or no text remain
while not arg_str_stripped and msg and msg[0].is_text():
arg_str += str(msg.pop(0))
arg_str_stripped = arg_str.lstrip()
has_arg = arg_str_stripped or msg has_arg = arg_str_stripped or msg
if ( if (
has_arg has_arg
@@ -146,7 +146,7 @@ class StartswithRule:
__slots__ = ("msg", "ignorecase") __slots__ = ("msg", "ignorecase")
def __init__(self, msg: Tuple[str, ...], ignorecase: bool = False): def __init__(self, msg: tuple[str, ...], ignorecase: bool = False):
self.msg = msg self.msg = msg
self.ignorecase = ignorecase self.ignorecase = ignorecase
@@ -178,7 +178,7 @@ class StartswithRule:
return False return False
def startswith(msg: Union[str, Tuple[str, ...]], ignorecase: bool = False) -> Rule: def startswith(msg: Union[str, tuple[str, ...]], ignorecase: bool = False) -> Rule:
"""匹配消息纯文本开头。 """匹配消息纯文本开头。
参数: 参数:
@@ -201,7 +201,7 @@ class EndswithRule:
__slots__ = ("msg", "ignorecase") __slots__ = ("msg", "ignorecase")
def __init__(self, msg: Tuple[str, ...], ignorecase: bool = False): def __init__(self, msg: tuple[str, ...], ignorecase: bool = False):
self.msg = msg self.msg = msg
self.ignorecase = ignorecase self.ignorecase = ignorecase
@@ -233,7 +233,7 @@ class EndswithRule:
return False return False
def endswith(msg: Union[str, Tuple[str, ...]], ignorecase: bool = False) -> Rule: def endswith(msg: Union[str, tuple[str, ...]], ignorecase: bool = False) -> Rule:
"""匹配消息纯文本结尾。 """匹配消息纯文本结尾。
参数: 参数:
@@ -256,7 +256,7 @@ class FullmatchRule:
__slots__ = ("msg", "ignorecase") __slots__ = ("msg", "ignorecase")
def __init__(self, msg: Tuple[str, ...], ignorecase: bool = False): def __init__(self, msg: tuple[str, ...], ignorecase: bool = False):
self.msg = tuple(map(str.casefold, msg) if ignorecase else msg) self.msg = tuple(map(str.casefold, msg) if ignorecase else msg)
self.ignorecase = ignorecase self.ignorecase = ignorecase
@@ -287,7 +287,7 @@ class FullmatchRule:
return False return False
def fullmatch(msg: Union[str, Tuple[str, ...]], ignorecase: bool = False) -> Rule: def fullmatch(msg: Union[str, tuple[str, ...]], ignorecase: bool = False) -> Rule:
"""完全匹配消息。 """完全匹配消息。
参数: 参数:
@@ -358,7 +358,7 @@ class CommandRule:
def __init__( def __init__(
self, self,
cmds: List[Tuple[str, ...]], cmds: list[tuple[str, ...]],
force_whitespace: Optional[Union[str, bool]] = None, force_whitespace: Optional[Union[str, bool]] = None,
): ):
self.cmds = tuple(cmds) self.cmds = tuple(cmds)
@@ -377,12 +377,13 @@ class CommandRule:
async def __call__( async def __call__(
self, self,
cmd: Optional[Tuple[str, ...]] = Command(), cmd: Optional[tuple[str, ...]] = Command(),
cmd_arg: Optional[Message] = CommandArg(),
cmd_whitespace: Optional[str] = CommandWhitespace(), cmd_whitespace: Optional[str] = CommandWhitespace(),
) -> bool: ) -> bool:
if cmd not in self.cmds: if cmd not in self.cmds:
return False return False
if self.force_whitespace is None: if self.force_whitespace is None or not cmd_arg:
return True return True
if isinstance(self.force_whitespace, str): if isinstance(self.force_whitespace, str):
return self.force_whitespace == cmd_whitespace return self.force_whitespace == cmd_whitespace
@@ -390,7 +391,7 @@ class CommandRule:
def command( def command(
*cmds: Union[str, Tuple[str, ...]], *cmds: Union[str, tuple[str, ...]],
force_whitespace: Optional[Union[str, bool]] = None, force_whitespace: Optional[Union[str, bool]] = None,
) -> Rule: ) -> Rule:
"""匹配消息命令。 """匹配消息命令。
@@ -407,7 +408,7 @@ def command(
force_whitespace: 是否强制命令后必须有指定空白符 force_whitespace: 是否强制命令后必须有指定空白符
用法: 用法:
使用默认 `command_start`, `command_sep` 配置 使用默认 `command_start`, `command_sep` 配置情况下:
命令 `("test",)` 可以匹配: `/test` 开头的消息 命令 `("test",)` 可以匹配: `/test` 开头的消息
命令 `("test", "sub")` 可以匹配: `/test.sub` 开头的消息 命令 `("test", "sub")` 可以匹配: `/test.sub` 开头的消息
@@ -420,7 +421,7 @@ def command(
config = get_driver().config config = get_driver().config
command_start = config.command_start command_start = config.command_start
command_sep = config.command_sep command_sep = config.command_sep
commands: List[Tuple[str, ...]] = [] commands: list[tuple[str, ...]] = []
for command in cmds: for command in cmds:
if isinstance(command, str): if isinstance(command, str):
command = (command,) command = (command,)
@@ -442,6 +443,8 @@ def command(
class ArgumentParser(ArgParser): class ArgumentParser(ArgParser):
"""`shell_like` 命令参数解析器,解析出错时不会退出程序。 """`shell_like` 命令参数解析器,解析出错时不会退出程序。
支持 {ref}`nonebot.adapters.Message` 富文本解析。
用法: 用法:
用法与 `argparse.ArgumentParser` 相同, 用法与 `argparse.ArgumentParser` 相同,
参考文档: [argparse](https://docs.python.org/3/library/argparse.html) 参考文档: [argparse](https://docs.python.org/3/library/argparse.html)
@@ -450,33 +453,57 @@ class ArgumentParser(ArgParser):
if TYPE_CHECKING: if TYPE_CHECKING:
@overload @overload
def parse_args( def parse_known_args(
self, args: Optional[Sequence[Union[str, MessageSegment]]] = ... self,
) -> Namespace: args: Optional[Sequence[Union[str, MessageSegment]]] = None,
... namespace: None = None,
) -> tuple[Namespace, list[Union[str, MessageSegment]]]: ...
@overload @overload
def parse_args( def parse_known_args(
self, args: Optional[Sequence[Union[str, MessageSegment]]], namespace: None
) -> Namespace:
... # type: ignore[misc]
@overload
def parse_args(
self, args: Optional[Sequence[Union[str, MessageSegment]]], namespace: T self, args: Optional[Sequence[Union[str, MessageSegment]]], namespace: T
) -> T: ) -> tuple[T, list[Union[str, MessageSegment]]]: ...
...
def parse_args( @overload
def parse_known_args(
self, *, namespace: T
) -> tuple[T, list[Union[str, MessageSegment]]]: ...
def parse_known_args( # pyright: ignore[reportIncompatibleMethodOverride]
self, self,
args: Optional[Sequence[Union[str, MessageSegment]]] = None, args: Optional[Sequence[Union[str, MessageSegment]]] = None,
namespace: Optional[T] = None, namespace: Optional[T] = None,
) -> Union[Namespace, T]: ) -> tuple[Union[Namespace, T], list[Union[str, MessageSegment]]]: ...
...
@overload
def parse_args(
self,
args: Optional[Sequence[Union[str, MessageSegment]]] = None,
namespace: None = None,
) -> Namespace: ...
@overload
def parse_args(
self, args: Optional[Sequence[Union[str, MessageSegment]]], namespace: T
) -> T: ...
@overload
def parse_args(self, *, namespace: T) -> T: ...
def parse_args(
self,
args: Optional[Sequence[Union[str, MessageSegment]]] = None,
namespace: Optional[T] = None,
) -> Union[Namespace, T]:
result, argv = self.parse_known_args(args, namespace)
if argv:
msg = gettext("unrecognized arguments: %s")
self.error(msg % " ".join(map(str, argv)))
return cast(Union[Namespace, T], result)
def _parse_optional( def _parse_optional(
self, arg_string: Union[str, MessageSegment] self, arg_string: Union[str, MessageSegment]
) -> Optional[Tuple[Optional[Action], str, Optional[str]]]: ) -> Optional[tuple[Optional[Action], str, Optional[str]]]:
return ( return (
super()._parse_optional(arg_string) if isinstance(arg_string, str) else None super()._parse_optional(arg_string) if isinstance(arg_string, str) else None
) )
@@ -503,7 +530,7 @@ class ShellCommandRule:
__slots__ = ("cmds", "parser") __slots__ = ("cmds", "parser")
def __init__(self, cmds: List[Tuple[str, ...]], parser: Optional[ArgumentParser]): def __init__(self, cmds: list[tuple[str, ...]], parser: Optional[ArgumentParser]):
self.cmds = tuple(cmds) self.cmds = tuple(cmds)
self.parser = parser self.parser = parser
@@ -523,7 +550,7 @@ class ShellCommandRule:
async def __call__( async def __call__(
self, self,
state: T_State, state: T_State,
cmd: Optional[Tuple[str, ...]] = Command(), cmd: Optional[tuple[str, ...]] = Command(),
msg: Optional[Message] = CommandArg(), msg: Optional[Message] = CommandArg(),
) -> bool: ) -> bool:
if cmd not in self.cmds or msg is None: if cmd not in self.cmds or msg is None:
@@ -541,7 +568,7 @@ class ShellCommandRule:
try: try:
args = self.parser.parse_args(state[SHELL_ARGV]) args = self.parser.parse_args(state[SHELL_ARGV])
state[SHELL_ARGS] = args state[SHELL_ARGS] = args
except ArgumentError as e: # pragma: py-gte-39 except ArgumentError as e:
state[SHELL_ARGS] = ParserExit(status=2, message=str(e)) state[SHELL_ARGS] = ParserExit(status=2, message=str(e))
except ParserExit as e: except ParserExit as e:
state[SHELL_ARGS] = e state[SHELL_ARGS] = e
@@ -551,19 +578,23 @@ class ShellCommandRule:
def shell_command( def shell_command(
*cmds: Union[str, Tuple[str, ...]], parser: Optional[ArgumentParser] = None *cmds: Union[str, tuple[str, ...]], parser: Optional[ArgumentParser] = None
) -> Rule: ) -> Rule:
"""匹配 `shell_like` 形式的消息命令。 """匹配 `shell_like` 形式的消息命令。
根据配置里提供的 {ref}``command_start` <nonebot.config.Config.command_start>`, 根据配置里提供的 {ref}``command_start` <nonebot.config.Config.command_start>`,
{ref}``command_sep` <nonebot.config.Config.command_sep>` 判断消息是否为命令。 {ref}``command_sep` <nonebot.config.Config.command_sep>` 判断消息是否为命令。
可以通过 {ref}`nonebot.params.Command` 获取匹配成功的命令(例: `("test",)` 可以通过 {ref}`nonebot.params.Command` 获取匹配成功的命令
通过 {ref}`nonebot.params.RawCommand` 获取匹配成功的原始命令文本(例: `"/test"` (例: `("test",)`
通过 {ref}`nonebot.params.ShellCommandArgv` 获取解析前的参数列表(例: `["arg", "-h"]` 通过 {ref}`nonebot.params.RawCommand` 获取匹配成功的原始命令文本
通过 {ref}`nonebot.params.ShellCommandArgs` 获取解析后的参数字典(例: `{"arg": "arg", "h": True}` (例: `"/test"`
通过 {ref}`nonebot.params.ShellCommandArgv` 获取解析前的参数列表
(例: `["arg", "-h"]`
通过 {ref}`nonebot.params.ShellCommandArgs` 获取解析后的参数字典
(例: `{"arg": "arg", "h": True}`)。
:::warning 警告 :::caution 警告
如果参数解析失败,则通过 {ref}`nonebot.params.ShellCommandArgs` 如果参数解析失败,则通过 {ref}`nonebot.params.ShellCommandArgs`
获取的将是 {ref}`nonebot.exception.ParserExit` 异常。 获取的将是 {ref}`nonebot.exception.ParserExit` 异常。
::: :::
@@ -573,7 +604,8 @@ def shell_command(
parser: {ref}`nonebot.rule.ArgumentParser` 对象 parser: {ref}`nonebot.rule.ArgumentParser` 对象
用法: 用法:
使用默认 `command_start`, `command_sep` 配置,更多示例参考 `argparse` 标准库文档。 使用默认 `command_start`, `command_sep` 配置,更多示例参考
[argparse](https://docs.python.org/3/library/argparse.html) 标准库文档。
```python ```python
from nonebot.rule import ArgumentParser from nonebot.rule import ArgumentParser
@@ -594,7 +626,7 @@ def shell_command(
config = get_driver().config config = get_driver().config
command_start = config.command_start command_start = config.command_start
command_sep = config.command_sep command_sep = config.command_sep
commands: List[Tuple[str, ...]] = [] commands: list[tuple[str, ...]] = []
for command in cmds: for command in cmds:
if isinstance(command, str): if isinstance(command, str):
command = (command,) command = (command,)
@@ -646,10 +678,7 @@ class RegexRule:
except Exception: except Exception:
return False return False
if matched := re.search(self.regex, str(msg), self.flags): if matched := re.search(self.regex, str(msg), self.flags):
state[REGEX_MATCHED] = matched.group() state[REGEX_MATCHED] = matched
state[REGEX_STR] = matched.group()
state[REGEX_GROUP] = matched.groups()
state[REGEX_DICT] = matched.groupdict()
return True return True
else: else:
return False return False
@@ -671,7 +700,8 @@ def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
::: :::
:::tip 提示 :::tip 提示
正则表达式匹配使用 `EventMessage` 的 `str` 字符串,而非 `EventMessage` 的 `PlainText` 纯文本字符串 正则表达式匹配使用 `EventMessage` 的 `str` 字符串,
而非 `EventMessage` 的 `PlainText` 纯文本字符串
::: :::
""" """
@@ -707,7 +737,7 @@ class IsTypeRule:
__slots__ = ("types",) __slots__ = ("types",)
def __init__(self, *types: Type[Event]): def __init__(self, *types: type[Event]):
self.types = types self.types = types
def __repr__(self) -> str: def __repr__(self) -> str:
@@ -723,7 +753,7 @@ class IsTypeRule:
return isinstance(event, self.types) return isinstance(event, self.types)
def is_type(*types: Type[Event]) -> Rule: def is_type(*types: type[Event]) -> Rule:
"""匹配事件类型。 """匹配事件类型。
参数: 参数:

View File

@@ -1,27 +1,22 @@
"""本模块定义了 NoneBot 模块中共享的一些类型。 """本模块定义了 NoneBot 模块中共享的一些类型。
下面的文档中,「类型」部分使用 Python 的 Type Hint 语法, 使用 Python 的 Type Hint 语法,
参考 [`PEP 484`](https://www.python.org/dev/peps/pep-0484/), 参考 [`PEP 484`](https://www.python.org/dev/peps/pep-0484/),
[`PEP 526`](https://www.python.org/dev/peps/pep-0526/) 和 [`PEP 526`](https://www.python.org/dev/peps/pep-0526/) 和
[`typing`](https://docs.python.org/3/library/typing.html)。 [`typing`](https://docs.python.org/3/library/typing.html)。
除了 Python 内置的类型,下面还出现了如下 NoneBot 自定类型,实际上它们是 Python 内置类型的别名。
FrontMatter: FrontMatter:
sidebar_position: 11 sidebar_position: 11
description: nonebot.typing 模块 description: nonebot.typing 模块
""" """
from typing import ( import sys
TYPE_CHECKING, import types
Any, import warnings
Dict, import typing as t
Union, import typing_extensions as t_ext
TypeVar, from typing import TYPE_CHECKING, TypeVar
Callable, from typing_extensions import ParamSpec, TypeAlias, get_args, override, get_origin
Optional,
Awaitable,
)
if TYPE_CHECKING: if TYPE_CHECKING:
from asyncio import Task from asyncio import Task
@@ -30,28 +25,107 @@ if TYPE_CHECKING:
from nonebot.permission import Permission from nonebot.permission import Permission
T = TypeVar("T") T = TypeVar("T")
P = ParamSpec("P")
T_Wrapped = TypeVar("T_Wrapped", bound=Callable) T_Wrapped: TypeAlias = t.Callable[P, T]
def overrides(InterfaceClass: object) -> Callable[[T_Wrapped], T_Wrapped]: def overrides(InterfaceClass: object):
"""标记一个方法为父类 interface 的 implement""" """标记一个方法为父类 interface 的 implement"""
def overrider(func: T_Wrapped) -> T_Wrapped: warnings.warn(
assert func.__name__ in dir(InterfaceClass), f"Error method: {func.__name__}" "overrides is deprecated and will be removed in a future version, "
return func "use @typing_extensions.override instead. "
"See [PEP 698](https://peps.python.org/pep-0698/) for more details.",
DeprecationWarning,
)
return override
return overrider
if sys.version_info < (3, 10):
def type_has_args(type_: type[t.Any]) -> bool:
"""判断类型是否有参数"""
return isinstance(type_, (t._GenericAlias, types.GenericAlias)) # type: ignore
else:
def type_has_args(type_: type[t.Any]) -> bool:
return isinstance(type_, (t._GenericAlias, types.GenericAlias, types.UnionType)) # type: ignore
if sys.version_info < (3, 10):
def origin_is_union(origin: t.Optional[type[t.Any]]) -> bool:
"""判断是否是 Union 类型"""
return origin is t.Union
else:
def origin_is_union(origin: t.Optional[type[t.Any]]) -> bool:
return origin is t.Union or origin is types.UnionType
def origin_is_literal(origin: t.Optional[type[t.Any]]) -> bool:
"""判断是否是 Literal 类型"""
return origin is t.Literal or origin is t_ext.Literal
def _literal_values(type_: type[t.Any]) -> tuple[t.Any, ...]:
return get_args(type_)
def all_literal_values(type_: type[t.Any]) -> list[t.Any]:
"""获取 Literal 类型包含的所有值"""
if not origin_is_literal(get_origin(type_)):
return [type_]
return [x for value in _literal_values(type_) for x in all_literal_values(value)]
def origin_is_annotated(origin: t.Optional[type[t.Any]]) -> bool:
"""判断是否是 Annotated 类型"""
return origin is t_ext.Annotated
NONE_TYPES = {None, type(None), t.Literal[None], t_ext.Literal[None]}
if sys.version_info >= (3, 10):
NONE_TYPES.add(types.NoneType)
def is_none_type(type_: type[t.Any]) -> bool:
"""判断是否是 None 类型"""
return type_ in NONE_TYPES
def evaluate_forwardref(
ref: t.ForwardRef, globalns: dict[str, t.Any], localns: dict[str, t.Any]
) -> t.Any:
# Python 3.13/3.12.4+ made `recursive_guard` a kwarg,
# so name it explicitly to avoid:
# TypeError: ForwardRef._evaluate()
# missing 1 required keyword-only argument: 'recursive_guard'
return ref._evaluate(globalns, localns, recursive_guard=frozenset())
# state # state
T_State = Dict[Any, Any] # use annotated flag to avoid ForwardRef recreate generic type (py >= 3.11)
class StateFlag:
def __repr__(self) -> str:
return "StateFlag()"
_STATE_FLAG = StateFlag()
T_State: TypeAlias = t.Annotated[dict[t.Any, t.Any], _STATE_FLAG]
"""事件处理状态 State 类型""" """事件处理状态 State 类型"""
_DependentCallable = Union[Callable[..., T], Callable[..., Awaitable[T]]] _DependentCallable: TypeAlias = t.Union[
t.Callable[..., T], t.Callable[..., t.Awaitable[T]]
]
# driver hooks # driver hooks
T_BotConnectionHook = _DependentCallable[Any] T_BotConnectionHook: TypeAlias = _DependentCallable[t.Any]
"""Bot 连接建立时钩子函数 """Bot 连接建立时钩子函数
依赖参数: 依赖参数:
@@ -60,7 +134,7 @@ T_BotConnectionHook = _DependentCallable[Any]
- BotParam: Bot 对象 - BotParam: Bot 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_BotDisconnectionHook = _DependentCallable[Any] T_BotDisconnectionHook: TypeAlias = _DependentCallable[t.Any]
"""Bot 连接断开时钩子函数 """Bot 连接断开时钩子函数
依赖参数: 依赖参数:
@@ -71,15 +145,17 @@ T_BotDisconnectionHook = _DependentCallable[Any]
""" """
# api hooks # api hooks
T_CallingAPIHook = Callable[["Bot", str, Dict[str, Any]], Awaitable[Any]] T_CallingAPIHook: TypeAlias = t.Callable[
["Bot", str, dict[str, t.Any]], t.Awaitable[t.Any]
]
"""`bot.call_api` 钩子函数""" """`bot.call_api` 钩子函数"""
T_CalledAPIHook = Callable[ T_CalledAPIHook: TypeAlias = t.Callable[
["Bot", Optional[Exception], str, Dict[str, Any], Any], Awaitable[Any] ["Bot", t.Optional[Exception], str, dict[str, t.Any], t.Any], t.Awaitable[t.Any]
] ]
"""`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result""" """`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result"""
# event hooks # event hooks
T_EventPreProcessor = _DependentCallable[Any] T_EventPreProcessor: TypeAlias = _DependentCallable[t.Any]
"""事件预处理函数 EventPreProcessor 类型 """事件预处理函数 EventPreProcessor 类型
依赖参数: 依赖参数:
@@ -90,8 +166,8 @@ T_EventPreProcessor = _DependentCallable[Any]
- StateParam: State 对象 - StateParam: State 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_EventPostProcessor = _DependentCallable[Any] T_EventPostProcessor: TypeAlias = _DependentCallable[t.Any]
"""事件处理函数 EventPostProcessor 类型 """事件处理函数 EventPostProcessor 类型
依赖参数: 依赖参数:
@@ -103,7 +179,7 @@ T_EventPostProcessor = _DependentCallable[Any]
""" """
# matcher run hooks # matcher run hooks
T_RunPreProcessor = _DependentCallable[Any] T_RunPreProcessor: TypeAlias = _DependentCallable[t.Any]
"""事件响应器运行前预处理函数 RunPreProcessor 类型 """事件响应器运行前预处理函数 RunPreProcessor 类型
依赖参数: 依赖参数:
@@ -115,7 +191,7 @@ T_RunPreProcessor = _DependentCallable[Any]
- MatcherParam: Matcher 对象 - MatcherParam: Matcher 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_RunPostProcessor = _DependentCallable[Any] T_RunPostProcessor: TypeAlias = _DependentCallable[t.Any]
"""事件响应器运行后后处理函数 RunPostProcessor 类型 """事件响应器运行后后处理函数 RunPostProcessor 类型
依赖参数: 依赖参数:
@@ -130,7 +206,7 @@ T_RunPostProcessor = _DependentCallable[Any]
""" """
# rule, permission # rule, permission
T_RuleChecker = _DependentCallable[bool] T_RuleChecker: TypeAlias = _DependentCallable[bool]
"""RuleChecker 即判断是否响应事件的处理函数。 """RuleChecker 即判断是否响应事件的处理函数。
依赖参数: 依赖参数:
@@ -141,7 +217,7 @@ T_RuleChecker = _DependentCallable[bool]
- StateParam: State 对象 - StateParam: State 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_PermissionChecker = _DependentCallable[bool] T_PermissionChecker: TypeAlias = _DependentCallable[bool]
"""PermissionChecker 即判断事件是否满足权限的处理函数。 """PermissionChecker 即判断事件是否满足权限的处理函数。
依赖参数: 依赖参数:
@@ -152,10 +228,11 @@ T_PermissionChecker = _DependentCallable[bool]
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_Handler = _DependentCallable[Any] T_Handler: TypeAlias = _DependentCallable[t.Any]
"""Handler 处理函数。""" """Handler 处理函数。"""
T_TypeUpdater = _DependentCallable[str] T_TypeUpdater: TypeAlias = _DependentCallable[str]
"""TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。默认会更新为 `message`。 """TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。
默认会更新为 `message`。
依赖参数: 依赖参数:
@@ -166,8 +243,9 @@ T_TypeUpdater = _DependentCallable[str]
- MatcherParam: Matcher 对象 - MatcherParam: Matcher 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_PermissionUpdater = _DependentCallable["Permission"] T_PermissionUpdater: TypeAlias = _DependentCallable["Permission"]
"""PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。默认会更新为当前事件的触发对象。 """PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。
默认会更新为当前事件的触发对象。
依赖参数: 依赖参数:
@@ -178,5 +256,5 @@ T_PermissionUpdater = _DependentCallable["Permission"]
- MatcherParam: Matcher 对象 - MatcherParam: Matcher 对象
- DefaultParam: 带有默认值的参数 - DefaultParam: 带有默认值的参数
""" """
T_DependencyCache = Dict[_DependentCallable[Any], "Task[Any]"] T_DependencyCache: TypeAlias = dict[_DependentCallable[t.Any], "Task[t.Any]"]
"""依赖缓存, 用于存储依赖函数的返回值""" """依赖缓存, 用于存储依赖函数的返回值"""

View File

@@ -10,29 +10,27 @@ import json
import asyncio import asyncio
import inspect import inspect
import importlib import importlib
import contextlib
import dataclasses import dataclasses
from pathlib import Path from pathlib import Path
from collections import deque
from contextvars import copy_context
from functools import wraps, partial from functools import wraps, partial
from contextlib import asynccontextmanager from contextlib import AbstractContextManager, asynccontextmanager
from typing_extensions import ParamSpec, get_args, get_origin from typing_extensions import ParamSpec, get_args, override, get_origin
from typing import ( from collections.abc import Mapping, Sequence, Coroutine, AsyncGenerator
Any, from typing import Any, Union, Generic, TypeVar, Callable, Optional, overload
Type,
Tuple,
Union,
TypeVar,
Callable,
Optional,
Coroutine,
AsyncGenerator,
ContextManager,
overload,
)
from pydantic.typing import is_union, is_none_type from pydantic import BaseModel
from nonebot.log import logger from nonebot.log import logger
from nonebot.typing import overrides from nonebot.typing import (
is_none_type,
type_has_args,
origin_is_union,
origin_is_literal,
all_literal_values,
)
P = ParamSpec("P") P = ParamSpec("P")
R = TypeVar("R") R = TypeVar("R")
@@ -52,27 +50,96 @@ def escape_tag(s: str) -> str:
return re.sub(r"</?((?:[fb]g\s)?[^<>\s]*)>", r"\\\g<0>", s) return re.sub(r"</?((?:[fb]g\s)?[^<>\s]*)>", r"\\\g<0>", s)
def deep_update(
mapping: dict[K, Any], *updating_mappings: dict[K, Any]
) -> dict[K, Any]:
"""深度更新合并字典"""
updated_mapping = mapping.copy()
for updating_mapping in updating_mappings:
for k, v in updating_mapping.items():
if (
k in updated_mapping
and isinstance(updated_mapping[k], dict)
and isinstance(v, dict)
):
updated_mapping[k] = deep_update(updated_mapping[k], v)
else:
updated_mapping[k] = v
return updated_mapping
def lenient_issubclass(
cls: Any, class_or_tuple: Union[type[Any], tuple[type[Any], ...]]
) -> bool:
"""检查 cls 是否是 class_or_tuple 中的一个类型子类并忽略类型错误。"""
try:
return isinstance(cls, type) and issubclass(cls, class_or_tuple)
except TypeError:
return False
def generic_check_issubclass( def generic_check_issubclass(
cls: Any, class_or_tuple: Union[Type[Any], Tuple[Type[Any], ...]] cls: Any, class_or_tuple: Union[type[Any], tuple[type[Any], ...]]
) -> bool: ) -> bool:
"""检查 cls 是否是 class_or_tuple 中的一个类型子类。 """检查 cls 是否是 class_or_tuple 中的一个类型子类。
特别的,如果 cls 是 `typing.Union` 或 `types.UnionType` 类型, 特别的
则会检查其中的类型是否是 class_or_tuple 中的一个类型子类。None 会被忽略)
- 如果 cls 是 `typing.Union` 或 `types.UnionType` 类型,
则会检查其中的所有类型是否是 class_or_tuple 中一个类型的子类或 None。
- 如果 cls 是 `typing.Literal` 类型,
则会检查其中的所有值是否是 class_or_tuple 中一个类型的实例。
- 如果 cls 是 `typing.TypeVar` 类型,
则会检查其 `__bound__` 或 `__constraints__`
是否是 class_or_tuple 中一个类型的子类或 None。
""" """
try: if not type_has_args(cls):
return issubclass(cls, class_or_tuple) with contextlib.suppress(TypeError):
except TypeError: return issubclass(cls, class_or_tuple)
origin = get_origin(cls)
if is_union(origin): origin = get_origin(cls)
if origin_is_union(origin):
return all(
is_none_type(type_) or generic_check_issubclass(type_, class_or_tuple)
for type_ in get_args(cls)
)
elif origin_is_literal(origin):
return all(
is_none_type(value) or isinstance(value, class_or_tuple)
for value in all_literal_values(cls)
)
# ensure generic List, Dict can be checked
elif origin:
# avoid class check error (typing.Final, typing.ClassVar, etc...)
try:
return issubclass(origin, class_or_tuple)
except TypeError:
return False
elif isinstance(cls, TypeVar):
if cls.__constraints__:
return all( return all(
is_none_type(type_) or generic_check_issubclass(type_, class_or_tuple) is_none_type(type_) or generic_check_issubclass(type_, class_or_tuple)
for type_ in get_args(cls) for type_ in cls.__constraints__
) )
elif origin: elif cls.__bound__:
return issubclass(origin, class_or_tuple) return generic_check_issubclass(cls.__bound__, class_or_tuple)
return False
def type_is_complex(type_: type[Any]) -> bool:
"""检查 type_ 是否是复杂类型"""
origin = get_origin(type_)
return _type_is_complex_inner(type_) or _type_is_complex_inner(origin)
def _type_is_complex_inner(type_: Optional[type[Any]]) -> bool:
if lenient_issubclass(type_, (str, bytes)):
return False return False
return lenient_issubclass(
type_, (BaseModel, Mapping, Sequence, tuple, set, frozenset, deque)
) or dataclasses.is_dataclass(type_)
def is_coroutine_callable(call: Callable[..., Any]) -> bool: def is_coroutine_callable(call: Callable[..., Any]) -> bool:
"""检查 call 是否是一个 callable 协程函数""" """检查 call 是否是一个 callable 协程函数"""
@@ -111,7 +178,8 @@ def run_sync(call: Callable[P, R]) -> Callable[P, Coroutine[None, None, R]]:
async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R: async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
pfunc = partial(call, *args, **kwargs) pfunc = partial(call, *args, **kwargs)
result = await loop.run_in_executor(None, pfunc) context = copy_context()
result = await loop.run_in_executor(None, partial(context.run, pfunc))
return result return result
return _wrapper return _wrapper
@@ -119,7 +187,7 @@ def run_sync(call: Callable[P, R]) -> Callable[P, Coroutine[None, None, R]]:
@asynccontextmanager @asynccontextmanager
async def run_sync_ctx_manager( async def run_sync_ctx_manager(
cm: ContextManager[T], cm: AbstractContextManager[T],
) -> AsyncGenerator[T, None]: ) -> AsyncGenerator[T, None]:
"""一个用于包装 sync context manager 为 async context manager 的执行函数""" """一个用于包装 sync context manager 为 async context manager 的执行函数"""
try: try:
@@ -135,25 +203,35 @@ async def run_sync_ctx_manager(
@overload @overload
async def run_coro_with_catch( async def run_coro_with_catch(
coro: Coroutine[Any, Any, T], coro: Coroutine[Any, Any, T],
exc: Tuple[Type[Exception], ...], exc: tuple[type[Exception], ...],
) -> Union[T, None]: return_on_err: None = None,
... ) -> Union[T, None]: ...
@overload @overload
async def run_coro_with_catch( async def run_coro_with_catch(
coro: Coroutine[Any, Any, T], coro: Coroutine[Any, Any, T],
exc: Tuple[Type[Exception], ...], exc: tuple[type[Exception], ...],
return_on_err: R, return_on_err: R,
) -> Union[T, R]: ) -> Union[T, R]: ...
...
async def run_coro_with_catch( async def run_coro_with_catch(
coro: Coroutine[Any, Any, T], coro: Coroutine[Any, Any, T],
exc: Tuple[Type[Exception], ...], exc: tuple[type[Exception], ...],
return_on_err: Optional[R] = None, return_on_err: Optional[R] = None,
) -> Optional[Union[T, R]]: ) -> Optional[Union[T, R]]:
"""运行协程并当遇到指定异常时返回指定值。
参数:
coro: 要运行的协程
exc: 要捕获的异常
return_on_err: 当发生异常时返回的值
返回:
协程的返回值或发生异常时的指定值
"""
try: try:
return await coro return await coro
except exc: except exc:
@@ -192,10 +270,20 @@ def resolve_dot_notation(
return instance return instance
class DataclassEncoder(json.JSONEncoder): class classproperty(Generic[T]):
"""在JSON序列化 {re}`nonebot.adapters._message.Message` (List[Dataclass]) 时使用的 `JSONEncoder`""" """类属性装饰器"""
@overrides(json.JSONEncoder) def __init__(self, func: Callable[[Any], T]) -> None:
self.func = func
def __get__(self, instance: Any, owner: Optional[type[Any]] = None) -> T:
return self.func(type(instance) if owner is None else owner)
class DataclassEncoder(json.JSONEncoder):
"""可以序列化 {ref}`nonebot.adapters.Message`(List[Dataclass]) 的 `JSONEncoder`"""
@override
def default(self, o): def default(self, o):
if dataclasses.is_dataclass(o): if dataclasses.is_dataclass(o):
return {f.name: getattr(o, f.name) for f in dataclasses.fields(o)} return {f.name: getattr(o, f.name) for f in dataclasses.fields(o)}
@@ -211,9 +299,11 @@ def logger_wrapper(logger_name: str):
返回: 返回:
日志记录函数 日志记录函数
- level: 日志等级 日志记录函数的参数:
- message: 日志信息
- exception: 异常信息 - level: 日志等级
- message: 日志信息
- exception: 异常信息
""" """
def log(level: str, message: str, exception: Optional[Exception] = None): def log(level: str, message: str, exception: Optional[Exception] = None):

View File

@@ -11,10 +11,31 @@
"start": "yarn workspace nonebot start", "start": "yarn workspace nonebot start",
"serve": "yarn workspace nonebot serve", "serve": "yarn workspace nonebot serve",
"clear": "yarn workspace nonebot clear", "clear": "yarn workspace nonebot clear",
"prettier": "prettier --config ./.prettierrc --write \"./website/\"" "prettier": "prettier --config ./.prettierrc --write \"./website/\"",
"lint": "yarn lint:js && yarn lint:style",
"lint:js": "eslint --cache --report-unused-disable-directives \"**/*.{js,jsx,ts,tsx,mjs}\"",
"lint:js:fix": "eslint --cache --report-unused-disable-directives --fix \"**/*.{js,jsx,ts,tsx,mjs}\"",
"lint:style": "stylelint \"**/*.css\"",
"lint:style:fix": "stylelint --fix \"**/*.css\"",
"pyright": "pyright"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"prettier": "^2.5.0" "eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regexp": "^1.15.0",
"prettier": "^3.0.3",
"pyright": "^1.1.317",
"stylelint": "^15.10.3",
"stylelint-config-standard": "^34.0.0",
"stylelint-prettier": "^4.0.2"
} }
} }

View File

@@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<a href="https://v2.nonebot.dev/"><img src="https://raw.githubusercontent.com/nonebot/nonebot2/master/docs/.vuepress/public/logo.png" width="200" height="200" alt="nonebot"></a> <a href="https://nonebot.dev/"><img src="https://nonebot.dev/logo.png" width="200" height="200" alt="nonebot"></a>
</p> </p>
<div align="center"> <div align="center">
@@ -17,11 +17,11 @@ _✨ NoneBot 本地文档插件 ✨_
<a href="https://pypi.python.org/pypi/nonebot-plugin-docs"> <a href="https://pypi.python.org/pypi/nonebot-plugin-docs">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-docs.svg" alt="pypi"> <img src="https://img.shields.io/pypi/v/nonebot-plugin-docs.svg" alt="pypi">
</a> </a>
<img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python"> <img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
</p> </p>
## 使用方式 ## 使用方式
加载插件并启动 Bot ,在浏览器内打开 `http://host:port/docs/` 加载插件并启动 Bot ,在浏览器内打开 `http://host:port/website/`
具体网址会在控制台内输出。 具体网址会在控制台内输出。

View File

@@ -2,6 +2,17 @@ import importlib
import nonebot import nonebot
from nonebot.log import logger from nonebot.log import logger
from nonebot.plugin import PluginMetadata
__plugin_meta__ = PluginMetadata(
name="NoneBot 离线文档",
description="在本地查看 NoneBot 文档",
usage="启动机器人后访问 http://localhost:port/website/ 查看文档",
type="application",
homepage="https://github.com/nonebot/nonebot2/blob/master/packages/nonebot-plugin-docs",
config=None,
supported_adapters=None,
)
def init(): def init():
@@ -17,7 +28,7 @@ def init():
register_route(driver) register_route(driver)
host = str(driver.config.host) host = str(driver.config.host)
port = driver.config.port port = driver.config.port
if host in ["0.0.0.0", "127.0.0.1"]: if host in {"0.0.0.0", "127.0.0.1"}:
host = "localhost" host = "localhost"
logger.opt(colors=True).info( logger.opt(colors=True).info(
f"Nonebot docs will be running at: " f"Nonebot docs will be running at: "

Some files were not shown because too many files have changed in this diff Show More