Compare commits

...

313 Commits

Author SHA1 Message Date
Ju4tCode
b6bbc7d228 🔀 Merge pull request #98
PreRelease 2.0.0a7
2020-12-05 01:46:47 +08:00
yanyongyu
621f93f75a 📝 update nonebot docstring 2020-12-05 01:43:58 +08:00
yanyongyu
5ebe7ff1cb 🔖 PreRelease 2.0.0a7 2020-12-05 01:22:28 +08:00
yanyongyu
d7a4593fcf 📝 update changelog 2020-12-04 02:11:20 +08:00
Ju4tCode
dc70f9a9cd 🔀 Merge pull request #97
Add MatcherGroup
2020-12-04 02:00:59 +08:00
yanyongyu
f6806c1d55 test matchergroup 2020-12-04 01:55:03 +08:00
yanyongyu
5b42454a55 add matcher group for plugin #90 2020-12-04 01:41:23 +08:00
Ju4tCode
b24649b6af 🔀 Merge pull request #94
Add dingding adapter
2020-12-03 19:33:58 +08:00
Ju4tCode
0838cdfbe7 🎨 improve format 2020-12-03 19:24:55 +08:00
Ju4tCode
71c5cdc445 revert plain text 2020-12-03 19:12:46 +08:00
Artin
be244f4538 🐛 Fix Message._construct error 2020-12-03 18:47:58 +08:00
yanyongyu
afd01796aa 🚧 update ding adapter 2020-12-03 17:08:16 +08:00
yanyongyu
dc691889e3 🎨 improve cqhttp 2020-12-03 16:04:14 +08:00
nonebot
4b764ccba3 📝 update api docs 2020-12-03 07:09:09 +00:00
yanyongyu
9658e446e5 🏗️ change exception structure 2020-12-03 15:07:03 +08:00
nonebot
8f89e0f26e 📝 update api docs 2020-12-03 05:23:47 +00:00
yanyongyu
7116532081 🚧 add exception 2020-12-03 13:22:12 +08:00
yanyongyu
b47bef3ef6 ✏️ fix builtin typo #96 2020-12-03 13:02:34 +08:00
Artin
3638da7f2d 🐛 Fix ding adapter exception 2020-12-03 12:22:45 +08:00
nonebot
da62e012c2 📝 update api docs 2020-12-03 04:09:54 +00:00
Artin
e718f25c3f 🏷️ 完善 typing 及注释 2020-12-03 12:08:09 +08:00
nonebot
f1a0ac099b 📝 update api docs 2020-12-02 17:49:14 +00:00
Artin
8c5c02f040 🏷️ Update BaseEvent typing 2020-12-03 01:46:55 +08:00
nonebot
33bd9d0fb8 📝 update api docs 2020-12-02 17:04:45 +00:00
Artin
edb4458031 Add ding adapter 2020-12-03 01:02:09 +08:00
Artin
f332199baa ♻️ Encapsulation MessageSegment
close: #93
2020-12-03 00:57:02 +08:00
Artin
8cda1b5417 ♻️ Split adapter by category 2020-12-03 00:56:25 +08:00
yanyongyu
45ceba47f3 👌 update changelog 2020-12-02 16:16:19 +08:00
yanyongyu
8a9a77656f 🍻 add funding 2020-12-02 16:11:46 +08:00
yanyongyu
064ed81758 📝 update adapter connection guide 2020-12-02 15:14:24 +08:00
Ju4tCode
0d5930fc3a 🔀 Merge pull request #92
Refactor: 更新内置 register_adapter 逻辑
2020-12-02 13:45:07 +08:00
yanyongyu
8601c61cd8 💄 update log style 2020-12-02 13:25:57 +08:00
yanyongyu
0738b275a5 💥 remove builtin adapter auto register 2020-12-02 13:17:27 +08:00
yanyongyu
6a25e42571 ⬆️ update lock file 2020-12-02 12:52:02 +08:00
yanyongyu
81d96888bd 📝 update plugin info 2020-12-01 19:10:05 +08:00
yanyongyu
c9d7b63f23 📝 update plugin installation guide 2020-12-01 18:53:03 +08:00
yanyongyu
4c179d9910 📝 update star guide 2020-12-01 17:08:15 +08:00
yanyongyu
a085b47eac 📝 update guide docs 2020-12-01 12:24:14 +08:00
yanyongyu
ad994f04fc 💬 update cqhttp links 2020-12-01 11:03:08 +08:00
yanyongyu
301e9093bd 📄 update license 2020-12-01 10:57:00 +08:00
yanyongyu
39a2658a25 👷 update release drafter 2020-12-01 10:48:46 +08:00
yanyongyu
d624f13f96 💥 remove nonebot test auto init 2020-12-01 10:44:58 +08:00
yanyongyu
6ac04d6507 remove extra dependency 2020-12-01 10:42:59 +08:00
yanyongyu
cc7ebe2f73 ⬆️ bump dependency version 2020-12-01 10:40:21 +08:00
Ju4tCode
bdb4d584e4 🔀 Merge pull request #91
Breaking change: remove built-in scheduler support
2020-12-01 10:33:20 +08:00
yanyongyu
38d502f7f5 💥 remove built-in scheduler support 2020-12-01 10:28:03 +08:00
yanyongyu
e931b535f1 📝 update readme 2020-12-01 00:56:19 +08:00
yanyongyu
0775a232ce ✏️ fix docstring typo 2020-11-30 12:43:44 +08:00
yanyongyu
e5463cc564 🎨 format docstring 2020-11-30 11:08:00 +08:00
Ju4tCode
5554c6e62d 🔀 Merge pull request #88
Plugin: 合并nonebot-plugin-docs
2020-11-28 12:24:14 +08:00
Ju4tCode
96cdb9c23e 🔀 Merge pull request #87
Plugin: 合并docs插件至官方仓库
2020-11-28 12:06:32 +08:00
yanyongyu
b75343d3e7 📝 update homepage and repo link 2020-11-28 11:59:26 +08:00
yanyongyu
62b93c1ba7 🔥 remove file header 2020-11-28 11:55:12 +08:00
yanyongyu
146134a1a7 🔖 update nonebot-plugin-docs author 2020-11-28 11:44:34 +08:00
yanyongyu
da5d63ae29 🔥 remove useless pull and lock file 2020-11-28 11:43:13 +08:00
pull[bot]
9cfcbc5b32 Merge pull request #18 from nonebot/master
[pull] master from nonebot:master
2020-11-26 19:34:04 +00:00
yanyongyu
ee80a4ea60 👷 update user info for pr 2020-11-26 23:54:24 +08:00
yanyongyu
dc0c634eab 🐛 fix workflow vulnerability #79 2020-11-26 23:54:24 +08:00
yanyongyu
168f366efc 📝 update guide 2020-11-26 23:54:24 +08:00
yanyongyu
39d96d9667 📝 add plugin publish guide 2020-11-26 23:54:24 +08:00
yanyongyu
47d1fab4bd 📝 add cross plugin guide 2020-11-26 23:54:24 +08:00
Ju4tCode
84756f3092 🔀Merge pull request #83
👷 update user info for pr
2020-11-26 21:05:16 +08:00
yanyongyu
309c6d1ed0 👷 update user info for pr 2020-11-26 20:53:28 +08:00
Ju4tCode
2bf63ce8aa 🔀 Merge pull request #81 2020-11-26 20:30:03 +08:00
Ju4tCode
b2902407d7 🔀 Merge pull request #80
Fix: GHSL-2020-244
2020-11-26 20:23:32 +08:00
yanyongyu
1fe38afa95 🐛 fix workflow vulnerability #79 2020-11-26 20:18:36 +08:00
pull[bot]
0200167ce2 Merge pull request #16 from nonebot/master
[pull] master from nonebot:master
2020-11-23 17:42:02 +00:00
yanyongyu
0dddbedd70 🍻 publish Sentry日志监控 2020-11-24 01:39:46 +08:00
Ju4tCode
458728ffdd Merge branch 'master' into master 2020-11-24 01:39:17 +08:00
Ju4tCode
df71a1e6ee 🔀 Merge pull request #77
Plugin: Sentry日志监控
2020-11-23 21:46:50 +08:00
yanyongyu
7e35f591d7 🍻 publish Sentry日志监控 2020-11-23 13:35:26 +00:00
yanyongyu
b7642394f4 📝 update guide 2020-11-23 14:15:30 +08:00
yanyongyu
bdd7e9514a 📝 add plugin publish guide 2020-11-23 13:46:36 +08:00
yanyongyu
f214c0b2cb 📝 add cross plugin guide 2020-11-23 13:41:57 +08:00
yanyongyu
5ff638f9e7 🔀 Merge branch 'origin/master' 2020-11-22 21:12:57 +08:00
yanyongyu
e92cbf2f50 🐛 bump version due to vuepress base error 2020-11-22 21:12:07 +08:00
yanyongyu
9d30f2dff3 👷 update release drafter 2020-11-22 09:18:27 +00:00
nonebot
f01295d936 🍻 publish NoneBot离线文档 2020-11-22 09:18:27 +00:00
yanyongyu
343a345ed2 👷 update release drafter 2020-11-22 16:40:06 +08:00
Ju4tCode
2965867516 🔀 Merge pull request #75
Plugin NoneBot离线文档
2020-11-22 16:31:29 +08:00
nonebot
68887086a6 🍻 publish NoneBot离线文档 2020-11-22 08:25:25 +00:00
pull[bot]
47b015a2d0 Merge pull request #5 from nonebot/master
[pull] master from nonebot:master
2020-11-21 21:18:25 +00:00
yanyongyu
1affeb8e20 🔖 release 2.0.0a6 2020-11-22 03:05:28 +08:00
yanyongyu
b5b8ff165c 👷 add release ci 2020-11-22 02:42:27 +08:00
yanyongyu
389211f740 🐛 fix error arg 2020-11-22 02:17:13 +08:00
yanyongyu
68ed443fa3 👽 update vuepress base 2020-11-21 18:00:59 +00:00
yanyongyu
9a819fc12c 💡 update docstring 2020-11-21 18:00:59 +00:00
yanyongyu
2b10f81326 ⚗️ add export require option 2020-11-21 18:00:59 +00:00
yanyongyu
689180ebe8 📝 update change log 2020-11-21 18:00:59 +00:00
yanyongyu
1aba139136 get plugin func 2020-11-21 18:00:59 +00:00
yanyongyu
e5213eb95a 🚑 fix not delete empty text 2020-11-21 18:00:59 +00:00
yanyongyu
5fb9799807 ✏️ fix typo 2020-11-21 18:00:59 +00:00
yanyongyu
9241f4df79 🐛 fix remain space after reply 2020-11-21 18:00:59 +00:00
yanyongyu
d55459cfcd 🚑 fix matcher check 2020-11-21 18:00:59 +00:00
yanyongyu
17747f94c8 🐛 fix #69 stop running expired matcher 2020-11-21 18:00:59 +00:00
yanyongyu
829f47c5e7 🐛 fix #66 resolve reply message 2020-11-21 18:00:59 +00:00
Muchan
557054cb8b feat(message): 传递matcher抛出的StopPropagation 2020-11-21 18:00:59 +00:00
yanyongyu
d726b75721 📝 add changelog 2020-11-21 18:00:59 +00:00
yanyongyu
47aede8f67 🐛 fix index error when check to me 2020-11-21 18:00:59 +00:00
synodriver
1557158cd9 修复了at机器人时的bug 2020-11-21 18:00:59 +00:00
Ju4tCode
de07a6594d 🔀 Merge pull request #73 2020-11-22 01:59:11 +08:00
yanyongyu
07b72f87d7 👽 update vuepress base 2020-11-22 01:51:23 +08:00
yanyongyu
8f4961613d 👷 update pull upstream ci 2020-11-22 01:25:13 +08:00
yanyongyu
339e6cd665 📦 add nonebot plugin docs 2020-11-22 01:20:14 +08:00
yanyongyu
1c87c83c45 👷 add pull upstream ci 2020-11-22 01:18:46 +08:00
yanyongyu
d70f622a24 💡 update docstring 2020-11-21 20:50:33 +08:00
yanyongyu
9373bd09ed ⚗️ add export require option 2020-11-21 20:40:09 +08:00
yanyongyu
b36f95862a 📝 update change log 2020-11-21 20:38:03 +08:00
yanyongyu
71fad44d23 get plugin func 2020-11-21 18:33:35 +08:00
Ju4tCode
cfbfeec69b 🔀 Merge pull request #72
👷 update plugin issue bot
2020-11-20 17:11:36 +08:00
hemengyang
318aa98c98 👷 update plugin issue bot 2020-11-20 16:39:52 +08:00
yanyongyu
009cca3c9d 👷 change ci secret 2020-11-20 13:38:28 +08:00
Ju4tCode
f53644ef26 🔀 Merge pull request #71
add plugin publish action
2020-11-20 13:31:44 +08:00
yanyongyu
7b15d0d01f 🚑 fix not delete empty text 2020-11-20 12:53:31 +08:00
yanyongyu
7fdddf4d8f ✏️ fix typo 2020-11-20 01:37:53 +08:00
yanyongyu
a734790bcf 🐛 fix remain space after reply 2020-11-20 01:07:24 +08:00
hemengyang
9e598cfa70 fix: 忘记改 push 的触发分支名 2020-11-20 00:36:07 +08:00
hemengyang
aca37736c4 ci: 添加插件议题机器人 2020-11-20 00:30:46 +08:00
yanyongyu
a5935e77c9 🚑 fix matcher check 2020-11-19 23:18:03 +08:00
Ju4tCode
93ee9a3b58 🔀 Merge pull request #70
Fix: running expired matcher
2020-11-19 22:08:31 +08:00
yanyongyu
0b6a1ca1a4 🐛 fix #69 stop running expired matcher 2020-11-19 22:04:44 +08:00
Ju4tCode
e9127f505a 🔀 Merge pull request #67
dynamic propagation block
2020-11-19 21:36:52 +08:00
Ju4tCode
30b839d736 🔀 Merge pull request #68
Fix: resolve reply message
2020-11-19 21:29:02 +08:00
yanyongyu
49ad65f449 🐛 fix #66 resolve reply message 2020-11-19 21:21:54 +08:00
Muchan
8b3af9fb47 feat(message): 传递matcher抛出的StopPropagation 2020-11-19 20:53:28 +08:00
yanyongyu
0c39b06355 📝 add changelog 2020-11-19 14:54:58 +08:00
Ju4tCode
73ce79472e 🔀 Merge pull request #64
修复了at机器人时的IndexError
2020-11-19 14:46:57 +08:00
yanyongyu
9e1eee166b 🐛 fix index error when check to me 2020-11-19 13:57:49 +08:00
synodriver
03c7b59df5 修复了at机器人时的bug 2020-11-19 13:07:02 +08:00
Ju4tCode
1654dffa4d 🔀 Merge pull request #63
Plugin: rauthman
2020-11-19 13:02:27 +08:00
yanyongyu
26a4daad33 🍻 publish rauthman 2020-11-19 12:58:35 +08:00
yanyongyu
c666366673 ✏️ fix bot send doc #62 2020-11-19 12:53:20 +08:00
synodriver
d5eb110626 Merge pull request #4 from nonebot/dev
Dev
2020-11-19 10:23:40 +08:00
Ju4tCode
04a3712bc7 🔀 Merge pull request #61
hot fix #60
2020-11-18 15:17:47 +08:00
yanyongyu
39f508bbdf 🔖 Pre Release 2.0.0a6 2020-11-18 15:12:48 +08:00
yanyongyu
0a6008ddc0 update changelog 2020-11-18 15:05:03 +08:00
Ju4tCode
9ba1dc614c 🔀 Merge pull request #60 2020-11-18 14:56:42 +08:00
hemengyang
31123b0573 修复阻止事件传递信号无效的问题 2020-11-18 14:43:12 +08:00
yanyongyu
aaa860de33 🚑 fix full extra apscheduler error 2020-11-18 12:02:26 +08:00
Ju4tCode
5efe1907ad 🔀 Merge pull request #58
Plugin Haruka Bot
2020-11-18 11:29:09 +08:00
yanyongyu
d0c19d09a3 🍻 publish Haruka Bot 2020-11-18 11:24:11 +08:00
yanyongyu
e6268f319d 📝 add advanced and changelog 2020-11-18 08:48:23 +08:00
yanyongyu
42e714ee7d 📝 add sub plugin guide 2020-11-17 17:35:53 +08:00
Ju4tCode
4bee48e9e5 🔀 Merge pull request #57
Pre Release 2.0.0a5
2020-11-17 17:01:41 +08:00
yanyongyu
c71c182834 📦 archive version doc 2020-11-17 16:50:37 +08:00
yanyongyu
9fc354af43 🔖 bump version to 2.0.0a5 2020-11-17 16:36:42 +08:00
Ju4tCode
bc8833ce8e 🔀 Merge pull request #54
fix temp matcher delete
2020-11-16 20:05:49 +08:00
nonebot
8524c32b93 📝 update api docs 2020-11-16 11:59:05 +00:00
yanyongyu
872df975f5 ✏️ fix rst typo 2020-11-16 19:57:49 +08:00
nonebot
36c0d995af 📝 update api docs 2020-11-16 11:42:47 +00:00
yanyongyu
1c31453ba0 🔥 remove unused exception 2020-11-16 19:39:51 +08:00
yanyongyu
2e2f3eee04 ✏️ fix config typo 2020-11-16 15:27:20 +08:00
yanyongyu
b3e6d1c803 💡 add message docstring 2020-11-16 15:06:37 +08:00
yanyongyu
829f085340 🐛 fix coding error 2020-11-16 12:35:04 +08:00
yanyongyu
6986232290 🎨 change temp matcher process #50 2020-11-16 11:25:42 +08:00
Ju4tCode
b5ea66359c 🔀 Merge pull request #53
Add __version__
2020-11-15 16:28:17 +08:00
yanyongyu
730cb82eb7 🥚 add __version__ 2020-11-15 16:18:23 +08:00
Ju4tCode
c4f99d8c77 🔀 Merge pull request #52
Plugin: nonebot-plugin-status
2020-11-15 15:30:41 +08:00
yanyongyu
218c8ea398 🍻 publish nonebot-plugin-status 2020-11-15 15:26:57 +08:00
yanyongyu
47869ccad5 👷 fix import typo 2020-11-15 15:20:15 +08:00
yanyongyu
bde256608b ✏️ fix doc typo 2020-11-15 13:26:20 +08:00
yanyongyu
bc00c1be82 💡 add message docstring 2020-11-13 17:15:45 +08:00
yanyongyu
781ec1ef67 🚑 fix index error in cqhttp check to_me 2020-11-13 16:51:14 +08:00
yanyongyu
c79a6df400 ✏️ fix issue template typo 2020-11-13 11:31:24 +08:00
yanyongyu
28e3177e60 💡 update source docstring #46 #49 2020-11-13 01:46:26 +08:00
yanyongyu
5c29abd724 ✏️ fix tip typo 2020-11-12 13:10:41 +08:00
yanyongyu
9803925bbb 📝 finish plugin guide 2020-11-12 09:32:35 +08:00
yanyongyu
47b1affc56 📝 update handler create doc 2020-11-11 16:49:11 +08:00
yanyongyu
b2a2234d5c 🎨 change permission check from driver into adapter #46 2020-11-11 15:14:29 +08:00
Ju4tCode
1f1f9cd7e6 🔀 Merge pull request #48 2020-11-10 17:42:08 +08:00
nonebot
3903b718cb 📝 update api docs 2020-11-10 09:36:13 +00:00
Artin
c3c2c7935d ♻️ add adapters/cqhttp directory 2020-11-10 17:34:02 +08:00
yanyongyu
09a511acf8 📝 add poetry install 2020-11-10 14:44:24 +08:00
yanyongyu
b3f7aaa580 📝 add create handler guide 2020-11-10 14:30:18 +08:00
yanyongyu
286036a936 ✏️ fix module docstring 2020-11-10 14:29:50 +08:00
synodriver
11889b57fe Merge pull request #2 from nonebot/dev
Dev
2020-11-10 01:16:35 +08:00
yanyongyu
9b3dffaab9 ⚗️ add prompt format support 2020-11-09 16:34:14 +08:00
yanyongyu
bb869b5263 📝 update matcher rule docs 2020-11-09 15:09:21 +08:00
yanyongyu
3528d38be1 📝 add create matcher guide 2020-11-09 12:47:59 +08:00
yanyongyu
17ad11212e 👷 add lint script 2020-11-09 12:46:28 +08:00
yanyongyu
50056228b6 📝 update plugin create 2020-11-09 12:33:17 +08:00
yanyongyu
946750a189 📝 add create plugin guide 2020-11-09 11:14:23 +08:00
yanyongyu
7ce69fb6f8 add processor test 2020-11-07 18:15:09 +08:00
Ju4tCode
b87df479a2 🔀 Merge pull request #45
add pre and post processors
2020-11-07 17:56:01 +08:00
nonebot
5458248403 📝 update api docs 2020-11-07 09:52:23 +00:00
yanyongyu
9b4121053c ⬆️ update lock file 2020-11-07 17:51:17 +08:00
yanyongyu
746b608d10 ⚗️ add pre and post processor #40 2020-11-07 17:35:44 +08:00
yanyongyu
9d7da873c4 📝 add plugin load doc 2020-11-07 12:36:47 +08:00
Ju4tCode
70c400da7f 🔀 Merge pull request #43
Pre Release 2.0.0a4
2020-11-04 13:46:05 +08:00
yanyongyu
2a5cfe712f 📝 update doc version 2020-11-04 13:41:52 +08:00
yanyongyu
533a045622 ⬆️ bump version and update dependency 2020-11-04 13:27:49 +08:00
Ju4tCode
93aa1791c9 🔀 Merge pull request #42
Fix: Plugin publish template
2020-11-02 20:25:28 +08:00
yanyongyu
06c76cc096 👷 fix plugin template 2020-11-02 20:20:41 +08:00
Ju4tCode
04df0e5f51 🔀 Merge pull request #41 2020-11-02 19:39:55 +08:00
yanyongyu
f99e029567 📌 update poetry lock file 2020-11-02 19:33:45 +08:00
yanyongyu
71ee9aee21 🚧 update plugin store 2020-11-02 19:07:53 +08:00
yanyongyu
d9ea95c67e 🚑 fix message segment get 2020-11-01 19:20:18 +08:00
yanyongyu
af7f42ac60 📝 update plugin store page 2020-11-01 18:21:31 +08:00
yanyongyu
15e59a1778 👷 update plugin template 2020-11-01 18:21:10 +08:00
yanyongyu
22962d55e1 👷 create plugin issue template 2020-11-01 16:18:57 +08:00
yanyongyu
70c7927006 💡 add docstring for cqhttp message 2020-10-30 16:49:31 +08:00
yanyongyu
89c3aa38a6 🎨 allow multi value for keyword rule 2020-10-30 16:26:04 +08:00
Ju4tCode
2eb330b8a8 🔀 Merge pull request #39 2020-10-30 15:57:31 +08:00
yanyongyu
383c0031a5 📝 update plugin 2020-10-30 01:59:45 +08:00
yanyongyu
06f20281a5 🔇 remove meta event logs #21 2020-10-29 17:06:07 +08:00
yanyongyu
a40f1a453c 📝 replace say with echo due to superuser perm 2020-10-29 16:27:20 +08:00
Ju4tCode
5d9f354209 🔀 Merge pull request #37 2020-10-28 13:49:53 +08:00
Ju4tCode
c3bd8ebf57 🚧 change result store 2020-10-28 13:45:54 +08:00
yanyongyu
c9c615c8cb 👷 try pull request target 2020-10-28 13:42:20 +08:00
Ju4tCode
47f491039c 💡 update regex docstring 2020-10-28 13:23:48 +08:00
yanyongyu
dc5c35a9ed 💡 update command docstrinrg 2020-10-28 13:17:41 +08:00
yanyongyu
c636186321 👷 update api doc action 2020-10-28 13:05:51 +08:00
Ju4tCode
aafc3dd060 🔀 Merge pull request #38 2020-10-28 12:52:27 +08:00
ayayaneru
38469611a4 Update README 2020-10-28 10:01:33 +08:00
rkroom
59a8bd8c97 add matched_string when rule regex
当使用正则匹配消息成功时,向state添加matched_string以保存匹配到的内容供接下来使用。
2020-10-26 17:18:26 +08:00
Ju4tCode
50cfd3c9b5 🔀 Merge pull request #36
Issue35:修改鉴权限制
2020-10-25 14:48:00 +08:00
yanyongyu
5d08d53c27 👽 update auth header 2020-10-25 14:42:46 +08:00
Ju4tCode
4f6f99146c 🔀 Merge pull request #33
修改 Command 实现逻辑
2020-10-22 22:36:23 +08:00
yanyongyu
32388d070d 🎨 improve command implementation 2020-10-22 22:08:19 +08:00
yanyongyu
d9f8bf38c6 🐛 fix matcher group send 2020-10-22 00:00:29 +08:00
yanyongyu
4e2b74af75 🚧 add plugin store page 2020-10-21 00:55:23 +08:00
yanyongyu
c2c28cebf5 👽 update nonebot theme 2020-10-21 00:54:09 +08:00
yanyongyu
24141b1a4b 🎨 remove shebang line #31 2020-10-20 22:40:16 +08:00
Ju4tCode
c85e50d73d 👷 Add release draft config 2020-10-20 17:28:51 +08:00
Ju4tCode
444156766a 👷 Update release drafter 2020-10-20 17:27:41 +08:00
yanyongyu
308824d0b1 🐛 fix matcher group args parser 2020-10-20 00:01:26 +08:00
yanyongyu
c3ed962837 add site cache to improve performance #29 2020-10-19 17:49:04 +08:00
Ju4tCode
2c13303d89 👷 Update issue templates 2020-10-19 00:00:11 +08:00
Ju4tCode
1304b94b61 🔀 Merge pull request #28
Update vuepress theme
2020-10-18 03:05:42 -05:00
yanyongyu
8ca677c271 👽 fix home link 2020-10-18 15:34:14 +08:00
yanyongyu
7c17412106 💡 add plugin docstring 2020-10-18 15:04:45 +08:00
yanyongyu
26207f762b 🏷️ fix class inherit in pyi 2020-10-18 15:02:56 +08:00
yanyongyu
8db70dbb0c 👽 fix theme smooth scroll 2020-10-18 02:30:01 +08:00
yanyongyu
1b6924a104 👽 update lock file 2020-10-18 02:04:32 +08:00
yanyongyu
c5a30a8a79 use custom theme 2020-10-18 01:39:34 +08:00
yanyongyu
56c9c24dc6 add kwargs support for matcher send/finish/pause/reject 2020-10-17 19:50:25 +08:00
yanyongyu
9ad629841b 📝 add uninstall nonebot 1.x tip 2020-10-16 17:15:40 +08:00
yanyongyu
78433bdae9 🚑 restore markdown 2020-10-16 16:08:51 +08:00
yanyongyu
5f44212faa 🚑 restore div 2020-10-16 16:07:04 +08:00
yanyongyu
df517b6b36 📝 use p instead of div 2020-10-16 16:03:49 +08:00
yanyongyu
6afe9b6f4f 📝 Update Readme (fix #27) 2020-10-16 15:59:34 +08:00
yanyongyu
1d79ac232f 🐛 fix missing param for on event 2020-10-16 15:12:15 +08:00
yanyongyu
0a64959973 💡 add driver docstring 2020-10-16 01:10:46 +08:00
yanyongyu
1e4b058681 👽 update repo link 2020-10-11 14:51:37 +08:00
yanyongyu
3c5d06a2de 📝 add todo tag 2020-10-11 13:49:58 +08:00
Ju4tCode
1ee7c792e8 🔀 Merge pull request #26
Pre Release 2.0.0a3
2020-10-11 13:46:01 +08:00
yanyongyu
39a950ea80 📌 update lock file 2020-10-11 13:39:45 +08:00
yanyongyu
5bb41395d8 🔖 Pre Release 2.0.0a3 2020-10-11 13:19:20 +08:00
yanyongyu
a68ba09910 📝 Update docs 2020-10-11 13:17:40 +08:00
yanyongyu
b4e0034876 💡 add driver docstring 2020-10-10 23:40:01 +08:00
yanyongyu
e58174f6ec 📝 remove outdated docs 2020-10-09 20:26:39 +08:00
yanyongyu
1377f7337d 🚑 fix message segment setitem 2020-10-09 00:57:30 +08:00
yanyongyu
96ce29fd52 add optional dependence nonebot-test 2020-10-09 00:48:50 +08:00
yanyongyu
f164d85c5c 🐛 fix message segment getitem 2020-10-09 00:10:50 +08:00
yanyongyu
ce758a2231 📝 add nonebot quick import doc 2020-10-08 21:36:57 +08:00
yanyongyu
05c3a4b84f 💡 fix nickname docstring 2020-10-08 21:36:32 +08:00
yanyongyu
1d31e646ad 🔇 reduce log for meta event #21 2020-10-08 21:25:13 +08:00
yanyongyu
927a963d4f 🐛 fix nickname 2020-10-06 22:29:05 +08:00
yanyongyu
727eef9a34 💡 add matcher docstring 2020-10-06 17:03:05 +08:00
yanyongyu
9f8d009309 add matcher.send method 2020-10-06 16:24:04 +08:00
yanyongyu
734d3cd333 💡 update docstring for several modules 2020-10-06 02:08:48 +08:00
yanyongyu
2e989b5fe1 💡 add matcher docstring 2020-10-05 23:10:20 +08:00
yanyongyu
781d0cf654 ⚗️ rewrite echo and say builtin plugin 2020-10-04 18:10:01 +08:00
yanyongyu
0a11bd3e8e ✏️ fix cqhttp sub_type typo 2020-10-04 16:27:58 +08:00
yanyongyu
2574ef3e7a 💡 add message docstring 2020-10-03 18:18:43 +08:00
Ju4tCode
b80f0bf202 🔀 Merge pull request #19 2020-10-03 15:06:46 +08:00
yanyongyu
c7f1859d99 🐛 fix white space before plain text #18 2020-10-03 14:56:38 +08:00
yanyongyu
d71260ed68 🐛 fix group attrs 2020-10-02 00:28:53 +08:00
yanyongyu
3e4dc1a123 💡 add adapter docstring 2020-10-01 23:52:56 +08:00
Ju4tCode
a308f4d4ee 🔀 Merge pull request #16 from nonebot/dev
Pre Release 2.0.0a2
2020-10-01 01:31:40 +08:00
yanyongyu
1aac3d562d ⬆️ update poetry.lock file 2020-10-01 01:24:16 +08:00
Ju4tCode
5b9e86275a Merge branch 'master' into dev 2020-10-01 01:09:17 +08:00
yanyongyu
1016986663 🔖 Pre Release 2.0.0a2 2020-10-01 00:55:03 +08:00
yanyongyu
ef29280585 💡 add escape_tag docstring 2020-10-01 00:39:44 +08:00
yanyongyu
5b0083c0a8 👷 add ci for dev branch 2020-09-30 19:12:44 +08:00
Ju4tCode
d823b1733b 🔀 Merge pull request #15
fix #14 logger escape
2020-09-30 18:08:03 +08:00
yanyongyu
921acff09e 🐛 fix logger escape tag #14 2020-09-30 18:01:31 +08:00
yanyongyu
edc3aadbb5 💡 add cqhttp event 2020-09-29 23:10:29 +08:00
yanyongyu
f3986ace51 💡 add cqhttp docstring 2020-09-29 22:33:08 +08:00
yanyongyu
0eafedefa1 🏷️ update cqhttp.pyi 2020-09-29 22:32:15 +08:00
Ju4tCode
73e6062a1b 👷 update api docs ci 2020-09-29 22:29:51 +08:00
yanyongyu
00f22e5f05 🏷️ update pyi files 2020-09-28 12:45:55 +08:00
yanyongyu
35ed536cdf 📝 generate docs 2020-09-28 00:12:11 +08:00
yanyongyu
e13561c374 🏷️ add typing for plugin 2020-09-28 00:09:12 +08:00
yanyongyu
2921ba0120 add command alias/group test 2020-09-27 23:52:03 +08:00
yanyongyu
4e4d494ffd 📝 update README 2020-09-27 23:22:33 +08:00
Ju4tCode
b955024818 👷 update api docs ci 2020-09-27 19:19:28 +08:00
Ju4tCode
1952d93324 🔀 (Close #11)Merge pull request #13 2020-09-27 18:29:52 +08:00
yanyongyu
e0cba7c20c 🎨 add command group to entry file 2020-09-27 18:20:39 +08:00
yanyongyu
2042097f83 🎨 change args into optional 2020-09-27 18:05:13 +08:00
yanyongyu
3dc95b904f ⚗️ add command alias and group #11 2020-09-27 17:55:28 +08:00
yanyongyu
ecbe465232 ⚗️ add matcher group #11 2020-09-27 13:34:16 +08:00
yanyongyu
2e87c40434 🐛 fix error ws closing 2020-09-27 12:37:15 +08:00
yanyongyu
3467eb3c29 🚑 (Close #12)fix matcher key parser 2020-09-26 17:36:04 +08:00
yanyongyu
457fdfb057 🏷️ update cqhttp pyi 2020-09-26 16:33:57 +08:00
yanyongyu
44fef77288 🚑 fix matcher key parser 2020-09-26 16:33:30 +08:00
yanyongyu
bbeea86fd5 🏷️ update pyi 2020-09-26 14:40:08 +08:00
yanyongyu
8bd1aa0662 ✏️ fix regex typo 2020-09-26 13:04:18 +08:00
yanyongyu
8b09c0be35 💄 update messenger style 2020-09-25 01:00:28 +08:00
yanyongyu
dee86ae607 👽 update dependence due to cli published 2020-09-24 16:17:31 +08:00
Ju4tCode
f8231ec7e9 🔀 Merge pull request #10 from nonebot/dev 2020-09-24 00:37:21 +08:00
Ju4tCode
3bd9a9cc73 Update api_docs.yml 2020-09-24 00:30:50 +08:00
Ju4tCode
9171894a15 👷 update api docs ci 2020-09-24 00:22:35 +08:00
Ju4tCode
1d7180e6cd 👷 update api docs ci 2020-09-24 00:04:43 +08:00
Ju4tCode
1045e6a797 👷 update api docs ci 2020-09-23 23:42:06 +08:00
Ju4tCode
68795c36f2 👷 update api docs ci 2020-09-23 23:36:06 +08:00
Ju4tCode
2319ab7d20 👷 update api docs ci 2020-09-23 23:32:34 +08:00
Ju4tCode
541dce6c54 Update api_docs.yml 2020-09-23 23:14:03 +08:00
Ju4tCode
4306d12f83 👷 add api docs ci 2020-09-13 22:32:55 +08:00
Ju4tCode
b4d7fded7f 🔀 Merge pull request #9 from nonebot/dev 2020-09-08 17:01:15 +08:00
Ju4tCode
0a8a53a764 🔀 Merge pull request #8 from nonebot/dev 2020-08-30 22:21:14 +08:00
CodeCreator
2089c773ac 🔀 Merge pull request #6 from nonebot/dev
update cqhttp apis
2020-08-26 17:57:23 +08:00
CodeCreator
310aeb8447 Merge pull request #5 from nonebot/dev 2020-08-26 14:52:34 +08:00
196 changed files with 21296 additions and 3532 deletions

2
.github/FUNDING.yml vendored Normal file
View File

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

33
.github/ISSUE_TEMPLATE/bug-report.md vendored Normal file
View File

@@ -0,0 +1,33 @@
---
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]
**截图**
If applicable, add screenshots to help explain your problem.

View File

@@ -0,0 +1,16 @@
---
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,36 @@
---
name: Plugin Publish
about: Publish your plugin to nonebot homepage and nb-cli
title: "Plugin: blabla 的插件"
labels: Plugin
assignees: ""
---
**你的插件名称:**
例:复读机
**简短描述插件功能:**
例:复读群友的消息
**插件 import 使用的名称**
nonebot_plugin_example
**插件 install 使用的名称**
例 1nonebot-plugin-example
通过 pypi 安装
> 请事先发布插件到[pypi](https://pypi.org/)
例 2git+https://github.com/nonebot/nonebot-plugin-example
从 github 仓库安装
**插件项目仓库/主页链接**
nonebot/nonebot2默认 github )或其他链接

38
.github/release-drafter.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '💥 Breaking Changes'
labels:
- 'Breaking'
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🍻 Plugin Publish'
label: 'Plugin'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Documentation
See: https://v2.nonebot.dev
## 💫 Changes
$CHANGES

37
.github/workflows/build_docs.yml vendored Normal file
View File

@@ -0,0 +1,37 @@
name: Build API Doc
on:
pull_request:
types: [ opened, synchronize, reopened ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
architecture: "x64"
- name: Install Dependences
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Build Doc
run: poetry run sphinx-build -M markdown ./docs_build ./build
- name: Copy Files
run: cp -r ./build/markdown/* ./docs/api/
- uses: actions/upload-artifact@v2
with:
name: docs
path: docs/

View File

@@ -0,0 +1,40 @@
name: Release Nonebot Plugin Docs
on:
release:
types: [ published ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '12'
- run: npm ci
- name: Build Docs
env:
VUEPRESS_BASE: '/docs/'
run: npx vuepress build docs --dest packages/nonebot-plugin-docs/nonebot_plugin_docs/dist
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
architecture: "x64"
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Publish Package
run: |
export NONEBOT_VERSION=`poetry version -s`
cd packages/nonebot-plugin-docs/
poetry version $NONEBOT_VERSION
poetry build
poetry publish -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.PYPI_PASSWORD}}

25
.github/workflows/plugin_issue.yml vendored Normal file
View File

@@ -0,0 +1,25 @@
name: 'Plugin Issue Bot'
on:
push:
branches:
- master
issues:
types: [opened, reopened, edited]
pull_request:
types: [closed]
jobs:
issue_bot:
runs-on: ubuntu-latest
name: plugin issue bot
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: NoneBot2 Plugin Issue Bot
uses: he0119/nonebot2-plugin-issue-bot@v0.2
with:
token: ${{ secrets.GH_TOKEN }}
base: master
path: docs/.vuepress/public/plugins.json

14
.github/workflows/release-draft.yml vendored Normal file
View File

@@ -0,0 +1,14 @@
name: Release Drafter
on:
push:
branches:
- master
jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

35
.github/workflows/upload_docs.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Upload API Doc
on:
workflow_run:
workflows: ["Build API Doc"]
types:
- completed
jobs:
upload:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_run.head_sha }}
token: ${{ secrets.GH_TOKEN }}
- uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: docs
path: docs/
- env:
REF: ${{ github.event.workflow_run.head_branch }}
PR_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
PR_USER: ${{ github.event.workflow_run.head_repository.owner.login }}
run: |
git config user.name $PR_USER
git config user.email $PR_USER@users.noreply.github.com
git add .
git diff-index --quiet HEAD || git commit -m ":memo: update api docs"
git remote add target https://github.com/$PR_REPO.git
git push target HEAD:$REF

1
.prettierignore Normal file
View File

@@ -0,0 +1 @@
.github/**/*.md

View File

@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2018 Richard Chien
Copyright (c) 2020 NoneBot Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@@ -16,4 +16,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

100
README.md
View File

@@ -1,36 +1,100 @@
<div align=center>
<img src="docs/.vuepress/public/logo.png" width="200" height="200">
<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>
</p>
<div align="center">
# NoneBot
[![License](https://img.shields.io/github/license/richardchien/nonebot.svg)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/nonebot.svg)](https://pypi.python.org/pypi/nonebot)
![Python Version](https://img.shields.io/badge/python-3.7+-blue.svg)
![CQHTTP Version](https://img.shields.io/badge/cqhttp-11+-black.svg)
[![QQ 群](https://img.shields.io/badge/qq%E7%BE%A4-768887710-orange.svg)](https://jq.qq.com/?_wv=1027&k=5OFifDh)
[![Telegram](https://img.shields.io/badge/telegram-chat-blue.svg)](https://t.me/cqhttp)
[![QQ 版本发布群](https://img.shields.io/badge/%E7%89%88%E6%9C%AC%E5%8F%91%E5%B8%83%E7%BE%A4-218529254-green.svg)](https://jq.qq.com/?_wv=1027&k=5Nl0zhE)
[![Telegram 版本发布频道](https://img.shields.io/badge/%E7%89%88%E6%9C%AC%E5%8F%91%E5%B8%83%E9%A2%91%E9%81%93-join-green.svg)](https://t.me/cqhttp_release)
_✨ Python 异步机器人框架 ✨_
</div>
<p align="center">
<a href="https://raw.githubusercontent.com/nonebot/nonebot2/master/LICENSE">
<img src="https://img.shields.io/github/license/nonebot/nonebot2.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot2">
<img src="https://img.shields.io/pypi/v/nonebot2.svg" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.7+-blue.svg" alt="python">
<img src="https://img.shields.io/badge/cqhttp-11+-black.svg" alt="cqhttp"><br />
<a href="https://jq.qq.com/?_wv=1027&k=5OFifDh">
<img src="https://img.shields.io/badge/qq%E7%BE%A4-768887710-orange.svg" alt="QQ Chat">
</a>
<a href="https://t.me/cqhttp">
<img src="https://img.shields.io/badge/telegram-chat-blue.svg" alt="Telegram Chat">
</a>
<a href="https://jq.qq.com/?_wv=1027&k=5Nl0zhE">
<img src="https://img.shields.io/badge/%E7%89%88%E6%9C%AC%E5%8F%91%E5%B8%83%E7%BE%A4-218529254-green.svg" alt="QQ Release">
</a>
<a href="https://t.me/cqhttp_release">
<img src="https://img.shields.io/badge/版本发布频道-join-green.svg" alt="Telegram Release">
</a>
</p>
<p align="center">
<a href="https://v2.nonebot.dev/">文档</a>
·
<a href="https://v2.nonebot.dev/guide/installation.html">安装</a>
·
<a href="https://v2.nonebot.dev/guide/getting-started.html">开始使用</a>
·
<a href="#插件">文档打不开?</a>
</p>
## 简介
**NoneBot2 尚在开发中**
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能
除了起到解析事件的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求
除了起到解析消息的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理器,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求
得益于 Python 的 [asyncio](https://docs.python.org/3/library/asyncio.html) 机制NoneBot 处理事件的吞吐量有了很大的保障,再配合 WebSocket 通信方式也是最建议的通信方式NoneBot 的性能可以达到 HTTP 通信方式的两倍以上,相较于传统同步 I/O 的 HTTP 通信,更是有质的飞跃
目前 NoneBot2 在 [FastAPI](https://fastapi.tiangolo.com/) 的基础上封装了与 [CQHTTP(OneBot) 协议](http://cqhttp.cc/)插件的网络交互。
## 特色
得益于 Python 的 [asyncio](https://docs.python.org/3/library/asyncio.html) 机制NoneBot 处理消息的吞吐量有了很大的保障,再配合 WebSocket 通信方式也是最建议的通信方式NoneBot 的性能可以达到 HTTP 通信方式的两倍以上,相较于传统同步 I/O 的 HTTP 通信,更是有质的飞跃。
NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义**,并且可以作为插件进行**替换/添加**
需要注意的是NoneBot 仅支持 Python 3.7+ 及 CQHTTP(OneBot) 插件 v11+。
目前 NoneBot2 内置的驱动框架:
## 文档
- [FastAPI](https://fastapi.tiangolo.com/)
文档目前尚未完成「API」部分由 sphinx 自动生成,你可以在 [这里](https://v2.nonebot.dev/) 查看。
目前 NoneBot2 内置的协议适配:
- [CQHTTP(OneBot) 协议](https://github.com/howmanybots/onebot/blob/master/README.md)
- [钉钉](https://ding-doc.dingtalk.com/doc#/serverapi2/krgddi) _开发中_
- [Telegram](https://core.telegram.org/bots/api) _计划中_
## 即刻开始
~~完整~~文档可以在 [这里](https://v2.nonebot.dev/) 查看。
懒得看文档?下面是快速安装指南:~~这是坏文明~~
1. (可选)使用你喜欢的 Python 环境管理工具创建新的虚拟环境。
2. 使用 `pip` (或其他) 安装 NoneBot 脚手架。
```bash
pip install nb-cli
```
3. 使用脚手架创建项目
```bash
nb create
```
## 插件
此外NoneBot2 还有丰富的官方以及第三方现成的插件供大家使用:
- [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs):离线文档至本地使用(别再说文档打不开了!)
```bash
nb plugin install nonebot_plugin_docs
```
- 其他插件请查看 [插件商店](https://v2.nonebot.dev/plugin-store.html)
## 贡献

View File

@@ -1,122 +0,0 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.rule 模块
## 规则
每个 `Matcher` 拥有一个 `Rule` ,其中是 **异步** `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
:::tip 提示
`RuleChecker` 既可以是 async function 也可以是 sync function
:::
## _class_ `Rule`
基类:`object`
* **说明**
`Matcher` 规则类,当事件传递时,在 `Matcher` 运行前进行检查。
* **示例**
```python
Rule(async_function) & sync_function
# 等价于
from nonebot.utils import run_sync
Rule(async_function, run_sync(sync_function))
```
### `__init__(*checkers)`
* **参数**
* `*checkers: Callable[[Bot, Event, dict], Awaitable[bool]]`: **异步** RuleChecker
### `checkers`
* **说明**
存储 `RuleChecker`
* **类型**
* `Set[Callable[[Bot, Event, dict], Awaitable[bool]]]`
### _async_ `__call__(bot, event, state)`
* **说明**
检查是否符合所有规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
* **返回**
* `bool`
## `startswith(msg)`
* **说明**
匹配消息开头
* **参数**
* `msg: str`: 消息开头字符串
## `endswith(msg)`
* **说明**
匹配消息结尾
* **参数**
* `msg: str`: 消息结尾字符串

View File

@@ -1,290 +0,0 @@
# 编写插件
本章将以一个天气查询插件为例,教学如何编写自己的命令。
## 加载插件
在 [创建一个完整的项目](creating-a-project) 一章节中,我们已经创建了插件目录 `awesome_bot/plugins`,现在我们在机器人入口文件中加载它。当然,你也可以单独加载一个插件。
:::tip 提示
加载插件目录时,目录下以 `_` 下划线开头的插件将不会被加载!
:::
`bot.py` 文件中添加以下行:
```python{5,7}
import nonebot
nonebot.init()
# 加载单独的一个插件参数为合法的python包名
nonebot.load_plugin("nonebot.plugins.base")
# 加载插件目录,该目录下为各插件,以下划线开头的插件将不会被加载
nonebot.load_plugins("awesome_bot/plugins")
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
尝试运行 `nb run` 或者 `python bot.py`,可以看到日志输出了类似如下内容:
```plain
09-19 21:51:59 [INFO] nonebot | Succeeded to import "nonebot.plugins.base"
09-19 21:51:59 [INFO] nonebot | Succeeded to import "plugin_in_folder"
```
## 创建插件
现在我们已经有了一个空的插件目录,我们可以开始创建插件了!插件有两种形式
### 单文件形式
在插件目录下创建名为 `weather.py` 的 Python 文件,暂时留空,此时目录结构如下:
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── awesome_bot
│ └── plugins
│ └── `weather.py`
├── .env
├── .env.dev
├── .env.prod
├── .gitignore
├── bot.py
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
:::
<!-- prettier-ignore-end -->
这个时候它已经可以被称为一个插件了,尽管它还什么都没做。
### 包形式
在插件目录下创建文件夹 `weather`,并在该文件夹下创建文件 `__init__.py`,此时目录结构如下:
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── awesome_bot
│ └── plugins
│ └── `weather`
│ └── `__init__.py`
├── .env
├── .env.dev
├── .env.prod
├── .gitignore
├── bot.py
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
:::
<!-- prettier-ignore-end -->
这个时候 `weather` 就是一个合法的 Python 包了,同时也是合法的 NoneBot 插件,插件内容可以在 `__init__.py` 中编写。
## 编写真正的内容
好了,现在插件已经可以正确加载,我们可以开始编写命令的实际代码了。在 `weather.py` 中添加如下代码:
```python
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event
weather = on_command("天气", rule=to_me(), priority=5)
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: dict):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
city_weather = await get_weather(city)
await weather.finish(city_weather)
async def get_weather(city: str):
return f"{city}的天气是..."
```
为了简单起见,我们在这里的例子中没有接入真实的天气数据,但要接入也非常简单,你可以使用中国天气网、和风天气等网站提供的 API。
下面我们来说明这段代码是如何工作的。
:::tip 提示
从这里开始,你需要对 Python 的 asyncio 编程有所了解,因为 NoneBot 是完全基于 asyncio 的,具体可以参考 [廖雪峰的 Python 教程](https://www.liaoxuefeng.com/wiki/1016959663602400/1017959540289152)
:::
### 注册一个 [事件响应器](../api/matcher.md)
```python{4}
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.permission import Permission
weather = on_command("天气", rule=to_me(), permission=Permission(), priority=5)
```
在上方代码中,我们注册了一个事件响应器 `Matcher`,它由几个部分组成:
1. `on_command` 注册一个消息类型的命令处理器
2. `"天气"` 指定 command 参数 - 命令名
3. `rule` 补充事件响应器的匹配规则
4. `priority` 事件响应器优先级
5. `block` 是否阻止事件传递
其他详细配置可以参考 API 文档,下面我们详细说明各个部分:
#### 事件响应器类型 type
事件响应器类型其实就是对应 `Event.type` NoneBot 提供了一个基础类型事件响应器 `on()` 以及一些内置的事件响应器。
- `on("事件类型")`: 基础事件响应器,第一个参数为事件类型,空字符串表示不限
- `on_metaevent()` ~ `on("meta_event")`: 元事件响应器
- `on_message()` ~ `on("message")`: 消息事件响应器
- `on_request()` ~ `on("request")`: 请求事件响应器
- `on_notice()` ~ `on("notice")`: 通知事件响应器
- `on_startswith(str)` ~ `on("message", startswith(str))`: 消息开头匹配处理器
- `on_endswith(str)` ~ `on("message", endswith(str))`: 消息结尾匹配处理器
- `on_command(str|tuple)` ~ `on("message", command(str|tuple))`: 命令处理器
- `on_regax(pattern_str)` ~ `on("message", regax(pattern_str))`: 正则匹配处理器
#### 匹配规则 rule
事件响应器的匹配规则即 `Rule`,由非负个 `RuleChecker` 组成,当所有 `RuleChecker` 返回 `True` 时匹配成功。这些 `RuleChecker` 的形式如下:
```python
async def check(bot: Bot, event: Event, state: dict) -> bool:
return True
def check(bot: Bot, event: Event, state: dict) -> bool:
return True
```
`Rule` 和 `RuleChecker` 之间可以使用 `&` 互相组合:
```python
from nonebot.rule import Rule
Rule(async_checker1) & sync_checker & async_checker2
```
:::danger 警告
`Rule(*checkers)` 只接受 async function或使用 `nonebot.utils.run_sync` 自行包裹 sync function。在使用 `&` 时NoneBot 会自动包裹 sync function
:::
#### 优先级 priority
事件响应器的优先级代表事件响应器的执行顺序,同一优先级的事件响应器会 **同时执行!**
:::tip 提示
使用 `nonebot-test` 可以看到当前所有事件响应器的执行流程,有助理解事件响应流程!
```bash
pip install nonebot2[test]
```
:::
#### 阻断 block
当有任意事件响应器发出了阻止事件传递信号时,该事件将不再会传递给下一优先级,直接结束处理。
NoneBot 内置的事件响应器中,所有 `message` 类的事件响应器默认会阻断事件传递,其他则不会。
### 编写事件处理函数 [Handler](../api/typing.md#handler)
```python{1,2,8,9}
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: dict):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
city_weather = await get_weather(city)
await weather.finish(city_weather)
```
在上面的代码中,我们给 `weather` 事件响应器添加了两个事件处理函数:`handle_first_receive`, `handle_city`
其中有几个要点,我们一一解释:
#### 添加一个事件处理函数
在事件响应器响应事件时,事件处理函数会依次顺序执行,也就是说,与添加顺序一致。
我们可以使用 `@matcher.handle()` 装饰器来简单地为该事件响应器添加一个处理函数。
同时NoneBot 内置了几种添加事件处理函数方式以方便处理:
- `@matcher.receive()`: 指示 NoneBot 接收一条新的用户消息以继续执行后续处理函数。
- `@matcher.got(key, [prompt="请输入key"], [args_parser=function])`: 指示 NoneBot 当 `state` 中不存在 `key` 时向用户发送 `prompt` 等待用户回复并赋值给 `state[key]`
这些装饰器可以套娃使用!例如:
```python
@matcher.got("key1")
@matcher.got("key2")
async def handle(bot: Bot, event: Event, state: dict):
pass
```
#### 事件处理函数参数
事件处理函数类型为 `Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]` 。
参数分别为:
1. [nonebot.typing.Bot](../api/typing.md#bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
2. [nonebot.typing.Event](../api/typing.md#event): 即上报事件对象,可以获取到上报的所有信息。
3. `state`: 状态字典,可以存储任意的信息
#### 处理事件
在事件处理函数中,我们只需要对 `event` 做出相应的处理,存入状态字典 `state` 中,或者向用户发送消息、调用某个机器人 API 等等。
在 NoneBot 中,提供了几种特殊的处理函数:
##### `@matcher.args_parser`
这是一个装饰器,装饰一个函数来使它成为参数的默认解析函数,当使用 `matcher.got(xxx, [args_parser])` 获取到一条消息时,会运行 `matcher.got` 的 `args_parser` ,如果不存在则运行 `@matcher.args_parser`。
##### `matcher.pause`
这个函数用于结束当前事件处理函数,强制接收一条新的消息再运行**下一个消息处理函数**。
##### `matcher.reject`
这个函数用于结束当前事件处理函数,强制接收一条新的消息再**再次运行当前消息处理函数**。
##### `matcher.finish`
这个函数用于直接结束当前事件处理。
以上三个函数都拥有一个参数 `prompt`,用于向用户发送一条消息。
## 结语
至此,相信你已经能够写出一个基础的插件了,更多的用法将会在 进阶 部分进行介绍,这里给出几个小提示:
- 请千万注意事件处理器的优先级设定
- 在匹配规则中请勿使用耗时极长的函数
- 同一个用户可以跨群(私聊)继续他的事件处理(除非做出权限限制,将在后续介绍)

View File

@@ -3,7 +3,7 @@ home: true
heroImage: /logo.png
tagline: An asynchronous QQ bot framework.
actionText: 开始使用
actionLink: /guide/
actionLink: guide/
features:
- title: 简洁
details: 提供极其简洁易懂的 API使你可以毫无压力地开始验证你的绝佳创意只需编写最少量的代码即可实现丰富的功能。

View File

@@ -0,0 +1,7 @@
# 深入
## 它如何工作?
<!-- TODO: how to work -->
~~未填坑~~

View File

@@ -0,0 +1 @@
# 权限控制

View File

@@ -0,0 +1 @@
# 运行时插槽

View File

@@ -0,0 +1 @@
# 定时任务

View File

@@ -7,16 +7,16 @@
* [nonebot](nonebot.html)
* [nonebot.typing](typing.html)
* [nonebot.config](config.html)
* [nonebot.sched](sched.html)
* [nonebot.plugin](plugin.html)
* [nonebot.log](log.html)
* [nonebot.message](message.html)
* [nonebot.matcher](matcher.html)
* [nonebot.rule](rule.html)
@@ -25,7 +25,28 @@
* [nonebot.permission](permission.html)
* [nonebot.sched](sched.html)
* [nonebot.log](log.html)
* [nonebot.utils](utils.html)
* [nonebot.typing](typing.html)
* [nonebot.exception](exception.html)
* [nonebot.drivers](drivers/)
* [nonebot.drivers.fastapi](drivers/fastapi.html)
* [nonebot.adapters](adapters/)
* [nonebot.adapters.cqhttp](adapters/cqhttp.html)

View File

@@ -0,0 +1,362 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters 模块
## 协议适配基类
各协议请继承以下基类,并使用 `driver.register_adapter` 注册适配器
## _class_ `BaseBot`
基类:`abc.ABC`
Bot 基类。用于处理上报消息,并提供 API 调用接口。
### _abstract_ `__init__(driver, connection_type, config, self_id, *, websocket=None)`
* **参数**
* `driver: Driver`: Driver 对象
* `connection_type: str`: http 或者 websocket
* `config: Config`: Config 对象
* `self_id: str`: 机器人 ID
* `websocket: Optional[WebSocket]`: Websocket 连接对象
### `driver`
Driver 对象
### `connection_type`
连接类型
### `config`
Config 配置对象
### `self_id`
机器人 ID
### `websocket`
Websocket 连接对象
### _abstract property_ `type`
Adapter 类型
### _abstract async classmethod_ `check_permission(driver, connection_type, headers, body)`
* **说明**
检查连接请求是否合法的函数,如果合法则返回当前连接 `唯一标识符`,通常为机器人 ID如果不合法则抛出 `RequestDenied` 异常。
* **参数**
* `driver: Driver`: Driver 对象
* `connection_type: str`: 连接类型
* `headers: dict`: 请求头
* `body: Optional[dict]`: 请求数据WebSocket 连接该部分为空
* **返回**
* `str`: 连接唯一标识符
* **异常**
* `RequestDenied`: 请求非法
### _abstract async_ `handle_message(message)`
* **说明**
处理上报消息的函数,转换为 `Event` 事件后调用 `nonebot.message.handle_event` 进一步处理事件。
* **参数**
* `message: dict`: 收到的上报消息
### _abstract async_ `call_api(api, **data)`
* **说明**
调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
* **参数**
* `api: str`: API 名称
* `**data`: API 数据
* **示例**
```python
await bot.call_api("send_msg", message="hello world"})
await bot.send_msg(message="hello world")
```
### _abstract async_ `send(event, message, **kwargs)`
* **说明**
调用机器人基础发送消息接口
* **参数**
* `event: Event`: 上报事件
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `**kwargs`
## _class_ `BaseEvent`
基类:`abc.ABC`
Event 基类。提供上报信息的关键信息,其余信息可从原始上报消息获取。
### `__init__(raw_event)`
* **参数**
* `raw_event: dict`: 原始上报消息
### _property_ `raw_event`
原始上报消息
### _abstract property_ `id`
事件 ID
### _abstract property_ `name`
事件名称
### _abstract property_ `self_id`
机器人 ID
### _abstract property_ `time`
事件发生时间
### _abstract property_ `type`
事件主类型
### _abstract property_ `detail_type`
事件详细类型
### _abstract property_ `sub_type`
事件子类型
### _abstract property_ `user_id`
触发事件的主体 ID
### _abstract property_ `group_id`
触发事件的主体群 ID
### _abstract property_ `to_me`
事件是否为发送给机器人的消息
### _abstract property_ `message`
消息内容
### _abstract property_ `reply`
回复的消息
### _abstract property_ `raw_message`
原始消息
### _abstract property_ `plain_text`
纯文本消息
### _abstract property_ `sender`
消息发送者信息
## _class_ `BaseMessageSegment`
基类:`abc.ABC`
消息段基类
### `type`
* 类型: `str`
* 说明: 消息段类型
### `data`
* 类型: `Dict[str, Union[str, list]]`
* 说明: 消息段数据
## _class_ `BaseMessage`
基类:`list`, `abc.ABC`
消息数组
### `__init__(message=None, *args, **kwargs)`
* **参数**
* `message: Union[str, dict, list, MessageSegment, Message]`: 消息内容
### `append(obj)`
* **说明**
添加一个消息段到消息数组末尾
* **参数**
* `obj: Union[str, MessageSegment]`: 要添加的消息段
### `extend(obj)`
* **说明**
拼接一个消息数组或多个消息段到消息数组末尾
* **参数**
* `obj: Union[Message, Iterable[MessageSegment]]`: 要添加的消息数组
### `reduce()`
* **说明**
缩减消息数组,即拼接相邻纯文本消息段
### `extract_plain_text()`
* **说明**
提取消息内纯文本消息

View File

@@ -0,0 +1,424 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.cqhttp 模块
## CQHTTP (OneBot) v11 协议适配
协议详情请看: [CQHTTP](http://cqhttp.cc/) | [OneBot](https://github.com/howmanybots/onebot)
## `log(level, message)`
* **说明**
用于打印 CQHTTP 日志。
* **参数**
* `level: str`: 日志等级
* `message: str`: 日志信息
## `escape(s, *, escape_comma=True)`
* **说明**
对字符串进行 CQ 码转义。
* **参数**
* `s: str`: 需要转义的字符串
* `escape_comma: bool`: 是否转义逗号(`,`)。
## `unescape(s)`
* **说明**
对字符串进行 CQ 码去转义。
* **参数**
* `s: str`: 需要转义的字符串
## `_b2s(b)`
转换布尔值为字符串。
## _async_ `_check_reply(bot, event)`
* **说明**
检查消息中存在的回复,去除并赋值 `event.reply`, `event.to_me`
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
## `_check_at_me(bot, event)`
* **说明**
检查消息开头或结尾是否存在 @机器人,去除并赋值 `event.to_me`
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
## `_check_nickname(bot, event)`
* **说明**
检查消息开头是否存在,去除并赋值 `event.to_me`
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
## `_handle_api_result(result)`
* **说明**
处理 API 请求返回值。
* **参数**
* `result: Optional[Dict[str, Any]]`: API 返回数据
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ActionFailed`: API 调用失败
## _class_ `Bot`
基类:[`nonebot.adapters.BaseBot`](README.md#nonebot.adapters.BaseBot)
CQHTTP 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
### _property_ `type`
* 返回: `"cqhttp"`
### _async classmethod_ `check_permission(driver, connection_type, headers, body)`
* **说明**
CQHTTP (OneBot) 协议鉴权。参考 [鉴权](https://github.com/howmanybots/onebot/blob/master/v11/specs/communication/authorization.md)
### _async_ `handle_message(message)`
* **说明**
调用 [_check_reply](#async-check-reply-bot-event), [_check_at_me](#check-at-me-bot-event), [_check_nickname](#check-nickname-bot-event) 处理事件并转换为 [Event](#class-event)
### _async_ `call_api(api, **data)`
* **说明**
调用 CQHTTP 协议 API
* **参数**
* `api: str`: API 名称
* `**data: Any`: API 参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
### _async_ `send(event, message, at_sender=False, **kwargs)`
* **说明**
根据 `event` 向触发事件的主体发送消息。
* **参数**
* `event: Event`: Event 对象
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `at_sender: bool`: 是否 @ 事件主体
* `**kwargs`: 覆盖默认参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ValueError`: 缺少 `user_id`, `group_id`
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
## _class_ `Event`
基类:[`nonebot.adapters.BaseEvent`](README.md#nonebot.adapters.BaseEvent)
CQHTTP 协议 Event 适配。继承属性参考 [BaseEvent](./#class-baseevent) 。
### _property_ `id`
* 类型: `Optional[int]`
* 说明: 事件/消息 ID
### _property_ `name`
* 类型: `str`
* 说明: 事件名称,由类型与 `.` 组合而成
### _property_ `self_id`
* 类型: `str`
* 说明: 机器人自身 ID
### _property_ `time`
* 类型: `int`
* 说明: 事件发生时间
### _property_ `type`
* 类型: `str`
* 说明: 事件类型
### _property_ `detail_type`
* 类型: `str`
* 说明: 事件详细类型
### _property_ `sub_type`
* 类型: `Optional[str]`
* 说明: 事件子类型
### _property_ `user_id`
* 类型: `Optional[int]`
* 说明: 事件主体 ID
### _property_ `group_id`
* 类型: `Optional[int]`
* 说明: 事件主体群 ID
### _property_ `to_me`
* 类型: `Optional[bool]`
* 说明: 消息是否与机器人相关
### _property_ `message`
* 类型: `Optional[Message]`
* 说明: 消息内容
### _property_ `reply`
* 类型: `Optional[dict]`
* 说明: 回复消息详情
### _property_ `raw_message`
* 类型: `Optional[str]`
* 说明: 原始消息
### _property_ `plain_text`
* 类型: `Optional[str]`
* 说明: 纯文本消息内容
### _property_ `sender`
* 类型: `Optional[dict]`
* 说明: 消息发送者信息
## _class_ `MessageSegment`
基类:[`nonebot.adapters.BaseMessageSegment`](README.md#nonebot.adapters.BaseMessageSegment)
CQHTTP 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
## _class_ `Message`
基类:[`nonebot.adapters.BaseMessage`](README.md#nonebot.adapters.BaseMessage)
CQHTTP 协议 Message 适配。

View File

@@ -194,10 +194,10 @@ SUPER_USERS=[12345789]
### `nickname`
* 类型: `Union[str, Set[str]]`
* 类型: `Set[str]`
* 默认值: `""`
* 默认值: `set()`
* 说明:

View File

@@ -0,0 +1,246 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers 模块
## 后端驱动适配基类
各驱动请继承以下基类
## _class_ `BaseDriver`
基类:`abc.ABC`
Driver 基类。将后端框架封装,以满足适配器使用。
### `_adapters`
* **类型**
`Dict[str, Type[Bot]]`
* **说明**
已注册的适配器列表
### _abstract_ `__init__(env, config)`
* **参数**
* `env: Env`: 包含环境信息的 Env 对象
* `config: Config`: 包含配置信息的 Config 对象
### `env`
* **类型**
`str`
* **说明**
环境名称
### `config`
* **类型**
`Config`
* **说明**
配置对象
### `_clients`
* **类型**
`Dict[str, Bot]`
* **说明**
已连接的 Bot
### _classmethod_ `register_adapter(name, adapter)`
* **说明**
注册一个协议适配器
* **参数**
* `name: str`: 适配器名称,用于在连接时进行识别
* `adapter: Type[Bot]`: 适配器 Class
### _abstract property_ `type`
驱动类型名称
### _abstract property_ `server_app`
驱动 APP 对象
### _abstract property_ `asgi`
驱动 ASGI 对象
### _abstract property_ `logger`
驱动专属 logger 日志记录器
### _property_ `bots`
* **类型**
`Dict[str, Bot]`
* **说明**
获取当前所有已连接的 Bot
### _abstract_ `on_startup(func)`
注册一个在驱动启动时运行的函数
### _abstract_ `on_shutdown(func)`
注册一个在驱动停止时运行的函数
### _abstract_ `run(host=None, port=None, *args, **kwargs)`
* **说明**
启动驱动框架
* **参数**
* `host: Optional[str]`: 驱动绑定 IP
* `post: Optional[int]`: 驱动绑定端口
* `*args`
* `**kwargs`
### _abstract async_ `_handle_http()`
用于处理 HTTP 类型请求的函数
### _abstract async_ `_handle_ws_reverse()`
用于处理 WebSocket 类型请求的函数
## _class_ `BaseWebSocket`
基类:`object`
WebSocket 连接封装,统一接口方便外部调用。
### _abstract_ `__init__(websocket)`
* **参数**
* `websocket: Any`: WebSocket 连接对象
### _property_ `websocket`
WebSocket 连接对象
### _abstract property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _abstract async_ `accept()`
接受 WebSocket 连接请求
### _abstract async_ `close(code)`
关闭 WebSocket 连接请求
### _abstract async_ `receive()`
接收一条 WebSocket 信息
### _abstract async_ `send(data)`
发送一条 WebSocket 信息

View File

@@ -0,0 +1,102 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.fastapi 模块
## FastAPI 驱动适配
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)
## _class_ `Driver`
基类:[`nonebot.drivers.BaseDriver`](README.md#nonebot.drivers.BaseDriver)
FastAPI 驱动框架
### _property_ `type`
驱动名称: `fastapi`
### _property_ `server_app`
`FastAPI APP` 对象
### _property_ `asgi`
`FastAPI APP` 对象
### _property_ `logger`
fastapi 使用的 logger
### `on_startup(func)`
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `on_shutdown(func)`
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 FastAPI
### _async_ `_handle_http(adapter, request, data=Body(Ellipsis))`
用于处理 HTTP 类型请求的函数
### _async_ `_handle_ws_reverse(adapter, websocket)`
用于处理 WebSocket 类型请求的函数
## _class_ `WebSocket`
基类:[`nonebot.drivers.BaseWebSocket`](README.md#nonebot.drivers.BaseWebSocket)
### _property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _async_ `accept()`
接受 WebSocket 连接请求
### _async_ `close(code=1000)`
关闭 WebSocket 连接请求
### _async_ `receive()`
接收一条 WebSocket 信息
### _async_ `send(data)`
发送一条 WebSocket 信息

View File

@@ -83,23 +83,6 @@ sidebarDepth: 0
## _exception_ `ExpiredException`
基类:`Exception`
* **说明**
指示 NoneBot 当前 `Matcher` 已失效。
* **用法**
`Matcher` 运行前检查时抛出。
## _exception_ `StopPropagation`
基类:`Exception`
@@ -117,6 +100,27 @@ sidebarDepth: 0
## _exception_ `RequestDenied`
基类:`Exception`
* **说明**
Bot 连接请求不合法。
* **参数**
* `status_code: int`: HTTP 状态码
* `reason: str`: 拒绝原因
## _exception_ `ApiNotAvailable`
基类:`Exception`
@@ -153,4 +157,4 @@ sidebarDepth: 0
* **参数**
* `retcode`: 错误代码
* `retcode: Optional[int]`: 错误代码

View File

@@ -0,0 +1,497 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.matcher 模块
## 事件响应器
该模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行 对话 。
## `matchers`
* **类型**
`Dict[int, List[Type[Matcher]]]`
* **说明**
用于存储当前所有的事件响应器
## _class_ `Matcher`
基类:`object`
事件响应器类
### `module`
* **类型**
`Optional[str]`
* **说明**
事件响应器所在模块名称
### `type`
* **类型**
`str`
* **说明**
事件响应器类型
### `rule`
* **类型**
`Rule`
* **说明**
事件响应器匹配规则
### `permission`
* **类型**
`Permission`
* **说明**
事件响应器触发权限
### `priority`
* **类型**
`int`
* **说明**
事件响应器优先级
### `block`
* **类型**
`bool`
* **说明**
事件响应器是否阻止事件传播
### `temp`
* **类型**
`bool`
* **说明**
事件响应器是否为临时
### `expire_time`
* **类型**
`Optional[datetime]`
* **说明**
事件响应器过期时间点
### `_default_state`
* **类型**
`dict`
* **说明**
事件响应器默认状态
### `_default_parser`
* **类型**
`Optional[ArgsParser]`
* **说明**
事件响应器默认参数解析函数
### `__init__()`
实例化 Matcher 以便运行
### `handlers`
* **类型**
`List[Handler]`
* **说明**
事件响应器拥有的事件处理函数列表
### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
* **说明**
创建一个新的事件响应器,并存储至 [matchers](#matchers)
* **参数**
* `type_: str`: 事件响应器类型,与 `event.type` 一致时触发,空字符串表示任意
* `rule: Optional[Rule]`: 匹配规则
* `permission: Optional[Permission]`: 权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器,即触发一次后删除
* `priority: int`: 响应优先级
* `block: bool`: 是否阻止事件向更低优先级的响应器传播
* `module: Optional[str]`: 事件响应器所在模块名称
* `default_state: Optional[dict]`: 默认状态 `state`
* `expire_time: Optional[datetime]`: 事件响应器最终有效时间点,过时即被删除
* **返回**
* `Type[Matcher]`: 新的事件响应器类
### _async classmethod_ `check_perm(bot, event)`
* **说明**
检查是否满足触发权限
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: 上报事件
* **返回**
* `bool`: 是否满足权限
### _async classmethod_ `check_rule(bot, event, state)`
* **说明**
检查是否满足匹配规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: 上报事件
* `state: dict`: 当前状态
* **返回**
* `bool`: 是否满足匹配规则
### _classmethod_ `args_parser(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认参数解析函数
* **参数**
* `func: ArgsParser`: 参数解析函数
### _classmethod_ `handle()`
* **说明**
装饰一个函数来向事件响应器直接添加一个处理函数
* **参数**
*
### _classmethod_ `receive()`
* **说明**
装饰一个函数来指示 NoneBot 在接收用户新的一条消息后继续运行该函数
* **参数**
*
### _classmethod_ `got(key, prompt=None, args_parser=None)`
* **说明**
装饰一个函数来指示 NoneBot 当要获取的 `key` 不存在时接收用户新的一条消息并经过 `ArgsParser` 处理后再运行该函数,如果 `key` 已存在则直接继续运行
* **参数**
* `key: str`: 参数名
* `prompt: Optional[Union[str, Message, MessageSegment]]`: 在参数不存在时向用户发送的消息
* `args_parser: Optional[ArgsParser]`: 可选参数解析函数,空则使用默认解析函数
### _async classmethod_ `send(message, **kwargs)`
* **说明**
发送一条消息给当前交互用户
* **参数**
* `message: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `finish(message=None, **kwargs)`
* **说明**
发送一条消息给当前交互用户并结束当前事件响应器
* **参数**
* `message: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `pause(prompt=None, **kwargs)`
* **说明**
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续下一个处理函数
* **参数**
* `prompt: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `reject(prompt=None, **kwargs)`
* **说明**
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后重新运行当前处理函数
* **参数**
* `prompt: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
## _class_ `MatcherGroup`
基类:`object`
事件响应器组合,统一管理。用法同 `Matcher`
### `__init__(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
* **说明**
创建一个事件响应器组合,参数为默认值,与 `Matcher.new` 一致
### `matchers`
* **类型**
`List[Type[Matcher]]`
* **说明**
组内事件响应器列表
### `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
* **说明**
在组中创建一个新的事件响应器,参数留空则使用组合默认值
:::danger 警告
如果使用 handlers 参数覆盖组合默认值则该事件响应器不会随组合一起添加新的事件处理函数
:::

View File

@@ -0,0 +1,143 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.message 模块
## 事件处理
NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供了多个插槽以进行事件的预处理等。
## `event_preprocessor(func)`
* **说明**
事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
* **参数**
事件预处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
## `event_postprocessor(func)`
* **说明**
事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
* **参数**
事件后处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前事件运行前 State
## `run_preprocessor(func)`
* **说明**
运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。
* **参数**
运行预处理函数接收四个参数。
* `matcher: Matcher`: 当前要运行的事件响应器
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
## `run_postprocessor(func)`
* **说明**
运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。
* **参数**
运行后处理函数接收五个参数。
* `matcher: Matcher`: 运行完毕的事件响应器
* `exception: Optional[Exception]`: 事件响应器运行错误(如果存在)
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
## _async_ `handle_event(bot, event)`
* **说明**
处理一个事件。调用该函数以实现分发事件。
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* **示例**
```python
import asyncio
asyncio.create_task(handle_event(bot, event))
```

View File

@@ -5,6 +5,52 @@ sidebarDepth: 0
# NoneBot 模块
## 快捷导入
为方便使用,`nonebot` 模块从子模块导入了部分内容
* `on_message` => `nonebot.plugin.on_message`
* `on_notice` => `nonebot.plugin.on_notice`
* `on_request` => `nonebot.plugin.on_request`
* `on_metaevent` => `nonebot.plugin.on_metaevent`
* `on_startswith` => `nonebot.plugin.on_startswith`
* `on_endswith` => `nonebot.plugin.on_endswith`
* `on_keyword` => `nonebot.plugin.on_keyword`
* `on_command` => `nonebot.plugin.on_command`
* `on_regex` => `nonebot.plugin.on_regex`
* `CommandGroup` => `nonebot.plugin.CommandGroup`
* `load_plugin` => `nonebot.plugin.load_plugin`
* `load_plugins` => `nonebot.plugin.load_plugins`
* `load_builtin_plugins` => `nonebot.plugin.load_builtin_plugins`
* `get_loaded_plugins` => `nonebot.plugin.get_loaded_plugins`
## `get_driver()`

View File

@@ -0,0 +1,629 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.plugin 模块
## 插件
为 NoneBot 插件开发提供便携的定义函数。
## `plugins`
* **类型**
`Dict[str, Plugin]`
* **说明**
已加载的插件
## _class_ `Plugin`
基类:`object`
存储插件信息
### `name`
* **类型**: `str`
* **说明**: 插件名称,使用 文件/文件夹 名称作为插件名
### `module`
* **类型**: `ModuleType`
* **说明**: 插件模块对象
### `matcher`
* **类型**: `Set[Type[Matcher]]`
* **说明**: 插件内定义的 `Matcher`
## `on(type='', rule=None, permission=None, *, handlers=None, temp=False, priority=1, block=False, state=None)`
* **说明**
注册一个基础事件响应器,可自定义类型。
* **参数**
* `type: str`: 事件响应器类型
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_metaevent(rule=None, *, handlers=None, temp=False, priority=1, block=False, state=None)`
* **说明**
注册一个元事件响应器。
* **参数**
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_message(rule=None, permission=None, *, handlers=None, temp=False, priority=1, block=True, state=None)`
* **说明**
注册一个消息事件响应器。
* **参数**
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_notice(rule=None, *, handlers=None, temp=False, priority=1, block=False, state=None)`
* **说明**
注册一个通知事件响应器。
* **参数**
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_request(rule=None, *, handlers=None, temp=False, priority=1, block=False, state=None)`
* **说明**
注册一个请求事件响应器。
* **参数**
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_startswith(msg, rule=None, **kwargs)`
* **说明**
注册一个消息事件响应器,并且当消息的\*\*文本部分\*\*以指定内容开头时响应。
* **参数**
* `msg: str`: 指定消息开头内容
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_endswith(msg, rule=None, **kwargs)`
* **说明**
注册一个消息事件响应器,并且当消息的\*\*文本部分\*\*以指定内容结尾时响应。
* **参数**
* `msg: str`: 指定消息结尾内容
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_keyword(keywords, rule=None, **kwargs)`
* **说明**
注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
* **参数**
* `keywords: Set[str]`: 关键词列表
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_command(cmd, rule=None, aliases=None, **kwargs)`
* **说明**
注册一个消息事件响应器,并且当消息以指定命令开头时响应。
命令匹配规则参考: [命令形式匹配](rule.html#command-command)
* **参数**
* `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## `on_regex(pattern, flags=0, rule=None, **kwargs)`
* **说明**
注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
命令匹配规则参考: [正则匹配](rule.html#regex-regex-flags-0)
* **参数**
* `pattern: str`: 正则表达式
* `flags: Union[int, re.RegexFlag]`: 正则匹配标志
* `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则
* `permission: Optional[Permission]`: 事件响应权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器(仅执行一次)
* `priority: int`: 事件响应器优先级
* `block: bool`: 是否阻止事件向更低优先级传递
* `state: Optional[dict]`: 默认的 state
* **返回**
* `Type[Matcher]`
## _class_ `CommandGroup`
基类:`object`
命令组,用于声明一组有相同名称前缀的命令。
### `__init__(cmd, **kwargs)`
* **参数**
* `cmd: Union[str, Tuple[str, ...]]`: 命令前缀
* `**kwargs`: 其他传递给 `on_command` 的参数默认值,参考 [on_command](#on-command-cmd-rule-none-aliases-none-kwargs)
### `basecmd`
* **类型**: `Tuple[str, ...]`
* **说明**: 命令前缀
### `base_kwargs`
* **类型**: `Dict[str, Any]`
* **说明**: 其他传递给 `on_command` 的参数默认值
### `command(cmd, **kwargs)`
* **说明**
注册一个新的命令。
* **参数**
* `cmd: Union[str, Tuple[str, ...]]`: 命令前缀
* `**kwargs`: 其他传递给 `on_command` 的参数,将会覆盖命令组默认值
* **返回**
* `Type[Matcher]`
## `load_plugin(module_path)`
* **说明**
使用 `importlib` 加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。
* **参数**
* `module_path: str`: 插件名称 `path.to.your.plugin`
* **返回**
* `Optional[Plugin]`
## `load_plugins(*plugin_dir)`
* **说明**
导入目录下多个插件,以 `_` 开头的插件不会被导入!
* **参数**
* `*plugin_dir: str`: 插件路径
* **返回**
* `Set[Plugin]`
## `load_builtin_plugins()`
* **说明**
导入 NoneBot 内置插件
* **返回**
* `Plugin`
## `get_loaded_plugins()`
* **说明**
获取当前已导入的插件。
* **返回**
* `Set[Plugin]`

210
archive/2.0.0a6/api/rule.md Normal file
View File

@@ -0,0 +1,210 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.rule 模块
## 规则
每个事件响应器 `Matcher` 拥有一个匹配规则 `Rule` ,其中是 **异步** `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
:::tip 提示
`RuleChecker` 既可以是 async function 也可以是 sync function但在最终会被 `nonebot.utils.run_sync` 转换为 async function
:::
## _class_ `Rule`
基类:`object`
* **说明**
`Matcher` 规则类,当事件传递时,在 `Matcher` 运行前进行检查。
* **示例**
```python
Rule(async_function) & sync_function
# 等价于
from nonebot.utils import run_sync
Rule(async_function, run_sync(sync_function))
```
### `__init__(*checkers)`
* **参数**
* `*checkers: Callable[[Bot, Event, dict], Awaitable[bool]]`: **异步** RuleChecker
### `checkers`
* **说明**
存储 `RuleChecker`
* **类型**
* `Set[Callable[[Bot, Event, dict], Awaitable[bool]]]`
### _async_ `__call__(bot, event, state)`
* **说明**
检查是否符合所有规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
* **返回**
* `bool`
## `startswith(msg)`
* **说明**
匹配消息开头
* **参数**
* `msg: str`: 消息开头字符串
## `endswith(msg)`
* **说明**
匹配消息结尾
* **参数**
* `msg: str`: 消息结尾字符串
## `keyword(*keywords)`
* **说明**
匹配消息关键词
* **参数**
* `*keywords: str`: 关键词
## `command(*cmds)`
* **说明**
命令形式匹配,根据配置里提供的 `command_start`, `command_sep` 判断消息是否为命令。
可以通过 `state["_prefix"]["command"]` 获取匹配成功的命令(例:`("test",)`),通过 `state["_prefix"]["raw_command"]` 获取匹配成功的原始命令文本(例:`"/test"`)。
* **参数**
* `*cmds: Union[str, Tuple[str, ...]]`: 命令内容
* **示例**
使用默认 `command_start`, `command_sep` 配置
命令 `("test",)` 可以匹配:`/test` 开头的消息
命令 `("test", "sub")` 可以匹配”`/test.sub` 开头的消息
:::tip 提示
命令内容与后续消息间无需空格!
:::
## `regex(regex, flags=0)`
* **说明**
根据正则表达式进行匹配。
可以通过 `state["_matched"]` 获取正则表达式匹配成功的文本。
* **参数**
* `regex: str`: 正则表达式
* `flags: Union[int, re.RegexFlag]`: 正则标志
:::tip 提示
正则表达式匹配使用 search 而非 match如需从头匹配请使用 `r"^xxx"` 来确保匹配开头
:::
## `to_me()`
* **说明**
通过 `event.to_me` 判断消息是否是发送给机器人
* **参数**
*

View File

@@ -110,7 +110,7 @@ sidebarDepth: 0
## `PreProcessor`
## `EventPreProcessor`
* **类型**
@@ -121,7 +121,55 @@ sidebarDepth: 0
* **说明**
消息预处理函数 PreProcessor 类型
事件预处理函数 EventPreProcessor 类型
## `EventPostProcessor`
* **类型**
`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件预处理函数 EventPostProcessor 类型
## `RunPreProcessor`
* **类型**
`Callable[[Matcher, Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件响应器运行前预处理函数 RunPreProcessor 类型
## `RunPostProcessor`
* **类型**
`Callable[[Matcher, Optional[Exception], Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件响应器运行前预处理函数 RunPostProcessor 类型,第二个参数为运行时产生的错误(如果存在)
@@ -142,6 +190,22 @@ sidebarDepth: 0
## `MatcherGroup`
* **类型**
`MatcherGroup`
* **说明**
MatcherGroup 为 Matcher 的集合。可以共享 Handler。
## `Rule`

View File

@@ -6,6 +6,29 @@ sidebarDepth: 0
# NoneBot.utils 模块
## `escape_tag(s)`
* **说明**
用于记录带颜色日志时转义 `<tag>` 类型特殊标签
* **参数**
* `s: str`: 需要转义的字符串
* **返回**
* `str`
## `run_sync(func)`

View File

@@ -18,14 +18,6 @@ NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人
需要注意的是NoneBot 仅支持 Python 3.7+ 及 CQHTTP(OneBot) 插件 v11+。
## 它如何工作?
NoneBot 的运行离不开 酷 Q 和 CQHTTP 插件。酷 Q 扮演着「无头 QQ 客户端」的角色,它进行实际的消息、通知、请求的接收和发送,当 酷 Q 收到消息时,它将这个消息包装为一个事件(通知和请求同理),并通过它自己的插件机制将事件传送给 CQHTTP 插件,后者再根据其配置中的 `post_url``ws_reverse_url` 等项来将事件发送至 NoneBot。
在 NoneBot 收到事件前,它底层的 aiocqhttp 实际已经先看到了事件aiocqhttp 根据事件的类型信息,通知到 NoneBot 的相应函数。特别地,对于消息类型的事件,还将消息内容转换成了 `aiocqhttp.message.Message` 类型,以便处理。
NoneBot 的事件处理函数收到通知后对于不同类型的事件再做相应的预处理和解析然后调用对应的插件并向其提供适合此类事件的会话Session对象。NoneBot 插件的编写者要做的,就是利用 Session 对象中提供的数据,在插件的处理函数中实现所需的功能。
## 特色
- 提供直观的测试前端

View File

@@ -0,0 +1,159 @@
# 事件处理
在上一章中,我们已经注册了事件响应器,现在我们可以正式编写事件处理逻辑了!
## [事件处理函数](../api/typing.md#handler)
```python{1,2,8,9}
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: dict):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
city_weather = await get_weather(city)
await weather.finish(city_weather)
```
在之前的样例中,我们定义了两个函数 `handle_first_receive`, `handle_city`,他们被事件响应器的装饰器装饰从而成为事件响应器的事件处理函数。
:::tip 提示
在事件响应器中,事件处理函数是**顺序**执行的!
:::
### 添加一个事件处理函数
事件响应器提供了三种装饰事件处理函数的装饰器,分别是:
1. [handle()](../api/matcher.md#classmethod-handle)
2. [receive()](../api/matcher.md#classmethod-receive)
3. [got(key, prompt, args_parser)](../api/matcher.md#classmethod-got-key-prompt-none-args-parser-none)
#### handle()
简单的为事件响应器添加一个事件处理函数,这个函数将会在上一个处理函数正常返回执行完毕后立即执行。
#### receive()
指示 NoneBot 接收一条新的用户消息后继续执行该处理函数。此时函数将会接收到新的消息而非前一条消息,之前相关信息可以存储在 state 中。
特别的,当装饰的函数前没有其他事件处理函数,那么 `receive()` 不会接收一条新的消息而是直接使用第一条接收到的消息。
#### got(key, prompt, args_parser)
指示 NoneBot 当 `state` 中不存在 `key` 时向用户发送 `prompt` 等待用户回复并赋值给 `state[key]`。
`prompt` 可以为 `str`, `Message`, `MessageSegment`,若为空则不会向用户发送,若不为空则会在 format 之后发送,即 `prompt.format(**state)`,注意对 `{}` 进行转义。示例:
```python
@matcher.receive()
async def handle(bot: Bot, event: Event, state: dict):
state["key"] = "hello"
@matcher.got("key2", prompt="{key}!")
async def handle2(bot: Bot, event: Event, state: dict):
pass
```
`args_parser` 为参数处理函数,在这里传入一个新的函数以覆盖默认的参数处理。详情参照 [args_parser](#参数处理函数-args-parser)
特别的,这些装饰器都可以套娃使用:
```python
@matcher.got("key1")
@matcher.got("key2")
async def handle(bot: Bot, event: Event, state: dict):
pass
```
### 事件处理函数参数
事件处理函数类型为 `Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]` 。
参数分别为:
1. [nonebot.typing.Bot](../api/typing.md#bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
2. [nonebot.typing.Event](../api/typing.md#event): 即上报事件对象,可以获取到上报的所有信息。
3. `state`: 状态字典,可以存储任意的信息,其中还包含一些特殊的值以获取 NoneBot 内部处理时的一些信息,如:
- `state["_current_key"]`: 存储当前 `got` 获取的参数名
- `state["_prefix"]`, `state["_suffix"]`: 存储当前 TRIE 匹配的前缀/后缀,可以通过该值获取用户命令的原始命令
### 参数处理函数 args_parser
在使用 `got` 获取用户输入参数时需要对用户的消息进行处理以转换为我们所需要的信息。在默认情况下NoneBot 会把用户的消息字符串原封不动的赋值给 `state[key]` 。可以通过以下两种方式修改默认处理逻辑:
- `@matcher.args_parser` 装饰器:直接装饰一个函数作为参数处理器
- `got(key, prompt, args_parser)`:直接把函数作为参数传入
参数处理函数类型为:`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`,即:
```python
async def parser(bot: Bot, event: Event, state: dict):
state[state["_current_key"]] = str(event.message)
```
特别的,`state["_current_key"]` 中存储了当前获取的参数名
### 逻辑控制
NoneBot 也为事件处理函数提供了一些便捷的逻辑控制函数:
#### `matcher.send`
这个函数用于发送一条消息给当前交互的用户。~~其实这并不是一个逻辑控制函数,只是不知道放在哪里……~~
#### `matcher.pause`
这个函数用于结束当前事件处理函数,强制接收一条新的消息再运行**下一个消息处理函数**。
#### `matcher.reject`
这个函数用于结束当前事件处理函数,强制接收一条新的消息再**再次运行当前消息处理函数**。常用于用户输入信息不符合预期。
#### `matcher.finish`
这个函数用于直接结束当前事件处理。
以上三个函数都拥有一个参数 `message` / `prompt`,用于向用户发送一条消息。以及 `**kwargs` 直接传递给 `bot.send` 的额外参数。
## 常用事件处理结构
```python
matcher = on_command("test")
# 修改默认参数处理
@matcher.args_parser
async def parse(bot: Bot, event: Event, state: dict):
print(state["_current_key"], ":", str(event.message))
state[state["_current_key"]] = str(event.message)
@matcher.handle()
async def first_receive(bot: Bot, event: Event, state: dict):
# 获取用户原始命令,如:/test
print(state["_prefix"]["raw_command"])
# 处理用户输入参数,如:/test arg1 arg2
raw_args = str(event.message).strip()
if raw_args:
arg_list = raw_args.split()
# 将参数存入state以阻止后续再向用户询问参数
state["arg1"] = arg_list[0]
@matcher.got("arg1", prompt="参数?")
async def arg_handle(bot: Bot, event: Event, state: dict):
# 在这里对参数进行验证
if state["arg1"] not in ["allow", "list"]:
await matcher.reject("参数不正确!请重新输入")
# 发送一些信息
await bot.send("message")
await matcher.send("message")
await matcher.finish("message")
```

View File

@@ -0,0 +1,144 @@
# 注册事件响应器
好了,现在插件已经创建完毕,我们可以开始编写实际代码了,下面将以一个简易单文件天气查询插件为例。
在插件目录下 `weather.py` 中添加如下代码:
```python
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event
weather = on_command("天气", rule=to_me(), priority=5)
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: dict):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
city_weather = await get_weather(city)
await weather.finish(city_weather)
async def get_weather(city: str):
return f"{city}的天气是..."
```
为了简单起见,我们在这里的例子中没有接入真实的天气数据,但要接入也非常简单,你可以使用中国天气网、和风天气等网站提供的 API。
接下来我们来说明这段代码是如何工作的。
:::tip 提示
从这里开始,你需要对 Python 的 asyncio 编程有所了解,因为 NoneBot 是完全基于 asyncio 的,具体可以参考 [廖雪峰的 Python 教程](https://www.liaoxuefeng.com/wiki/1016959663602400/1017959540289152)
:::
## [事件响应器](../api/matcher.md)
```python{4}
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.permission import Permission
weather = on_command("天气", rule=to_me(), permission=Permission(), priority=5)
```
在上方代码中,我们注册了一个事件响应器 `Matcher`,它由几个部分组成:
1. `on_command` 注册一个消息类型的命令处理器
2. `"天气"` 指定 command 参数 - 命令名
3. `rule` 补充事件响应器的匹配规则
4. `priority` 事件响应器优先级
5. `block` 是否阻止事件传递
其他详细配置可以参考 API 文档,下面我们详细说明各个部分:
### 事件响应器类型 type
事件响应器类型其实就是对应事件的类型 `Event.type` NoneBot 提供了一个基础类型事件响应器 `on()` 以及一些其他内置的事件响应器。
以下所有类型的事件响应器都是由 `on(type, rule)` 的形式进行了简化封装。
- `on("事件类型")`: 基础事件响应器,第一个参数为事件类型,空字符串表示不限
- `on_metaevent()` ~ `on("meta_event")`: 元事件响应器
- `on_message()` ~ `on("message")`: 消息事件响应器
- `on_request()` ~ `on("request")`: 请求事件响应器
- `on_notice()` ~ `on("notice")`: 通知事件响应器
- `on_startswith(str)` ~ `on("message", startswith(str))`: 消息开头匹配响应器,参考 [startswith](../api/rule.md#startswith-msg)
- `on_endswith(str)` ~ `on("message", endswith(str))`: 消息结尾匹配响应器,参考 [endswith](../api/rule.md#endswith-msg)
- `on_keyword(set)` ~ `on("message", keyword(str))`: 消息关键词匹配响应器,参考 [keyword](../api/rule.md#keyword-keywords)
- `on_command(str|tuple)` ~ `on("message", command(str|tuple))`: 命令响应器,参考 [command](../api/rule.md#command-cmds)
- `on_regex(pattern_str)` ~ `on("message", regex(pattern_str))`: 正则匹配处理器,参考 [regex](../api/rule.md#regex-regex-flags-0)
### 匹配规则 rule
事件响应器的匹配规则即 `Rule`,详细内容在下方介绍。[直达](#自定义-rule)
### 优先级 priority
事件响应器的优先级代表事件响应器的执行顺序,同一优先级的事件响应器会 **同时执行!**,优先级数字**越小**越先响应!优先级请从 `1` 开始排序!
:::tip 提示
使用 `nonebot-test` 可以看到当前所有事件响应器的执行流程,有助理解事件响应流程!
```bash
pip install nonebot2[test]
```
:::
### 阻断 block
当有任意事件响应器发出了阻止事件传递信号时,该事件将不再会传递给下一优先级,直接结束处理。
NoneBot 内置的事件响应器中,所有 `message` 类的事件响应器默认会阻断事件传递,其他则不会。
## 自定义 rule
rule 的出现使得 nonebot 对事件的响应可以非常自由nonebot 内置了一些规则:
- [startswith(msg)](../api/rule.md#startswith-msg)
- [endswith(msg)](../api/rule.md#endswith-msg)
- [keyword(\*keywords)](../api/rule.md#keyword-keywords)
- [command(\*cmds)](../api/rule.md#command-cmds)
- [regex(regex, flag)](../api/rule.md#regex-regex-flags-0)
以上规则都是返回类型为 `Rule` 的函数,`Rule` 由非负个 `RuleChecker` 组成,当所有 `RuleChecker` 返回 `True` 时匹配成功。这些 `Rule`, `RuleChecker` 的形式如下:
```python
from nonebot.rule import Rule
async def async_checker(bot: Bot, event: Event, state: dict) -> bool:
return True
def sync_checker(bot: Bot, event: Event, state: dict) -> bool:
return True
def check(arg1, args2):
async def _checker(bot: Bot, event: Event, state: dict) -> bool:
return bool(arg1 + arg2)
return Rule(_check)
```
`Rule` 和 `RuleChecker` 之间可以使用 `&` 互相组合:
```python
from nonebot.rule import Rule
Rule(async_checker1) & sync_checker & async_checker2
```
**_请勿将事件处理的逻辑写入 `rule` 中这会使得事件处理返回奇怪的响应。_**
:::danger 警告
`Rule(*checkers)` 只接受 async function或使用 `nonebot.utils.run_sync` 自行包裹 sync function。在使用 `&` 时NoneBot 会自动包裹 sync function
:::

View File

@@ -0,0 +1,113 @@
# 创建插件
如果之前使用 `nb-cli` 生成了项目结构,那我们已经有了一个空的插件目录 `Awesome-Bot/awesome_bot/plugins`,并且它已在 `bot.py` 中被加载,我们现在可以开始创建插件了!
插件通常有两种形式,下面分别介绍
## 单文件形式
在插件目录下创建名为 `foo.py` 的 Python 文件,暂时留空,此时目录结构如下:
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── awesome_bot
│ └── plugins
│ └── `foo.py`
├── .env
├── .env.dev
├── .env.prod
├── .gitignore
├── bot.py
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
:::
<!-- prettier-ignore-end -->
这个时候它已经可以被称为一个插件了,尽管它还什么都没做。
## 包形式(推荐)
在插件目录下创建文件夹 `foo`,并在该文件夹下创建文件 `__init__.py`,此时目录结构如下:
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── awesome_bot
│ └── plugins
│ └── `foo`
│ └── `__init__.py`
├── .env
├── .env.dev
├── .env.prod
├── .gitignore
├── bot.py
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
:::
<!-- prettier-ignore-end -->
这个时候 `foo` 就是一个合法的 Python 包了,同时也是合法的 NoneBot 插件,插件内容可以在 `__init__.py` 中编写。
### 推荐结构(仅供参考)
<!-- prettier-ignore-start -->
:::vue
foo
├── `__init__.py`
├── `config.py`
├── `data_source.py`
└── `model.py`
:::
<!-- prettier-ignore-end -->
#### \_\_init\_\_.py
在该文件中编写各类事件响应及处理逻辑。
#### config.py
在该文件中使用 `pydantic` 定义插件所需要的配置项以及类型。
示例:
```python
from pydantic import BaseSetting
class Config(BaseSetting):
# plugin custom config
plugin_setting: str = "default"
class Config:
extra = "ignore"
```
并在 `__init__.py` 文件中添加以下行
```python
import nonebot
from .config import Config
global_config = nonebot.get_driver().config
plugin_config = Config(**global_config.dict())
```
此时就可以通过 `plugin_config.plugin_setting` 获取到插件所需要的配置项了。
#### data_source.py
在该文件中编写数据获取函数。
:::warning 警告
数据获取应尽量使用**异步**处理!例如使用 [httpx](https://www.python-httpx.org/) 而非 [requests](https://requests.readthedocs.io/en/master/)
:::
#### model.py
在该文件中编写数据库模型。

View File

@@ -0,0 +1,9 @@
# 结语
至此,相信你已经能够写出一个基础的插件了,更多的用法将会在 进阶 部分进行介绍,这里给出几个小提示:
- 请千万注意事件处理器的优先级设定
- 在匹配规则中请勿使用耗时极长的函数
- 同一个用户可以**跨群**(**私聊**)继续他的事件处理(除非做出权限限制,将在后续介绍)
如果你还不能满足,前往 [进阶](../advanced/README.md) 获得更多的功能信息。

View File

@@ -136,11 +136,11 @@ QQ 协议端举例:
现在,尝试向你的 QQ 机器人账号发送如下内容:
```default
/say 你好,世界
/echo 你好,世界
```
到这里如果一切 OK你应该会收到机器人给你回复了 `你好,世界`。这一历史性的对话标志着你已经成功地运行了一个 NoneBot 的最小实例,开始了编写更强大的 QQ 机器人的创意之旅!
<ClientOnly>
<Messenger :messages="[{ position: 'right', msg: '/say 你好,世界' }, { position: 'left', msg: '你好,世界' }]"/>
<Messenger :messages="[{ position: 'right', msg: '/echo 你好,世界' }, { position: 'left', msg: '你好,世界' }]"/>
</ClientOnly>

View File

@@ -6,11 +6,23 @@
请确保你的 Python 版本 >= 3.7。
:::
请在安装 nonebot2 之前卸载 nonebot 1.x
```bash
pip uninstall nonebot
pip install nonebot2
```
如果你需要使用最新的(可能尚未发布的)特性,可以克隆 Git 仓库后手动安装:
如果你需要使用最新的(可能尚未发布的)特性,可以直接从 GitHub 仓库安装:
```bash
# master
poetry add git+https://github.com/nonebot/nonebot2.git#master
# dev
poetry add git+https://github.com/nonebot/nonebot2.git#dev
```
或者克隆 Git 仓库后手动安装:
```bash
git clone https://github.com/nonebot/nonebot2.git

View File

@@ -0,0 +1,127 @@
# 加载插件
在 [创建一个完整的项目](creating-a-project) 一章节中,我们已经创建了插件目录 `awesome_bot/plugins`,现在我们在机器人入口文件中加载它。当然,你也可以单独加载一个插件。
## 加载内置插件
`bot.py` 文件中添加以下行:
```python{5}
import nonebot
nonebot.init()
# 加载 nonebot 内置插件
nonebot.load_bulitin_plugins()
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
这将会加载 nonebot 内置的插件,它包含:
- 命令 `say`:可由**superuser**使用,可以将消息内容由特殊纯文本转为富文本
- 命令 `echo`:可由任何人使用,将消息原样返回
以上命令均需要指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称。参考 [Rule: to_me](../api/rule.md#to-me)
## 加载插件目录
在 `bot.py` 文件中添加以下行:
```python{5}
import nonebot
nonebot.init()
# 加载插件目录,该目录下为各插件,以下划线开头的插件将不会被加载
nonebot.load_plugins("awesome_bot/plugins")
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
:::tip 提示
加载插件目录时,目录下以 `_` 下划线开头的插件将不会被加载!
:::
:::warning 提示
**插件不能存在相同名称!**
:::
:::danger 警告
插件间不应该存在过多的耦合,如果确实需要导入某个插件内的数据,可以使用如下两种方法:
1. (推荐) `from plugin_name import xxx` 而非 `from awesome_bot.plugins.plugin_name import xxx`
2. 在需要导入其他插件的文件中添加 `__package__ = "plugins"; from .plugin_name import xxx` (将共同的上层目录设定为父包后使用相对导入)
具体可以参考:[nonebot/nonebot2#32](https://github.com/nonebot/nonebot2/issues/32)
:::
## 加载单个插件
在 `bot.py` 文件中添加以下行:
```python{5,7}
import nonebot
nonebot.init()
# 加载一个 pip 安装的插件
nonebot.load_plugin("nonebot_plugin_status")
# 加载本地的单独插件
nonebot.load_plugin("awesome_bot.plugins.xxx")
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
## 子插件(嵌套插件)
<!-- TODO: 子插件 -->
在插件中同样可以加载子插件,例如如下插件目录结构:
<!-- prettier-ignore-start -->
:::vue
foo_plugin
├── `plugins`
│ ├── `sub_plugin1`
│ │ └── \_\_init\_\_.py
│ └── `sub_plugin2.py`
├── `__init__.py`
└── config.py
:::
<!-- prettier-ignore-end -->
在插件目录下的 `__init__.py` 中添加如下代码:
```python
from pathlib import Path
import nonebot
# store all subplugins
_sub_plugins = set()
# load sub plugins
_sub_plugins |= nonebot.load_plugins(
str((Path(__file__).parent / "plugins").resolve()))
```
插件将会被加载并存储于 `_sub_plugins` 中。
:::tip 提示
如果在父插件中需要定义事件响应器,应在**子插件被加载后**进行定义
:::
## 运行结果
尝试运行 `nb run` 或者 `python bot.py`,可以看到日志输出了类似如下内容:
```plain
09-19 21:51:59 [INFO] nonebot | Succeeded to import "nonebot.plugins.base"
09-19 21:51:59 [INFO] nonebot | Succeeded to import "plugin_in_folder"
```

View File

@@ -1,4 +1,5 @@
{
"sidebar": {},
"locales": {
"/": {
"label": "简体中文",
@@ -14,17 +15,28 @@
"text": "指南",
"link": "/guide/"
},
{
"text": "进阶",
"link": "/advanced/"
},
{
"text": "API",
"link": "/api/"
},
{
"text": "插件广场",
"link": "/plugin-store"
},
{
"text": "更新日志",
"link": "/changelog"
}
],
"sidebarDepth": 2,
"sidebar": {
"/guide/": [
{
"title": "指南",
"path": "",
"title": "开始",
"collapsable": false,
"sidebar": "auto",
"children": [
@@ -32,8 +44,32 @@
"installation",
"getting-started",
"creating-a-project",
"basic-configuration",
"writing-a-plugin"
"basic-configuration"
]
},
{
"title": "编写插件",
"collapsable": false,
"sidebar": "auto",
"children": [
"loading-a-plugin",
"creating-a-plugin",
"creating-a-matcher",
"creating-a-handler",
"end-or-start"
]
}
],
"/advanced/": [
{
"title": "进阶",
"collapsable": false,
"sidebar": "auto",
"children": [
"",
"scheduler",
"permission",
"runtime-hook"
]
}
],
@@ -47,21 +83,21 @@
"title": "nonebot 模块",
"path": "nonebot"
},
{
"title": "nonebot.typing 模块",
"path": "typing"
},
{
"title": "nonebot.config 模块",
"path": "config"
},
{
"title": "nonebot.sched 模块",
"path": "sched"
"title": "nonebot.plugin 模块",
"path": "plugin"
},
{
"title": "nonebot.log 模块",
"path": "log"
"title": "nonebot.message 模块",
"path": "message"
},
{
"title": "nonebot.matcher 模块",
"path": "matcher"
},
{
"title": "nonebot.rule 模块",
@@ -71,13 +107,41 @@
"title": "nonebot.permission 模块",
"path": "permission"
},
{
"title": "nonebot.sched 模块",
"path": "sched"
},
{
"title": "nonebot.log 模块",
"path": "log"
},
{
"title": "nonebot.utils 模块",
"path": "utils"
},
{
"title": "nonebot.typing 模块",
"path": "typing"
},
{
"title": "nonebot.exception 模块",
"path": "exception"
},
{
"title": "nonebot.drivers 模块",
"path": "drivers/"
},
{
"title": "nonebot.drivers.fastapi 模块",
"path": "drivers/fastapi"
},
{
"title": "nonebot.adapters 模块",
"path": "adapters/"
},
{
"title": "nonebot.adapters.cqhttp 模块",
"path": "adapters/cqhttp"
}
]
}

15
archive/2.0.0a7/README.md Normal file
View File

@@ -0,0 +1,15 @@
---
home: true
heroImage: /logo.png
tagline: An asynchronous QQ bot framework.
actionText: 开始使用
actionLink: guide/
features:
- title: 简洁
details: 提供极其简洁易懂的 API使你可以毫无压力地开始验证你的绝佳创意只需编写最少量的代码即可实现丰富的功能。
- title: 易于扩展
details: 精心设计的消息处理流程使得你可以很方便地将原型扩充为具有大量实用功能的完整聊天机器人,并持续保证扩展性。
- title: 高性能
details: 采用异步 I/O利用 WebSocket 进行通信,以获得极高的性能;同时,支持使用多账号同时接入,减少业务宕机的可能。
footer: MIT Licensed | Copyright © 2018 - 2020 NoneBot Team
---

View File

@@ -0,0 +1,7 @@
# 深入
## 它如何工作?
<!-- TODO: how to work -->
~~未填坑~~

View File

@@ -0,0 +1 @@
# 跨插件访问

View File

@@ -0,0 +1 @@
# 权限控制

View File

@@ -0,0 +1 @@
# 发布插件

View File

@@ -0,0 +1 @@
# 运行时插槽

View File

@@ -0,0 +1 @@
# 定时任务

View File

@@ -0,0 +1,52 @@
# NoneBot Api Reference
* **模块索引**
* [nonebot](nonebot.html)
* [nonebot.config](config.html)
* [nonebot.plugin](plugin.html)
* [nonebot.message](message.html)
* [nonebot.matcher](matcher.html)
* [nonebot.rule](rule.html)
* [nonebot.permission](permission.html)
* [nonebot.log](log.html)
* [nonebot.utils](utils.html)
* [nonebot.typing](typing.html)
* [nonebot.exception](exception.html)
* [nonebot.drivers](drivers/)
* [nonebot.drivers.fastapi](drivers/fastapi.html)
* [nonebot.adapters](adapters/)
* [nonebot.adapters.cqhttp](adapters/cqhttp.html)
* [nonebot.adapters.ding](adapters/ding.html)

View File

@@ -0,0 +1,362 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters 模块
## 协议适配基类
各协议请继承以下基类,并使用 `driver.register_adapter` 注册适配器
## _class_ `BaseBot`
基类:`abc.ABC`
Bot 基类。用于处理上报消息,并提供 API 调用接口。
### _abstract_ `__init__(driver, connection_type, config, self_id, *, websocket=None)`
* **参数**
* `driver: Driver`: Driver 对象
* `connection_type: str`: http 或者 websocket
* `config: Config`: Config 对象
* `self_id: str`: 机器人 ID
* `websocket: Optional[WebSocket]`: Websocket 连接对象
### `driver`
Driver 对象
### `connection_type`
连接类型
### `config`
Config 配置对象
### `self_id`
机器人 ID
### `websocket`
Websocket 连接对象
### _abstract property_ `type`
Adapter 类型
### _abstract async classmethod_ `check_permission(driver, connection_type, headers, body)`
* **说明**
检查连接请求是否合法的函数,如果合法则返回当前连接 `唯一标识符`,通常为机器人 ID如果不合法则抛出 `RequestDenied` 异常。
* **参数**
* `driver: Driver`: Driver 对象
* `connection_type: str`: 连接类型
* `headers: dict`: 请求头
* `body: Optional[dict]`: 请求数据WebSocket 连接该部分为空
* **返回**
* `str`: 连接唯一标识符
* **异常**
* `RequestDenied`: 请求非法
### _abstract async_ `handle_message(message)`
* **说明**
处理上报消息的函数,转换为 `Event` 事件后调用 `nonebot.message.handle_event` 进一步处理事件。
* **参数**
* `message: dict`: 收到的上报消息
### _abstract async_ `call_api(api, **data)`
* **说明**
调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
* **参数**
* `api: str`: API 名称
* `**data`: API 数据
* **示例**
```python
await bot.call_api("send_msg", message="hello world"})
await bot.send_msg(message="hello world")
```
### _abstract async_ `send(event, message, **kwargs)`
* **说明**
调用机器人基础发送消息接口
* **参数**
* `event: Event`: 上报事件
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `**kwargs`
## _class_ `BaseEvent`
基类:`abc.ABC`, `typing.Generic`
Event 基类。提供上报信息的关键信息,其余信息可从原始上报消息获取。
### `__init__(raw_event)`
* **参数**
* `raw_event: Union[dict, T]`: 原始上报消息
### _property_ `raw_event`
原始上报消息
### _abstract property_ `id`
事件 ID
### _abstract property_ `name`
事件名称
### _abstract property_ `self_id`
机器人 ID
### _abstract property_ `time`
事件发生时间
### _abstract property_ `type`
事件主类型
### _abstract property_ `detail_type`
事件详细类型
### _abstract property_ `sub_type`
事件子类型
### _abstract property_ `user_id`
触发事件的主体 ID
### _abstract property_ `group_id`
触发事件的主体群 ID
### _abstract property_ `to_me`
事件是否为发送给机器人的消息
### _abstract property_ `message`
消息内容
### _abstract property_ `reply`
回复的消息
### _abstract property_ `raw_message`
原始消息
### _abstract property_ `plain_text`
纯文本消息
### _abstract property_ `sender`
消息发送者信息
## _class_ `BaseMessageSegment`
基类:`abc.ABC`
消息段基类
### `type`
* 类型: `str`
* 说明: 消息段类型
### `data`
* 类型: `Dict[str, Union[str, list]]`
* 说明: 消息段数据
## _class_ `BaseMessage`
基类:`list`, `abc.ABC`
消息数组
### `__init__(message=None, *args, **kwargs)`
* **参数**
* `message: Union[str, dict, list, BaseModel, MessageSegment, Message]`: 消息内容
### `append(obj)`
* **说明**
添加一个消息段到消息数组末尾
* **参数**
* `obj: Union[str, MessageSegment]`: 要添加的消息段
### `extend(obj)`
* **说明**
拼接一个消息数组或多个消息段到消息数组末尾
* **参数**
* `obj: Union[Message, Iterable[MessageSegment]]`: 要添加的消息数组
### `reduce()`
* **说明**
缩减消息数组,即按 MessageSegment 的实现拼接相邻消息段
### `extract_plain_text()`
* **说明**
提取消息内纯文本消息

View File

@@ -0,0 +1,442 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.cqhttp 模块
## `escape(s, *, escape_comma=True)`
* **说明**
对字符串进行 CQ 码转义。
* **参数**
* `s: str`: 需要转义的字符串
* `escape_comma: bool`: 是否转义逗号(`,`)。
## `unescape(s)`
* **说明**
对字符串进行 CQ 码去转义。
* **参数**
* `s: str`: 需要转义的字符串
## _exception_ `CQHTTPAdapterException`
基类:[`nonebot.exception.AdapterException`](../exception.md#nonebot.exception.AdapterException)
## _exception_ `ActionFailed`
基类:[`nonebot.exception.ActionFailed`](../exception.md#nonebot.exception.ActionFailed), `nonebot.adapters.cqhttp.exception.CQHTTPAdapterException`
* **说明**
API 请求返回错误信息。
* **参数**
* `retcode: Optional[int]`: 错误码
## _exception_ `NetworkError`
基类:[`nonebot.exception.NetworkError`](../exception.md#nonebot.exception.NetworkError), `nonebot.adapters.cqhttp.exception.CQHTTPAdapterException`
* **说明**
网络错误。
* **参数**
* `retcode: Optional[int]`: 错误码
## _exception_ `ApiNotAvailable`
基类:[`nonebot.exception.ApiNotAvailable`](../exception.md#nonebot.exception.ApiNotAvailable), `nonebot.adapters.cqhttp.exception.CQHTTPAdapterException`
## _async_ `_check_reply(bot, event)`
* **说明**
检查消息中存在的回复,去除并赋值 `event.reply`, `event.to_me`
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
## `_check_at_me(bot, event)`
* **说明**
检查消息开头或结尾是否存在 @机器人,去除并赋值 `event.to_me`
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
## `_check_nickname(bot, event)`
* **说明**
检查消息开头是否存在,去除并赋值 `event.to_me`
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
## `_handle_api_result(result)`
* **说明**
处理 API 请求返回值。
* **参数**
* `result: Optional[Dict[str, Any]]`: API 返回数据
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ActionFailed`: API 调用失败
## _class_ `Bot`
基类:[`nonebot.adapters.BaseBot`](README.md#nonebot.adapters.BaseBot)
CQHTTP 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
### _property_ `type`
* 返回: `"cqhttp"`
### _async classmethod_ `check_permission(driver, connection_type, headers, body)`
* **说明**
CQHTTP (OneBot) 协议鉴权。参考 [鉴权](https://github.com/howmanybots/onebot/blob/master/v11/specs/communication/authorization.md)
### _async_ `handle_message(message)`
* **说明**
调用 [_check_reply](#async-check-reply-bot-event), [_check_at_me](#check-at-me-bot-event), [_check_nickname](#check-nickname-bot-event) 处理事件并转换为 [Event](#class-event)
### _async_ `call_api(api, **data)`
* **说明**
调用 CQHTTP 协议 API
* **参数**
* `api: str`: API 名称
* `**data: Any`: API 参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
### _async_ `send(event, message, at_sender=False, **kwargs)`
* **说明**
根据 `event` 向触发事件的主体发送消息。
* **参数**
* `event: Event`: Event 对象
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `at_sender: bool`: 是否 @ 事件主体
* `**kwargs`: 覆盖默认参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ValueError`: 缺少 `user_id`, `group_id`
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
## _class_ `Event`
基类:[`nonebot.adapters.BaseEvent`](README.md#nonebot.adapters.BaseEvent)
CQHTTP 协议 Event 适配。继承属性参考 [BaseEvent](./#class-baseevent) 。
### _property_ `id`
* 类型: `Optional[int]`
* 说明: 事件/消息 ID
### _property_ `name`
* 类型: `str`
* 说明: 事件名称,由类型与 `.` 组合而成
### _property_ `self_id`
* 类型: `str`
* 说明: 机器人自身 ID
### _property_ `time`
* 类型: `int`
* 说明: 事件发生时间
### _property_ `type`
* 类型: `str`
* 说明: 事件类型
### _property_ `detail_type`
* 类型: `str`
* 说明: 事件详细类型
### _property_ `sub_type`
* 类型: `Optional[str]`
* 说明: 事件子类型
### _property_ `user_id`
* 类型: `Optional[int]`
* 说明: 事件主体 ID
### _property_ `group_id`
* 类型: `Optional[int]`
* 说明: 事件主体群 ID
### _property_ `to_me`
* 类型: `Optional[bool]`
* 说明: 消息是否与机器人相关
### _property_ `message`
* 类型: `Optional[Message]`
* 说明: 消息内容
### _property_ `reply`
* 类型: `Optional[dict]`
* 说明: 回复消息详情
### _property_ `raw_message`
* 类型: `Optional[str]`
* 说明: 原始消息
### _property_ `plain_text`
* 类型: `Optional[str]`
* 说明: 纯文本消息内容
### _property_ `sender`
* 类型: `Optional[dict]`
* 说明: 消息发送者信息
## _class_ `MessageSegment`
基类:[`nonebot.adapters.BaseMessageSegment`](README.md#nonebot.adapters.BaseMessageSegment)
CQHTTP 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
## _class_ `Message`
基类:[`nonebot.adapters.BaseMessage`](README.md#nonebot.adapters.BaseMessage)
CQHTTP 协议 Message 适配。

View File

@@ -0,0 +1,380 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.ding 模块
## _exception_ `DingAdapterException`
基类:[`nonebot.exception.AdapterException`](../exception.md#nonebot.exception.AdapterException)
* **说明**
钉钉 Adapter 错误基类
## _exception_ `ActionFailed`
基类:[`nonebot.exception.ActionFailed`](../exception.md#nonebot.exception.ActionFailed), `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
API 请求返回错误信息。
* **参数**
* `errcode: Optional[int]`: 错误码
* `errmsg: Optional[str]`: 错误信息
## _exception_ `ApiNotAvailable`
基类:[`nonebot.exception.ApiNotAvailable`](../exception.md#nonebot.exception.ApiNotAvailable), `nonebot.adapters.ding.exception.DingAdapterException`
## _exception_ `NetworkError`
基类:[`nonebot.exception.NetworkError`](../exception.md#nonebot.exception.NetworkError), `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
网络错误。
* **参数**
* `retcode: Optional[int]`: 错误码
## _exception_ `SessionExpired`
基类:[`nonebot.exception.ApiNotAvailable`](../exception.md#nonebot.exception.ApiNotAvailable), `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
发消息的 session 已经过期。
## _class_ `Bot`
基类:[`nonebot.adapters.BaseBot`](README.md#nonebot.adapters.BaseBot)
钉钉 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
### _property_ `type`
* 返回: `"ding"`
### _async classmethod_ `check_permission(driver, connection_type, headers, body)`
* **说明**
钉钉协议鉴权。参考 [鉴权](https://ding-doc.dingtalk.com/doc#/serverapi2/elzz1p)
### _async_ `handle_message(body)`
* **说明**
处理上报消息的函数,转换为 `Event` 事件后调用 `nonebot.message.handle_event` 进一步处理事件。
* **参数**
* `message: dict`: 收到的上报消息
### _async_ `call_api(api, event=None, **data)`
* **说明**
调用 钉钉 协议 API
* **参数**
* `api: str`: API 名称
* `**data: Any`: API 参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
### _async_ `send(event, message, at_sender=False, **kwargs)`
* **说明**
根据 `event` 向触发事件的主体发送消息。
* **参数**
* `event: Event`: Event 对象
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `at_sender: bool`: 是否 @ 事件主体
* `**kwargs`: 覆盖默认参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ValueError`: 缺少 `user_id`, `group_id`
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
## _class_ `Event`
基类:[`nonebot.adapters.BaseEvent`](README.md#nonebot.adapters.BaseEvent)
钉钉 协议 Event 适配。继承属性参考 [BaseEvent](./#class-baseevent) 。
### _property_ `raw_event`
原始上报消息
### _property_ `id`
* 类型: `Optional[str]`
* 说明: 消息 ID
### _property_ `name`
* 类型: `str`
* 说明: 事件名称,由 type.\`detail_type\` 组合而成
### _property_ `self_id`
* 类型: `str`
* 说明: 机器人自身 ID
### _property_ `time`
* 类型: `int`
* 说明: 消息的时间戳,单位 s
### _property_ `type`
* 类型: `str`
* 说明: 事件类型
### _property_ `detail_type`
* 类型: `str`
* 说明: 事件详细类型
### _property_ `sub_type`
* 类型: `None`
* 说明: 钉钉适配器无事件子类型
### _property_ `user_id`
* 类型: `Optional[str]`
* 说明: 发送者 ID
### _property_ `group_id`
* 类型: `Optional[str]`
* 说明: 事件主体群 ID
### _property_ `to_me`
* 类型: `Optional[bool]`
* 说明: 消息是否与机器人相关
### _property_ `message`
* 类型: `Optional[Message]`
* 说明: 消息内容
### _property_ `reply`
* 类型: `None`
* 说明: 回复消息详情
### _property_ `raw_message`
* 类型: `Optional[str]`
* 说明: 原始消息
### _property_ `plain_text`
* 类型: `Optional[str]`
* 说明: 纯文本消息内容
### _property_ `sender`
* 类型: `Optional[dict]`
* 说明: 消息发送者信息
## _class_ `MessageSegment`
基类:[`nonebot.adapters.BaseMessageSegment`](README.md#nonebot.adapters.BaseMessageSegment)
钉钉 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
### _static_ `actionCardSingleMultiBtns(title, text, btns=[], hideAvatar=False, btnOrientation='1')`
* **参数**
* `btnOrientation`: 0按钮竖直排列 1按钮横向排列
* `btns`: [{ "title": title, "actionURL": actionURL }, ...]
### _static_ `feedCard(links=[])`
* **参数**
* `links`: [{ "title": xxx, "messageURL": xxx, "picURL": xxx }, ...]
### _static_ `empty()`
不想回复消息到群里
## _class_ `Message`
基类:[`nonebot.adapters.BaseMessage`](README.md#nonebot.adapters.BaseMessage)
钉钉 协议 Message 适配。

View File

@@ -0,0 +1,285 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.config 模块
## 配置
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/) 文档。
## _class_ `Env`
基类:`pydantic.env_settings.BaseSettings`
运行环境配置。大小写不敏感。
将会从 `nonebot.init 参数` > `环境变量` > `.env 环境配置文件` 的优先级读取配置。
### `environment`
* **类型**: `str`
* **默认值**: `"prod"`
* **说明**
当前环境名。 NoneBot 将从 `.env.{environment}` 文件中加载配置。
## _class_ `Config`
基类:`nonebot.config.BaseConfig`
NoneBot 主要配置。大小写不敏感。
除了 NoneBot 的配置项外,还可以自行添加配置项到 `.env.{environment}` 文件中。
这些配置将会在 json 反序列化后一起带入 `Config` 类中。
### `driver`
* **类型**: `str`
* **默认值**: `"nonebot.drivers.fastapi"`
* **说明**
NoneBot 运行所使用的 `Driver` 。继承自 `nonebot.driver.BaseDriver`
### `host`
* **类型**: `IPvAnyAddress`
* **默认值**: `127.0.0.1`
* **说明**
NoneBot 的 HTTP 和 WebSocket 服务端监听的 IP/主机名。
### `port`
* **类型**: `int`
* **默认值**: `8080`
* **说明**
NoneBot 的 HTTP 和 WebSocket 服务端监听的端口。
### `debug`
* **类型**: `bool`
* **默认值**: `False`
* **说明**
是否以调试模式运行 NoneBot。
### `api_root`
* **类型**: `Dict[str, str]`
* **默认值**: `{}`
* **说明**
以机器人 ID 为键,上报地址为值的字典,环境变量或文件中应使用 json 序列化。
* **示例**
```default
API_ROOT={"123456": "http://127.0.0.1:5700"}
```
### `api_timeout`
* **类型**: `Optional[float]`
* **默认值**: `30.`
* **说明**
API 请求超时时间,单位: 秒。
### `access_token`
* **类型**: `Optional[str]`
* **默认值**: `None`
* **说明**
API 请求以及上报所需密钥,在请求头中携带。
* **示例**
```http
POST /cqhttp/ HTTP/1.1
Authorization: Bearer kSLuTF2GC2Q4q4ugm3
```
### `secret`
* **类型**: `Optional[str]`
* **默认值**: `None`
* **说明**
HTTP POST 形式上报所需签名,在请求头中携带。
* **示例**
```http
POST /cqhttp/ HTTP/1.1
X-Signature: sha1=f9ddd4863ace61e64f462d41ca311e3d2c1176e2
```
### `superusers`
* **类型**: `Set[int]`
* **默认值**: `set()`
* **说明**
机器人超级用户。
* **示例**
```default
SUPER_USERS=[12345789]
```
### `nickname`
* **类型**: `Set[str]`
* **默认值**: `set()`
* **说明**
机器人昵称。
### `command_start`
* **类型**: `Set[str]`
* **默认值**: `{"/"}`
* **说明**
命令的起始标记,用于判断一条消息是不是命令。
### `command_sep`
* **类型**: `Set[str]`
* **默认值**: `{"."}`
* **说明**
命令的分隔标记,用于将文本形式的命令切分为元组(实际的命令名)。
### `session_expire_timeout`
* **类型**: `timedelta`
* **默认值**: `timedelta(minutes=2)`
* **说明**
等待用户回复的超时时间。
* **示例**
```default
SESSION_EXPIRE_TIMEOUT=120 # 单位: 秒
SESSION_EXPIRE_TIMEOUT=[DD ][HH:MM]SS[.ffffff]
SESSION_EXPIRE_TIMEOUT=P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
```

View File

@@ -0,0 +1,246 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers 模块
## 后端驱动适配基类
各驱动请继承以下基类
## _class_ `BaseDriver`
基类:`abc.ABC`
Driver 基类。将后端框架封装,以满足适配器使用。
### `_adapters`
* **类型**
`Dict[str, Type[Bot]]`
* **说明**
已注册的适配器列表
### _abstract_ `__init__(env, config)`
* **参数**
* `env: Env`: 包含环境信息的 Env 对象
* `config: Config`: 包含配置信息的 Config 对象
### `env`
* **类型**
`str`
* **说明**
环境名称
### `config`
* **类型**
`Config`
* **说明**
配置对象
### `_clients`
* **类型**
`Dict[str, Bot]`
* **说明**
已连接的 Bot
### _classmethod_ `register_adapter(name, adapter)`
* **说明**
注册一个协议适配器
* **参数**
* `name: str`: 适配器名称,用于在连接时进行识别
* `adapter: Type[Bot]`: 适配器 Class
### _abstract property_ `type`
驱动类型名称
### _abstract property_ `server_app`
驱动 APP 对象
### _abstract property_ `asgi`
驱动 ASGI 对象
### _abstract property_ `logger`
驱动专属 logger 日志记录器
### _property_ `bots`
* **类型**
`Dict[str, Bot]`
* **说明**
获取当前所有已连接的 Bot
### _abstract_ `on_startup(func)`
注册一个在驱动启动时运行的函数
### _abstract_ `on_shutdown(func)`
注册一个在驱动停止时运行的函数
### _abstract_ `run(host=None, port=None, *args, **kwargs)`
* **说明**
启动驱动框架
* **参数**
* `host: Optional[str]`: 驱动绑定 IP
* `post: Optional[int]`: 驱动绑定端口
* `*args`
* `**kwargs`
### _abstract async_ `_handle_http()`
用于处理 HTTP 类型请求的函数
### _abstract async_ `_handle_ws_reverse()`
用于处理 WebSocket 类型请求的函数
## _class_ `BaseWebSocket`
基类:`object`
WebSocket 连接封装,统一接口方便外部调用。
### _abstract_ `__init__(websocket)`
* **参数**
* `websocket: Any`: WebSocket 连接对象
### _property_ `websocket`
WebSocket 连接对象
### _abstract property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _abstract async_ `accept()`
接受 WebSocket 连接请求
### _abstract async_ `close(code)`
关闭 WebSocket 连接请求
### _abstract async_ `receive()`
接收一条 WebSocket 信息
### _abstract async_ `send(data)`
发送一条 WebSocket 信息

View File

@@ -0,0 +1,118 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.fastapi 模块
## FastAPI 驱动适配
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)
## _class_ `Driver`
基类:[`nonebot.drivers.BaseDriver`](README.md#nonebot.drivers.BaseDriver)
FastAPI 驱动框架
* **上报地址**
* `/{adapter name}/`: HTTP POST 上报
* `/{adapter name}/http/`: HTTP POST 上报
* `/{adapter name}/ws`: WebSocket 上报
* `/{adapter name}/ws/`: WebSocket 上报
### _property_ `type`
驱动名称: `fastapi`
### _property_ `server_app`
`FastAPI APP` 对象
### _property_ `asgi`
`FastAPI APP` 对象
### _property_ `logger`
fastapi 使用的 logger
### `on_startup(func)`
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `on_shutdown(func)`
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 FastAPI
### _async_ `_handle_http(adapter, request, data=Body(Ellipsis))`
用于处理 HTTP 类型请求的函数
### _async_ `_handle_ws_reverse(adapter, websocket)`
用于处理 WebSocket 类型请求的函数
## _class_ `WebSocket`
基类:[`nonebot.drivers.BaseWebSocket`](README.md#nonebot.drivers.BaseWebSocket)
### _property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _async_ `accept()`
接受 WebSocket 连接请求
### _async_ `close(code=1000)`
关闭 WebSocket 连接请求
### _async_ `receive()`
接收一条 WebSocket 信息
### _async_ `send(data)`
发送一条 WebSocket 信息

View File

@@ -0,0 +1,182 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.exception 模块
## 异常
下列文档中的异常是所有 NoneBot 运行时可能会抛出的。
这些异常并非所有需要用户处理,在 NoneBot 内部运行时被捕获,并进行对应操作。
## _exception_ `NoneBotException`
基类:`Exception`
* **说明**
所有 NoneBot 发生的异常基类。
## _exception_ `IgnoredException`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
* **参数**
* `reason`: 忽略事件的原因
## _exception_ `PausedException`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 结束当前 `Handler` 并等待下一条消息后继续下一个 `Handler`
可用于用户输入新信息。
* **用法**
可以在 `Handler` 中通过 `Matcher.pause()` 抛出。
## _exception_ `RejectedException`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 结束当前 `Handler` 并等待下一条消息后重新运行当前 `Handler`
可用于用户重新输入。
* **用法**
可以在 `Handler` 中通过 `Matcher.reject()` 抛出。
## _exception_ `FinishedException`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 结束当前 `Handler` 且后续 `Handler` 不再被运行。
可用于结束用户会话。
* **用法**
可以在 `Handler` 中通过 `Matcher.finish()` 抛出。
## _exception_ `StopPropagation`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 终止事件向下层传播。
* **用法**
`Matcher.block == True` 时抛出。
## _exception_ `RequestDenied`
基类:`nonebot.exception.NoneBotException`
* **说明**
Bot 连接请求不合法。
* **参数**
* `status_code: int`: HTTP 状态码
* `reason: str`: 拒绝原因
## _exception_ `AdapterException`
基类:`nonebot.exception.NoneBotException`
* **说明**
代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception`
* **参数**
* `adapter_name: str`: 标识 adapter
## _exception_ `ApiNotAvailable`
基类:`nonebot.exception.AdapterException`
* **说明**
在 API 连接不可用时抛出。
## _exception_ `NetworkError`
基类:`nonebot.exception.AdapterException`
* **说明**
在网络出现问题时抛出,如: API 请求地址不正确, API 请求无返回或返回状态非正常等。
## _exception_ `ActionFailed`
基类:`nonebot.exception.AdapterException`
* **说明**
API 请求成功返回数据,但 API 操作失败。

View File

@@ -0,0 +1,55 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.log 模块
## 日志
NoneBot 使用 [loguru](https://github.com/Delgan/loguru) 来记录日志信息。
自定义 logger 请参考 [loguru](https://github.com/Delgan/loguru) 文档。
## `logger`
* **说明**
NoneBot 日志记录器对象。
* **默认信息**
* 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
* 等级: `DEBUG` / `INFO` ,根据 config 配置改变
* 输出: 输出至 stdout
* **用法**
```python
from nonebot.log import logger
```
## _class_ `LoguruHandler`
基类:`logging.Handler`
### `emit(record)`
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so
raises a NotImplementedError.

View File

@@ -0,0 +1,452 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.matcher 模块
## 事件响应器
该模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行 对话 。
## `matchers`
* **类型**
`Dict[int, List[Type[Matcher]]]`
* **说明**
用于存储当前所有的事件响应器
## _class_ `Matcher`
基类:`object`
事件响应器类
### `module`
* **类型**
`Optional[str]`
* **说明**
事件响应器所在模块名称
### `type`
* **类型**
`str`
* **说明**
事件响应器类型
### `rule`
* **类型**
`Rule`
* **说明**
事件响应器匹配规则
### `permission`
* **类型**
`Permission`
* **说明**
事件响应器触发权限
### `priority`
* **类型**
`int`
* **说明**
事件响应器优先级
### `block`
* **类型**
`bool`
* **说明**
事件响应器是否阻止事件传播
### `temp`
* **类型**
`bool`
* **说明**
事件响应器是否为临时
### `expire_time`
* **类型**
`Optional[datetime]`
* **说明**
事件响应器过期时间点
### `_default_state`
* **类型**
`dict`
* **说明**
事件响应器默认状态
### `_default_parser`
* **类型**
`Optional[ArgsParser]`
* **说明**
事件响应器默认参数解析函数
### `__init__()`
实例化 Matcher 以便运行
### `handlers`
* **类型**
`List[Handler]`
* **说明**
事件响应器拥有的事件处理函数列表
### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
* **说明**
创建一个新的事件响应器,并存储至 [matchers](#matchers)
* **参数**
* `type_: str`: 事件响应器类型,与 `event.type` 一致时触发,空字符串表示任意
* `rule: Optional[Rule]`: 匹配规则
* `permission: Optional[Permission]`: 权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器,即触发一次后删除
* `priority: int`: 响应优先级
* `block: bool`: 是否阻止事件向更低优先级的响应器传播
* `module: Optional[str]`: 事件响应器所在模块名称
* `default_state: Optional[dict]`: 默认状态 `state`
* `expire_time: Optional[datetime]`: 事件响应器最终有效时间点,过时即被删除
* **返回**
* `Type[Matcher]`: 新的事件响应器类
### _async classmethod_ `check_perm(bot, event)`
* **说明**
检查是否满足触发权限
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: 上报事件
* **返回**
* `bool`: 是否满足权限
### _async classmethod_ `check_rule(bot, event, state)`
* **说明**
检查是否满足匹配规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: 上报事件
* `state: dict`: 当前状态
* **返回**
* `bool`: 是否满足匹配规则
### _classmethod_ `args_parser(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认参数解析函数
* **参数**
* `func: ArgsParser`: 参数解析函数
### _classmethod_ `handle()`
* **说明**
装饰一个函数来向事件响应器直接添加一个处理函数
* **参数**
*
### _classmethod_ `receive()`
* **说明**
装饰一个函数来指示 NoneBot 在接收用户新的一条消息后继续运行该函数
* **参数**
*
### _classmethod_ `got(key, prompt=None, args_parser=None)`
* **说明**
装饰一个函数来指示 NoneBot 当要获取的 `key` 不存在时接收用户新的一条消息并经过 `ArgsParser` 处理后再运行该函数,如果 `key` 已存在则直接继续运行
* **参数**
* `key: str`: 参数名
* `prompt: Optional[Union[str, Message, MessageSegment]]`: 在参数不存在时向用户发送的消息
* `args_parser: Optional[ArgsParser]`: 可选参数解析函数,空则使用默认解析函数
### _async classmethod_ `send(message, **kwargs)`
* **说明**
发送一条消息给当前交互用户
* **参数**
* `message: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `finish(message=None, **kwargs)`
* **说明**
发送一条消息给当前交互用户并结束当前事件响应器
* **参数**
* `message: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `pause(prompt=None, **kwargs)`
* **说明**
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续下一个处理函数
* **参数**
* `prompt: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `reject(prompt=None, **kwargs)`
* **说明**
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后重新运行当前处理函数
* **参数**
* `prompt: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api

View File

@@ -0,0 +1,143 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.message 模块
## 事件处理
NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供了多个插槽以进行事件的预处理等。
## `event_preprocessor(func)`
* **说明**
事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
* **参数**
事件预处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
## `event_postprocessor(func)`
* **说明**
事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
* **参数**
事件后处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前事件运行前 State
## `run_preprocessor(func)`
* **说明**
运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。
* **参数**
运行预处理函数接收四个参数。
* `matcher: Matcher`: 当前要运行的事件响应器
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
## `run_postprocessor(func)`
* **说明**
运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。
* **参数**
运行后处理函数接收五个参数。
* `matcher: Matcher`: 运行完毕的事件响应器
* `exception: Optional[Exception]`: 事件响应器运行错误(如果存在)
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
## _async_ `handle_event(bot, event)`
* **说明**
处理一个事件。调用该函数以实现分发事件。
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* **示例**
```python
import asyncio
asyncio.create_task(handle_event(bot, event))
```

View File

@@ -0,0 +1,266 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot 模块
## 快捷导入
为方便使用,`nonebot` 模块从子模块导入了部分内容
* `on_message` => `nonebot.plugin.on_message`
* `on_notice` => `nonebot.plugin.on_notice`
* `on_request` => `nonebot.plugin.on_request`
* `on_metaevent` => `nonebot.plugin.on_metaevent`
* `on_startswith` => `nonebot.plugin.on_startswith`
* `on_endswith` => `nonebot.plugin.on_endswith`
* `on_keyword` => `nonebot.plugin.on_keyword`
* `on_command` => `nonebot.plugin.on_command`
* `on_regex` => `nonebot.plugin.on_regex`
* `CommandGroup` => `nonebot.plugin.CommandGroup`
* `MatcherGroup` => `nonebot.plugin.MatcherGroup`
* `load_plugin` => `nonebot.plugin.load_plugin`
* `load_plugins` => `nonebot.plugin.load_plugins`
* `load_builtin_plugins` => `nonebot.plugin.load_builtin_plugins`
* `get_plugin` => `nonebot.plugin.get_plugin`
* `get_loaded_plugins` => `nonebot.plugin.get_loaded_plugins`
* `export` => `nonebot.plugin.export`
* `require` => `nonebot.plugin.require`
## `get_driver()`
* **说明**
获取全局 Driver 对象。可用于在计划任务的回调中获取当前 Driver 对象。
* **返回**
* `Driver`: 全局 Driver 对象
* **异常**
* `ValueError`: 全局 Driver 对象尚未初始化 (nonebot.init 尚未调用)
* **用法**
```python
driver = nonebot.get_driver()
```
## `get_app()`
* **说明**
获取全局 Driver 对应 Server App 对象。
* **返回**
* `Any`: Server App 对象
* **异常**
* `ValueError`: 全局 Driver 对象尚未初始化 (nonebot.init 尚未调用)
* **用法**
```python
app = nonebot.get_app()
```
## `get_asgi()`
* **说明**
获取全局 Driver 对应 Asgi 对象。
* **返回**
* `Any`: Asgi 对象
* **异常**
* `ValueError`: 全局 Driver 对象尚未初始化 (nonebot.init 尚未调用)
* **用法**
```python
asgi = nonebot.get_asgi()
```
## `get_bots()`
* **说明**
获取所有通过 ws 连接 NoneBot 的 Bot 对象。
* **返回**
* `Dict[str, Bot]`: 一个以字符串 ID 为键Bot 对象为值的字典
* **异常**
* `ValueError`: 全局 Driver 对象尚未初始化 (nonebot.init 尚未调用)
* **用法**
```python
bots = nonebot.get_bots()
```
## `init(*, _env_file=None, **kwargs)`
* **说明**
初始化 NoneBot 以及 全局 Driver 对象。
NoneBot 将会从 .env 文件中读取环境信息,并使用相应的 env 文件配置。
你也可以传入自定义的 _env_file 来指定 NoneBot 从该文件读取配置。
* **参数**
* `_env_file: Optional[str]`: 配置文件名,默认从 .env.{env_name} 中读取配置
* `**kwargs`: 任意变量,将会存储到 Config 对象里
* **返回**
* `None`
* **用法**
```python
nonebot.init(database=Database(...))
```
## `run(host=None, port=None, *args, **kwargs)`
* **说明**
启动 NoneBot即运行全局 Driver 对象。
* **参数**
* `host: Optional[str]`: 主机名IP若不传入则使用配置文件中指定的值
* `port: Optional[int]`: 端口,若不传入则使用配置文件中指定的值
* `*args`: 传入 Driver.run 的位置参数
* `**kwargs`: 传入 Driver.run 的命名参数
* **返回**
* `None`
* **用法**
```python
nonebot.run(host="127.0.0.1", port=8080)
```

View File

@@ -0,0 +1,121 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.permission 模块
## 权限
每个 `Matcher` 拥有一个 `Permission` ,其中是 **异步** `PermissionChecker` 的集合,只要有一个 `PermissionChecker` 检查结果为 `True` 时就会继续运行。
:::tip 提示
`PermissionChecker` 既可以是 async function 也可以是 sync function
:::
## `MESSAGE`
* **说明**: 匹配任意 `message` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 message type 的 Matcher。
## `NOTICE`
* **说明**: 匹配任意 `notice` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 notice type 的 Matcher。
## `REQUEST`
* **说明**: 匹配任意 `request` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 request type 的 Matcher。
## `METAEVENT`
* **说明**: 匹配任意 `meta_event` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 meta_event type 的 Matcher。
## `USER(*user, perm=<nonebot.permission.Permission object>)`
* **说明**
在白名单内且满足 perm
* **参数**
* `*user: int`: 白名单
* `perm: Permission`: 需要同时满足的权限
## `PRIVATE`
* **说明**: 匹配任意私聊消息类型事件
## `PRIVATE_FRIEND`
* **说明**: 匹配任意好友私聊消息类型事件
## `PRIVATE_GROUP`
* **说明**: 匹配任意群临时私聊消息类型事件
## `PRIVATE_OTHER`
* **说明**: 匹配任意其他私聊消息类型事件
## `GROUP`
* **说明**: 匹配任意群聊消息类型事件
## `GROUP_MEMBER`
* **说明**: 匹配任意群员群聊消息类型事件
:::warning 警告
该权限通过 event.sender 进行判断且不包含管理员以及群主!
:::
## `GROUP_ADMIN`
* **说明**: 匹配任意群管理员群聊消息类型事件
## `GROUP_OWNER`
* **说明**: 匹配任意群主群聊消息类型事件
## `SUPERUSER`
* **说明**: 匹配任意超级用户消息类型事件
## `EVERYBODY`
* **说明**: 匹配任意消息类型事件

File diff suppressed because it is too large Load Diff

210
archive/2.0.0a7/api/rule.md Normal file
View File

@@ -0,0 +1,210 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.rule 模块
## 规则
每个事件响应器 `Matcher` 拥有一个匹配规则 `Rule` ,其中是 **异步** `RuleChecker` 的集合,只有当所有 `RuleChecker` 检查结果为 `True` 时继续运行。
:::tip 提示
`RuleChecker` 既可以是 async function 也可以是 sync function但在最终会被 `nonebot.utils.run_sync` 转换为 async function
:::
## _class_ `Rule`
基类:`object`
* **说明**
`Matcher` 规则类,当事件传递时,在 `Matcher` 运行前进行检查。
* **示例**
```python
Rule(async_function) & sync_function
# 等价于
from nonebot.utils import run_sync
Rule(async_function, run_sync(sync_function))
```
### `__init__(*checkers)`
* **参数**
* `*checkers: Callable[[Bot, Event, dict], Awaitable[bool]]`: **异步** RuleChecker
### `checkers`
* **说明**
存储 `RuleChecker`
* **类型**
* `Set[Callable[[Bot, Event, dict], Awaitable[bool]]]`
### _async_ `__call__(bot, event, state)`
* **说明**
检查是否符合所有规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: dict`: 当前 State
* **返回**
* `bool`
## `startswith(msg)`
* **说明**
匹配消息开头
* **参数**
* `msg: str`: 消息开头字符串
## `endswith(msg)`
* **说明**
匹配消息结尾
* **参数**
* `msg: str`: 消息结尾字符串
## `keyword(*keywords)`
* **说明**
匹配消息关键词
* **参数**
* `*keywords: str`: 关键词
## `command(*cmds)`
* **说明**
命令形式匹配,根据配置里提供的 `command_start`, `command_sep` 判断消息是否为命令。
可以通过 `state["_prefix"]["command"]` 获取匹配成功的命令(例:`("test",)`),通过 `state["_prefix"]["raw_command"]` 获取匹配成功的原始命令文本(例:`"/test"`)。
* **参数**
* `*cmds: Union[str, Tuple[str, ...]]`: 命令内容
* **示例**
使用默认 `command_start`, `command_sep` 配置
命令 `("test",)` 可以匹配:`/test` 开头的消息
命令 `("test", "sub")` 可以匹配”`/test.sub` 开头的消息
:::tip 提示
命令内容与后续消息间无需空格!
:::
## `regex(regex, flags=0)`
* **说明**
根据正则表达式进行匹配。
可以通过 `state["_matched"]` 获取正则表达式匹配成功的文本。
* **参数**
* `regex: str`: 正则表达式
* `flags: Union[int, re.RegexFlag]`: 正则标志
:::tip 提示
正则表达式匹配使用 search 而非 match如需从头匹配请使用 `r"^xxx"` 来确保匹配开头
:::
## `to_me()`
* **说明**
通过 `event.to_me` 判断消息是否是发送给机器人
* **参数**
*

View File

@@ -0,0 +1,300 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.typing 模块
## 类型
下面的文档中,「类型」部分使用 Python 的 Type Hint 语法,见 [PEP 484](https://www.python.org/dev/peps/pep-0484/)、[PEP 526](https://www.python.org/dev/peps/pep-0526/) 和 [typing](https://docs.python.org/3/library/typing.html)。
除了 Python 内置的类型,下面还出现了如下 NoneBot 自定类型,实际上它们是 Python 内置类型的别名。
以下类型均可从 nonebot.typing 模块导入。
## `Driver`
* **类型**
`BaseDriver`
* **说明**
所有 Driver 的基类。
## `WebSocket`
* **类型**
`BaseWebSocket`
* **说明**
所有 WebSocket 的基类。
## `Bot`
* **类型**
`BaseBot`
* **说明**
所有 Bot 的基类。
## `Event`
* **类型**
`BaseEvent`
* **说明**
所有 Event 的基类。
## `Message`
* **类型**
`BaseMessage`
* **说明**
所有 Message 的基类。
## `MessageSegment`
* **类型**
`BaseMessageSegment`
* **说明**
所有 MessageSegment 的基类。
## `EventPreProcessor`
* **类型**
`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件预处理函数 EventPreProcessor 类型
## `EventPostProcessor`
* **类型**
`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件预处理函数 EventPostProcessor 类型
## `RunPreProcessor`
* **类型**
`Callable[[Matcher, Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件响应器运行前预处理函数 RunPreProcessor 类型
## `RunPostProcessor`
* **类型**
`Callable[[Matcher, Optional[Exception], Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
事件响应器运行前预处理函数 RunPostProcessor 类型,第二个参数为运行时产生的错误(如果存在)
## `Matcher`
* **类型**
`Matcher`
* **说明**
Matcher 即响应事件的处理类。通过 Rule 判断是否响应事件,运行 Handler。
## `MatcherGroup`
* **类型**
`MatcherGroup`
* **说明**
MatcherGroup 为 Matcher 的集合。可以共享 Handler。
## `Rule`
* **类型**
`Rule`
* **说明**
Rule 即判断是否响应事件的处理类。内部存储 RuleChecker ,返回全为 True 则响应事件。
## `RuleChecker`
* **类型**
`Callable[[Bot, Event, dict], Union[bool, Awaitable[bool]]]`
* **说明**
RuleChecker 即判断是否响应事件的处理函数。
## `Permission`
* **类型**
`Permission`
* **说明**
Permission 即判断是否响应消息的处理类。内部存储 PermissionChecker ,返回只要有一个 True 则响应消息。
## `PermissionChecker`
* **类型**
`Callable[[Bot, Event], Union[bool, Awaitable[bool]]]`
* **说明**
RuleChecker 即判断是否响应消息的处理函数。
## `Handler`
* **类型**
`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
Handler 即事件的处理函数。
## `ArgsParser`
* **类型**
`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
ArgsParser 即消息参数解析函数,在 Matcher.got 获取参数时被运行。

View File

@@ -0,0 +1,60 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.utils 模块
## `escape_tag(s)`
* **说明**
用于记录带颜色日志时转义 `<tag>` 类型特殊标签
* **参数**
* `s: str`: 需要转义的字符串
* **返回**
* `str`
## `run_sync(func)`
* **说明**
一个用于包装 sync function 为 async function 的装饰器
* **参数**
* `func: Callable[..., Any]`: 被装饰的同步函数
* **返回**
* `Callable[..., Awaitable[Any]]`
## _class_ `DataclassEncoder`
* **说明**
在JSON序列化 `Message` (List[Dataclass]) 时使用的 `JSONEncoder`

View File

@@ -0,0 +1,33 @@
# 概览
<!-- :::tip 提示
如果在阅读本文档时遇到难以理解的词汇,请随时查阅 [术语表](../glossary.md) 或使用 [Google 搜索](https://www.google.com/)
::: -->
:::tip 提示
初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。
:::
## 简介
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。
除了起到解析事件的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
得益于 Python 的 [asyncio](https://docs.python.org/3/library/asyncio.html) 机制NoneBot 处理事件的吞吐量有了很大的保障,再配合 WebSocket 通信方式也是最建议的通信方式NoneBot 的性能可以达到 HTTP 通信方式的两倍以上,相较于传统同步 I/O 的 HTTP 通信,更是有质的飞跃。
需要注意的是NoneBot 仅支持 **Python 3.7+**
## 特色
NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义**,并且可以作为插件进行**替换/添加**
- 提供使用简易的脚手架
- 提供丰富的官方插件
- 提供可添加/替换的驱动以及协议选项
- 基于异步 I/O
- 同时支持 HTTP 和反向 WebSocket 通信方式
- 支持多个机器人账号负载均衡
- 提供直观的交互式会话接口
- 提供可自定义的权限控制机制
- 多种方式渲染要发送的消息内容,使对话足够自然

View File

@@ -0,0 +1,68 @@
# 基本配置
到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。
在上一章节中,我们创建了默认的项目结构,其中 `.env`, `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。
:::danger 警告
请勿将敏感信息写入配置文件并提交至开源仓库!
:::
## .env 文件
NoneBot 在启动时将会从系统环境变量或者 `.env` 文件中寻找变量 `ENVIRONMENT` (大小写不敏感),默认值为 `prod`
这将引导 NoneBot 从系统环境变量或者 `.env.{ENVIRONMENT}` 文件中进一步加载具体配置。
现在,我们在 `.env` 文件中写入当前环境信息
```bash
# .env
ENVIRONMENT=dev
```
## .env.\* 文件
详细配置文件,使用 [pydantic](https://pydantic-docs.helpmanual.io/) 加载配置。在 NoneBot 初始化时可以指定忽略 `.env` 中的环境信息转而加载某个配置文件: `nonebot.init(_env_file=".env.dev")`
:::warning 提示
由于 `pydantic` 使用 JSON 加载配置项,请确保配置项值为 JSON 能够解析的数据。如果 JSON 解析失败将作为字符串处理。
:::
示例及说明:
```bash
HOST=0.0.0.0 # 配置 NoneBot 监听的 IP/主机名
PORT=8080 # 配置 NoneBot 监听的端口
DEBUG=true # 开启 debug 模式 **请勿在生产环境开启**
SUPERUSERS=["123456789", "987654321"] # 配置 NoneBot 超级用户
NICKNAME=["awesome", "bot"] # 配置机器人的昵称
COMMAND_START=["/", ""] # 配置命令起始字符
COMMAND_SEP=["."] # 配置命令分割字符
# Custom Configs
CUSTOM_CONFIG1="config in env file"
CUSTOM_CONFIG2= # 留空则从系统环境变量读取,如不存在则为空字符串
```
详细的配置项参考 [Config Reference](../api/config.md) 。
## bot.py 文件
配置项也可以在 NoneBot 初始化时传入。此处可以传入任意合法 Python 变量。当然也可以在初始化完成后修改或新增。
示例:
```python
# bot.py
import nonebot
nonebot.init(custom_config3="config on init")
config = nonebot.get_driver().config
config.custom_config3 = "changed after init"
config.custom_config4 = "new config after init"
```
## 优先级
`bot.py init` > `env file` > `system env`

View File

@@ -0,0 +1,159 @@
# 事件处理
在上一章中,我们已经注册了事件响应器,现在我们可以正式编写事件处理逻辑了!
## [事件处理函数](../api/typing.md#handler)
```python{1,2,8,9}
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: dict):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
city_weather = await get_weather(city)
await weather.finish(city_weather)
```
在之前的样例中,我们定义了两个函数 `handle_first_receive`, `handle_city`,他们被事件响应器的装饰器装饰从而成为事件响应器的事件处理函数。
:::tip 提示
在事件响应器中,事件处理函数是**顺序**执行的!
:::
### 添加一个事件处理函数
事件响应器提供了三种装饰事件处理函数的装饰器,分别是:
1. [handle()](../api/matcher.md#classmethod-handle)
2. [receive()](../api/matcher.md#classmethod-receive)
3. [got(key, prompt, args_parser)](../api/matcher.md#classmethod-got-key-prompt-none-args-parser-none)
#### handle()
简单的为事件响应器添加一个事件处理函数,这个函数将会在上一个处理函数正常返回执行完毕后立即执行。
#### receive()
指示 NoneBot 接收一条新的用户消息后继续执行该处理函数。此时函数将会接收到新的消息而非前一条消息,之前相关信息可以存储在 state 中。
特别的,当装饰的函数前没有其他事件处理函数,那么 `receive()` 不会接收一条新的消息而是直接使用第一条接收到的消息。
#### got(key, prompt, args_parser)
指示 NoneBot 当 `state` 中不存在 `key` 时向用户发送 `prompt` 等待用户回复并赋值给 `state[key]`。
`prompt` 可以为 `str`, `Message`, `MessageSegment`,若为空则不会向用户发送,若不为空则会在 format 之后发送,即 `prompt.format(**state)`,注意对 `{}` 进行转义。示例:
```python
@matcher.receive()
async def handle(bot: Bot, event: Event, state: dict):
state["key"] = "hello"
@matcher.got("key2", prompt="{key}!")
async def handle2(bot: Bot, event: Event, state: dict):
pass
```
`args_parser` 为参数处理函数,在这里传入一个新的函数以覆盖默认的参数处理。详情参照 [args_parser](#参数处理函数-args-parser)
特别的,这些装饰器都可以套娃使用:
```python
@matcher.got("key1")
@matcher.got("key2")
async def handle(bot: Bot, event: Event, state: dict):
pass
```
### 事件处理函数参数
事件处理函数类型为 `Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]` 。
参数分别为:
1. [nonebot.typing.Bot](../api/typing.md#bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
2. [nonebot.typing.Event](../api/typing.md#event): 即上报事件对象,可以获取到上报的所有信息。
3. `state`: 状态字典,可以存储任意的信息,其中还包含一些特殊的值以获取 NoneBot 内部处理时的一些信息,如:
- `state["_current_key"]`: 存储当前 `got` 获取的参数名
- `state["_prefix"]`, `state["_suffix"]`: 存储当前 TRIE 匹配的前缀/后缀,可以通过该值获取用户命令的原始命令
### 参数处理函数 args_parser
在使用 `got` 获取用户输入参数时需要对用户的消息进行处理以转换为我们所需要的信息。在默认情况下NoneBot 会把用户的消息字符串原封不动的赋值给 `state[key]` 。可以通过以下两种方式修改默认处理逻辑:
- `@matcher.args_parser` 装饰器:直接装饰一个函数作为参数处理器
- `got(key, prompt, args_parser)`:直接把函数作为参数传入
参数处理函数类型为:`Callable[[Bot, Event, dict], Union[Awaitable[None], Awaitable[NoReturn]]]`,即:
```python
async def parser(bot: Bot, event: Event, state: dict):
state[state["_current_key"]] = str(event.message)
```
特别的,`state["_current_key"]` 中存储了当前获取的参数名
### 逻辑控制
NoneBot 也为事件处理函数提供了一些便捷的逻辑控制函数:
#### `matcher.send`
这个函数用于发送一条消息给当前交互的用户。~~其实这并不是一个逻辑控制函数,只是不知道放在哪里……~~
#### `matcher.pause`
这个函数用于结束当前事件处理函数,强制接收一条新的消息再运行**下一个消息处理函数**。
#### `matcher.reject`
这个函数用于结束当前事件处理函数,强制接收一条新的消息再**再次运行当前消息处理函数**。常用于用户输入信息不符合预期。
#### `matcher.finish`
这个函数用于直接结束当前事件处理。
以上三个函数都拥有一个参数 `message` / `prompt`,用于向用户发送一条消息。以及 `**kwargs` 直接传递给 `bot.send` 的额外参数。
## 常用事件处理结构
```python
matcher = on_command("test")
# 修改默认参数处理
@matcher.args_parser
async def parse(bot: Bot, event: Event, state: dict):
print(state["_current_key"], ":", str(event.message))
state[state["_current_key"]] = str(event.message)
@matcher.handle()
async def first_receive(bot: Bot, event: Event, state: dict):
# 获取用户原始命令,如:/test
print(state["_prefix"]["raw_command"])
# 处理用户输入参数,如:/test arg1 arg2
raw_args = str(event.message).strip()
if raw_args:
arg_list = raw_args.split()
# 将参数存入state以阻止后续再向用户询问参数
state["arg1"] = arg_list[0]
@matcher.got("arg1", prompt="参数?")
async def arg_handle(bot: Bot, event: Event, state: dict):
# 在这里对参数进行验证
if state["arg1"] not in ["allow", "list"]:
await matcher.reject("参数不正确!请重新输入")
# 发送一些信息
await bot.send(event, "message")
await matcher.send("message")
await matcher.finish("message")
```

View File

@@ -0,0 +1,144 @@
# 注册事件响应器
好了,现在插件已经创建完毕,我们可以开始编写实际代码了,下面将以一个简易单文件天气查询插件为例。
在插件目录下 `weather.py` 中添加如下代码:
```python
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event
weather = on_command("天气", rule=to_me(), priority=5)
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
args = str(event.message).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: dict):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
city_weather = await get_weather(city)
await weather.finish(city_weather)
async def get_weather(city: str):
return f"{city}的天气是..."
```
为了简单起见,我们在这里的例子中没有接入真实的天气数据,但要接入也非常简单,你可以使用中国天气网、和风天气等网站提供的 API。
接下来我们来说明这段代码是如何工作的。
:::tip 提示
从这里开始,你需要对 Python 的 asyncio 编程有所了解,因为 NoneBot 是完全基于 asyncio 的,具体可以参考 [廖雪峰的 Python 教程](https://www.liaoxuefeng.com/wiki/1016959663602400/1017959540289152)
:::
## [事件响应器](../api/matcher.md)
```python{4}
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.permission import Permission
weather = on_command("天气", rule=to_me(), permission=Permission(), priority=5)
```
在上方代码中,我们注册了一个事件响应器 `Matcher`,它由几个部分组成:
1. `on_command` 注册一个消息类型的命令处理器
2. `"天气"` 指定 command 参数 - 命令名
3. `rule` 补充事件响应器的匹配规则
4. `priority` 事件响应器优先级
5. `block` 是否阻止事件传递
其他详细配置可以参考 API 文档,下面我们详细说明各个部分:
### 事件响应器类型 type
事件响应器类型其实就是对应事件的类型 `Event.type` NoneBot 提供了一个基础类型事件响应器 `on()` 以及一些其他内置的事件响应器。
以下所有类型的事件响应器都是由 `on(type, rule)` 的形式进行了简化封装。
- `on("事件类型")`: 基础事件响应器,第一个参数为事件类型,空字符串表示不限
- `on_metaevent()` ~ `on("meta_event")`: 元事件响应器
- `on_message()` ~ `on("message")`: 消息事件响应器
- `on_request()` ~ `on("request")`: 请求事件响应器
- `on_notice()` ~ `on("notice")`: 通知事件响应器
- `on_startswith(str)` ~ `on("message", startswith(str))`: 消息开头匹配响应器,参考 [startswith](../api/rule.md#startswith-msg)
- `on_endswith(str)` ~ `on("message", endswith(str))`: 消息结尾匹配响应器,参考 [endswith](../api/rule.md#endswith-msg)
- `on_keyword(set)` ~ `on("message", keyword(str))`: 消息关键词匹配响应器,参考 [keyword](../api/rule.md#keyword-keywords)
- `on_command(str|tuple)` ~ `on("message", command(str|tuple))`: 命令响应器,参考 [command](../api/rule.md#command-cmds)
- `on_regex(pattern_str)` ~ `on("message", regex(pattern_str))`: 正则匹配处理器,参考 [regex](../api/rule.md#regex-regex-flags-0)
### 匹配规则 rule
事件响应器的匹配规则即 `Rule`,详细内容在下方介绍。[直达](#自定义-rule)
### 优先级 priority
事件响应器的优先级代表事件响应器的执行顺序,同一优先级的事件响应器会 **同时执行!**,优先级数字**越小**越先响应!优先级请从 `1` 开始排序!
:::tip 提示
使用 `nonebot-test` 可以看到当前所有事件响应器的执行流程,有助理解事件响应流程!
```bash
pip install nonebot2[test]
```
:::
### 阻断 block
当有任意事件响应器发出了阻止事件传递信号时,该事件将不再会传递给下一优先级,直接结束处理。
NoneBot 内置的事件响应器中,所有 `message` 类的事件响应器默认会阻断事件传递,其他则不会。
## 自定义 rule
rule 的出现使得 nonebot 对事件的响应可以非常自由nonebot 内置了一些规则:
- [startswith(msg)](../api/rule.md#startswith-msg)
- [endswith(msg)](../api/rule.md#endswith-msg)
- [keyword(\*keywords)](../api/rule.md#keyword-keywords)
- [command(\*cmds)](../api/rule.md#command-cmds)
- [regex(regex, flag)](../api/rule.md#regex-regex-flags-0)
以上规则都是返回类型为 `Rule` 的函数,`Rule` 由非负个 `RuleChecker` 组成,当所有 `RuleChecker` 返回 `True` 时匹配成功。这些 `Rule`, `RuleChecker` 的形式如下:
```python
from nonebot.rule import Rule
async def async_checker(bot: Bot, event: Event, state: dict) -> bool:
return True
def sync_checker(bot: Bot, event: Event, state: dict) -> bool:
return True
def check(arg1, args2):
async def _checker(bot: Bot, event: Event, state: dict) -> bool:
return bool(arg1 + arg2)
return Rule(_check)
```
`Rule` 和 `RuleChecker` 之间可以使用 `&` 互相组合:
```python
from nonebot.rule import Rule
Rule(async_checker1) & sync_checker & async_checker2
```
**_请勿将事件处理的逻辑写入 `rule` 中这会使得事件处理返回奇怪的响应。_**
:::danger 警告
`Rule(*checkers)` 只接受 async function或使用 `nonebot.utils.run_sync` 自行包裹 sync function。在使用 `&` 时NoneBot 会自动包裹 sync function
:::

View File

@@ -0,0 +1,119 @@
# 创建插件
如果之前使用 `nb-cli` 生成了项目结构,那我们已经有了一个空的插件目录 `Awesome-Bot/awesome_bot/plugins`,并且它已在 `bot.py` 中被加载,我们现在可以开始创建插件了!
使用 `nb-cli` 创建包形式插件,或自行创建文件(夹)
```bash
nb plugin new
```
插件通常有两种形式,下面分别介绍
## 单文件形式
在插件目录下创建名为 `foo.py` 的 Python 文件,暂时留空,此时目录结构如下:
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── awesome_bot
│ └── plugins
│ └── `foo.py`
├── .env
├── .env.dev
├── .env.prod
├── .gitignore
├── bot.py
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
:::
<!-- prettier-ignore-end -->
这个时候它已经可以被称为一个插件了,尽管它还什么都没做。
## 包形式(推荐)
在插件目录下创建文件夹 `foo`,并在该文件夹下创建文件 `__init__.py`,此时目录结构如下:
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── awesome_bot
│ └── plugins
│ └── `foo`
│ └── `__init__.py`
├── .env
├── .env.dev
├── .env.prod
├── .gitignore
├── bot.py
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
:::
<!-- prettier-ignore-end -->
这个时候 `foo` 就是一个合法的 Python 包了,同时也是合法的 NoneBot 插件,插件内容可以在 `__init__.py` 中编写。
### 推荐结构(仅供参考)
<!-- prettier-ignore-start -->
:::vue
foo
├── `__init__.py`
├── `config.py`
├── `data_source.py`
└── `model.py`
:::
<!-- prettier-ignore-end -->
#### \_\_init\_\_.py
在该文件中编写各类事件响应及处理逻辑。
#### config.py
在该文件中使用 `pydantic` 定义插件所需要的配置项以及类型。
示例:
```python
from pydantic import BaseSetting
class Config(BaseSetting):
# plugin custom config
plugin_setting: str = "default"
class Config:
extra = "ignore"
```
并在 `__init__.py` 文件中添加以下行
```python
import nonebot
from .config import Config
global_config = nonebot.get_driver().config
plugin_config = Config(**global_config.dict())
```
此时就可以通过 `plugin_config.plugin_setting` 获取到插件所需要的配置项了。
#### data_source.py
在该文件中编写数据获取函数。
:::warning 警告
数据获取应尽量使用**异步**处理!例如使用 [httpx](https://www.python-httpx.org/) 而非 [requests](https://requests.readthedocs.io/en/master/)
:::
#### model.py
在该文件中编写数据库模型。

View File

@@ -0,0 +1,51 @@
# 创建一个完整的项目
上一章中我们已经运行了一个最小的 NoneBot 实例,在这一章,我们将从零开始一个完整的项目。
## 目录结构
首先,我们可以使用 `nb-cli` 或者自行创建完整的项目目录:
```bash
nb create
```
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
├── `awesome_bot` _(**或是 src**)_
│ └── `plugins`
├── `.env` _(**可选的**)_
├── `.env.dev` _(**可选的**)_
├── `.env.prod` _(**可选的**)_
├── .gitignore
├── `bot.py`
├── docker-compose.yml
├── Dockerfile
├── `pyproject.toml`
└── README.md
:::
<!-- prettier-ignore-end -->
- `awesome_bot/plugins``src/plugins`: 用于存放编写的 bot 插件
- `.env`, `.env.dev`, `.env.prod`: 各环境配置文件
- `bot.py`: bot 入口文件
- `pyproject.toml`: 项目依赖管理文件,默认使用 [poetry](https://python-poetry.org/)
## 启动 Bot
如果你使用 `nb-cli`
```bash
nb run [--file=bot.py] [--app=app]
```
或者使用
```bash
python bot.py
```
:::tip 提示
如果在 bot 入口文件内定义了 asgi server `nb-cli` 将会为你启动**冷重载模式**
:::

View File

@@ -0,0 +1,9 @@
# 结语
至此,相信你已经能够写出一个基础的插件了,更多的用法将会在 进阶 部分进行介绍,这里给出几个小提示:
- 请千万注意事件处理器的优先级设定
- 在匹配规则中请勿使用耗时极长的函数
- 同一个用户可以**跨群**(**私聊**)继续他的事件处理(除非做出权限限制,将在后续介绍)
如果你还不能满足,前往 [进阶](../advanced/README.md) 获得更多的功能信息。

View File

@@ -0,0 +1,173 @@
# 开始使用
一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备。
## 最小实例
如果你已经按照推荐方式安装了 `nb-cli`,使用脚手架创建一个空项目:
```bash
nb create
```
根据脚手架引导,将在当前目录下创建一个项目目录,项目目录内包含 `bot.py`
如果未安装 `nb-cli`,使用你最熟悉的编辑器或 IDE创建一个名为 `bot.py` 的文件,内容如下:
```python{3,4,7}
import nonebot
from nonebot.adapters.cqhttp import Bot as CQHTTPBot
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter("cqhttp", CQHTTPBot)
nonebot.load_builtin_plugins()
if __name__ == "__main__":
nonebot.run()
```
## 解读
在上方 `bot.py` 中,这几行高亮代码将依次:
1. 使用默认配置初始化 NoneBot
2. 加载 NoneBot 内置的插件
3. 在地址 `127.0.0.1:8080` 运行 NoneBot
在命令行使用如下命令即可运行这个 NoneBot 实例:
```bash
# nb-cli
nb run
# 其他
python bot.py
```
运行后会产生如下日志:
```plain
09-14 21:02:00 [INFO] nonebot | Succeeded to import "nonebot.plugins.base"
09-14 21:02:00 [INFO] nonebot | Running NoneBot...
09-14 21:02:00 [INFO] uvicorn | Started server process [1234]
09-14 21:02:00 [INFO] uvicorn | Waiting for application startup.
09-14 21:02:00 [INFO] uvicorn | Application startup complete.
09-14 21:02:00 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
```
## 配置 QQ 协议端
单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。
目前支持的协议有:
- [OneBot(CQHTTP)](https://github.com/howmanybots/onebot/blob/master/README.md)
QQ 协议端举例:
- [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) (基于 [MiraiGo](https://github.com/Mrs4s/MiraiGo))
- [cqhttp-mirai-embedded](https://github.com/yyuueexxiinngg/cqhttp-mirai/tree/embedded)
- [Mirai](https://github.com/mamoe/mirai) + [cqhttp-mirai](https://github.com/yyuueexxiinngg/cqhttp-mirai)
- [Mirai](https://github.com/mamoe/mirai) + [Mirai Native](https://github.com/iTXTech/mirai-native) + [CQHTTP](https://github.com/richardchien/coolq-http-api)
- [OICQ-http-api](https://github.com/takayama-lily/onebot) (基于 [OICQ](https://github.com/takayama-lily/oicq))
这里以 [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 为例
1. 下载 go-cqhttp 对应平台的 release 文件,[点此前往](https://github.com/Mrs4s/go-cqhttp/releases)
2. 运行 exe 文件或者使用 `./go-cqhttp` 启动
3. 生成默认配置文件并修改默认配置
```json{2,3,35-36,42}
{
"uin": 你的QQ号,
"password": "你的密码",
"encrypt_password": false,
"password_encrypted": "",
"enable_db": true,
"access_token": "",
"relogin": {
"enabled": true,
"relogin_delay": 3,
"max_relogin_times": 0
},
"_rate_limit": {
"enabled": false,
"frequency": 0,
"bucket_size": 0
},
"ignore_invalid_cqcode": false,
"force_fragmented": true,
"heartbeat_interval": 0,
"http_config": {
"enabled": false,
"host": "0.0.0.0",
"port": 5700,
"timeout": 0,
"post_urls": {}
},
"ws_config": {
"enabled": false,
"host": "0.0.0.0",
"port": 6700
},
"ws_reverse_servers": [
{
"enabled": true,
"reverse_url": "ws://127.0.0.1:8080/cqhttp/ws",
"reverse_api_url": "",
"reverse_event_url": "",
"reverse_reconnect_interval": 3000
}
],
"post_message_format": "array",
"use_sso_address": false,
"debug": false,
"log_level": "",
"web_ui": {
"enabled": true,
"host": "0.0.0.0",
"web_ui_port": 9999,
"web_input": false
}
}
```
其中 `ws://127.0.0.1:8080/cqhttp/ws` 中的 `127.0.0.1` 和 `8080` 应分别对应 nonebot 配置的 HOST 和 PORT
## 历史性的第一次对话
一旦新的配置文件正确生效之后NoneBot 所在的控制台(如果正在运行的话)应该会输出类似下面的内容(两条访问日志):
```default
09-14 21:31:16 [INFO] uvicorn | ('127.0.0.1', 12345) - "WebSocket /cqhttp/ws" [accepted]
09-14 21:31:16 [INFO] nonebot | WebSocket Connection from CQHTTP Bot 你的QQ号 Accepted!
```
这表示 QQ 协议端已经成功地使用 CQHTTP 协议连接上了 NoneBot。
:::warning 注意
如果到这一步你没有看到上面这样的成功日志CQHTTP 的日志中在不断地重连或无反应,请注意检查配置中的 IP 和端口是否确实可以访问。比较常见的出错点包括:
- NoneBot 监听 `0.0.0.0`,然后在 CQHTTP 配置中填了 `ws://0.0.0.0:8080/cqhttp/ws`
- 在 Docker 容器内运行 CQHTTP并通过 `127.0.0.1` 访问宿主机上的 NoneBot
- 想从公网访问,但没有修改云服务商的安全组策略或系统防火墙
- NoneBot 所监听的端口存在冲突,已被其它程序占用
- 弄混了 NoneBot 的 `host`、`port` 参数与 CQHTTP 配置中的 `host`、`port` 参数
- 使用了 `ws_reverse_api_url` 和 `ws_reverse_event_url` 而非 universal client
- `ws://` 错填为 `http://`
- CQHTTP 或 NoneBot 启动时遭到外星武器干扰
请尝试重启 CQHTTP、重启 NoneBot、更换端口、修改防火墙、重启系统、仔细阅读前面的文档及提示、更新 CQHTTP 和 NoneBot 到最新版本等方式来解决。
:::
现在,尝试向你的 QQ 机器人账号发送如下内容:
```default
/echo 你好,世界
```
到这里如果一切 OK你应该会收到机器人给你回复了 `你好,世界`。这一历史性的对话标志着你已经成功地运行了一个 NoneBot 的最小实例,开始了编写更强大的 QQ 机器人的创意之旅!
<ClientOnly>
<Messenger :messages="[{ position: 'right', msg: '/echo 你好,世界' }, { position: 'left', msg: '你好,世界' }]"/>
</ClientOnly>

View File

@@ -0,0 +1,87 @@
# 安装
## NoneBot
:::warning 注意
请确保你的 Python 版本 >= 3.7。
:::
:::warning 注意
请在安装 nonebot2 之前卸载 nonebot 1.x
```bash
pip uninstall nonebot
```
:::
### 通过脚手架安装(推荐安装方式)
1. (可选)使用你喜欢的 Python 环境管理工具创建新的虚拟环境。
2. 使用 `pip` (或其他) 安装 NoneBot 脚手架。
```bash
pip install nb-cli
```
3. 点个 star 吧
nonebot2: [![nb-cli](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2)
nb-cli: [![nb-cli](https://img.shields.io/github/stars/nonebot/nb-cli?style=social)](https://github.com/nonebot/nb-cli)
### 不使用脚手架(纯净安装)
```bash
# poetry
poetry add nonebot2
# pip
pip install nonebot2
```
如果你需要使用最新的(可能**尚未发布**的)特性,可以直接从 GitHub 仓库安装:
```bash
# master
poetry add git+https://github.com/nonebot/nonebot2.git#master
# dev
poetry add git+https://github.com/nonebot/nonebot2.git#dev
```
或者克隆 Git 仓库后手动安装:
```bash
git clone https://github.com/nonebot/nonebot2.git
cd nonebot2
poetry install --no-dev # 推荐
pip install . # 不推荐
```
## 安装插件
插件可以通过 `nb-cli` 进行安装,也可以自行安装并加载插件。
```bash
# 列出所有的插件
nb plugin list
# 搜索插件
nb plugin search xxx
# 安装插件
nb plugin install xxx
```
如果急于上线 Bot 或想要使用现成的插件,以下插件可作为参考:
### 官方插件
~~自用插件~~ ~~确信~~
- [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs) 离线文档插件
- [NoneBot-Plugin-Test](https://github.com/nonebot/plugin-test) 本地机器人测试前端插件
- [NoneBot-Plugin-APScheduler](https://github.com/nonebot/plugin-apscheduler) 定时任务插件
- [NoneBot-Plugin-Sentry](https://github.com/cscs181/QQ-GitHub-Bot/tree/master/src/plugins/nonebot_plugin_sentry) Sentry 在线日志分析插件
- [NoneBot-Plugin-Status](https://github.com/cscs181/QQ-GitHub-Bot/tree/master/src/plugins/nonebot_plugin_status) 服务器状态查看插件
### 其他插件
还有更多的插件在 [这里](/plugin-store.md) 等着你发现~

View File

@@ -0,0 +1,116 @@
# 加载插件
在 [创建一个完整的项目](creating-a-project) 一章节中,我们已经创建了插件目录 `awesome_bot/plugins`,现在我们在机器人入口文件中加载它。当然,你也可以单独加载一个插件。
## 加载内置插件
`bot.py` 文件中添加以下行:
```python{5}
import nonebot
nonebot.init()
# 加载 nonebot 内置插件
nonebot.load_builtin_plugins()
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
这将会加载 nonebot 内置的插件,它包含:
- 命令 `say`:可由**superuser**使用,可以将消息内容由特殊纯文本转为富文本
- 命令 `echo`:可由任何人使用,将消息原样返回
以上命令均需要指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称。参考 [Rule: to_me](../api/rule.md#to-me)
## 加载插件目录
在 `bot.py` 文件中添加以下行:
```python{5}
import nonebot
nonebot.init()
# 加载插件目录,该目录下为各插件,以下划线开头的插件将不会被加载
nonebot.load_plugins("awesome_bot/plugins")
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
:::tip 提示
加载插件目录时,目录下以 `_` 下划线开头的插件将不会被加载!
:::
:::warning 提示
**插件不能存在相同名称!**
:::
:::danger 警告
插件间不应该存在过多的耦合,如果确实需要导入某个插件内的数据,可以参考 [进阶-跨插件访问](../advanced/export-and-require.md)
:::
## 加载单个插件
在 `bot.py` 文件中添加以下行:
```python{5,7}
import nonebot
nonebot.init()
# 加载一个 pip 安装的插件
nonebot.load_plugin("nonebot_plugin_status")
# 加载本地的单独插件
nonebot.load_plugin("awesome_bot.plugins.xxx")
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
## 子插件(嵌套插件)
在插件中同样可以加载子插件,例如如下插件目录结构:
<!-- prettier-ignore-start -->
:::vue
foo_plugin
├── `plugins`
│ ├── `sub_plugin1`
│ │ └── \_\_init\_\_.py
│ └── `sub_plugin2.py`
├── `__init__.py`
└── config.py
:::
<!-- prettier-ignore-end -->
在插件目录下的 `__init__.py` 中添加如下代码:
```python
from pathlib import Path
import nonebot
# store all subplugins
_sub_plugins = set()
# load sub plugins
_sub_plugins |= nonebot.load_plugins(
str((Path(__file__).parent / "plugins").resolve()))
```
插件将会被加载并存储于 `_sub_plugins` 中。
## 运行结果
尝试运行 `nb run` 或者 `python bot.py`,可以看到日志输出了类似如下内容:
```plain
09-19 21:51:59 [INFO] nonebot | Succeeded to import "nonebot.plugins.base"
09-19 21:51:59 [INFO] nonebot | Succeeded to import "plugin_in_folder"
```

View File

@@ -0,0 +1,161 @@
{
"sidebar": {},
"locales": {
"/": {
"label": "简体中文",
"selectText": "Languages",
"editLinkText": "在 GitHub 上编辑此页",
"lastUpdated": "上次更新",
"nav": [
{
"text": "主页",
"link": "/"
},
{
"text": "指南",
"link": "/guide/"
},
{
"text": "进阶",
"link": "/advanced/"
},
{
"text": "API",
"link": "/api/"
},
{
"text": "插件广场",
"link": "/plugin-store"
},
{
"text": "更新日志",
"link": "/changelog"
}
],
"sidebarDepth": 2,
"sidebar": {
"/guide/": [
{
"title": "开始",
"collapsable": false,
"sidebar": "auto",
"children": [
"",
"installation",
"getting-started",
"creating-a-project",
"basic-configuration"
]
},
{
"title": "编写插件",
"collapsable": false,
"sidebar": "auto",
"children": [
"loading-a-plugin",
"creating-a-plugin",
"creating-a-matcher",
"creating-a-handler",
"end-or-start"
]
}
],
"/advanced/": [
{
"title": "进阶",
"collapsable": false,
"sidebar": "auto",
"children": [
"",
"scheduler",
"permission",
"runtime-hook",
"export-and-require"
]
},
{
"title": "发布",
"collapsable": false,
"sidebar": "auto",
"children": [
"publish-plugin"
]
}
],
"/api/": [
{
"title": "NoneBot Api Reference",
"path": "",
"collapsable": false,
"children": [
{
"title": "nonebot 模块",
"path": "nonebot"
},
{
"title": "nonebot.config 模块",
"path": "config"
},
{
"title": "nonebot.plugin 模块",
"path": "plugin"
},
{
"title": "nonebot.message 模块",
"path": "message"
},
{
"title": "nonebot.matcher 模块",
"path": "matcher"
},
{
"title": "nonebot.rule 模块",
"path": "rule"
},
{
"title": "nonebot.permission 模块",
"path": "permission"
},
{
"title": "nonebot.log 模块",
"path": "log"
},
{
"title": "nonebot.utils 模块",
"path": "utils"
},
{
"title": "nonebot.typing 模块",
"path": "typing"
},
{
"title": "nonebot.exception 模块",
"path": "exception"
},
{
"title": "nonebot.drivers 模块",
"path": "drivers/"
},
{
"title": "nonebot.drivers.fastapi 模块",
"path": "drivers/fastapi"
},
{
"title": "nonebot.adapters 模块",
"path": "adapters/"
},
{
"title": "nonebot.adapters.cqhttp 模块",
"path": "adapters/cqhttp"
},
{
"title": "nonebot.adapters.ding 模块",
"path": "adapters/ding"
}
]
}
]
}
}
}
}

View File

@@ -1,7 +1,7 @@
<template>
<div class="qq-chat">
<v-app
><v-main>
<v-app>
<v-main>
<v-card class="elevation-6">
<v-toolbar color="primary" dark dense flat>
<v-row no-gutters>
@@ -139,19 +139,15 @@ export default {
default: () => []
}
},
data: () => ({
wow: null
}),
methods: {
initWOW: function() {
this.wow = new WOW({
new WOW({
noxClass: "wow",
animateClass: "animate__animated",
offset: 0,
mobile: true,
live: true
});
this.wow.init();
}).init();
}
},
mounted() {
@@ -167,6 +163,7 @@ export default {
.chat {
min-height: 150px;
overflow-x: hidden;
}
.chat-bg {
background-color: #f3f6f9;
@@ -214,3 +211,9 @@ export default {
font-size: 12px;
}
</style>
<style>
.v-application--wrap {
min-height: 0 !important;
}
</style>

View File

@@ -0,0 +1,162 @@
<template>
<div class="plugins">
<v-app>
<v-main>
<v-row>
<v-col cols="12" sm="4">
<v-text-field
v-model="filterText"
dense
rounded
outlined
clearable
hide-details
label="Filter Plugin"
>
<template v-slot:prepend-inner>
<div class="v-input__icon v-input__icon--prepend-inner">
<v-icon small>fa-filter</v-icon>
</div>
</template>
</v-text-field>
</v-col>
<v-col cols="12" sm="4">
<v-btn
block
color="primary"
target="_blank"
rel="noopener noreferrer"
href="https://github.com/nonebot/nonebot2/issues/new?template=plugin-publish.md"
>Publish Your Plugin
</v-btn>
</v-col>
<v-col cols="12" sm="4">
<v-pagination
v-model="page"
:length="pageNum"
prev-icon="fa-caret-left"
next-icon="fa-caret-right"
></v-pagination>
</v-col>
</v-row>
<hr />
<v-row>
<v-col
cols="12"
sm="6"
v-for="(plugin, index) in filteredPlugins"
:key="index"
>
<v-card>
<v-card-title>
{{ plugin.name }}
<v-spacer></v-spacer>
<a
class="repo-link"
v-if="repoLink(plugin.repo)"
rel="noopener noreferrer"
target="_blank"
:title="plugin.repo"
:href="repoLink(plugin.repo)"
>
<v-icon>fab fa-github</v-icon>
</a>
</v-card-title>
<v-card-text>{{ plugin.desc }}</v-card-text>
<v-card-text>
<v-icon x-small>fa-fingerprint</v-icon>
{{ plugin.id }}
<v-icon x-small class="ml-2">fa-user</v-icon>
{{ plugin.author }}
</v-card-text>
<v-card-actions>
<v-btn
block
depressed
class="btn-copy"
@click="copyCommand(plugin)"
>
copy nb-cli command
<v-icon right small>fa-copy</v-icon>
</v-btn>
<v-snackbar v-model="snackbar">Copied!</v-snackbar>
</v-card-actions>
</v-card>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
<v-pagination
v-model="page"
:length="pageNum"
prev-icon="fa-caret-left"
next-icon="fa-caret-right"
></v-pagination>
</v-col>
</v-row>
</v-main>
</v-app>
</div>
</template>
<script>
import copy from "copy-to-clipboard";
import plugins from "../public/plugins.json";
export default {
name: "Plugins",
data() {
return {
plugins: plugins,
snackbar: false,
filterText: "",
page: 1
};
},
computed: {
pageNum() {
return Math.ceil(this.filteredPlugins.length / 10);
},
filteredPlugins() {
return this.plugins.filter(plugin => {
return (
plugin.id.indexOf(this.filterText) != -1 ||
plugin.name.indexOf(this.filterText) != -1 ||
plugin.desc.indexOf(this.filterText) != -1 ||
plugin.author.indexOf(this.filterText) != -1
);
});
}
},
methods: {
repoLink(repo) {
if (repo) {
return /^https?:/.test(repo) ? repo : `https://github.com/${repo}`;
}
return null;
},
copyCommand(plugin) {
copy(`nb plugin install ${plugin.id}`, {
format: "text/plain"
});
this.snackbar = true;
}
}
};
</script>
<style>
.v-application--wrap {
min-height: 0 !important;
}
</style>
<style scoped>
.repo-link {
text-decoration: none !important;
display: inline-block;
}
.repo-link:hover i {
color: #ea5252;
}
</style>

View File

@@ -1,6 +1,7 @@
const path = require("path");
module.exports = context => ({
base: process.env.VUEPRESS_BASE || "/",
title: "NoneBot",
description: "基于 酷Q 的 Python 异步 QQ 机器人框架",
markdown: {
@@ -13,7 +14,8 @@ module.exports = context => ({
*/
head: [
["link", { rel: "icon", href: "/logo.png" }],
["meta", { name: "theme-color", content: "#d32f2f" }],
["link", { rel: "manifest", href: "/manifest.json" }],
["meta", { name: "theme-color", content: "#ea5252" }],
["meta", { name: "application-name", content: "NoneBot" }],
["meta", { name: "apple-mobile-web-app-title", content: "NoneBot" }],
["meta", { name: "apple-mobile-web-app-capable", content: "yes" }],
@@ -21,6 +23,26 @@ module.exports = context => ({
"meta",
{ name: "apple-mobile-web-app-status-bar-style", content: "black" }
],
[
"link",
{ rel: "apple-touch-icon", href: "/icons/apple-touch-icon-180x180.png" }
],
[
"link",
{
rel: "mask-icon",
href: "/icons/safari-pinned-tab.svg",
color: "#ea5252"
}
],
[
"meta",
{
name: "msapplication-TileImage",
content: "/icons/mstile-150x150.png"
}
],
["meta", { name: "msapplication-TileColor", content: "#ea5252" }],
[
"link",
{
@@ -38,12 +60,12 @@ module.exports = context => ({
}
},
theme: "titanium",
theme: "nonebot",
themeConfig: {
logo: "/logo.png",
repo: "nonebot/nonebot",
repo: "nonebot/nonebot2",
docsDir: "docs",
docsBranch: "dev2",
docsBranch: "dev",
docsDirVersioned: "archive",
docsDirPages: "pages",
editLinks: true,
@@ -58,14 +80,16 @@ module.exports = context => ({
nav: [
{ text: "主页", link: "/" },
{ text: "指南", link: "/guide/" },
{ text: "API", link: "/api/" }
{ text: "进阶", link: "/advanced/" },
{ text: "API", link: "/api/" },
{ text: "插件广场", link: "/plugin-store" },
{ text: "更新日志", link: "/changelog" }
],
sidebarDepth: 2,
sidebar: {
"/guide/": [
{
title: "指南",
path: "",
title: "开始",
collapsable: false,
sidebar: "auto",
children: [
@@ -73,9 +97,40 @@ module.exports = context => ({
"installation",
"getting-started",
"creating-a-project",
"basic-configuration",
"writing-a-plugin"
"basic-configuration"
]
},
{
title: "编写插件",
collapsable: false,
sidebar: "auto",
children: [
"loading-a-plugin",
"creating-a-plugin",
"creating-a-matcher",
"creating-a-handler",
"end-or-start"
]
}
],
"/advanced/": [
{
title: "进阶",
collapsable: false,
sidebar: "auto",
children: [
"",
"scheduler",
"permission",
"runtime-hook",
"export-and-require"
]
},
{
title: "发布",
collapsable: false,
sidebar: "auto",
children: ["publish-plugin"]
}
],
"/api/": [
@@ -88,21 +143,21 @@ module.exports = context => ({
title: "nonebot 模块",
path: "nonebot"
},
{
title: "nonebot.typing 模块",
path: "typing"
},
{
title: "nonebot.config 模块",
path: "config"
},
{
title: "nonebot.sched 模块",
path: "sched"
title: "nonebot.plugin 模块",
path: "plugin"
},
{
title: "nonebot.log 模块",
path: "log"
title: "nonebot.message 模块",
path: "message"
},
{
title: "nonebot.matcher 模块",
path: "matcher"
},
{
title: "nonebot.rule 模块",
@@ -112,13 +167,41 @@ module.exports = context => ({
title: "nonebot.permission 模块",
path: "permission"
},
{
title: "nonebot.log 模块",
path: "log"
},
{
title: "nonebot.utils 模块",
path: "utils"
},
{
title: "nonebot.typing 模块",
path: "typing"
},
{
title: "nonebot.exception 模块",
path: "exception"
},
{
title: "nonebot.drivers 模块",
path: "drivers/"
},
{
title: "nonebot.drivers.fastapi 模块",
path: "drivers/fastapi"
},
{
title: "nonebot.adapters 模块",
path: "adapters/"
},
{
title: "nonebot.adapters.cqhttp 模块",
path: "adapters/cqhttp"
},
{
title: "nonebot.adapters.ding 模块",
path: "adapters/ding"
}
]
}
@@ -131,6 +214,16 @@ module.exports = context => ({
plugins: [
"@vuepress/plugin-back-to-top",
"@vuepress/plugin-medium-zoom",
[
"@vuepress/pwa",
{
serviceWorker: true,
updatePopup: {
message: "发现新内容",
buttonText: "刷新"
}
}
],
[
"versioning",
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1008 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="500.000000pt" height="500.000000pt" viewBox="0 0 500.000000 500.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.11, written by Peter Selinger 2001-2013
</metadata>
<g transform="translate(0.000000,500.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M2478 4525 c-2 -1 -57 -5 -122 -9 -65 -4 -122 -8 -125 -10 -3 -2 -30
-7 -60 -11 -141 -18 -404 -102 -561 -180 -68 -34 -238 -132 -250 -145 -3 -3
-32 -25 -65 -49 -246 -182 -465 -442 -604 -719 -212 -422 -271 -933 -159
-1377 11 -44 21 -88 23 -97 8 -38 86 -238 120 -308 206 -415 542 -749 952
-945 90 -43 265 -111 309 -119 11 -2 48 -12 84 -21 82 -21 94 -24 155 -31 28
-4 53 -8 56 -10 11 -6 172 -17 264 -17 88 -1 239 9 282 17 11 3 43 8 70 12
280 40 611 181 855 363 118 87 221 181 311 284 173 195 309 424 392 657 14 41
28 82 30 90 2 8 13 51 25 95 25 93 27 103 34 159 3 22 8 52 11 65 9 46 16 166
17 276 1 704 -363 1359 -960 1728 -201 125 -484 234 -677 263 -16 3 -52 9 -79
15 -27 5 -92 12 -145 15 -53 3 -115 7 -138 8 -23 2 -43 2 -45 1z m162 -89
c691 -39 1330 -482 1622 -1121 74 -163 137 -364 152 -490 4 -27 9 -63 11 -80
17 -106 21 -305 10 -430 -8 -84 -49 -307 -60 -325 -2 -4 -6 -20 -9 -36 -3 -17
-23 -77 -44 -135 -194 -521 -605 -937 -1124 -1135 -562 -214 -1202 -155 -1713
160 -317 195 -564 466 -735 806 -60 120 -141 358 -156 465 -3 17 -9 55 -15 85
-11 61 -23 217 -22 295 3 525 201 1002 571 1373 340 340 782 542 1247 568 55
3 101 7 102 8 2 1 20 1 40 0 21 -2 76 -5 123 -8z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,20 @@
{
"name": "NoneBot",
"short_name": "NoneBot",
"background-color": "#ffffff",
"theme-color": "#ea5252",
"description": "An asynchronous python bot framework.",
"display": "standalone",
"icons": [
{
"src": "/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/icons/android-chrome-384x384.png",
"sizes": "384x384",
"type": "image/png"
}
]
}

View File

@@ -0,0 +1,42 @@
[
{
"id": "nonebot_plugin_status",
"link": "nonebot-plugin-status",
"name": "服务器状态查看",
"desc": "通过戳一戳获取服务器状态",
"author": "yanyongyu",
"repo": "cscs181/QQ-GitHub-Bot/tree/master/src/plugins/nonebot_plugin_status"
},
{
"id": "haruka_bot",
"link": "haruka-bot",
"name": "HarukaBot",
"desc": "将B站UP主的动态和直播信息推送至QQ",
"author": "SK-415",
"repo": "SK-415/HarukaBot"
},
{
"id": "nonebot_plugin_rauthman",
"link": "nonebot-plugin-rauthman",
"name": "rauthman",
"desc": "基于规则的授权管理",
"author": "Lancercmd",
"repo": "Lancercmd/nonebot_plugin_rauthman"
},
{
"id": "nonebot_plugin_docs",
"link": "nonebot-plugin-docs",
"author": "nonebot",
"desc": "在本地浏览NoneBot文档",
"name": "NoneBot离线文档",
"repo": "nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs"
},
{
"id": "nonebot_plugin_sentry",
"link": "nonebot-plugin-sentry",
"author": "yanyongyu",
"desc": "使用Sentry监控机器人日志并处理报错",
"name": "Sentry日志监控",
"repo": "cscs181/QQ-GitHub-Bot/tree/master/src/plugins/nonebot_plugin_sentry"
}
]

View File

@@ -1,3 +1,4 @@
[
"2.0.0a1"
"2.0.0a7",
"2.0.0a6"
]

View File

@@ -3,7 +3,7 @@ home: true
heroImage: /logo.png
tagline: An asynchronous QQ bot framework.
actionText: 开始使用
actionLink: /guide/
actionLink: guide/
features:
- title: 简洁
details: 提供极其简洁易懂的 API使你可以毫无压力地开始验证你的绝佳创意只需编写最少量的代码即可实现丰富的功能。
@@ -11,5 +11,5 @@ features:
details: 精心设计的消息处理流程使得你可以很方便地将原型扩充为具有大量实用功能的完整聊天机器人,并持续保证扩展性。
- title: 高性能
details: 采用异步 I/O利用 WebSocket 进行通信,以获得极高的性能;同时,支持使用多账号同时接入,减少业务宕机的可能。
footer: MIT Licensed | Copyright © 2020 NoneBot Team
footer: MIT Licensed | Copyright © 2018 - 2020 NoneBot Team
---

7
docs/advanced/README.md Normal file
View File

@@ -0,0 +1,7 @@
# 深入
## 它如何工作?
<!-- TODO: how to work -->
~~未填坑~~

View File

@@ -0,0 +1 @@
# 跨插件访问

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