Compare commits

...

1200 Commits

Author SHA1 Message Date
Ju4tCode
cfd992b6b1 🔀 Merge pull request #547
Release 2.0.0a16
2021-10-02 20:31:49 +08:00
yanyongyu
6ec1159f95 🔥 remove outdated versions 2021-10-02 18:01:26 +08:00
nonebot
38ac45f687 📝 update api docs 2021-10-02 09:51:48 +00:00
yanyongyu
1331cbf8a3 🔀 Merge master into dev 2021-10-02 17:48:56 +08:00
yanyongyu
a6fc0e408c 📝 update readme 2021-10-02 17:44:43 +08:00
yanyongyu
66b2153493 🔖 bump version 2.0.0a16 2021-10-02 17:35:10 +08:00
yanyongyu
94b98b74b9 ⚗️ add fastapi/quart uvicorn configs 2021-10-02 15:35:15 +08:00
Ju4tCode
f3abd2f1a3 🔀 Merge pull request #546
Feature: Add support for mirai adapter NudgeEvent
2021-10-02 15:10:32 +08:00
yanyongyu
1280cf9ba3 🎨 fix docstring format 2021-10-02 15:07:32 +08:00
nonebot
bac56635c0 📝 update api docs 2021-10-02 06:42:39 +00:00
Mix
6d9caadffc add support for mirai adapter NudgeEvent, fix #494 2021-10-02 14:30:02 +08:00
Mix
4a7c07a7ac 🔀 Merge pull request #545
Feature: support use `Message` object as message template
2021-10-02 14:14:03 +08:00
nonebot
910d18e79f 📝 update api docs 2021-10-02 06:07:16 +00:00
Mix
5cff80812e 🔥 remove Message.__init__ method of mirai adapter 2021-10-02 14:06:00 +08:00
Mix
c8a8ff28ec support use Message object as message template 2021-10-02 14:05:54 +08:00
yanyongyu
292b8e6366 ⬆️ update dependencies 2021-10-02 11:25:30 +08:00
yanyongyu
9e9608abd8 📝 update changelog 2021-10-01 23:45:47 +08:00
yanyongyu
3452880b16 ⚗️ add fastapi reload include/exclude 2021-09-30 01:22:12 +08:00
Ju4tCode
ef2c98c6af 🔀 Merge pull request #543
Plugin: pornhub风格图标生成
2021-09-29 00:52:57 +08:00
kexue-z
246b8ccbe7 🍻 publish plugin pornhub风格图标生成 2021-09-28 16:45:05 +00:00
Ju4tCode
2355c6385d 🔀 Merge pull request #541
Docs: 插件发布指引文档
2021-09-29 00:07:37 +08:00
XZhouQD
75811c0b64 📝 update api docs 2021-09-28 15:12:40 +00:00
XZhouQD
3a510e3888 📝 plugin publish docs 2021-09-28 23:09:34 +08:00
yanyongyu
161cfbe1b8 ⚗️ add more uvicorn config 2021-09-28 21:20:29 +08:00
yanyongyu
0b08d23e34 ⬆️ upgrade uvicorn 2021-09-28 20:56:05 +08:00
Mix
2ebf7fc096 🔀 Merge pull request #539
Fix: remove return value in event handle
2021-09-27 22:33:57 +08:00
yanyongyu
041b59011b 🔥 remove return value in event handle 2021-09-27 12:52:21 +08:00
yanyongyu
92a411e3b4 🎨 isort format code 2021-09-27 00:19:30 +08:00
Ju4tCode
81cbf84dca 🔀 Merge pull request #538
Bot: HarukaBot repository link update
2021-09-26 16:30:58 +08:00
SK
4364685b30 Fix HarukaBot repository link 2021-09-26 02:07:56 -04:00
yanyongyu
cfdebb30b7 🐛 fix log not escaped in forward driver 2021-09-25 19:14:16 +08:00
Mix
049d14295e 🔀 Merge pull request #536
完善飞书相关文档和部分事件Model
2021-09-25 10:04:35 +08:00
StarHeartHunt
3dc93f7997 🐛 fix __event__ value 2021-09-25 09:10:13 +08:00
StarHeartHunt
b19c2e4191 implement meeting, vc_meeting and attendance events 2021-09-25 09:05:48 +08:00
StarHeartHunt
d121a2080b implement drive, meeting and calendar events 2021-09-25 08:30:55 +08:00
StarHeartHunt
919e3ebf8c implement calendar acl event 2021-09-24 22:45:11 +08:00
StarHeartHunt
b0f4b8ffa1 implement contact events 2021-09-24 22:08:03 +08:00
StarHeart
b3bf9470cf 📝 improve doc
Co-authored-by: Mix <32300164+mnixry@users.noreply.github.com>
2021-09-24 21:33:24 +08:00
StarHeartHunt
16029a33e8 📝 format doc 2021-09-24 20:29:27 +08:00
StarHeartHunt
b31d04dc5d 🎨 improve code style 2021-09-24 20:26:50 +08:00
StarHeartHunt
e0f73ba193 📝 complete feishu doc 2021-09-24 20:26:12 +08:00
Mix
0b35d5e724 🔀 Merge pull request #534
Plugin: SimpleMusic
2021-09-21 23:26:56 +08:00
kanomahoro
c747342709 🍻 publish plugin SimpleMusic 2021-09-21 15:17:30 +00:00
Mix
244df12069 🔀 Merge pull request #532
Plugin: HTTP静态文件托管
2021-09-21 01:03:22 +08:00
mnixry
368afe6d63 🍻 publish plugin HTTP静态文件托管 2021-09-20 16:58:26 +00:00
StarHeartHunt
5cd61c09a8 🚨 re-export base adapter init
according to pep484
2021-09-18 20:22:38 +08:00
StarHeartHunt
1e55fbf6b1 🚨 re-export feishu init
according to pep484
2021-09-18 20:03:53 +08:00
yanyongyu
463ff260c4 🐛 fix doc build error 2021-09-18 18:04:19 +08:00
yanyongyu
89e32a3241 ⬆️ bump dependencies 2021-09-18 17:18:53 +08:00
yanyongyu
4f8771acbd 🚨 re-export according to pep484 2021-09-18 16:11:03 +08:00
Ju4tCode
a212baf90b 🔀 Merge pull request #528
Plugin: HanayoriBot
2021-09-18 13:10:34 +08:00
kanomahoro
5db8b124ab 🍻 publish plugin HanayoriBot 2021-09-18 02:59:21 +00:00
yanyongyu
a273d75b07 add send pause reject finish template 2021-09-17 23:28:08 +08:00
StarHeart
55a402203e Merge pull request #524 from nonebot/fix/feishu-private-msg
🐛 fix feishu private message event response
2021-09-17 20:46:27 +08:00
StarHeartHunt
64967e8807 🎨 resort dev dependencies 2021-09-17 20:36:08 +08:00
StarHeartHunt
43917b5aad ⬆️ bump nonebot-plugin-test to 0.3.0 2021-09-16 20:54:34 +08:00
nonebot
b97133fb59 📝 update api docs 2021-09-16 12:30:31 +00:00
StarHeartHunt
855f61d837 💚 fix missing module in API docs config 2021-09-16 20:29:06 +08:00
StarHeartHunt
e2003e27df parse data based on content-type of response 2021-09-16 20:29:05 +08:00
nonebot
d82749c48e 📝 update api docs 2021-09-16 20:29:05 +08:00
StarHeartHunt
0a802f9b13 add get_all_user_id for MessageEvent 2021-09-16 17:36:05 +08:00
yanyongyu
e0610fdcc0 🐛 fix publish field not required 2021-09-15 21:03:18 +08:00
Ju4tCode
20d0ecfc7f Merge pull request #526 from nonebot/ci/store-publish
👷 update store publish bot
2021-09-15 20:38:49 +08:00
hemengyang
fa15e5b0ee 👷 update store publish bot
仓库迁移至 NoneBot 组织
2021-09-15 17:16:15 +08:00
StarHeartHunt
d9cc912ccb 💥 use open_id to send private message instead 2021-09-14 21:52:31 +08:00
StarHeartHunt
09d9f414ce 🔊 add desc and name of NoticeEvent 2021-09-14 21:51:01 +08:00
yanyongyu
ca09fb8372 🔥 remove outdated doc version 2021-09-14 11:00:14 +08:00
Artin
b25a0387ba Merge pull request #521 from nonebot/fix-ding 2021-09-13 01:44:28 +08:00
artin
9931563d80 🐛 fix ding adapter issues
1. cannot send complicate message, such as actionCard
2. fix judge current connection mode
2021-09-13 01:19:14 +08:00
yanyongyu
53a576dae5 📝 update api doc 2021-09-11 19:49:32 +08:00
yanyongyu
44d13acc81 ♻️ rename message formatter into template 2021-09-11 19:48:46 +08:00
yanyongyu
59f567004f 🔥 remove outdated docs 2021-09-11 13:45:59 +08:00
yanyongyu
956e581d72 📝 update changelog 2021-09-11 13:45:07 +08:00
yanyongyu
b635d01519 💥 matcher prompt support message formatter 2021-09-11 13:45:03 +08:00
synodriver
12c1f6d764 🐛 fix USER bug 2021-09-09 23:17:54 +08:00
Ju4tCode
b66a4df4c5 🔀 Merge pull request #517
Plugin: ATRI语音包
2021-09-05 17:24:05 +08:00
FYWinds
46c61df081 🍻 publish plugin ATRI语音包 2021-09-05 09:05:30 +00:00
yanyongyu
b6ec81c21d 🐛 fix cqhttp get forward msg type error 2021-09-03 14:27:36 +08:00
StarHeart
f9f2f1b0bd 📝 update APScheduler doc link (x2) 2021-08-30 16:36:58 +08:00
StarHeart
45396e3163 📝 update APScheduler doc link 2021-08-30 16:34:34 +08:00
Mix
7ced508f9d 🔀 Merge pull request #514
🐛 Fix endswith match bug
2021-08-29 19:53:52 +08:00
ishkong
ed1f1c27e2 🐛 Fix endswith match bug 2021-08-29 19:18:36 +08:00
yanyongyu
3fa75b1c78 ♻️ separate adapter abstract classes 2021-08-29 00:24:28 +08:00
yanyongyu
258ef670e2 📝 update changelog 2021-08-29 00:11:52 +08:00
yanyongyu
5cf665fa21 🐛 fix format field error 2021-08-28 19:42:32 +08:00
yanyongyu
116f16b470 🐛 fix stringify when formatting 2021-08-28 19:39:54 +08:00
Ju4tCode
9518e3c568 🔀 Merge pull request #510
Feature: str.format like message formatting support
2021-08-28 13:06:02 +08:00
Mix
57827ea4bb 🔀 Merge pull request #513
Docs: Add FAQ link to `README.md`
2021-08-27 20:29:10 +08:00
Mix
8e41422055 📝 update faq link to official redirection domain
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2021-08-27 19:58:08 +08:00
Mix
fcd168fd3e 📝 Add frequently asked questions link to README 2021-08-27 19:43:35 +08:00
Mix
fe1bd87ff8 📝 Add markdownlint ignore comment 2021-08-27 19:30:47 +08:00
Mix
efe1615d16 🔀 Merge pull request #512
Bot: Takker
2021-08-27 19:26:26 +08:00
nonebot
ca26609308 📝 update api docs 2021-08-27 11:25:23 +00:00
Mix
01e818f6a4 📝 allow document generate from nonebot.adapters._formatter 2021-08-27 19:24:12 +08:00
Mix
1c73a9adfa 💡 add comment to describe template formatter usage 2021-08-27 19:13:08 +08:00
FYWinds
a739b93561 🍻 publish bot Takker 2021-08-27 09:37:38 +00:00
yanyongyu
7cfdc2dd37 🔥 use Any for format type 2021-08-27 15:08:26 +08:00
yanyongyu
a6ff3711bb 🐛 fix link error in runtime hook doc 2021-08-27 14:52:17 +08:00
yanyongyu
58d10abd32 🎨 change typing for formatter 2021-08-27 14:46:15 +08:00
Mix
f0bc47ec5e Add message template formatter
ref: https://github.com/nonebot/discussions/discussions/27
2021-08-27 02:52:24 +08:00
yanyongyu
b5f2b1a76d 🐛 fix fastapi driver ws missing header 2021-08-25 23:04:48 +08:00
Mix
4f4a072dd7 🔀 Merge pull request #509
MessageSegment.image 的 BytesIO
2021-08-23 00:26:03 +08:00
jinser
fff7d3bff6 🐛 BytesIO cursor 可能不在开头 2021-08-23 00:12:47 +08:00
Ju4tCode
474fd10613 🔀 Merge pull request #508
Remove unsupported adapter
2021-08-21 22:50:57 +08:00
Jigsaw
9bea710e45 🔥 Remove unsupported adapter 2021-08-21 18:52:20 +08:00
Jigsaw
3c76c6ff8b 🔥 Remove unsupported adapter 2021-08-21 18:49:46 +08:00
Ju4tCode
a8a61623d2 🔀 Merge pull request #507
Bot: SetuBot
2021-08-19 19:55:04 +08:00
yuban10703
24ce531598 🍻 publish bot SetuBot 2021-08-19 11:12:18 +00:00
Ju4tCode
a6be0c370f 🔀 Merge pull request #503
Fix exception raised when constructing MessageChain from string
2021-08-19 10:12:57 +08:00
Mix
22c7371f2e 🐛 Fix exception raised when trying to construct message from plain 2021-08-19 01:36:51 +08:00
Ju4tCode
bfb77e9cdf 🔀 Merge pull request #501
Plugin: ELF_RSS
2021-08-17 10:36:30 +08:00
Quan666
9aa346fb1f 🍻 publish plugin ELF_RSS 2021-08-17 02:35:08 +00:00
Ju4tCode
1dfe5d49fc 🔀 Merge pull request #499
Plugin: Epic 限免游戏资讯
2021-08-17 10:34:50 +08:00
monsterxcn
e48788e41f 🍻 publish plugin Epic 限免游戏资讯 2021-08-17 01:56:10 +00:00
StarHeart
802c39da32 Merge pull request #495 from mri-moe/master
添加设置项,使得可以切换飞书和Lark API地址
2021-08-16 17:40:27 +08:00
mri-moe
0d23a9ab8d 📝 update api docs 2021-08-16 09:36:39 +00:00
StarHeartHunt
109cae6dac 🔧 add config for lark users 2021-08-16 17:35:22 +08:00
mri-moe
f63ef8d23b 📝 update desc
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2021-08-16 17:35:13 +08:00
yanyongyu
3d4d3b0f24 🐛 fix got handler running more than once 2021-08-16 16:47:57 +08:00
mri-moe
a3fa1a36c9 📝 update api docs 2021-08-16 08:30:19 +00:00
mri-moe
45cec05bbc Update bot.py 2021-08-16 16:24:33 +08:00
mri-moe
e4d1462585 📝 update api docs 2021-08-16 08:10:42 +00:00
mri-moe
18c6bea451 ✏️ add switcher for lark 2021-08-14 13:04:15 +08:00
Ju4tCode
c4e3309026 🔀 Merge pull request #490
Release 2.0.0a15
2021-08-13 00:36:34 +08:00
yanyongyu
57a60ae45b 🏷️ add missing type hint 2021-08-13 00:20:41 +08:00
yanyongyu
e7f5097e17 📝 update archive doc 2021-08-12 23:50:46 +08:00
Ju4tCode
e437c13bb3 🔀 Merge pull request #492
feature: mirai multiple accounts support
2021-08-12 23:48:37 +08:00
Ju4tCode
edd7f3ccc8 🔀 Merge pull request #491
bugfix: catch setup factory exception
2021-08-12 23:27:24 +08:00
Mix
26f0d66017 add multiple account support for mirai adapter 2021-08-12 23:14:45 +08:00
Mix
5791018af1 🥅 catch exception raised in setup factory 2021-08-12 22:26:41 +08:00
yanyongyu
2c6b41f62c ⬆️ bump adapter version 2.0.0a15 2021-08-12 17:59:52 +08:00
yanyongyu
f2b23f1b44 🎨 escape message before colorful log 2021-08-12 16:45:22 +08:00
yanyongyu
a534f7b58c 🔖 bump version 2.0.0a15 2021-08-12 14:14:01 +08:00
yanyongyu
81398bb803 📝 update changelog 2021-08-12 14:01:09 +08:00
yanyongyu
3a0265b0f6 🐛 fix fastapi forward reconnect error 2021-08-12 13:59:01 +08:00
yanyongyu
59db66ef27 🐛 check data instead of object in to_me 2021-08-12 13:57:52 +08:00
Ju4tCode
a04957a354 🔀 Merge pull request #489
Bugfix: remove mirai session expiry
2021-08-11 22:50:54 +08:00
Mix
371cfd4a0e 🐛 Remove expiry check in nonebot.adapter.mirai.bot.SessionManager 2021-08-11 22:15:17 +08:00
Ju4tCode
037a5ccce0 🔀 Merge pull request #485
Plugin: nonebot-plugin-flexperm
2021-08-10 13:43:53 +08:00
rmuchan
879767df01 🍻 publish plugin nonebot-plugin-flexperm 2021-08-10 03:01:04 +00:00
Ju4tCode
31b18e36e7 🔀 Merge pull request #483
Plugin: 布谷机器人
2021-08-10 00:46:57 +08:00
Sclock
eb3e20abfb 🍻 publish plugin 布谷机器人 2021-08-09 16:45:05 +00:00
Ju4tCode
b96823b5bd 🔀 Merge pull request #481
Plugin: 孤寡机器人
2021-08-10 00:44:46 +08:00
Sclock
b098c8477b 🍻 publish plugin 孤寡机器人 2021-08-09 13:39:24 +00:00
Ju4tCode
02b2589eeb 🔀 Merge pull request #476
Plugin: nonebot-plugin-autohelp
2021-08-08 14:21:16 +08:00
ffreemt
05ea21becd 🍻 publish plugin nonebot-plugin-autohelp 2021-08-08 05:44:37 +00:00
Ju4tCode
2836f50e74 🔀 Merge pull request #474
飞书适配器重定向aiocache logging到统一logger
2021-08-08 11:18:40 +08:00
StarHeartHunt
7b3d66cd2a 🔊 force aiocache to use standard logger 2021-08-08 10:05:42 +08:00
yanyongyu
ceebe0e95d 🐛 fix absolute import 2021-08-06 15:13:36 +08:00
Ju4tCode
2fe01f33e0 Merge pull request #471 from nonebot/bugfix/mirai-tag-escape
Fix log tag escape error in `event.get_description` in mirai adapter
2021-08-06 02:32:53 +08:00
Mix
410266acb1 🐛 Fix log tag escape error in event.get_description 2021-08-05 23:11:57 +08:00
Ju4tCode
02924d56cd 🔀 Merge pull request #468
Plugin: 和风天气
2021-08-05 23:02:36 +08:00
kexue-z
0bd8d4fbbc 🍻 publish plugin 和风天气 2021-08-05 07:30:36 +00:00
Ju4tCode
547bebebd9 🔀 Merge pull request #466
Bot: DicePP
2021-08-05 00:31:53 +08:00
pear-studio
f8703557a0 🍻 publish bot DicePP 2021-08-04 16:23:52 +00:00
yanyongyu
8e97a84ad8 💥 correct message segment mapping funcs 2021-08-04 19:35:03 +08:00
yanyongyu
3564228183 🐛 fix message segment mapping error 2021-08-04 19:11:59 +08:00
Ju4tCode
bb93757f51 🔀 Merge pull request #464
Docs: update guide docs
2021-08-04 15:55:49 +08:00
yanyongyu
e18b3d04fb 📝 update mirai guide 2021-08-04 15:35:02 +08:00
yanyongyu
458085b317 📝 update guide doc 2021-08-04 15:02:24 +08:00
Ju4tCode
832875e7cf 🔀 Merge pull request #462
Release: 2.0.0a14
2021-08-04 14:08:55 +08:00
yanyongyu
73762e65bb Merge branch 'dev' of github.com:nonebot/nonebot2 into dev 2021-08-04 13:52:14 +08:00
Ju4tCode
26e627c36c Merge branch 'master' into dev 2021-08-04 13:50:18 +08:00
yanyongyu
8b93dc7769 🔖 Release 2.0.0a14 2021-08-04 13:42:21 +08:00
yanyongyu
6cfd44224d ⬆️ update dependencies 2021-08-04 12:55:30 +08:00
Ju4tCode
dc8b7887d7 🔀 Merge pull request #461
Add forward driver support for mirai-api-http adapter
2021-08-04 12:46:30 +08:00
nonebot
18f98e4cbc 📝 update api docs 2021-08-04 04:42:56 +00:00
yanyongyu
db73d2b621 📝 update doc 2021-08-04 12:41:53 +08:00
nonebot
7a3cd8c395 📝 update api docs 2021-08-03 16:44:13 +00:00
Mix
358528b495 👽 Add forward driver support for mirai-api-http adapter 2021-08-04 00:35:31 +08:00
yanyongyu
cda1ad093f 💥 change forward setup api 2021-07-31 12:24:11 +08:00
yanyongyu
f48c61c2e0 🐛 improve sub plugin detect 2021-07-29 17:31:28 +08:00
yanyongyu
571cdef826 📝 fix sphinx build errors 2021-07-28 16:32:50 +08:00
yanyongyu
0ce3ee6c20 💡 support sphinx 4.0 2021-07-26 12:14:29 +08:00
Ju4tCode
600fc4fffd 🔀 Merge pull request #452
修复由于 quart.exception在新版Quart被移除导致import出错
2021-07-26 11:16:00 +08:00
Mix
c1b10a0e48 👽 🐛 fix quart.exception removal caused import error 2021-07-26 10:41:38 +08:00
yanyongyu
904f285f62 ⬆️ update outdated dependencies 2021-07-25 12:09:25 +08:00
Ju4tCode
8680695586 Merge pull request #451 from nonebot/plugin/issue450
Adapter: feishu
2021-07-25 10:51:32 +08:00
StarHeartHunt
a1803553fb 🍻 publish adapter feishu 2021-07-25 01:40:55 +00:00
yanyongyu
9c647682e7 📌 update lock file 2021-07-23 15:34:02 +08:00
Ju4tCode
fb6e5a69f2 🔀 Merge pull request #448
飞书适配器import顺序格式化
2021-07-23 15:10:55 +08:00
Ju4tCode
cf85cbecb3 🔀 Merge pull request #449
修复依赖项git链接
2021-07-23 15:09:34 +08:00
nonebot
948ea93599 📝 update api docs 2021-07-23 07:00:01 +00:00
StarHeart
de48ed99a7 💚 fix git link 2021-07-23 14:58:03 +08:00
StarHeartHunt
8a6c26440c 🎨 sort imports in feishu adapter 2021-07-23 14:46:55 +08:00
yanyongyu
cf747f954c fastapi driver support forward connect 2021-07-23 00:51:19 +08:00
yanyongyu
54a7e4808c ⬆️ update lock file 2021-07-22 23:59:04 +08:00
yanyongyu
03f5683d52 ⬆️ update dependencies 2021-07-22 23:26:36 +08:00
Ju4tCode
58c922f042 🔀 Merge pull request #447
Publish plugin web-monitor
2021-07-22 13:01:56 +08:00
Abrahum
98e65ebdec 🍻 publish web monitor 2021-07-22 12:46:13 +08:00
Ju4tCode
e4a4a8127e 🔀 Merge pull request #444
Docs: 文档支持 algolia 全文搜索
2021-07-22 00:08:05 +08:00
yanyongyu
72b0ee0130 use pypi instead of aliyun 2021-07-22 00:07:20 +08:00
Ju4tCode
679ec94020 🔀 Merge pull request #446
Bot: dumbot傻瓜机器人
2021-07-21 23:49:31 +08:00
yanyongyu
1f0be1e1e3 improve aiohttp main loop performance 2021-07-21 23:47:18 +08:00
ffreemt
bcc55a9143 🍻 publish bot dumbot傻瓜机器人 2021-07-21 09:25:38 +00:00
StarHeartHunt
749d33478a 📝 add algolia search 2021-07-21 17:23:16 +08:00
yanyongyu
cb68e0ee1b 📝 update doc 2021-07-20 15:47:52 +08:00
yanyongyu
ecc613f6c5 add cqhttp forward support 2021-07-20 15:36:20 +08:00
yanyongyu
04b3fda40c cqhttp support forward websocket 2021-07-19 23:46:29 +08:00
yanyongyu
32787fdc1e ⚗️ experimenting aiohttp driver 2021-07-19 14:51:28 +08:00
yanyongyu
637c48aea7 🚧 update aiohttp driver 2021-07-19 01:20:17 +08:00
Ju4tCode
5768b5bdd6 🔀 Merge pull request #425
Feature: 添加飞书适配器支持
2021-07-18 22:42:37 +08:00
Ju4tCode
96d05cb521 🔀 Merge pull request #442
Plugin: nonebot_plugin_fr24
2021-07-18 19:43:23 +08:00
IronWolf-K
92e5b8ea88 🍻 publish plugin FlightRadar24查询模块 2021-07-18 10:28:27 +00:00
StarHeartHunt
59ed869ed0 📝 update api docs 2021-07-18 07:09:27 +00:00
yanyongyu
a14d475de2 🎨 format and update lock file 2021-07-18 15:07:30 +08:00
Ju4tCode
8ea4561f1c 🔀 Merge pull request #440
Optimize the description of multiple plugins
2021-07-18 13:50:48 +08:00
Lan
5ac43eb459 🚸 Improve user experience 2021-07-17 23:26:20 +08:00
Ju4tCode
c22d97fe47 🔀 Merge pull request #438
Plugin: nonebot_plugin_setu
2021-07-16 00:09:40 +08:00
ayanamiblhx
bb964213f1 🍻 publish plugin nonebot_plugin_setu 2021-07-15 13:04:43 +00:00
StarHeartHunt
ef1547cbfe Merge branch 'feishu-adapter' of https://github.com/StarHeartHunt/nonebot2-vercel-mirror into feishu-adapter 2021-07-14 10:43:03 +08:00
StarHeartHunt
f2295318a9 📝 update index 2021-07-14 10:42:47 +08:00
StarHeartHunt
66b54de869 📝 update copyright 2021-07-14 10:39:39 +08:00
StarHeartHunt
d802fad111 📝 update adapter store 2021-07-14 10:39:00 +08:00
StarHeartHunt
8acd561de6 📝 update api docs 2021-07-14 02:31:27 +00:00
StarHeartHunt
b4e20e00e4 Merge branch 'feishu-adapter' of https://github.com/StarHeartHunt/nonebot2-vercel-mirror into feishu-adapter 2021-07-14 10:29:12 +08:00
StarHeartHunt
3230dfc14a 📝 update main api doc 2021-07-14 10:28:48 +08:00
StarHeartHunt
607f338934 📝 update api docs 2021-07-14 02:24:35 +00:00
StarHeartHunt
758108229a 📝 add feishu api doc 2021-07-14 10:22:31 +08:00
StarHeartHunt
aac4571d43 📝 add feishu adapter doc 2021-07-14 10:19:37 +08:00
StarHeartHunt
0436c1b7b8 update test env 2021-07-14 09:26:53 +08:00
Ju4tCode
a740a9cfea 🔀 Merge pull request #435
Docs: scheduler docs typo
2021-07-11 15:21:51 +08:00
Ju4tCode
57ff73269b Update scheduler.md 2021-07-11 15:19:04 +08:00
StarHeartHunt
625c12fc12 implement all self-built app event 2021-07-11 12:26:11 +08:00
StarHeartHunt
4fc655323d 🎨 format code 2021-07-11 12:25:27 +08:00
Ju4tCode
f0482bb636 🔀 Merge pull request #434
Docs: 修复漏字
2021-07-11 12:20:40 +08:00
StarHeart
df6486f926 📝 fix docstring 2021-07-11 11:37:14 +08:00
Ju4tCode
141cd10651 🔀 Merge pull request #432
Bot: ATRI
2021-07-09 22:21:34 +08:00
Kyomotoi
711fffe3b0 🍻 publish bot ATRI 2021-07-09 09:09:14 +00:00
StarHeartHunt
2c056364c1 🚧 message read event should implement NoticeEvent 2021-07-09 16:18:19 +08:00
StarHeartHunt
c6921c731c update test file 2021-07-09 16:15:24 +08:00
StarHeartHunt
8c7498eeb5 🔥 self-built app hasn't MetaEvent 2021-07-09 16:14:25 +08:00
StarHeartHunt
30cb6be104 📝 tweak 2021-07-09 16:09:25 +08:00
StarHeartHunt
fbd60e30fc 🔥 remove check_reply 2021-07-09 16:09:01 +08:00
StarHeartHunt
2908cb3ce2 🐛 tweak 2021-07-09 16:02:54 +08:00
StarHeartHunt
b1c5013088 implement check_reply check_atme check_nickname 2021-07-09 16:01:32 +08:00
StarHeartHunt
70e424b58f ️ support cache tenant token 2021-07-09 09:22:56 +08:00
StarHeartHunt
730186cfd4 remove optional param 2021-07-08 23:06:48 +08:00
StarHeartHunt
d2ae2e2982 🚑 safely get dict value 2021-07-08 23:05:12 +08:00
StarHeartHunt
67770ffa6f implement at parser 2021-07-08 22:30:39 +08:00
StarHeartHunt
15ab958a70 🎨 format code 2021-07-08 22:30:21 +08:00
StarHeartHunt
af6f63dc44 🚧 add todo 2021-07-08 16:13:07 +08:00
StarHeartHunt
7c7994e2e2 implement rich text serializer 2021-07-08 16:12:43 +08:00
StarHeartHunt
f597303698 ♻️ improve segment-string parser 2021-07-08 14:52:34 +08:00
StarHeartHunt
1222972b73 ️ optimize import 2021-07-08 14:39:38 +08:00
StarHeartHunt
7df407056b implement text merger 2021-07-08 10:49:02 +08:00
StarHeartHunt
79b6601d12 🍻 tweak 2021-07-08 10:07:55 +08:00
Ju4tCode
53d98f3d2e 🔀 Merge pull request #430
修复mirai adapter中上传相关api操作报错
2021-07-08 09:27:36 +08:00
StarHeartHunt
fe43c8d69a 💩 should implement rich text parser 2021-07-07 22:36:08 +08:00
StarHeartHunt
e490be9eb0 🎨 tweak 2021-07-07 22:29:13 +08:00
Mix
3af8b55985 🐛 fix access denied for mirai adapter upload related action 2021-07-07 20:39:46 +08:00
yanyongyu
aaed345a20 🚨 remove linter error 2021-07-07 14:09:03 +08:00
yanyongyu
f42d578765 🐛 fix log tag unescaped 2021-07-07 14:08:44 +08:00
StarHeartHunt
f5843dd3ad 🔊 forgot to add backspace 2021-07-06 22:11:34 +08:00
StarHeartHunt
840580334f 🔊 optimize log 2021-07-06 22:08:38 +08:00
StarHeartHunt
5a8b5b5696 ️ optimize import 2021-07-06 22:08:22 +08:00
StarHeartHunt
dc5aa3d4bf 🔥 remove rich_text parser 2021-07-06 22:01:02 +08:00
StarHeartHunt
b9befc8350 🔇 remove print 2021-07-06 21:15:02 +08:00
StarHeartHunt
e3c3e370cb ️ remove unnecessary code 2021-07-06 21:12:49 +08:00
StarHeartHunt
603a63a629 implement message serializer & deserializer 2021-07-06 18:01:41 +08:00
Ju4tCode
276d09bb54 🔀 Merge pull request #428
Plugin: nonebot_plugin_statistical
2021-07-06 15:18:48 +08:00
StarHeartHunt
5635c83bfb 🐛 fix p2p model parse 2021-07-06 14:58:38 +08:00
StarHeartHunt
0ec7cdc3aa update testcase 2021-07-06 14:58:00 +08:00
HibiKier
932963e71c 🍻 publish plugin nonebot_plugin_statistical 2021-07-06 06:14:20 +00:00
StarHeartHunt
322ac98c50 🐛 validate schema field & fix request construct 2021-07-06 10:57:51 +08:00
StarHeartHunt
811e94e186 implement message target guessing 2021-07-06 10:45:00 +08:00
StarHeartHunt
0c39300f4b add call_api and implement send func 2021-07-05 11:10:49 +08:00
StarHeartHunt
33bd7582be 🎨 sort import 2021-07-05 11:10:49 +08:00
StarHeartHunt
b6979594a7 implement group and private message 2021-07-05 11:10:49 +08:00
StarHeartHunt
150ef30b73 add custom exception 2021-07-05 11:10:49 +08:00
StarHeartHunt
1042759d60 ️ make api_endpoint hard_encoded 2021-07-05 11:10:49 +08:00
StarHeartHunt
866149902c update testcase 2021-07-05 11:10:49 +08:00
StarHeartHunt
136b13b4cc ️ remove unused import 2021-07-05 11:10:49 +08:00
StarHeartHunt
cc11e2e885 🔧 add config api_endpoint 2021-07-05 11:10:49 +08:00
StarHeartHunt
f9f1e33262 implement message constructor 2021-07-05 11:10:49 +08:00
StarHeartHunt
7a8f881b04 implement event parser 2021-07-05 11:10:49 +08:00
StarHeartHunt
20c3c24a6d 👷 implement testcase 2021-07-05 11:10:49 +08:00
yanyongyu
f80ba8451f 🎨 fix linter error 2021-07-05 11:10:49 +08:00
StarHeartHunt
b1fa2bbb80 🔧 add configs 2021-07-05 11:10:49 +08:00
StarHeartHunt
406511496d 🏷️ add events 2021-07-05 11:10:49 +08:00
StarHeartHunt
24144a9474 implement check_permission procedure 2021-07-05 11:10:23 +08:00
yanyongyu
3571a5fdc0 🐛 fix missing json encode for cqhttp http 2021-07-04 23:23:39 +08:00
StarHeartHunt
4afd681ca9 🏷️ add segment schema 2021-07-03 13:56:47 +08:00
StarHeartHunt
48816308f8 add encryption support 2021-07-03 13:55:20 +08:00
StarHeartHunt
3e66eb2fdb add encryption dependency 2021-07-03 13:53:43 +08:00
StarHeartHunt
d669fed5e9 add testcase for feishu adapter 2021-07-03 13:53:01 +08:00
yanyongyu
8e915f808b 🎨 fix linter error 2021-07-03 11:50:56 +08:00
StarHeartHunt
46ace83106 🎉 init feishu adapter 2021-07-01 07:59:50 +08:00
Ju4tCode
da16bdbb96 🔀 Merge pull request #421
Docs: fix typo
2021-06-27 21:20:01 +08:00
StarHeart
c1b7b78929 ✏️ fix typo 2021-06-27 20:01:05 +08:00
midori
b9de8baac4 New: get_bot function (#419)
Co-authored-by: nonebot <nonebot@users.noreply.github.com>
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2021-06-27 14:03:54 +08:00
yanyongyu
b3718c3042 ⚗️ add forward driver aiohttp 2021-06-21 01:25:58 +08:00
yanyongyu
69cee3844e support dot notation for driver config 2021-06-21 01:25:58 +08:00
Ju4tCode
1db462e4ad 🔀 Merge pull request #416
Plugin: nonebot_plugin_russian
2021-06-20 21:24:44 +08:00
HibiKier
23cfa5564a 🍻 publish plugin nonebot_plugin_russian 2021-06-20 06:04:57 +00:00
Ju4tCode
7879346ca1 Merge pull request #414 from nonebot/remove-print
remove unnecessary print
2021-06-20 09:58:19 +08:00
nonebot
ef5a49933f 📝 update api docs 2021-06-20 01:28:07 +00:00
StarHeart
e0bd7e11d5 🔥 remove unnecessary print 2021-06-20 09:25:55 +08:00
yanyongyu
0c5bbdaabe 🎨 remove linter error 2021-06-19 15:18:57 +08:00
yanyongyu
d8e29a81aa support absolute plugin import 2021-06-19 15:15:00 +08:00
yanyongyu
9f15b69724 allow change handlers list when running 2021-06-18 16:27:41 +08:00
yanyongyu
cd12718dcb 🐛 update mirai adapter 2021-06-18 01:23:13 +08:00
Ju4tCode
94c3c47523 🔀 Merge pull request #412
Plugin: nonebot_plugin_pixivrank_search
2021-06-17 18:00:33 +08:00
HibiKier
fde6181d3c 🍻 publish plugin nonebot_plugin_pixivrank_search 2021-06-17 08:10:24 +00:00
Ju4tCode
a4c6d834ff 🔀 Merge pull request #410
Bug: 修复shell_command多次--help时重复输出
2021-06-17 10:59:27 +08:00
rmuchan
c8e494ca83 📝 update api docs 2021-06-17 02:20:46 +00:00
Muchan
f87c23c9a7 🐛 fix duplicated help 2021-06-17 10:14:36 +08:00
yanyongyu
b2f21ab974 🎨 fix message typing error 2021-06-17 01:07:19 +08:00
yanyongyu
6749afe75e 🚨 remove linter error 2021-06-16 00:58:47 +08:00
Ju4tCode
8849cb73bb 🔀 Merge pull request #409
Docs: typo
2021-06-15 10:21:03 +08:00
yanyongyu
ad2060e651 📝 update api docs 2021-06-15 10:16:31 +08:00
yanyongyu
c76dae584e 🐛 fix quart implement 2021-06-15 10:16:17 +08:00
StarHeart
edb7c79acf 📝 typo 2021-06-15 09:53:25 +08:00
yanyongyu
76c830739c 🎨 change reverse driver abstract methods 2021-06-15 01:23:12 +08:00
yanyongyu
8e6f8fada8 🐛 fix import recursion when same plugin and file name (fix #401) 2021-06-15 01:13:05 +08:00
yanyongyu
ddd96271b0 🎨 improve typing 2021-06-14 19:52:35 +08:00
Ju4tCode
e9bc98e74d 🔀 Merge pull request #406
Feature: 支持自定义 Response
2021-06-14 14:14:43 +08:00
StarHeartHunt
af6e9217c7 📝 update api docs 2021-06-13 18:08:29 +00:00
StarHeartHunt
c0d78449be support custom response 2021-06-14 02:06:37 +08:00
Mix
d7f2837efe 🔀 Merge pull request #408
Docs: 完善文档 Python 版本描述
2021-06-12 16:47:36 +08:00
StarHeart
cf9b5fd980 📝 complete python version requirement 2021-06-12 15:34:27 +08:00
Ju4tCode
b42cafafd6 🔀 Merge pull request #407
修复Mirai加群通过时报错
2021-06-11 23:02:57 +08:00
Mix
136c9a2687 🐛 Fix Mirai group join event approve failed, fix #400 2021-06-11 20:20:14 +08:00
yanyongyu
cf45572211 ⬆️ upgrade fastapi 2021-06-11 01:48:52 +08:00
Ju4tCode
c9d80255ae 🔀 Merge pull request #405
Bot: 绪山真寻bot
2021-06-10 13:10:07 +08:00
HibiKier
393be3baa4 🍻 publish bot 绪山真寻bot 2021-06-10 00:21:43 +00:00
Ju4tCode
fd01213697 🔀 Merge pull request #403
Bot: YanXiBot
2021-06-09 23:42:10 +08:00
Melodyknit
2f5eb1a0f9 🍻 publish bot YanXiBot 2021-06-09 15:19:27 +00:00
StarHeart
ca31ec5fe3 Merge pull request #398 from nonebot/StarHeartHunt-patch-1
Docs: update tagline
2021-06-02 10:23:55 +08:00
StarHeart
2003dfd703 📝 update tagline in README 2021-06-02 08:45:14 +08:00
StarHeart
f3342722f5 📝 update tagline 2021-06-02 08:43:01 +08:00
yanyongyu
b2f5f93603 🐛 fix error inherit state in session when using state_factory 2021-05-31 21:54:17 +08:00
yanyongyu
830276d110 🐛 fix state error when matcher update(fix #397) 2021-05-31 21:49:25 +08:00
Ju4tCode
9342d03f4d 🔀 Merge pull request #396
Update plugins.json
2021-05-31 16:19:30 +08:00
HibiKier
fe588caebb Update plugins.json 2021-05-31 16:04:11 +08:00
Ju4tCode
b0026831d0 🔀 Merge pull request #395
Update plugins.json
2021-05-31 15:38:54 +08:00
HibiKier
46d7804c98 Update plugins.json 2021-05-31 12:20:13 +08:00
yanyongyu
accbf57776 🚨 remove some linter warning 2021-05-31 01:06:56 +08:00
yanyongyu
62c0dd6e74 💡 add docstring 2021-05-31 00:27:31 +08:00
yanyongyu
916bb5b0e6 💡 update docstring 2021-05-30 11:07:27 +08:00
yanyongyu
45e1126f37 🐛 fix missing update when reject or pause (fix #394) 2021-05-30 10:55:34 +08:00
yanyongyu
57cf8e9bd8 🐛 fix cqhttp event session id mismatch for group 2021-05-29 19:32:05 +08:00
Ju4tCode
f609a9fe0e 🔀 Merge pull request #392
Docs: update telegram links
2021-05-29 18:26:34 +08:00
Ju4tCode
4795f01583 Merge branch 'dev' into richardchien-patch-1 2021-05-29 18:15:32 +08:00
Richard Chien
06f9f795aa 🔗 add discord badge 2021-05-29 14:09:19 +08:00
Richard Chien
2d7d8992c0 🔗 update community links 2021-05-29 13:53:43 +08:00
Ju4tCode
15007feea7 🔀 Merge pull request #391
Docs: add discord server badge
2021-05-29 00:08:47 +08:00
nonebot
8095be9ab9 📝 update api docs 2021-05-28 14:31:02 +00:00
StarHeart
ea48b86310 📝 add discord server link 2021-05-28 22:27:49 +08:00
Ju4tCode
6402d8a4de Merge pull request #388 from HibiKier/patch-2
Update plugins.json
2021-05-28 13:25:43 +08:00
HibiKier
5ec30c5122 Update plugins.json 2021-05-28 13:20:59 +08:00
yanyongyu
c4b83a60f1 🚧 add http request and response class 2021-05-27 01:01:58 +08:00
Ju4tCode
0fec4c8592 🔀 Merge pull request #387 2021-05-26 17:42:18 +08:00
HibiKier
a09e09b942 Update plugins.json 2021-05-26 17:13:06 +08:00
Ju4tCode
7e8296b36e 🔀 Merge pull request #386
typo
2021-05-25 21:10:53 +08:00
nonebot
322477638a 📝 update api docs 2021-05-25 12:48:51 +00:00
StarHeart
e659b4b2b6 🐛 typo 2021-05-25 20:46:27 +08:00
yanyongyu
27fe6e4fcb 🔥 remove cqhttp api self_id arg 2021-05-25 16:59:26 +08:00
Ju4tCode
7d8b0843a0 Merge pull request #382 from nonebot/plugin/issue381
Plugin: Nonebot2 消息撤回插件
2021-05-24 21:31:38 +08:00
MeetWq
e44b427b7a 🍻 publish plugin Nonebot2 消息撤回插件 2021-05-24 12:42:34 +00:00
Ju4tCode
2ff6f87842 🔀 Merge pull request #380
Update plugins.json
2021-05-24 17:13:48 +08:00
HibiKier
84dfe18f39 Update plugins.json 2021-05-24 16:59:05 +08:00
yanyongyu
918b375ece 💥 drop self_id call_api support 2021-05-24 16:49:27 +08:00
StarHeart
c82a4820f7 Merge pull request #377 from Cosmos-Break/patch-3
Docs: Readme.md 增加 awesome-nonebot 资源库
2021-05-23 20:26:34 +08:00
StarHeartHunt
c6e62957ab 📝 tweak expression 2021-05-23 15:48:13 +08:00
Cosmos-Break
8a14177219 📝 add link to awesome-nonebot 2021-05-23 15:45:30 +08:00
StarHeart
24268072fc Merge pull request #378 from Cosmos-Break/patch-4
Docs: Add mirai adapter port config
2021-05-23 15:33:40 +08:00
Cosmos-Break
3c65f2dd19 📝 add mirai port config 2021-05-23 15:28:48 +08:00
Jigsaw
3f14a92a3e Merge pull request #374 from nonebot/docs/mah-user-guide
更新 Mirai-API-HTTP 用户指南
2021-05-23 01:31:52 +08:00
Mix
adf2016f4e 📝 Update Mirai-API-HTTP user guide, fix #373 2021-05-23 01:29:52 +08:00
Ju4tCode
81bb8be7f3 🔀 Merge pull request #371
Plugin: nonebot-plugin-alias
2021-05-22 18:53:10 +08:00
MeetWq
744f9e9f5d 🍻 publish plugin nonebot-plugin-alias 2021-05-22 09:59:57 +00:00
Ju4tCode
e2de13e122 🔀 Merge pull request #369
Flow: add .DS_store to .gitignore
2021-05-22 11:32:46 +08:00
StarHeartHunt
3939dfa024 🙈 ignore .DS_Store 2021-05-22 11:27:16 +08:00
yanyongyu
8680a954f8 ♻️ separate driver 2021-05-21 17:06:20 +08:00
Ju4tCode
20001764bf 🔀 Merge pull request #367
Plugin: remove todo plugin
2021-05-21 15:18:09 +08:00
yanyongyu
61512ff01f 🏷️ add type hint for logger 2021-05-21 15:15:04 +08:00
Jigsaw
2488c6295e 📝 Remove nonebot_plugin_todo 2021-05-21 13:26:42 +08:00
Ju4tCode
100f560558 🔀 Merge pull request #366
Docs: update permission doc
2021-05-21 00:51:14 +08:00
StarHeartHunt
01678005f0 🎨 reformat docs 2021-05-21 00:46:09 +08:00
StarHeartHunt
00dc72b6c4 🔥 remove .DS_Store 2021-05-20 22:41:54 +08:00
AkiraXie
ca21fb8202 📝 fix typo 2021-05-20 20:28:11 +08:00
AkiraXie
5989c3fecd 📝 update permission doc 2021-05-20 20:20:51 +08:00
yanyongyu
7376933c31 📝 update api doc build 2021-05-20 15:09:59 +08:00
Ju4tCode
a573266cab Merge pull request #364 from nonebot/plugin/issue363
Plugin: nonebot_plugin_gamedraw
2021-05-17 11:28:00 +08:00
HibiKier
8374f86fde 🍻 publish plugin nonebot_plugin_gamedraw 2021-05-17 03:08:42 +00:00
Ju4tCode
4a18772d2c 🔀 Merge pull request #362
Plugin: Nonebot2插件轻量帮助列表
2021-05-17 10:07:42 +08:00
XZhouQD
5d0ac94bfe 🍻 publish plugin Nonebot2插件轻量帮助列表 2021-05-17 00:50:29 +00:00
Ju4tCode
a636ddfab4 🔀 Merge pull request #360
Docs: 添加中国大陆文档镜像
2021-05-15 10:45:32 +08:00
StarHeartHunt
5c2840ca27 📝 add chinese mainland docs mirror 2021-05-14 22:56:11 +08:00
Ju4tCode
44850a279d 🔀 Merge pull request #359
Docs: update cqhttp implementations name
2021-05-12 12:09:27 +08:00
XZhouQD
17f3258207 📝 update api docs 2021-05-12 04:03:04 +00:00
Xiaowei Zhou
b95fed69b0 [Docs] Fix: oicq-plugin-onebot -> node-onebot
Also fixed url there
2021-05-12 09:38:25 +08:00
Xiaowei Zhou
059935aedb [Docs] Update: oicq-plugin-onebot renmae 2021-05-12 09:20:51 +08:00
Xiaowei Zhou
c99e1880d3 [Doc] Update: Onebot-Kotlin rename
Update: cqhttp-mirai / cqhttp-mirai-embedded has been renamed to Onebot-Mirai / Onebot-Kotlin by its author [yyuueexxiinngg](https://github.com/yyuueexxiinngg). Since the embedded branch was abandoned, both links here point to master branch of [onebot-kotlin](https://github.com/yyuueexxiinngg/onebot-kotlin).
2021-05-12 08:54:19 +08:00
yanyongyu
faf7a3b500 📝 update doc 2021-05-10 18:42:32 +08:00
yanyongyu
41c5ac0ac7 improve plugin matcher system 2021-05-10 18:39:59 +08:00
yanyongyu
f8ad9ef278 ⚗️ support segment typing for message 2021-05-10 00:54:15 +08:00
Mix
5146a30836 🔀 Merge pull request #356
Plugin: Minecraft 服务器状态查询
2021-05-09 22:51:56 +08:00
Jigsaw111
db59cd9578 🍻 publish plugin Minecraft 服务器状态查询 2021-05-09 14:26:01 +00:00
yanyongyu
4b38afdcd7 cqhttp message segment support more types 2021-05-04 11:08:31 +08:00
Ju4tCode
b87971247a 🔀 Merge pull request #350
Docs: fix store link
2021-05-03 15:00:13 +08:00
yanyongyu
dcf4838fda 📝 fix store link 2021-05-03 14:56:24 +08:00
StarHeart
6f40365407 🐛 fix store link 2021-05-03 14:10:12 +08:00
Ju4tCode
315fdb97d3 🔀 Merge pull request #349
Adapter: gocq
2021-05-02 16:39:04 +08:00
yanyongyu
9a3e974063 🐛 fix adapter publish id link error 2021-05-02 16:37:57 +08:00
Jigsaw111
6b3183cdfa 🍻 publish adapter gocq 2021-05-02 08:37:17 +00:00
yanyongyu
5189a182b5 ✏️ fix typo 2021-05-02 16:26:47 +08:00
yanyongyu
884a7b966f 🐛 fix missing bool to str convert in cqhttp message segment 2021-05-02 14:24:12 +08:00
Ju4tCode
fa73c13800 🔀 Merge pull request #344
Docs: update load a plugin
2021-05-01 10:59:14 +08:00
Ju4tCode
593d593a62 📝 update doc 2021-05-01 10:53:18 +08:00
Jigsaw
c2c8906b7d 📝 update loading-a-plugin docs 2021-04-30 16:24:23 +08:00
Ju4tCode
71f68fc1ce 🔀 Merge pull request #343 2021-04-29 22:58:14 +08:00
Jigsaw111
add2bda2c1 🍻 publish plugin nonebot_plugin_puppet 2021-04-29 14:22:11 +00:00
Ju4tCode
beef2ad8cf 🔀 Merge pull request #338
Bot: Github Bot
2021-04-26 22:43:03 +08:00
yanyongyu
554865f97f 🍻 publish bot Github Bot 2021-04-26 14:35:25 +00:00
Ju4tCode
d3e7ed4a71 🔀 Merge pull request #336
Docs: update handlers overload
2021-04-25 13:23:05 +08:00
yanyongyu
56e489b458 📝 update doc 2021-04-25 13:18:36 +08:00
AkiraXie
5f3bd91321 📝 update description in handler-overload doc 2021-04-25 02:31:37 +08:00
AkiraXie
4655bf1df8 📝 update handlers-overload docs 2021-04-25 02:08:52 +08:00
yanyongyu
9052214e6d raise ImportError when exec_module 2021-04-21 18:26:58 +08:00
Ju4tCode
59405bbe7a 🔀 Merge pull request #335
Bot: change repository url
2021-04-20 01:08:39 +08:00
Ailitonia
260d119711 Bot: change repository url
Updated new repository url for Bot: Omega Miya
2021-04-19 23:30:42 +08:00
yanyongyu
5abc0d9614 📝 update changelog 2021-04-19 21:51:36 +08:00
Ju4tCode
4ba6ff106c Merge pull request #334 from nonebot/yanyongyu/issue332
Fix: log module name error
2021-04-19 21:50:11 +08:00
Ju4tCode
9e51df9116 🔀 Merge pull request #333
New: support custom log level config
2021-04-19 21:44:25 +08:00
yanyongyu
64d51448b8 🐛 fix log module name error 2021-04-19 21:43:28 +08:00
yanyongyu
79d3bbcdfe 🔊 change log level add level config 2021-04-19 21:15:10 +08:00
yanyongyu
c24d0def09 🔖 bump adapter cqhttp version 2021-04-18 23:30:57 +08:00
Ju4tCode
e08843dd5c 🔀 Merge pull request #331
Docs: 一点小修改
2021-04-16 15:47:35 +08:00
StarHeart
ec35ef041a 📝 tweak 2021-04-16 09:03:00 +08:00
Ju4tCode
efe8dd98b5 🔀 Merge pull request #330
Plugin: 待办事项提醒(闹钟)
2021-04-15 01:14:09 +08:00
Jigsaw111
3fb9b25284 🍻 publish plugin 待办事项提醒(闹钟) 2021-04-14 12:28:02 +00:00
Ju4tCode
06deb13826 🔀 Merge pull request #328
Docs: 文档优化
2021-04-13 13:09:38 +08:00
StarHeartHunt
7d189392d2 📝 recommend pylance 2021-04-13 00:24:49 +08:00
StarHeartHunt
2a07b49cb7 📝 tweak 2021-04-12 23:35:51 +08:00
yanyongyu
0be145491d 🚸 add question template 2021-04-12 13:06:03 +08:00
Ju4tCode
58dd4a2183 🔀 Merge pull request #326
优化 issue 模板 bug 报告
2021-04-12 12:44:15 +08:00
StarHeart
810477749b 🚸 implement bug report template 2021-04-12 12:08:54 +08:00
Ju4tCode
92b035bea8 🔀 Merge pull request #322
New: `handle_event` will return excecption
2021-04-09 12:50:47 +08:00
yanyongyu
9801a8cebd 🎨 format code 2021-04-09 12:26:27 +08:00
Mix
f5a22b3d4b 🥅 return event handling exception 2021-04-08 23:35:08 +08:00
Ju4tCode
abbcb36131 🔀 Merge pull request #321
add documentation issue template
2021-04-08 00:43:21 -05:00
Ju4tCode
d4860af85f 🔀 Merge pull request #320
忽略 yarn.lock 防止意外提交
2021-04-08 00:41:46 -05:00
Ju4tCode
50a4cbdb80 🔀 Merge pull request #319
Docs: 更新 go-cqhttp 配置文件
2021-04-08 00:38:51 -05:00
StarHeart
dff9a74f35 🚸 add doc issue template 2021-04-08 13:26:34 +08:00
StarHeartHunt
a5c2b06493 🙈 ignore yarn.lock 2021-04-08 13:05:41 +08:00
StarHeartHunt
7bb49f0b3c 📝 update go-cqhttp config file 2021-04-08 12:34:01 +08:00
Mix
00b4b880e9 🔀 Merge pull request #316
Docs: 写明所需 Python 最低版本小版本号
2021-04-07 01:18:17 +08:00
StarHeart
87d93def62 📝 declare patch version of minimal supported python version 2021-04-07 01:13:44 +08:00
Ju4tCode
0315aa7d8f 🔀 Merge pull request #314
Doc: update store style
2021-04-05 03:49:06 -05:00
yanyongyu
b9812ea11b 🎨 revert v-row 2021-04-05 16:39:26 +08:00
yanyongyu
207750774d 🎨 improve format 2021-04-05 16:35:29 +08:00
StarHeartHunt
176dbd5830 📝 update api docs 2021-04-05 05:52:25 +00:00
StarHeartHunt
1c6711355e 🎨 format files 2021-04-05 13:49:01 +08:00
StarHeartHunt
20e1bf9624 📝 improve store display effect 2021-04-05 13:34:35 +08:00
yanyongyu
d1a438a287 ⚗️ support tuple prefix in startswith 2021-04-04 12:28:10 +08:00
yanyongyu
0d467d9275 add startswith endswith ignorecase option #312 2021-04-04 12:19:03 +08:00
yanyongyu
c402b7599f 🐛 fix missing matcher when load external plugin with dot 2021-04-03 17:32:01 +08:00
Ju4tCode
916d620012 🔀 Merge pull request #311
Pre Release 2.0.0a13.post1
2021-04-01 12:42:58 -05:00
yanyongyu
0fd82d4f54 📝 archive doc 2021-04-02 01:38:42 +08:00
yanyongyu
e425571b08 🐛 fix protocol not found in py37 2021-04-02 01:17:33 +08:00
yanyongyu
85f0023350 🔥 improve matcher store 2021-04-02 01:09:40 +08:00
yanyongyu
0eadf5f4e9 🐛 fix load error 2021-04-02 00:05:27 +08:00
Ju4tCode
b09a7518f5 🔀 Merge pull request #310
Pre Release 2.0.0a13
2021-04-01 07:44:52 -05:00
yanyongyu
0235af770f 📌 bump version 2021-04-01 20:34:49 +08:00
yanyongyu
e03e3f6130 📝 update doc 2021-04-01 20:27:27 +08:00
yanyongyu
f0a6ff4627 ⚗️ add called api hook 2021-04-01 20:23:55 +08:00
Ju4tCode
6b763e20d0 🔀 Merge pull request #309
Fix: matcher got  recursion
2021-04-01 07:09:08 -05:00
yanyongyu
fcb1c5d316 🚑 fix matcher got recursion 2021-04-01 20:05:31 +08:00
Ju4tCode
953328903c 🔀 Merge pull request #308
Pre Release 2.0.0a12
2021-03-31 08:55:18 -05:00
yanyongyu
afba90838f 📝 archive doc 2021-03-31 21:37:01 +08:00
nonebot
f1ed783776 📝 update api docs 2021-03-31 13:27:02 +00:00
yanyongyu
59ec5bacde 📝 update changelog 2021-03-31 21:20:07 +08:00
yanyongyu
ca08c56df7 🐛 fix import hook export 2021-03-31 20:38:00 +08:00
yanyongyu
d1e8925fe0 ⬆️ bump version 2021-03-31 20:25:45 +08:00
yanyongyu
68ba1c1af2 🐛 fix reply get fail broken down 2021-03-31 20:09:00 +08:00
Ju4tCode
03ac119313 🔀 Merge pull request #307
New: add call_api hook
2021-03-31 04:00:18 -05:00
yanyongyu
8f99b01fb5 ⚗️ add call_api hook 2021-03-31 16:53:10 +08:00
yanyongyu
4e7592de98 🔒 ensure cqhttp str radd escaped 2021-03-30 16:21:56 +08:00
Ju4tCode
5db819738e 🔀 Merge pull request #300
Fix: mirai empty message chain when check at
2021-03-30 02:55:02 -05:00
SinonJZH
ade5d923ab 🐛 fix mirai message chain empty 2021-03-30 12:16:12 +08:00
yanyongyu
43b185a3b8 🔊 add log for event handle 2021-03-27 14:42:43 +08:00
yanyongyu
65ec4828a9 📝 update changelog 2021-03-26 14:27:05 +08:00
yanyongyu
1f585d8bcb store message in ParserExit exception 2021-03-26 11:25:13 +08:00
yanyongyu
b861149e0b add argparse help message 2021-03-25 18:22:56 +08:00
Ju4tCode
534b51bc73 🔀 Merge pull request #294
Doc: update hook docs
2021-03-25 02:14:41 -05:00
AkiraXie
430b3467cc 📝 fix typo 2021-03-24 20:04:48 +08:00
AkiraXie
2dc7107990 📝 update hook docs 2021-03-24 19:52:47 +08:00
Ju4tCode
81edb535a4 🔀 Merge pull request #293
Docs: runtime hook
2021-03-24 12:09:34 +08:00
yanyongyu
f00ce8b4f6 🐛 matcher.send returned none 2021-03-24 00:28:37 +08:00
StarHeartHunt
696ae2da6b 📝 update api docs 2021-03-23 15:11:34 +00:00
StarHeartHunt
b7e5ce88ea 📝 Correct params of hook functions 2021-03-23 23:10:05 +08:00
Ju4tCode
8fc8cb6112 🔀 Merge pull request #291
Plugin: 本地数据存储
2021-03-22 17:28:48 +08:00
yanyongyu
48fae782d7 📝 update plugin doc 2021-03-22 17:27:31 +08:00
yanyongyu
f3e78cc82e 🍻 publish plugin 本地数据存储 2021-03-22 09:25:11 +00:00
yanyongyu
45199a247b 🐛 fix plugin matcher data 2021-03-22 16:41:29 +08:00
yanyongyu
f0a8b47c06 💩 remove __manager__ 2021-03-22 01:23:09 +08:00
yanyongyu
6371cd6bfe 🐛 fix error matcher module when import 2021-03-22 01:15:15 +08:00
yanyongyu
d738f8674d 📝 update doc and chqnglog 2021-03-20 16:38:42 +08:00
Ju4tCode
abfda3113b 🔀 Merge pull request #276
Breaking: change cqhttp ding session id
2021-03-20 16:36:22 +08:00
yanyongyu
a941b32dd5 📝 update changelog 2021-03-20 16:33:16 +08:00
yanyongyu
1527fb55f5 💡 update handler docstring 2021-03-20 16:33:16 +08:00
Ju4tCode
ffc1cd7d8d 🔀 Merge pull request #290
Fix: cqhttp post secret checking error
2021-03-20 16:32:51 +08:00
Reverier-Xu
7f27957164 💥 change cqhttp ding session id 2021-03-20 16:13:02 +08:00
yanyongyu
f8c057b135 📌 update lock file 2021-03-20 15:13:08 +08:00
yanyongyu
2166595e50 🐛 fix cqhttp secret checking #289 2021-03-20 14:49:58 +08:00
yanyongyu
22033e1cfb 🐛 fix typing 2021-03-19 15:02:01 +08:00
yanyongyu
fc334ec7b9 add logger id 2021-03-19 00:24:38 +08:00
yanyongyu
e7dc4e1eec ⚗️ finish handler class 2021-03-18 21:30:52 +08:00
yanyongyu
6bd12b7f2c ⚗️ add handler class 2021-03-18 19:16:18 +08:00
Ju4tCode
5d48a92d1d 🔀 Merge pull request #287
Plugin: bilibili视频、番剧解析
2021-03-16 18:08:03 +08:00
mengshouer
4bc87ca747 🍻 publish plugin bilibili视频、番剧解析 2021-03-16 10:04:32 +00:00
yanyongyu
62135dc117 🔊 fix logger color tag 2021-03-16 16:20:58 +08:00
yanyongyu
1e294b8fbe 🐛 fix config load due to pydantic breaking change 2021-03-16 16:17:34 +08:00
Ju4tCode
9258bb09b4 🔀 Merge pull request #285
Doc: backword for 2.0.0a11 archive
2021-03-14 11:52:55 +08:00
StarHeartHunt
b31317720b 📝 add tips for separated adapters in 2.0.0a11 docs 2021-03-14 08:49:22 +08:00
yanyongyu
211c571508 🐛 fix reimport by require 2021-03-13 18:21:56 +08:00
yanyongyu
785eac1345 🏷️ fix regex rule typing error 2021-03-13 15:35:13 +08:00
yanyongyu
bb64c6fb71 🐛 fix type and permission updater 2021-03-12 16:28:56 +08:00
Ju4tCode
782232fb1a 🔀 Merge pull request #282
Bug: typo in built-in plugin
2021-03-11 14:57:09 +08:00
Artin
0fec9915de ding: send by webhook
close: #189

Feature: 钉钉添加 `send_by_webhook` 方法 #189
2021-03-11 13:26:16 +08:00
StarHeart
efacff698d 🐛 typo 2021-03-11 10:55:18 +08:00
Ju4tCode
36d0628e4f 🔀 Merge pull request #281
Fix: store bot display and readme
2021-03-11 00:39:08 +08:00
yanyongyu
46c65b919f 🐛 fix bot display bug 2021-03-11 00:27:32 +08:00
Ju4tCode
0b9aad09cf 🔀 Merge pull request #280
Bot: Omega Miya
2021-03-11 00:23:55 +08:00
Ailitonia
717e74f01d 🍻 publish bot Omega Miya 2021-03-10 16:22:39 +00:00
Ju4tCode
ef4f8df5a7 🔀 Merge pull request #278
Bot: HarukaBot
2021-03-11 00:21:13 +08:00
SK-415
dce1187750 🍻 publish bot HarukaBot 2021-03-10 14:45:43 +00:00
yanyongyu
5ee6beb4b8 🚑 fix test reload 2021-03-10 17:32:14 +08:00
Mix
3af8cc45ea 🔀 Merge pull request #274
Fix: Plugin Store link in README
2021-03-08 17:27:58 +08:00
yanyongyu
89ff2dd3c5 📝 update readme 2021-03-08 17:16:37 +08:00
SK-415
e7101a1f39 fix: Plugin Store link in README 2021-03-08 16:39:33 +08:00
Ju4tCode
2af7f2bedb 🔀 Merge pull request #273
Fix: mah friend request
2021-03-07 09:08:35 -06:00
notnotype
ad70fac377 📝 update api docs 2021-03-07 14:41:18 +00:00
notnotype
2885e6053c fix: mah adapter 不能接受好友请求 2021-03-07 22:36:38 +08:00
Ju4tCode
4661adc564 🔀 Merge pull request #272
Fix: errors in doc
2021-03-07 08:34:03 -06:00
yanyongyu
edc6da9e61 ✏️ fix plugin link 2021-03-07 22:24:04 +08:00
Ju4tCode
d49749e5a1 🔀 Merge pull request #269
Fix typo
2021-03-07 08:22:05 -06:00
Ju4tCode
8544fb2f69 🔀 Merge pull request #268
Doc: add adapter install guide
2021-03-07 08:20:52 -06:00
Ju4tCode
80e41d26e2 🔀 Merge pull request #270
Fix: doc plugin publish
2021-03-07 08:19:22 -06:00
StarHeart
8d6bb3768b 🐛 correct params order 2021-03-07 19:09:03 +08:00
StarHeart
c54007d7a4 🐛 typo 2021-03-07 18:54:00 +08:00
Ju4tCode
35bf3ef772 🔀 Merge pull request #267
Plugin: 插件管理器
2021-03-07 04:40:55 -06:00
StarHeartHunt
06e1459667 Merge branch 'docs' of github.com:StarHeartHunt/nonebot2-vercel-mirror into docs 2021-03-07 18:13:43 +08:00
StarHeartHunt
da97a18497 📝 remove redundant characters 2021-03-07 18:12:14 +08:00
StarHeartHunt
61e33e24e9 📝 update api docs 2021-03-07 10:04:53 +00:00
StarHeartHunt
f49a581193 📝 replace inaccurate words 2021-03-07 18:01:30 +08:00
StarHeartHunt
f30b9e4fb9 📝 tips for getting adapters list 2021-03-07 17:59:25 +08:00
StarHeartHunt
c3a8dc709f 📝 tips for installing separated adapters 2021-03-07 17:55:29 +08:00
Jigsaw111
63d6f173d6 🍻 publish plugin 插件管理器 2021-03-07 08:42:10 +00:00
Ju4tCode
8d80b610d1 🔀 Merge pull request #265
ci: 更新商店发布议题机器人
2021-03-06 11:19:58 -06:00
hemengyang
80a54914e2 👷 update publish issue bot 2021-03-07 00:43:12 +08:00
yanyongyu
ac613b5839 🐛 fix subplugin detect bug 2021-03-06 22:25:50 +08:00
yanyongyu
33412f9bd2 ⚗️ add reload dir config for fastapi 2021-03-06 11:56:58 +08:00
Ju4tCode
51304fdd8e 🔀 Merge pull request #262
Fix: exclude all `__init__.py` in adapter packaging
2021-03-05 11:46:22 -06:00
yanyongyu
e139c883a3 🚑 exclude all __init__ in packaging 2021-03-06 01:40:20 +08:00
Ju4tCode
662c5c09a6 🔀 Merge pull request #261
Fix: fix adapter override namespace file
2021-03-05 10:40:39 -06:00
yanyongyu
a99d33198f 🐛 fix override 2021-03-06 00:09:26 +08:00
yanyongyu
e6ac07e608 🔀 Merge branch 'dev' 2021-03-05 20:49:16 +08:00
yanyongyu
d476c7e999 👷 update release drafter 2021-03-05 20:48:44 +08:00
Ju4tCode
22655005f9 🔀 Merge pull request #260
Pre Release 2.0.0a11
2021-03-05 06:39:19 -06:00
yanyongyu
f7dd898379 📝 update api doc 2021-03-05 20:29:47 +08:00
nonebot
d568a31684 📝 update api docs 2021-03-05 12:17:22 +00:00
yanyongyu
46795ecd4b 📌 update lock file 2021-03-05 20:09:42 +08:00
yanyongyu
f1f510604e 📝 archive 2.0.0a11 doc 2021-03-05 20:01:55 +08:00
yanyongyu
611049681a change publish and issue 2021-03-05 16:27:43 +08:00
Ju4tCode
15c6f30fc3 🔀 Merge pull request #259
Plugin: biliav小程序转换器
2021-03-04 04:58:51 -06:00
nonebot
59a855f2ed 📝 update api docs 2021-03-04 10:55:07 +00:00
knva
db61a93de8 🍻 publish biliav小程序转换器 2021-03-04 10:52:37 +00:00
yanyongyu
4ed5b06db0 📝 update changelog 2021-03-03 16:09:37 +08:00
yanyongyu
9e04e497b7 ⚗️ add type and permission updater hook 2021-03-03 16:06:19 +08:00
yanyongyu
464f0d4a89 🔀 Merge branch 'master' 2021-03-02 15:59:38 +08:00
Ju4tCode
1df24a683e 🔀 Merge pull request #255
Fix: prompt type error
2021-03-02 01:57:45 -06:00
nonebot
873aa62825 📝 update api docs 2021-03-02 07:41:23 +00:00
yanyongyu
cb6c1cccca 🐛 fix upload ci bug 2021-03-02 15:38:47 +08:00
yanyongyu
f6289ff1b3 🐛 fix prompt error 2021-03-02 14:35:02 +08:00
Ju4tCode
7b61cd370e 🔀 Merge pull request #254 2021-03-01 08:53:17 -06:00
anlen123
7f4ee24f87 🍻 publish 缩写查询器 2021-03-01 22:48:23 +08:00
yanyongyu
3c8dca67fa ⬆️ bump dependency 2021-03-01 19:24:03 +08:00
yanyongyu
b962bc43e6 ⬆️ bump httpx 2021-03-01 17:39:44 +08:00
Ju4tCode
e70b29bb9e 🔀 Merge pull request #251
Plugin: 缩写查询器
2021-03-01 01:59:31 -06:00
anlen123
94a55fead5 🍻 publish 缩写查询器 2021-03-01 06:47:51 +00:00
yanyongyu
b23e845726 ⬆️ fit pydantic 1.8 2021-03-01 00:30:06 +08:00
Ju4tCode
dc17d514b4 🔀 Merge pull request #249
Plugin: 猜猜看
2021-02-28 21:43:10 +08:00
ffreemt
5e24300619 🍻 publish 猜猜看 2021-02-28 12:29:11 +00:00
yanyongyu
dc38a98180 ⬆️ bump and fit pydantic 1.8 2021-02-28 00:35:40 +08:00
Ju4tCode
af27e8f3f5 🔀 Merge pull request #246
Docs: 添加 Vercel 文档镜像链接
2021-02-27 15:32:35 +08:00
StarHeart
01af05742c 📝 Add link to docs mirror (hosted on Vercel) 2021-02-26 22:51:33 +08:00
Ju4tCode
11052dbcd1 🔀 Merge pull request #245
Plugin: nonebot-plugin-r6s
2021-02-26 17:29:45 +08:00
Ju4tCode
f9e4d077d4 🔀 Merge pull request #243
Bug: adapter can be register more than once
2021-02-26 17:28:04 +08:00
abrahum
3477c0d8b4 🍻 publish nonebot-plugin-r6s 2021-02-26 09:25:35 +00:00
yanyongyu
8c9e096a84 🐛 ignore adapter register with same name 2021-02-26 17:22:39 +08:00
Ju4tCode
19a780eabb 🔀 Merge pull request #242
Docs: update how-to-work doc
2021-02-26 17:06:26 +08:00
yanyongyu
3c312d9759 📝 update how to work doc
Co-authored-by: AkiraXie <l997460364@outlook.com>
2021-02-26 17:00:38 +08:00
yanyongyu
bb37d757da 💡 remove comment 2021-02-26 12:03:48 +08:00
Ju4tCode
9ea80abf8c 🔀 Merge pull request #238
fix builtin plugin single session
2021-02-25 10:56:20 +08:00
AkiraXie
117758658e Merge branch 'bug/single_session-bug' of https://github.com/AkiraXie/nonebot2 into bug/single_session-bug 2021-02-24 23:57:29 +08:00
AkiraXie
da290dad07 🥅 fix ValueError to Exception 2021-02-24 23:56:52 +08:00
AkiraXie
00daaed074 📝 update api docs 2021-02-24 14:27:44 +00:00
AkiraXie
6f2b9a1d13 🐛 fix single_session bug 2021-02-24 22:21:47 +08:00
yanyongyu
04e11c3b3e 💡 update docstring 2021-02-24 17:56:43 +08:00
yanyongyu
eb8e5aa39d add plugin loading using json/toml 2021-02-24 17:48:08 +08:00
Ju4tCode
93ffc93a80 🔀 Merge pull request #236
fix nonebot_plugin_cocdicer link error
2021-02-24 12:24:41 +08:00
Abrahum
d3091cdb3e fix nonebot_plugin_cocdicer link error 2021-02-24 11:51:23 +08:00
yanyongyu
869df38238 ✏️ fix typo 2021-02-23 23:34:24 +08:00
yanyongyu
507000b63b 🐛 fix command match #235 2021-02-23 22:50:25 +08:00
Ju4tCode
6ab18f2d14 🔀 Merge pull request #232
Plugin: 跑团记录记录器
2021-02-23 17:20:37 +08:00
Jigsaw111
80714c9b61 🍻 publish 跑团记录记录器 2021-02-23 06:45:19 +00:00
Ju4tCode
42157f3dd1 🔀 Merge pull request #231
Fix: deploy ci
2021-02-23 10:12:18 +08:00
Ju4tCode
854c2ae499 🔀 Merge pull request #230
Plugin: nonebot-plugin-cocdicer
2021-02-23 10:09:03 +08:00
yanyongyu
f397789516 👷 fix deploy ci 2021-02-23 10:08:32 +08:00
abrahum
fe8d711108 🍻 publish nonebot-plugin-cocdicer 2021-02-22 15:02:17 +00:00
yanyongyu
f31318b7f4 🚸 wrap version with try 2021-02-22 10:44:42 +08:00
Ju4tCode
74ce56817c 🔀 Merge pull request #226
Update installation.md
2021-02-21 15:55:24 +08:00
danuonuo
31682f5f28 Update installation.md
根据我之前的一个issue,完善文档
2021-02-21 15:26:15 +08:00
Ju4tCode
7d3b397ff4 🔀 Merge pull request #224
New: Import hook
Fix: literal event type
2021-02-21 11:09:52 +08:00
nonebot
352f9f85c1 📝 update api docs 2021-02-21 03:06:51 +00:00
yanyongyu
f9d4bcba3d ⚗️ change allowed types for cqhttp #222
Co-authored-by: synodriver <624805065@qq.com>
2021-02-21 11:00:45 +08:00
yanyongyu
2c85b2aa19 👷 update ci 2021-02-21 10:52:37 +08:00
yanyongyu
9bbadddfa9 🐛 fix sub plugin relative import 2021-02-20 11:09:16 +08:00
yanyongyu
247456df56 📝 update docs 2021-02-19 15:24:52 +08:00
yanyongyu
be674c0efc ⚗️ add load all plugin function 2021-02-19 15:15:46 +08:00
yanyongyu
f26fb9d6fb ⚗️ change import hook 2021-02-19 14:58:26 +08:00
yanyongyu
6cd6750729 📝 update change log 2021-02-18 19:59:18 +08:00
Ju4tCode
19c4602354 🔀 Merge pull request #218
Breaking: change nonebot project structure
2021-02-17 23:31:49 +08:00
nonebot
60ef01b66f 📝 update api docs 2021-02-17 15:23:23 +00:00
yanyongyu
f40f1788df 📝 update README 2021-02-17 23:16:43 +08:00
Ju4tCode
c855ebcfb1 🔀 Merge pull request #217
Doc: Add launching from IDE warning
2021-02-17 21:58:28 +08:00
yanyongyu
24f3900c69 👷 udpate ci 2021-02-17 21:55:19 +08:00
StarHeart
70581abcef 📝 Add tips for IDE start-ups 2021-02-17 20:55:31 +08:00
Ju4tCode
f2c732722f 🔀 Merge pull request #215
Fix: `nonebot-plugin-ncm` repo link error
2021-02-17 14:28:09 +08:00
Ju4tCode
e76430a43b ✏️ fix plugin ncm repo link 2021-02-17 14:21:40 +08:00
Ju4tCode
20e19d34b8 Merge pull request #214 from nonebot/plugin/issue213
Plugin: 网易云无损音乐下载
2021-02-13 19:09:16 +08:00
kitUIN
f58eb61f2d 🍻 publish 网易云无损音乐下载 2021-02-13 10:59:06 +00:00
yanyongyu
35e9321feb 👷 disable commit comment 2021-02-12 13:38:48 +08:00
yanyongyu
631743171f 📝 update authors 2021-02-12 13:30:11 +08:00
yanyongyu
fc2694497e add adapter publish template 2021-02-11 17:55:57 +08:00
yanyongyu
31b8a5ff77 🏗️ change nonebot project structure 2021-02-11 17:29:16 +08:00
Ju4tCode
6ce034ca20 🔀 Merge pull request #211
Add Docs ci/cd
2021-02-10 14:08:27 +08:00
yanyongyu
3cc738c205 👷 update ci 2021-02-10 13:53:41 +08:00
yanyongyu
7b2af1b2f3 👷 update ci 2021-02-10 13:42:09 +08:00
yanyongyu
eeec690e71 👷 update ci 2021-02-10 13:00:25 +08:00
yanyongyu
aba18a2f68 👷 update ci 2021-02-10 12:58:24 +08:00
yanyongyu
17c7903bee 👷 update ci 2021-02-10 12:23:52 +08:00
yanyongyu
ad47c24b60 👷 update ci 2021-02-10 12:19:32 +08:00
yanyongyu
6eab05d57f 👷 update ci 2021-02-10 12:15:11 +08:00
yanyongyu
f4d623be25 👷 update ci 2021-02-10 12:09:37 +08:00
yanyongyu
4a961d8584 👷 update ci 2021-02-10 12:02:12 +08:00
yanyongyu
36e6f5b5c1 👷 update ci 2021-02-10 11:52:34 +08:00
yanyongyu
332a3a4f93 👷 update ci 2021-02-10 11:46:00 +08:00
yanyongyu
145caee37a 👷 update ci 2021-02-10 11:44:49 +08:00
yanyongyu
2fa7b7ca00 👷 update ci 2021-02-10 11:38:56 +08:00
yanyongyu
d60fca90f6 👷 update doc publish ci 2021-02-10 11:35:54 +08:00
Ju4tCode
4abfa2cf2b 🔀 Merge pull request #210
Plugin: hk-reporter
2021-02-10 10:33:55 +08:00
felinae98
ada964e5aa 🍻 publish hk-reporter 2021-02-09 15:29:52 +00:00
Ju4tCode
16cf694a77 🔀 Merge pull request #208
Plugin: Arcaea 查分器
2021-02-09 10:56:55 +08:00
iyume
362b8724fc 🍻 publish Arcaea 查分器 2021-02-09 02:54:24 +00:00
Ju4tCode
d06a927085 🔀 Merge pull request #206
update doc
2021-02-08 11:09:20 +08:00
Ju4tCode
031faa5923 🔀 Merge pull request #205
update doc
2021-02-08 11:04:08 +08:00
yanyongyu
a2c1e5fd26 📝 update README 2021-02-08 11:00:11 +08:00
StarHeartHunt
ac35c13727 📝 tweak 2021-02-08 10:27:21 +08:00
StarHeartHunt
f7b8c7ab8d 📝 add runtime hook doc 2021-02-08 10:26:39 +08:00
StarHeartHunt
802250eb71 📝 tweak 2021-02-08 10:25:58 +08:00
Ju4tCode
3fb002c977 🔀 Merge pull request #204 2021-02-07 23:47:41 +08:00
yanyongyu
98d1d407c3 📝 archive docs 2021-02-07 23:44:58 +08:00
Ju4tCode
8821218bfd 🔀 Merge pull request #202
Pre Release 2.0.0a10
2021-02-07 23:42:08 +08:00
Ju4tCode
27b9b413df Restore .env.dev 2021-02-07 23:36:56 +08:00
yanyongyu
2b67b0f12e 🔇 remove unused type hint 2021-02-07 23:36:04 +08:00
nonebot
d26d7bba55 📝 update api docs 2021-02-07 13:30:19 +00:00
Mix
0761a60443 🩹 fix reply process in mirai adapter 2021-02-07 21:28:58 +08:00
yanyongyu
217b1a5fac revert command change 2021-02-07 20:57:08 +08:00
yanyongyu
ef98a6f23c 🔖 bump version 2.0.0a10 2021-02-07 20:51:09 +08:00
nonebot
c6a6dc6e21 📝 update api docs 2021-02-07 09:17:49 +00:00
Mix
f3b77a7f60 ✏️ fix typo in docs 2021-02-07 17:16:12 +08:00
Mix
f625c34269 📝 update descriptions about plugin 2021-02-07 17:10:29 +08:00
Mix
ac5c4acf09 🔖 bump version 2.0.0a9.post2 2021-02-07 16:39:34 +08:00
Ju4tCode
9a3464744f 🔀 Merge pull request #201
Hotfix: error module name for plugin wordbank
2021-02-07 14:10:25 +08:00
yanyongyu
91bdfc4704 🚑 hotfix error module name for plugin-wordbank 2021-02-07 14:06:48 +08:00
Ju4tCode
6f8aa49d0e 🔀 Merge pull request #200
Doc typo
2021-02-07 14:03:23 +08:00
StarHeartHunt
be57798eac 📝 update api docs 2021-02-07 05:39:13 +00:00
StarHeart
4855e65b1a 📝 typo 2021-02-07 13:37:15 +08:00
Ju4tCode
a3fe3a1ad8 🔀 Merge pull request #199
Fix mirai adapter command process
2021-02-07 12:55:49 +08:00
Mix
382a9b6e12 🔊 improve message logging 2021-02-07 12:40:31 +08:00
Mix
24349953e3 update test case 2021-02-07 12:17:34 +08:00
Mix
85aba9e36f 🐛 fix bug founded during test in mirai adapter 2021-02-07 12:17:21 +08:00
Mix
49010bf5b7 ⚗️ trying to change mirai adapter message processing behavior 2021-02-07 11:52:50 +08:00
yanyongyu
b1c7f309f8 📝 update doc 2021-02-07 11:09:20 +08:00
Ju4tCode
458ddaa167 🔀 Merge pull request #196
New: Quart driver
2021-02-07 11:02:23 +08:00
Ju4tCode
ab97334cf8 🔀 Merge pull request #197
Docs: export and require
2021-02-07 11:01:20 +08:00
Ju4tCode
112fdf7ed3 📝 update export require doc 2021-02-07 10:59:13 +08:00
Mix
b59ff03abf revert changes to change implement method
This reverts commit bf7b2a8cbe.
2021-02-07 10:15:18 +08:00
Mix
bdd9f5ae30 🐛 fix bad type hinting 2021-02-07 02:27:09 +08:00
Mix
abcdbc4de9 💥 🐛 add support for non-plaintext start message 2021-02-07 02:21:31 +08:00
AkiraXie
1715139494 📝 update docs 2021-02-06 20:53:25 +08:00
AkiraXie
b862c506e4 📝 update export-and-require doc 2021-02-06 17:34:06 +08:00
nonebot
4fd4fbfb08 📝 update api docs 2021-02-06 03:44:30 +00:00
Mix
6cb9fda53a 🎨 remove unused imports 2021-02-06 11:43:01 +08:00
Mix
4f7a033b9c use dynamic routing in quart driver 2021-02-06 11:38:21 +08:00
Mix
c537841bc1 📝 add index in document for quart driver 2021-02-06 11:15:46 +08:00
Mix
7d9a8eaf19 💚 add extra install in document build 2021-02-06 11:15:46 +08:00
Mix
86965ee06d 💡 add comments in quart driver 2021-02-06 11:15:30 +08:00
Mix
496f64f103 🐛 fix bugs in quart driver 2021-02-06 10:34:52 +08:00
Mix
9e0862bc97 finish quart driver implement 2021-02-06 09:41:17 +08:00
Mix
6b43ad5575 add quart as a extra requirement 2021-02-06 09:40:57 +08:00
yanyongyu
bf7b2a8cbe matcher.send will return bot.send 2021-02-05 23:13:35 +08:00
Ju4tCode
7232c89292 🔀 Merge pull request #195
Fix: mirai adapter not escape tag in log
2021-02-05 20:55:54 +08:00
Mix
bc164ca2f2 add a dependcies for quart 2021-02-05 20:29:53 +08:00
Mix
ad8429e7fa 🐛 fix log escape in mirai adapter 2021-02-05 20:09:19 +08:00
yanyongyu
c268e0105d 🐛 fix escape comma 2021-02-05 14:26:03 +08:00
Ju4tCode
050137fb3f 🔀 Merge pull request #194
Pre Release 2.0.0a9.post1
2021-02-05 13:41:35 +08:00
yanyongyu
f2d04c598c 📝 update doc 2021-02-05 13:34:38 +08:00
nonebot
49307a3df2 📝 update api docs 2021-02-05 05:32:52 +00:00
yanyongyu
ff9f0bc74a 📝 update doc 2021-02-05 13:31:33 +08:00
yanyongyu
f929f25abd 🔖 Pre Release 2.0.0a9.post1 2021-02-05 13:05:46 +08:00
Ju4tCode
6af0a2574d 🔀 Merge pull request #193
Fix: MatcherGroup rule override
2021-02-05 11:56:05 +08:00
nonebot
c61a159eff 📝 update api docs 2021-02-05 03:51:53 +00:00
yanyongyu
59bdd03b1e 🐛 fix rule override bug 2021-02-05 11:49:12 +08:00
yanyongyu
35ea1e78ec 📝 update readme 2021-02-03 14:47:26 +08:00
yanyongyu
7db386b752 🔖 bump version a9.post1 2021-02-03 11:29:51 +08:00
yanyongyu
e6a68feb0c 🚑 hotfix missing return when rule check failed 2021-02-03 11:23:13 +08:00
Ju4tCode
78b0450d66 🔀 Merge pull request #188
update doc
2021-02-02 22:01:49 +08:00
Ju4tCode
bd5fb46e0a 🔥 Delete yarn.lock 2021-02-02 21:56:12 +08:00
Ju4tCode
cc3ed735f1 📝 update doc 2021-02-02 21:55:18 +08:00
StarHeartHunt
3f0c3f1f37 🔧 revert e1ff0a7 and add yarn.lock 2021-02-02 20:00:49 +08:00
StarHeartHunt
e1ff0a7221 🔧 ignore yarn.lock 2021-02-02 19:45:17 +08:00
StarHeartHunt
2bf8b4d313 📝 docs grammar 2021-02-02 19:45:17 +08:00
StarHeartHunt
188aa8a50a 🎨 lint 2021-02-02 19:45:17 +08:00
StarHeart
1538d2094a 📝 Update runtime-hook.md 2021-02-02 19:44:52 +08:00
StarHeart
16eb74e88b 📝 Update scheduler.md 2021-02-02 18:32:08 +08:00
Ju4tCode
3460d445b8 🔀 Merge pull request #187
Pre Release 2.0.0a9
2021-02-02 15:00:48 +08:00
yanyongyu
461b65700f 📝 archive doc 2021-02-02 14:36:51 +08:00
yanyongyu
e809c7c500 📝 update readme 2021-02-02 13:17:29 +08:00
yanyongyu
8e0572d5d3 📝 update changelog 2021-02-02 13:13:27 +08:00
yanyongyu
7555051df6 🔖 Pre Release 2.0.0a9 2021-02-02 13:09:20 +08:00
yanyongyu
d913be5c0d 🐛 fix matcher 2021-02-02 12:48:16 +08:00
yanyongyu
98b67ad829 📝 update docstring 2021-02-02 12:39:23 +08:00
Ju4tCode
0d8e51ff3f 🔀 Merge pull request #186
New shell like command support
2021-02-02 12:20:53 +08:00
AkiraXie
223b9bc887 📝 update api docs 2021-02-02 04:16:37 +00:00
yanyongyu
a54fd2f235 💡 update docstring 2021-02-02 12:15:20 +08:00
AkiraXie
88bbb57c66 📝 update api docs 2021-02-02 04:06:57 +00:00
Ju4tCode
c9a8e7ff0d Merge branch 'dev' into master 2021-02-02 12:04:01 +08:00
yanyongyu
9e4e9f29d1 rewrite shell command 2021-02-02 11:59:14 +08:00
AkiraXie
c8ebaf38b6 📝 update api docs 2021-02-01 17:22:53 +00:00
AkiraXie
f8fb36a1f7 Support shell-like command 2021-02-02 01:20:36 +08:00
Ju4tCode
bbeeb11502 🔀 Merge pull request #179
New mah adapter
2021-02-01 21:16:20 +08:00
yanyongyu
27c6457c20 📝 update README 2021-02-01 21:11:41 +08:00
nonebot
02a780f3b0 📝 update api docs 2021-02-01 13:00:25 +00:00
yanyongyu
00858416f9 🎨 format code and bump dependency 2021-02-01 20:58:12 +08:00
nonebot
9b79c83c3d 📝 update api docs 2021-02-01 11:30:11 +00:00
Mix
d6ae1ca01c 📄 add agpl v3 license for mirai adapter 2021-02-01 19:28:56 +08:00
Mix
f446411f08 📝 add start guide for mirai adapter 2021-02-01 18:37:30 +08:00
Mix
ad3a08f514 💡 🗑️ remove some invalid comments in mirai adapter 2021-02-01 16:53:06 +08:00
nonebot
f2ab618083 📝 update api docs 2021-02-01 08:39:38 +00:00
Mix
da1218221c add specified test for mirai adapter 2021-02-01 16:38:15 +08:00
Mix
c0fa137fed 🚸 add support of rule to_me in mirai adapter 2021-02-01 16:38:15 +08:00
Mix
5a63827f22 💬 💡 rename MiraiBot to Bot, fix a comment style 2021-02-01 16:38:15 +08:00
Mix
a739e71df6 📝 update scheduler.md @StarHeartHunt (#184) 2021-02-01 14:05:55 +08:00
nonebot
6c0b20e5b7 📝 update api docs 2021-02-01 05:51:45 +00:00
Mix
d2a62ebd3d 📝 💡 fix some typo and style in mirai adapter 2021-02-01 13:50:25 +08:00
StarHeart
b67d2ebce6 Update scheduler.md 2021-02-01 13:45:31 +08:00
nonebot
6a273a8eea 📝 update api docs 2021-02-01 05:21:33 +00:00
Mix
35d34a787b 📝 update document building struct to fit changes in mirai adapter 2021-02-01 13:20:09 +08:00
Mix
8fe562e864 💡 🚸 complete comments and optimize usage in mirai adapter 2021-02-01 13:19:37 +08:00
Ju4tCode
34c2ba8faa 🔀 Merge pull request #183
Fix rule override state
2021-02-01 11:52:48 +08:00
nonebot
616e07cd2d 📝 update api docs 2021-02-01 03:49:26 +00:00
yanyongyu
f6c24ec92f 🐛 change matcher check-run 2021-02-01 11:42:05 +08:00
Ju4tCode
68945d2f20 Merge pull request #182 from nonebot/plugin/issue181
Plugin: 风格化字符串管理
2021-02-01 11:03:34 +08:00
jks15satoshi
977c10524e 🍻 publish 风格化字符串管理 2021-01-31 18:31:29 +00:00
nonebot
923cbd3b8c 📝 update api docs 2021-01-31 17:05:56 +00:00
Mix
56592fc413 🚧 💡 add comments for message etc. in mirai adapter 2021-02-01 01:04:41 +08:00
nonebot
7fdfd89525 📝 update api docs 2021-01-31 16:02:54 +00:00
Mix
7c9cbe7b58 💬 💡 rename some dataclass, add comments for events in mirai adapter 2021-02-01 00:01:31 +08:00
nonebot
ceeb37f8ec 📝 update api docs 2021-01-31 14:45:07 +00:00
Mix
858639bebe 💡 📝 add some comments in code, add document build struct for mirai adapter 2021-01-31 22:43:43 +08:00
Mix
a39785d6d9 💡 add some comments in mirai adapter 2021-01-31 18:00:40 +08:00
nonebot
7b04854b43 📝 update api docs 2021-01-31 18:00:40 +08:00
Mix
20b299c758 🚸 add .approve and .reject method for request event in mirai adapter 2021-01-31 17:01:04 +08:00
Mix
3f56da9245 🚧 add support of reverse post and forward ws for mirai adapter 2021-01-31 16:03:15 +08:00
Ju4tCode
0428b1dd81 Merge pull request #178 from nonebot/plugin/issue177
Plugin: songpicker2
2021-01-31 13:10:07 +08:00
maxesisn
95aad49fb4 🍻 publish songpicker2 2021-01-31 05:07:38 +00:00
Mix
73be9151b0 🚸 add factory classmethods in MessageSegment at mirai adapter 2021-01-30 21:51:51 +08:00
Mix
95f27824ee 🚧 add api methods define 2021-01-30 20:40:00 +08:00
Mix
c82ceefc8b revert call method to http post, add api handle 2021-01-30 19:11:17 +08:00
Ju4tCode
ea615946f6 Merge pull request #175 from nonebot/plugin/issue174
Plugin: 消息交互式 python 解释器
2021-01-30 18:40:23 +08:00
iyume
84504c9daf 🍻 publish 消息交互式 python 解释器 2021-01-30 10:37:12 +00:00
Ju4tCode
6137c1f341 Merge pull request #173 from nonebot/plugin/issue172
Plugin: mqtt接入
2021-01-30 13:46:04 +08:00
Mix
5b3ef53301 🎨 add support for on_bot_* event handler 2021-01-30 13:45:55 +08:00
Mix
8b3eb4e076 add retry for mirai adapter when websocket connection down 2021-01-30 13:36:31 +08:00
synodriver
9cbe182ff4 🍻 publish mqtt接入 2021-01-30 05:31:40 +00:00
yanyongyu
b140ebd149 🐛 fix wrong data in CQ:share #170 2021-01-30 10:56:58 +08:00
Mix
e2f837055e add dependency of websockets 2021-01-30 10:55:06 +08:00
Mix
5de41a18f9 🎨 sort imports in file 2021-01-30 06:10:04 +08:00
Mix
02af1c1227 🚧 finish forward websocket receive 2021-01-30 05:58:30 +08:00
Mix
0bb0d16d93 🚧 basically completed event serialize 2021-01-29 21:19:13 +08:00
Mix
5a9798121c 🚧 add some support for mirai basic events 2021-01-29 17:38:39 +08:00
Mix
8574b2ec72 🚧 start working on mirai-api-http adapter 2021-01-29 17:37:44 +08:00
Artin
5f6a2fffc5 📝 update ding-guide 2021-01-29 14:41:04 +08:00
Artin
27e06dd4e8 🐛 fix ding adapter
1. fix send `at_sender`
2. fix event parse error
3. `MessageSegment` add `atDingtalkIds`/`code`
2021-01-29 14:31:36 +08:00
Artin
06837d4a56 📝 add ding-guide 2021-01-29 14:29:29 +08:00
Ju4tCode
62cb63aa1d Merge pull request #168 from nonebot/plugin/issue167
Plugin: 冷却事件
2021-01-28 11:09:46 +08:00
jks15satoshi
d43dcdf03f 🍻 publish 冷却事件 2021-01-27 15:56:14 +00:00
yanyongyu
a6fcc1ea2a 📝 add group link to doc 2021-01-27 12:08:22 +08:00
Ju4tCode
3047214676 🔀 Merge pull request #166
New: common config loading from .env
2021-01-27 11:54:27 +08:00
nonebot
115132a188 📝 update api docs 2021-01-27 03:46:47 +00:00
yanyongyu
5e3f1b5435 new common config loading from .env 2021-01-27 11:39:34 +08:00
yanyongyu
2e75671d56 ⚗️ add processor to ensure single matcher 2021-01-26 15:03:37 +08:00
yanyongyu
f8304406c5 ⚗️ add new builtin plugin 2021-01-25 18:15:25 +08:00
Ju4tCode
e8d892ebc8 Merge pull request #164 from nonebot/plugin/issue161
Plugin: nonebot-plugin-wordbank
2021-01-25 13:49:08 +08:00
Joenothing-lst
9f37fb23d6 🍻 publish nonebot-plugin-wordbank 2021-01-25 05:45:55 +00:00
yanyongyu
853b797cd9 🐛 change USER perm and temp matcher type 2021-01-24 18:16:18 +08:00
yanyongyu
eb330c3260 🐛 fix plugin store pagination error 2021-01-24 14:36:11 +08:00
yanyongyu
109125b583 🐛 remove args in creating bot 2021-01-21 12:41:52 +08:00
Ju4tCode
c06e9bd432 🔀 Merge pull request #160
Plugin: 模拟抽卡
2021-01-21 11:18:06 +08:00
Ju4tCode
30132e21e8 🔀 Merge pull request #158
fix doc typo
2021-01-21 11:17:51 +08:00
yanyongyu
fbf2eb638e ✏️ fix typo 2021-01-21 11:14:35 +08:00
abrahum
a729b8fa3c 🍻 publish 模拟抽卡 2021-01-21 03:09:57 +00:00
StarHeartHunt
de0bca5c51 📝 update api docs 2021-01-20 23:42:48 +00:00
StarHeart
a028766cf8 Update creating-a-matcher.md 2021-01-21 07:41:12 +08:00
yanyongyu
8973e66ec5 👷 update ci add cache 2021-01-18 14:43:06 +08:00
yanyongyu
b0a71b461f missing aiofiles dependency for docs plugin 2021-01-18 14:38:08 +08:00
yanyongyu
9685a4b1bf ⚗️ seperate configs 2021-01-17 13:46:29 +08:00
yanyongyu
7c3b2b514a add request event approve reject 2021-01-16 11:47:48 +08:00
yanyongyu
fcac6f8a0f improve session id support 2021-01-16 11:10:54 +08:00
Ju4tCode
27189ebfbe 🔀 Merge pull request #149
add fastapi driver configs
2021-01-12 18:07:17 +08:00
yanyongyu
a1d801ba14 ⚗️ new fastapi config settings 2021-01-12 18:02:05 +08:00
yanyongyu
9d047daef5 🚧 move cqhttp config into adapter 2021-01-12 17:55:27 +08:00
yanyongyu
719858168e 📝 update change log 2021-01-12 17:27:23 +08:00
yanyongyu
01fa2ece6e 🐛 fix wrong space strip 2021-01-12 15:48:31 +08:00
yanyongyu
e7993a4485 🐛 fix plain text escaped 2021-01-08 18:14:18 +08:00
yanyongyu
b6bf477551 ⚗️ add got receive overload #142 2021-01-06 18:29:41 +08:00
Ju4tCode
a211f09a99 🔀 Merge pull request #143
fix config typo
2021-01-05 23:11:35 +08:00
theprimone
fe3122adbd 📝 update api docs 2021-01-05 15:08:58 +00:00
yanyongyu
0c517acee2 ✏️ fix config typo 2021-01-05 23:06:36 +08:00
theprimone
9d31fcce2e 📝 update api docs 2021-01-05 14:51:38 +00:00
云生
5abac36647 Fix typo 2021-01-05 22:48:59 +08:00
yanyongyu
60fd092410 🐛 fix none message 2021-01-05 12:12:41 +08:00
Artin
877fa1a75a 🐛 Fix cqhttp Message null parameter 2021-01-04 22:24:43 +08:00
yanyongyu
2218fa2b33 🐛 fix missing return after close ws 2021-01-04 18:09:42 +08:00
Ju4tCode
6b26cecd17 🔀 Merge pull request #140
fix empty array process error
2021-01-04 13:32:16 +08:00
yanyongyu
bc5391d711 🐛 ensure message is not empty 2021-01-04 13:27:49 +08:00
Ju4tCode
3ea2c27e17 🔀 Merge pull request #138
PreRelease 2.0.0a8.post2
2021-01-02 04:10:10 -06:00
yanyongyu
17960b2868 🔖 PreRelease 2.0.0a8.post2 2021-01-02 18:04:44 +08:00
Ju4tCode
22416bf512 🔀 Merge pull request #137 2021-01-02 01:10:43 -06:00
yanyongyu
a4cb7f13be 🐛 fix error guess when reply to event #136 2021-01-02 14:42:13 +08:00
Ju4tCode
822709ceeb 🔀 Merge pull request #135
fix incorrect removing temp matcher
2021-01-01 21:02:18 -06:00
yanyongyu
4dffc879d9 🐛 fix incorrect remove temp matcher 2021-01-02 10:57:55 +08:00
Ju4tCode
f036057b2b 🔀 Merge pull request #133
Pre Release 2.0.0a8.post1
2021-01-01 09:55:13 -06:00
yanyongyu
38ab392b91 🚑 Fix Release 2.0.0a8.post1 2021-01-01 23:47:51 +08:00
Ju4tCode
a45d88ef29 🔀 Merge pull request #132
Fix doc typo
2021-01-01 09:32:06 -06:00
Lan
996c57df62 📝 Update creating-a-handler.md 2021-01-01 19:23:51 +08:00
Lan
8f69b2449d 📝 Update creating-a-matcher.md 2021-01-01 19:21:46 +08:00
Lan
db7e10cb4d ✏️ Fix typo 2021-01-01 18:21:02 +08:00
yanyongyu
b446fcc929 🐛 fix action failed info display error 2021-01-01 18:18:01 +08:00
yanyongyu
5cc5375cb5 🐛 fix missing group_id when PokeNotifyEvent 2021-01-01 18:01:05 +08:00
Ju4tCode
ebf3766cfb 🔀 Merge pull request #131
Fix GroupMessageEvent parse error
2021-01-01 15:25:45 +08:00
Mix
fbaf19e454 :critical: fix group event serialization error 2021-01-01 15:16:55 +08:00
Ju4tCode
a966f82192 🔀 Merge pull request #128
PreRelease 2.0.0a8
2020-12-31 20:19:07 +08:00
yanyongyu
210496f760 📝 update changelog 2020-12-31 20:10:26 +08:00
yanyongyu
13adfa5b55 📝 update doc 2020-12-31 19:56:27 +08:00
yanyongyu
d7e4b52d10 📌 bump version 2.0.0a8 2020-12-31 18:07:38 +08:00
yanyongyu
53c8028646 ⬆️ update dependency 2020-12-31 18:05:49 +08:00
yanyongyu
49201f5346 📝 update doc 2020-12-31 17:58:09 +08:00
yanyongyu
938b5bf275 🐛 fix message construct typing and plugins loading 2020-12-31 14:00:59 +08:00
Ju4tCode
a98417a878 🔀 Merge pull request #127
Update ding adapter
2020-12-30 20:29:18 +08:00
Ju4tCode
1bd223eab2 Restore test_permission.py 2020-12-30 20:19:24 +08:00
yanyongyu
55f1bd1f2d ✏️ update code style 2020-12-30 20:08:22 +08:00
nonebot
380977bc67 📝 update api docs 2020-12-30 10:35:51 +00:00
Artin
086a998b20 improve ding adapter
add tests/test_ding.py
add some log
2020-12-30 18:33:54 +08:00
yanyongyu
d4f344d247 improve command 2020-12-30 12:42:10 +08:00
nonebot
3cb2b44130 📝 update api docs 2020-12-29 16:38:15 +00:00
yanyongyu
c8cd6de2f2 improve ding adapter 2020-12-30 00:36:29 +08:00
nonebot
0221d02ca7 📝 update api docs 2020-12-29 06:51:55 +00:00
Artin
a5947922b6 Update nonebot/adapters/__init__.py
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2020-12-29 14:50:24 +08:00
Artin
13f6a692a7 Update nonebot/adapters/__init__.py
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2020-12-29 14:50:15 +08:00
Artin
f13befc4d8 Update nonebot/adapters/__init__.py
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
2020-12-29 14:50:07 +08:00
nonebot
f4ba97ebab 📝 update api docs 2020-12-29 04:20:09 +00:00
Artin
1bdbbca12f Update ding adapter event logic 2020-12-29 12:12:35 +08:00
Ju4tCode
5028f6408a 🔀 Merge pull request #125
typo fixed
2020-12-29 02:10:27 +08:00
jinser
f53cf80221 Update creating-a-plugin.md 2020-12-29 02:02:23 +08:00
Ju4tCode
e052692a57 🔀 Merge pull request #124
Add scheduler doc
2020-12-28 17:42:12 +08:00
yanyongyu
ab61be26a9 improve radd support for messagesegment 2020-12-28 17:39:33 +08:00
yanyongyu
e02b5f1de8 📝 update scheduler doc 2020-12-28 16:53:53 +08:00
Ju4tCode
de5ca44d6b fix warning block syntax 2020-12-28 15:57:43 +08:00
Lan
9de421b2d2 Revert changes 2020-12-28 15:51:46 +08:00
Lan
82abd2e6ce 📝 Update scheduler.md 2020-12-28 15:43:03 +08:00
Lan
13fb2de964 ✏️ Fix typo 2020-12-28 15:23:18 +08:00
Lan
53de7eab96 📝 Add scheduler.md 2020-12-28 15:18:16 +08:00
Ju4tCode
e14d3d8d73 🔀 Merge pull request #123
New: WebSocket Connection Hook
2020-12-28 14:12:04 +08:00
nonebot
c23a777a9f 📝 update api docs 2020-12-28 06:01:32 +00:00
yanyongyu
1c9df5ac02 🎨 change method into private 2020-12-28 13:59:54 +08:00
nonebot
0c43d83494 📝 update api docs 2020-12-28 05:57:28 +00:00
yanyongyu
299c259d50 🐛 fix hook block event receiving bug 2020-12-28 13:53:24 +08:00
yanyongyu
c993f15bca ⚗️ add ws connection hook 2020-12-28 13:36:00 +08:00
yanyongyu
2d63eb32e1 🚑 hotfix due to cq security problem 2020-12-28 00:24:18 +08:00
yanyongyu
2ae76ff78b ⚗️ new stop propagation method 2020-12-24 22:19:08 +08:00
yanyongyu
41663e1b08 🚧 update cqcode 2020-12-23 17:12:53 +08:00
yanyongyu
c3df90c541 📝 update changelog 2020-12-22 20:14:52 +08:00
yanyongyu
ab256e57b1 🐛 fix missing escape in builtin plugin #117 2020-12-22 20:12:00 +08:00
yanyongyu
054df580eb 📝 update docs 2020-12-22 09:59:48 +08:00
yanyongyu
5fecb5f506 📝 update readme badge 2020-12-22 00:41:33 +08:00
yanyongyu
44a15d684b ✏️ fix typo 2020-12-21 19:32:58 +08:00
yanyongyu
f3243f8989 📝 update changelog 2020-12-21 16:23:29 +08:00
yanyongyu
bc459b5ff4 🐛 fix non text cqcode not unescaped 2020-12-21 16:19:02 +08:00
Ju4tCode
338d5e6f17 🔀 Merge pull request #115
Add default state factory support
2020-12-20 12:20:22 +08:00
nonebot
340e8c3760 📝 update api docs 2020-12-20 04:15:01 +00:00
yanyongyu
e44cde0600 add test case 2020-12-20 12:09:30 +08:00
yanyongyu
1b00fe7921 add state factory support #113 2020-12-20 11:59:51 +08:00
yanyongyu
168cc3801a 📝 build api doc 2020-12-19 15:31:14 +08:00
yanyongyu
4ec4adf003 💡 add adapter docstring 2020-12-19 15:30:34 +08:00
yanyongyu
a88a2f4a4f 🔊 revert log string 2020-12-19 14:16:47 +08:00
yanyongyu
a539fd0062 🔊 improve adapter not found log 2020-12-19 11:20:41 +08:00
yanyongyu
83addf045f improve actionfailed info 2020-12-19 00:50:17 +08:00
yanyongyu
00305a8436 🎨 change event log 2020-12-19 00:26:24 +08:00
yanyongyu
799144e64d finish typing change 2020-12-17 21:09:30 +08:00
yanyongyu
6bd69e6708 🐛 fix typing 2020-12-17 01:52:16 +08:00
yanyongyu
784bc7b0cf ⚗️ new dynamic handler args 2020-12-16 23:13:00 +08:00
yanyongyu
ca8f764b8b 📝 update changelog 2020-12-16 13:36:40 +08:00
yanyongyu
a63a5fea3c 🐛 fix invalid cq code catched 2020-12-16 13:35:34 +08:00
Ju4tCode
a068040cbf Merge pull request #112 from nonebot/plugin/issue111
Plugin: translator
2020-12-15 13:55:03 +08:00
Lancercmd
f5d3ae9efb 🍻 publish translator 2020-12-15 05:43:04 +00:00
yanyongyu
e4377faa67 💄 update docs 2020-12-13 12:53:33 +08:00
yanyongyu
12ef3e7bf1 🚧 update cqhttp adapter event 2020-12-13 12:53:16 +08:00
yanyongyu
3d4adaa444 ⚗️ auto import plugin when require 2020-12-13 12:19:01 +08:00
yanyongyu
7d2a87b73e 🐛 fix plugin publish link 2020-12-12 17:20:37 +08:00
yanyongyu
6c08982ca7 🚧 update process 2020-12-11 16:29:12 +08:00
yanyongyu
f4cea065d8 ✏️ fix validator 2020-12-10 21:33:51 +08:00
Ju4tCode
b651f89865 🔀 Merge pull request #108
Plugin: 通用数据库连接
2020-12-10 17:14:46 +08:00
synodriver
ae73facd89 🍻 publish 通用数据库连接 2020-12-10 08:38:28 +00:00
yanyongyu
72653c6116 🚧 update messages 2020-12-10 02:13:25 +08:00
yanyongyu
a57cd396fa 🚧 update cqhttp event parse 2020-12-10 00:39:43 +08:00
yanyongyu
783efeaf0e 🚧 add event parser 2020-12-09 19:57:49 +08:00
yanyongyu
2c97902f4e 🚧 update cqhttp bot 2020-12-09 17:51:24 +08:00
yanyongyu
2bc05b2576 🚧 update event models 2020-12-09 14:39:25 +08:00
yanyongyu
73bda494d9 🏗️ update cqhttp models 2020-12-09 13:20:14 +08:00
Ju4tCode
e7b44710cc Merge pull request #106
Plugin: 图片搜索
2020-12-09 11:56:01 +08:00
synodriver
2d76209c8a 🍻 publish 图片搜索 2020-12-09 03:52:26 +00:00
yanyongyu
ddf044d6d3 🏗️ add model for cqhttp 2020-12-09 11:13:37 +08:00
yanyongyu
f220a01a30 📝 update doc 2020-12-07 22:15:26 +08:00
Artin
8443c01303 📝 update docs 2020-12-07 21:02:08 +08:00
yanyongyu
f8d0b691ec 📝 update docs typing 2020-12-07 14:09:43 +08:00
yanyongyu
e0d44f3fa7 📝 update api docs 2020-12-07 00:52:26 +08:00
yanyongyu
a420af75fc 🐛 fix type checking for bot 2020-12-07 00:31:14 +08:00
yanyongyu
6b3f6a46e6 🎨 impove typing 2020-12-07 00:06:09 +08:00
yanyongyu
629eed08b6 🎨 update typing support 2020-12-06 02:30:19 +08:00
Ju4tCode
9ab7176eaf 🔀 Merge pull request #104
Fix typing
2020-12-05 20:44:11 +08:00
yanyongyu
3345142db2 🔥 remove useless noreturn 2020-12-05 20:32:38 +08:00
Mix
b1ab5d91a4 🐛 Fix some wrong type hint 2020-12-05 17:19:23 +08:00
yanyongyu
3ba59da0ab 📌 update lock file 2020-12-05 15:58:37 +08:00
Ju4tCode
308acff19a 🔀 Merge pull request #103 2020-12-05 13:33:07 +08:00
Mix
de64e38a07 📝 Optimize expression in installation.md 2020-12-05 13:06:27 +08:00
Ju4tCode
4a22a50f19 🔀 Merge pull request #102
Plugin: 定时任务
2020-12-05 02:05:54 +08:00
yanyongyu
997114477c 🍻 publish 定时任务 2020-12-04 18:00:08 +00:00
Ju4tCode
700407ba98 🔀 Merge pull request #100
Plugin: 前端测试机器人插件
2020-12-05 01:59:44 +08:00
yanyongyu
d42d975d9e 🍻 publish 前端测试机器人插件 2020-12-04 17:56:08 +00:00
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
392 changed files with 61342 additions and 9465 deletions

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

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

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

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

14
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,14 @@
blank_issues_enabled: false
contact_links:
- name: Question
url: https://github.com/nonebot/discussions/discussions/new
about: Ask questions about nonebot
- name: Plugin Publish
url: https://v2.nonebot.dev/store.html
about: Publish your plugin to nonebot homepage and nb-cli
- name: Adapter Publish
url: https://v2.nonebot.dev/store.html
about: Publish your adapter to nonebot homepage and nb-cli
- name: Bot Publish
url: https://v2.nonebot.dev/store.html
about: Publish your bot to nonebot homepage and nb-cli

17
.github/ISSUE_TEMPLATE/document.md vendored Normal file
View File

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

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.

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

@@ -0,0 +1,42 @@
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'
- title: '🍻 Bot Publish'
label: 'Bot'
- title: '🍻 Adapter Publish'
label: 'Adapter'
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

View File

@@ -1,41 +0,0 @@
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/
- run: |
git config user.name nonebot
git config user.email nonebot@nonebot.dev
git add .
git diff-index --quiet HEAD || git commit -m ":memo: update api docs"
git remote -vv
git remote add target ${{github.event.pull_request.head.repo.clone_url}}
git push target HEAD:${{github.event.pull_request.head.ref}}

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

@@ -0,0 +1,44 @@
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"
- uses: Gr1N/setup-poetry@v4
- uses: actions/cache@v1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Set up dependencies
run: |
poetry install -E all
- 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}}

27
.github/workflows/publish_bot.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
name: 'NoneBot2 Publish Bot'
on:
push:
branches:
- master
issues:
types: [opened, reopened, edited]
pull_request:
types: [closed]
jobs:
publish_bot:
runs-on: ubuntu-latest
name: nonebot2 publish bot
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: NoneBot2 Publish Bot
uses: nonebot/nonebot2-publish-bot@main
with:
token: ${{ secrets.GH_TOKEN }}
base: master
plugin_path: docs/.vuepress/public/plugins.json
bot_path: docs/.vuepress/public/bots.json
adapter_path: docs/.vuepress/public/adapters.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 }}

65
.github/workflows/site_deploy.yml vendored Normal file
View File

@@ -0,0 +1,65 @@
name: Build Upload Site
on:
push:
pull_request_target:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
if: github.event_name == 'push'
- uses: actions/checkout@v2
if: github.event_name != 'push'
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache Packages
id: yarn-cache
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install and build
run: |
yarn install
yarn build
- name: Get Branch Name
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Get Deploy Name
if: github.event_name == 'push'
run: |
echo "DEPLOY_NAME=${{ env.BRANCH_NAME }}" >> $GITHUB_ENV
echo "PRODUCTION=${{ env.BRANCH_NAME == 'master' }}" >> $GITHUB_ENV
- name: Get Deploy Name
if: github.event_name != 'push'
run: |
echo "DEPLOY_NAME=deploy-preview-${{ github.event.number }}" >> $GITHUB_ENV
echo "PRODUCTION=false" >> $GITHUB_ENV
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v1.1
with:
publish-dir: './docs/.vuepress/dist'
production-deploy: ${{ env.PRODUCTION }}
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: 'Deploy ${{ env.DEPLOY_NAME }}@${{ github.sha }}'
enable-commit-comment: false
alias: ${{ env.DEPLOY_NAME }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.SITE_ID }}

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

@@ -0,0 +1,36 @@
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 }}
run_id: ${{ github.event.workflow_run.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

3
.gitignore vendored
View File

@@ -188,3 +188,6 @@ typings/
dev
docs_build/_build
!tests/.env
*.xmind
yarn.lock
.DS_Store

1
.prettierignore Normal file
View File

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

9
.prettierrc Normal file
View File

@@ -0,0 +1,9 @@
{
"tabWidth": 2,
"useTabs": false,
"endOfLine": "lf",
"arrowParens": "always",
"singleQuote": false,
"trailingComma": "es5",
"semi": true
}

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.

143
README.md
View File

@@ -1,37 +1,146 @@
<div align=center>
<img src="./docs/.vuepress/public/logo.png" width="200" height="200">
<!-- markdownlint-disable MD033 MD041-->
<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/nonebot/nonebot2.svg)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/nonebot2.svg)](https://pypi.python.org/pypi/nonebot2)
![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)
<!-- prettier-ignore-start -->
<!-- markdownlint-disable-next-line MD036 -->
_✨ 跨平台 Python 异步机器人框架 ✨_
<!-- prettier-ignore-end -->
</div>
<p align="center">
<a href="https://raw.githubusercontent.com/nonebot/nonebot2/master/LICENSE">
<img src="https://img.shields.io/github/license/nonebot/nonebot2" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot2">
<img src="https://img.shields.io/pypi/v/nonebot2" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.7.3+-blue" alt="python"><br />
<a href="https://github.com/howmanybots/onebot/blob/master/README.md">
<img src="https://img.shields.io/badge/OneBot-v11-black?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="cqhttp">
</a>
<a href="http://github.com/mamoe/mirai">
<img src="https://img.shields.io/badge/mirai-HTTP-lightgrey?style=social">
</a>
<a href="https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p">
<img src="https://img.shields.io/badge/%E9%92%89%E9%92%89-Bot-lightgrey?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAnFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4jUzeAAAAM3RSTlMAQKSRaA+/f0YyFevh29R3cyklIfrlyrGsn41tVUs48c/HqJm9uZdhX1otGwkF9IN8V1CX0Q+IAAABY0lEQVRYw+3V2W7CMBAF0JuNQAhhX9OEfYdu9///rUVWpagE27Ef2gfO+0zGozsKnv6bMGzAhkNytIe5gDdzrwtTCwrbI8x4/NF668NAxgI3Q3UtFi3TyPwNQtPLUUmDd8YfqGLNe4v22XwEYb5zoOuF5baHq2UHtsKe5ivWfGAwrWu2mC34QM0PoCAuqZdOmiwV+5BLyMRtZ7dTSEcs48rzWfzwptMLyzpApka1SJ5FtR4kfCqNIBPEVDmqoqgwUYY5plQOlf6UEjNoOPnuKB6wzDyCrks///TDza8+PnR109WQdxLo8RKWq0PPnuXG0OXKQ6wWLFnCg75uYYbhmMIVVdQ709q33aHbGIj6Duz+2k1HQFX9VwqmY8xYsEJll2ahvhWgsjYLHFRXvIi2Qb0jzMQCzC3FAoydxCma88UCzE3JCWwkjCNYyMUCzHX4DiuTMawEwwhW6hnshPhjZzzJfAH0YacpbmRd7QAAAABJRU5ErkJggg==" alt="ding">
</a>
<a href="https://core.telegram.org/bots/api">
<img src="https://img.shields.io/badge/telegram-Bot-lightgrey?style=social&logo=telegram">
</a>
<a href="https://open.feishu.cn/document/home/index">
<img src="https://img.shields.io/badge/%E9%A3%9E%E4%B9%A6-Bot-lightgrey?style=social&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAk1BMVEX///8zMzNJSUlSUlJcXFxtbW0zMzNLS0szMzMzMzNBQUGVlZUzMzM1NTU0NDQzMzMzMzM0NDQ0NDQ0NDQ3NzdDQ0M0NDQ2NjY4ODg9PT0zMzM0NDQ5OTk7OzszMzM0NDQ3NzczMzM0NDQ0NDQ0NDQ0NDQ3Nzc2NjY4ODg2NjY7Ozs0NDQ6Ojo6Ojo3Nzc4ODgzMzNGdMWJAAAAMHRSTlMD6h0TDgr8GNf0KQbvhLT45KKTmm4jwHVJLdLFQzbcjFTgzsq7rl58T2kyqD46Y1riMDRhAAAFr0lEQVR42uzZWXKiUACF4YMyqKAQhyjOc7STmLP/1bVlLukESIJ3sLGKbwFU/Q8HuIBKpVKpVCqVSqVSqVQqlUqlUvmNM10Mcfda/U6TPdw3e9lb8ayLO+bPniYu+amjNcPd8U7PFhML0RE5uCvnaY/5SVt0WFvckcu0vxjiYmDxbu5cl2mn9UVHRMa4B2LaP3RYKD1vL6adccRFLSLL/izxxbRz7UXHimdLlFdq2mlvnztYRznZh96cP3G/dkxQRrOnR5c/c5eiQ+S2UTbe/sHir9zD1w6+okz8aXvMItyRqE46ApSHmHYRYdLRoPCMcrAP3TkLC6fpDp5QAn/EtItqij3UG/zgQZH5aWc7ZqJjzA9jKFGf9ppXC3I6uMB/Mzh2mpQQ/Mnp4BSy1Kctx4pFx5qfhA4kqE87pCyrldfBDm6sLqat2mGnttXHDfkvYtryooHo2PCrFm5lcNw1qWr1XUeEm7BH3QYVRJNGcOmoietNmNKDWeKFnCo6b3Wc1drW/NsOLpFRqmmT4xgfPFw42Q7XhkFi2kq2DtKcR2Y8wpTacRdQ3aZYB59ggiOmrS6sFevgDNr9GW6pzRAZdsQsC3rV3x4i6uQha8+sB2h9am9c6rVBDj9ixr5k007rIs+CGV65pl3wXjRi2hrKYjFtM/rI02JaW3XaPYtGtZHHY9qL0lN7QuO2yBMzpenLTvtkZNos+AY1ZcpObtoLtWmrj6TNlCOuJqZ9M3PkaDBlIBHCmwpHyHpjSgMS2ryhcIqsmsWULmR0eTPhK7LsMdMOKHdJM+nw8E+8ZoYDOT3eRDDDuz6HNt7VeszaQtYDJch+38WRZ51TDO+0Y54hylzy0XHib2JI83c0zIoLd1hAeUus1jenQe2HQ79Dg6wB3i1d/uoNpS2JrulgHWqcRxqySjoObrFjfUlLVrVrOtiGMmdCA+ZJx8hlEa9QZ2+oXcNLOkIWEUAHe22sYxqykGdoUV//5w6eoKlkTI3Gdbx7CVmQB10lDWqzSTpemyyoAW28ubYO++oOLqBPbUUtJknHrMnCRihdyaOTdAQsLHSgtSTS2BEHLK4DvQYWFW2lOtiHZi3Fko6fXCjgNVooV0nHl7tMBP1aAaXtJDvYgwGxdMmzLzu1JUyYNSU7IAwiiZ8OJrxKlTzI38QnMORFoqSn8Fh9gikvIa/UVejgDMZMQ9mOOa8WwKCRyysslF6hn2HSwZX4+ew1KGEPCSZKhoqHMw9mLd1rO8aUMYZpexbRV/2AsYBxy7/t3NtuglAQheFR6wEPVEQtaq1WxQNqnfd/urY08QJFYHZS15D9vcHckMzOz/QWA9/3jqHrbmbr1bT10a90ncQcoiclgKY/Vq81q6P2JJqfI+NHPqdDSMRzsEtIXmYGcQcQk2fwKgHxTCIVJGMWwTu6sWGxPSFx+QpkOfz3QcYEJWQhtGsbR5aKCIrHInjXNsSDeITFZ6ELYZEMAnltY8AyawKz4KJAr21IBzkRmB6LOIRGOEhIaHYsciA0uxIshwa/DLQIzrAEy2HswBIBwck9yNOvbWT4YgHEU4zbEiyHsQsXhnmKccmxp2cbxvb8CyDbMBXwD4hsw1BQguUw9s4Mk20YOTFQtmHiDJVtGJhjZRtyEVi2ITbhnLBOMd5qOvqXwz9RFy3bkJpU0LINeTCsJdvIztHVZhsJo77SbOPG6FNltpFQqMxsE7hmS+9ymJxE7XKYUGupyzZS1Kbaso00tbWybONBTadyObyjPlaVbTycRFO28Uh9oyjbEJ/E2JImnVDXy1y6zpHvW5E2npJsI5unI9vIwVe3HKYZaMg2clkoyDby6Wl5mcv0Bp9t5DVEzzZyG4JnG/kdsLONArbQ2UYRlwZwtlHIsoGbbRSdRNtymGbf0LYcpgleQbMNwdUCbcthmrP2j++VjqdSy7Isy7Isy4LxDTcBnqEPd5jdAAAAAElFTkSuQmCC" alt="feishu">
</a>
<br />
<a href="https://jq.qq.com/?_wv=1027&k=5OFifDh">
<img src="https://img.shields.io/badge/qq%E7%BE%A4-768887710-orange?style=flat-square" alt="QQ Chat">
</a>
<a href="https://t.me/botuniverse">
<img src="https://img.shields.io/badge/telegram-botuniverse-blue?style=flat-square" alt="Telegram Channel">
</a>
<a href="https://discord.gg/VKtE6Gdc4h">
<img src="https://discordapp.com/api/guilds/847819937858584596/widget.png?style=shield" alt="Discord Server">
</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>
<!-- markdownlint-enable MD033 -->
## 简介
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能。
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。
除了起到解析消息的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
除了起到解析事件的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
目前 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 通信,更是有质的飞跃
得益于 Python 的 [asyncio](https://docs.python.org/3/library/asyncio.html) 机制NoneBot 处理消息的吞吐量有了很大的保障,再配合 WebSocket 通信方式也是最建议的通信方式NoneBot 的性能可以达到 HTTP 通信方式的两倍以上,相较于传统同步 I/O 的 HTTP 通信,更是有质的飞跃。
## 特色
需要注意的是NoneBot 仅支持 Python 3.7+ 及 CQHTTP(OneBot) 插件 v11+。
NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义**,并且可以作为插件进行**替换/添加**
## 文档
目前 NoneBot2 内置的驱动框架:
文档目前尚未完成「API」部分由 sphinx 自动生成,你可以在 [这里](https://v2.nonebot.dev/) 查看。
- [FastAPI](https://fastapi.tiangolo.com/)
- [Quart](https://pgjones.gitlab.io/quart/) (异步 flask )
目前 NoneBot2 官方维护的协议适配:
- [OneBot(CQHTTP) 协议](https://github.com/howmanybots/onebot/blob/master/README.md) (QQ 等)
- [Mirai-API-HTTP 协议](https://github.com/project-mirai/mirai-api-http)
- [钉钉](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)
- [Telegram](https://core.telegram.org/bots/api)
- [飞书](https://open.feishu.cn/document/home/index)
更多:[商店](https://v2.nonebot.dev/store.html)
## 即刻开始
~~完整~~文档可以在 [这里](https://v2.nonebot.dev/) 查看。
懒得看文档?下面是快速安装指南:~~这是坏文明~~
1. (可选)使用你喜欢的 Python 环境管理工具创建新的虚拟环境。
2. 使用 `pip` (或其他) 安装 NoneBot 脚手架。
```bash
pip install nb-cli
```
3. 使用脚手架创建项目
```bash
nb create
```
## 社区资源
### 常见问题
- [常见问题解答(FAQ)](https://faq.nonebot.dev/)
### 教程/实际项目/经验分享
- [awesome-nonebot](https://github.com/nonebot/awesome-nonebot)
### 插件
此外NoneBot2 还有丰富的官方以及第三方现成的插件供大家使用:
- [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs):离线文档至本地使用(别再说文档打不开了!)
```bash
nb plugin install nonebot_plugin_docs
```
或者尝试以下镜像:
- [文档镜像(中国境内)](https://nb2.baka.icu)
- [文档镜像(vercel)](https://nonebot2-vercel-mirror.vercel.app)
- 其他插件请查看 [商店](https://v2.nonebot.dev/store.html)
## 贡献
如果你在使用过程中发现任何问题,可以 [提交 issue](https://github.com/nonebot/nonebot2/issues/new) 或自行 fork 修改后提交 pull request。
如果你要提交 pull request请确保你的代码风格和项目已有的代码保持一致遵循 [PEP 8](https://www.python.org/dev/peps/pep-0008/),变量命名清晰,有适当的注释。
## 许可证
`NoneBot` 采用 `MIT` 协议开源,协议文件参考 [LICENSE](./LICENSE)。
特别的,由于 `mirai` 使用 `AGPLv3` 协议并要求使用 `mirai` 的软件同样以 `AGPLv3` 协议开源,本项目 `mirai` 适配器部分(即 [`packages/nonebot-adapter-mirai`](./packages/nonebot-adapter-mirai/) 目录)以 `AGPLv3` 协议开源,协议文件参考 [LICENSE](./packages/nonebot-adapter-mirai/LICENSE)。

View File

@@ -0,0 +1,15 @@
---
home: true
heroImage: /logo.png
tagline: 跨平台 Python 异步 QQ 机器人框架
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,177 @@
# 深入
## 它如何工作?
如同[概览](../guide/README.md)所言:
> NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。
`Nonebot2` 是一个可以对机器人上报的事件进行处理并完成具体功能的机器人框架,在这里,我们将简要讲述它的工作内容。
**便捷起见,以下内容对 `Nonebot2` 会被称为 `nonebot`,与 `Nonebot2` 交互的机器人实现会被称为 `协议端`**
在实际应用中,`nonebot` 会充当一个高性能,轻量级的 Python 微服务框架。协议端可以通过 `http`, `websocket` 等方式与之通信,这个通信往往是双向的:一方面,协议端可以上报数据给 `nonebot``nonebot` 会处理数据并返回响应给协议端;另一方面,`nonebot` 可以主动推送数据给协议端。而 `nonebot` 便是围绕双向通信进行工作的。
在开始工作之前,`nonebot` 需要进行准备工作:
1. **运行 `nonebot.init` 初始化函数**,它会读取配置文件,并初始化 `nonebot` 和后端驱动 `driver` 对象。
2. **注册协议适配器 `adapter`**
3. **加载插件**
准备工作完成后,`nonebot` 会利用 `uvicorn` 启动,并运行 `on_startup` 钩子函数。
随后,倘若一个协议端与 `nonebot` 进行了连接,`nonebot` 的后端驱动 `driver` 就会将 `adapter` 实例化为 `bot``nonebot` 便会利用 `bot` 开始工作,它的工作内容分为两个方面:
1. **事件处理**`bot` 会将协议端上报的数据转化为 `事件`(`Event`),之后 `nonebot` 会根据一套既定流程来处理 `事件`
2. **调用 `API`**, 在**事件处理**的过程中,`nonebot` 可以通过 `bot` 调用协议端指定的 `API` 来获取更多数据,或者反馈响应给协议端; `nonebot` 也可以通过调用 `API` 向协议端主动请求数据或者主动推送数据。
在**指南**模块, 我们已经叙述了[如何配置 nonebot](../guide/basic-configuration.md), [如何注册协议适配器](../guide/getting-started.md)[如何加载插件](../guide/loading-a-plugin.md), 在这里便不再赘述。
下面,我们将对**事件处理** **调用 API**进行说明。
## 事件处理
我们可以先看事件处理的流程图:
![handle-event](../guide/images/Handle-Event.png)
在流程图里,我们可以看到,`nonebot` 会有三个阶段来处理事件:
1. **driver 处理上报数据**
2. **adapter 处理原始数据**
3. **nonebot 处理 Event**
我们将顺序说明这三个阶段。其中,会将第三个阶段拆分成**概念解释****处理 Event****特殊异常处理**三个部分来说明。
### driver 处理上报数据
1. 协议端会通过 `websocket` 或者 `http` 等方式与 `nonebot` 的后端驱动 `driver` 连接,`driver` 会根据之前注册的 `adapter` 和配置文件的内容来进行鉴权,从而获得这个连接的唯一识别 id `self-id`,随后 `adapter` 就会利用 `self-id` 实例化为 `bot` 对象。
::: tip
需要注意的是,如果协议端通过 `websocket``nonebot` 连接,这个步骤只会在建立连接时进行,并在之后运行 `on_bot_connect` 钩子函数;通过 `http` 方式连接时,会在协议端每次上报数据时都进行这个步骤。
:::
::: warning
连接之前必须要注册 `adapter`
:::
::: warning
`self-id` 是帐号的唯一识别 ID这意味着不能出现相同的 `self-id`
:::
2. `driver` 会将接收到的数据转交给 `bot` 对象进一步处理。
### adapter 处理原始数据
1. `bot` 会利用事先定义好的 `Event Model` 对上报的数据进行分析处理,将数据转化为 `nonebot` 可以处理的 `Event` 对象。
::: tip
`adapter` 在转换数据格式的同时可以进行一系列的特殊操作,例如 `CQHTTP` 会对 `reply` 信息进行提取。
:::
2. `Event` 会传入 `nonebot` 做进一步处理。
### nonebot 处理 Event
在讲述这个阶段之前,我们需要先对几个概念进行解释。
#### 概念解释
1. **hook**,或者说**钩子函数**,它们可以在 `nonebot` 处理 `Event` 的不同时刻进行拦截,修改或者扩展,在 `nonebot` 中,钩子函数分为 `事件预处理hook``运行预处理hook``运行后处理hook``事件后处理hook`
::: tip
关于`hook`的更多信息,可以查阅[这里](./runtime-hook.md)
:::
2. **Matcher**与**matcher**,在**指南**中,我们讲述了[如何注册事件响应器](../guide/creating-a-matcher),这里的事件响应器或者说 `Matcher` 并不是一个具体的实例 `instance`,而是一个具有特定属性的类 `class`。只有当 `Matcher` **响应事件**时,才会实例化为具体的 `instance`,也就是 `matcher``matcher` 可以认为是 `nonebot` 处理 `Event` 的基本单位,运行 `matcher``nonebot`工作的主要内容。
3. **handler**,或者说**事件处理函数**, 它们可以认为是 `nonebot` 处理 `Event` 的最小单位。在不考虑 `hook` 的情况下,**运行 matcher 就是顺序运行 matcher.handlers**,这句话换种表达方式就是,`handler` 只有添加到 `matcher.handlers` 时,才可以参与到 `nonebot` 的工作中来。
::: tip
如何让 `handler` 添加到 `matcher.handlers`
一方面,我们可以参照[这里](../guide/creating-a-handler)利用装饰器来添加;另一方面,我们在用 `on()` 或者 `on_*()` 注册事件响应器时,可以添加 `handlers=[handler1, handler2, ...]` 这样的关键词参数来添加。
:::
#### 处理 Event
1. **执行事件预处理 hook** `nonebot` 接收到 `Event` 后,会传入到 `事件预处理hook` 中进行处理。
::: warning
需要注意的是,执行多个 `事件预处理hook` 时并无顺序可言,它们是**并行运行**的。这个原则同样适用于其他的 `hook`
:::
2. **按优先级升序选出同一优先级的 Matcher**`nonebot` 提供了一个全局字典 `matchers`,这个字典的 `key` 是优先级 `priority``value` 是一个 `list`,里面存放着同一优先级的 `Matcher`。在注册 `Matcher` 时,它和优先级 `priority` 会添加到里面。
在执行 `事件预处理hook` 后,`nonebot` 会对 `matchers``key` 升序排序并选择出当前最小优先级的 `Matcher`
3. **根据 Matcher 定义的 Rule, Permission 判断是否运行**,在选出 `Matcher` 后,`nonebot` 会将 `bot``Event` 传入到 `Matcher.check_rule``Matcher.check_perm` 两个函数中,两个函数分别对 Matcher 定义的 Rule, Permission 进行 check当 check 通过后,这个 `Matcher` 就会响应事件。但是当同一个优先级的所有 `Matcher` 均没有响应时,`nonebot` 会返回到上一个步骤,选择出下一优先级的 `Matcher`
4. **实例化 matcher 并执行运行预处理 hook**,当 `Matcher` 响应事件后,它便会实例化为 `matcher`,并执行 `运行预处理hook`
5. **顺序运行 matcher 的所有 handlers**`运行预处理hook` 执行完毕后,便会运行 `matcher`,也就是**顺序运行**它的 `handlers`
::: tip
`matcher` 运行 `handlers` 的顺序是: 先运行该 `matcher` 的类 `Matcher` 注册时添加的 `handlers`(如果有的话),再按照装饰器装饰顺序运行装饰的 `handlers`
:::
6. **执行运行后处理 hook**`matcher``handlers` 运行完毕后,会执行 `运行后处理hook`
7. **判断是否停止事件传播**`nonebot` 会根据当前优先级所有 `matcher``block` 参数或者 `StopPropagation` 异常判断是否停止传播 `Event`,如果事件没有停止传播,`nonebot` 便会返回到第 2 步, 选择出下一优先级的 `Matcher`
8. **执行事件后处理 hook**,在 `Event` 停止传播或执行完所有响应的 `Matcher` 后,`nonebot` 会执行 `事件后处理hook`
`事件后处理hook` 执行完毕后,当前`Event`的处理周期就顺利结束了。
#### 特殊异常处理
在这个阶段,`nonebot` 规定了几个特殊的异常,当 `nonebot` 捕获到它们时,会用特定的行为来处理它们。
1. **IgnoredException**
这个异常可以在 `事件预处理hook``运行预处理hook` 抛出。
`事件预处理hook` 抛出它时,`nonebot` 会忽略当前的 `Event`,不进行处理。
`运行预处理hook` 抛出它时,`nonebot` 会忽略当前的 `matcher`,结束当前 `matcher` 的运行。
::: warning
`hook` 需要抛出这个异常时,要写明原因。
:::
2. **PausedException**
这个异常可以在 `handler` 中由 `Matcher.pause` 抛出。
`nonebot` 捕获到它时,会停止运行当前 `handler` 并结束当前 `matcher` 的运行,并将后续的 `handler` 交给一个临时 `Matcher` 来响应当前交互用户的下一个消息事件,当临时 `Matcher` 响应时,临时 `Matcher` 会运行后续的 handlers。
3. **RejectedException**
这个异常可以在 `handler` 中由 `Matcher.reject` 抛出。
`nonebot` 捕获到它时,会停止运行当前 `handler` 并结束当前 `matcher` 的运行,并将当前 handler 和后续 `handler` 交给一个临时 `Matcher` 来响应当前交互用户的下一个消息事件,当临时 `Matcher` 响应时,临时 `Matcher` 会运行当前 `handler` 和后续的 `handler`
4. **FinishedException**
这个异常可以在 `handler` 中由 `Matcher.finish` 抛出。
`nonebot` 捕获到它时,会停止运行当前 `handler` 并结束当前 `matcher` 的运行。
5. **StopPropagation**
这个异常一般会在执行 `运行后处理hook` 后抛出。
`nonebot` 捕获到它时, 会停止传播当前 `Event`,不再寻找下一优先级的 `Matcher`,直接执行 `事件后处理hook`
## 调用 API
`nonebot` 可以通过 `bot` 来调用 `API` `API` 可以向协议端发送数据,也可以向协议端请求更多的数据。
::: tip
不同 `adapter` 规定了不同的 API对应的 API 列表请参照协议规范。
:::
一般来说,我们可以用 `bot.*` 来调用 `API`(\*是 `API``action` 或者 `endpoint`)。
对于发送消息而言,一方面可以调用既有的 API另一方面 `nonebot` 实现了两个便捷方法,`bot.send(event, message, **kwargs)` 方法和可以在 `handler` 中使用的 `Matcher.send(message, **kwargs)` 方法,来向事件主体发送消息。

View File

@@ -0,0 +1,117 @@
# 跨插件访问
由于 `nonebot2` 独特的插件加载机制,在使用 python 原有的 import 机制来进行插件之间的访问时,很可能会有奇怪的或者意料以外的情况发生。为了避免这种情况的发生,您可以有两种方法来实现跨插件访问:
1. 将插件间的要使用的公共代码剥离出来,作为公共文件或者文件夹,提供给插件加以调用。
2. 使用 `nonebot2` 提供的 `export``require` 机制,来实现插件间的互相调用。
第一种方法比较容易理解和实现,这里不再赘述,但需要注意的是,请不要将公共文件或者公共文件夹作为**插件**被 `nonebot2` 加载。
下面将介绍第二种方法—— `export``require` 机制:
## 使用 export 和 require
现在,假定有两个插件 `pluginA``pluginB`,需要在 `pluginB` 中调用 `pluginA` 中的一个变量 `varA` 和一个函数 `funcA`
在上面的条件中涉及到了两种操作:一种是在 `pluginA``导出对象` 操作;而另一种是在 `pluginB``导入对象` 操作。在 `nonebot2` 中,`导出对象` 的操作用 `export` 机制来实现,`导入对象` 的操作用 `require` 机制来实现。下面,我们将逐一进行介绍。
:::warning 警告
使用这个方法进行跨插件访问时,**需要先加载`导出对象`的插件,再加载`导入对象`的插件。**
:::
### 使用 export
`pluginA` 中,我们调用 `export` 机制 `导出对象`
`export` 机制调用前,我们需要保证导出的对象已经被定义,比如:
```python
varA = "varA"
def funcA():
return "funcA"
```
在确保定义之后,我们可以从 `nonebot.plugin` 导入 `export()` 方法, `export()` 方法会返回一个特殊的字典 `export`
```python
from nonebot.plugin import export
export=export()
```
这个字典可以用来装载导出的对象,它的 key 是对象导出后的命名value 是对象本身,我们可以直接创建新的 `key` - `value` 对导出对象:
```python
export.vA = varA
export.fA = funcA
```
除此之外,也支持 `嵌套` 导出对象:
```python
export.sub.vA = varA
export.sub.fA = funcA
```
特别地,对于 `函数对象` 而言,`export` 支持用 `装饰器` 的方法来导出,因此,我们可以这样定义 `funcA`
```python
@export.sub
def funcA():
return "funcA"
```
或者:
```python
@export
def funcA():
return "funcA"
```
通过 `装饰器` 的方法导出函数时,命名固定为函数的命名,也就是说,上面的两个例子等同于:
```python
export.sub.funcA = funcA
export.funcA = funcA
```
这样,我们就成功导出 `varA``funcA` 对象了。
下面我们将介绍如何在 `pluginB` 中导入这些对象。
### 使用 require
`pluginB` 中,我们调用 `require` 机制 `导入对象`
:::warning 警告
在导入来自其他插件的对象时, 请确保导出该对象的插件在引用该对象的插件之前加载。如果该插件并未被加载,则会尝试加载,加载失败则会返回 `None`
:::
我们可以从 `nonebot.plugin` 中导入 `require()` 方法:
```python
from nonebot.plugin import require
```
`require()` 方法的参数是插件名, 它会返回在指定插件中,用 `export()` 方法创建的字典。
```python
require_A = require('pluginA')
```
在之前,这个字典已经存入了 `'vA'` - `varA`, `'fA'` - `funcA``'funcA'` - `funcA` 这样的 `key` - `value` 对。因此在这里我们直接用 `属性` 的方法来获取导入对象:
```python
varA = require_A.vA
funcA = require_A.fA or require_A.funcA
```
这样,我们就在 `pluginB` 中成功导入了 `varA``funcA` 对象了。

View File

@@ -0,0 +1 @@
# 事件处理函数重载

View File

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

View File

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

View File

@@ -0,0 +1,163 @@
# 钩子函数
[`钩子编程`](https://zh.wikipedia.org/wiki/%E9%92%A9%E5%AD%90%E7%BC%96%E7%A8%8B)
> 钩子编程hooking也称作“挂钩”是计算机程序设计术语指通过拦截软件模块间的函数调用、消息传递、事件传递来修改或扩展操作系统、应用程序或其他软件组件的行为的各种技术。处理被拦截的函数调用、事件、消息的代码被称为钩子hook
`nonebot2` 中有一系列预定义的钩子函数,分为两类:`全局钩子函数``事件钩子函数` ,这些钩子函数可以用装饰器的形式来使用。
## 全局钩子函数
全局钩子函数是指 `nonebot2` 针对其本身运行过程的钩子函数。
这些钩子函数是由其后端驱动 `driver`来运行的,故需要先获得全局 `driver` 对象:
```python
from nonebot import get_driver
driver=get_driver()
```
共分为六种函数:
### 启动准备
这个钩子函数会在 `nonebot2` 启动时运行。
```python
@driver.on_startup
async def do_something():
pass
```
### 终止处理
这个钩子函数会在 `nonebot2` 终止时运行。
```python
@driver.on_shutdown
async def do_something():
pass
```
### bot 连接处理
这个钩子函数会在 `bot` 通过 `websocket` 连接到 `nonebot2` 时运行。
```python
@driver.on_bot_connect
async def do_something(bot: Bot):
pass
```
### bot 断开处理
这个钩子函数会在 `bot` 断开与 `nonebot2``websocket` 连接时运行。
```python
@driver.on_bot_disconnect
async def do_something(bot: Bot):
pass
```
### bot api 调用钩子
这个钩子函数会在 `Bot` 调用 API 时运行。
```python
from nonebot.adapters import Bot
@Bot.on_calling_api
async def handle_api_call(bot: Bot, api: str, data: Dict[str, Any]):
pass
```
### bot api 调用后钩子
这个钩子函数会在 `Bot` 调用 API 后运行。
```python
from nonebot.adapters import Bot
@Bot.on_called_api
async def handle_api_result(bot: Bot, exception: Optional[Exception], api: str, data: Dict[str, Any], result: Any):
pass
```
## 事件处理钩子
这些钩子函数指的是影响 `nonebot2` 进行 `事件处理` 的函数。
:::tip 提示
关于 `事件处理` 的流程,可以在[这里](./README)查阅。
:::
:::warning 注意
1.在事件处理钩子函数中,与 `matcher` 运行状态相关的函数将不可用,如 `matcher.finish()`
2.如果需要在事件处理钩子函数中打断整个对话的执行,请参考以下范例:
```python
from nonebot.exception import IgnoredException
@event_preprocessor
async def do_something(bot: Bot, event: Event, state: T_State):
raise IgnoredException("reason")
```
:::
共分为四种函数:
### 事件预处理
这个钩子函数会在 `Event` 上报到 `nonebot2` 时运行
```python
from nonebot.message import event_preprocessor
@event_preprocessor
async def do_something(bot: Bot, event: Event, state: T_State):
pass
```
### 事件后处理
这个钩子函数会在 `nonebot2` 处理 `Event` 后运行
```python
from nonebot.message import event_postprocessor
@event_postprocessor
async def do_something(bot: Bot, event: Event, state: T_State):
pass
```
### 运行预处理
这个钩子函数会在 `nonebot2`运行 `matcher` 前运行。
```python
from nonebot.message import run_preprocessor
@run_preprocessor
async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State):
pass
```
### 运行后处理
这个钩子函数会在 `nonebot2`运行 `matcher` 后运行。
```python
from nonebot.message import run_postprocessor
@run_postprocessor
async def do_something(matcher: Matcher, exception: Optional[Exception], bot: Bot, event: Event, state: T_State):
pass
```

View File

@@ -0,0 +1,135 @@
# 定时任务
[`APScheduler`](https://apscheduler.readthedocs.io/en/latest/index.html) —— Advanced Python Scheduler
> Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline.
## 从 NoneBot v1 迁移
`APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/store.html) 中找到它。
相比于 `nonebot` v1`nonebot` v2 只需要安装插件并修改 `scheduler` 的导入方式即可完成迁移。
## 安装插件
### 通过 nb-cli
如正在使用 `nb-cli` 构建项目,你可以从插件市场复制安装命令或手动输入以下命令以添加 `nonebot_plugin_apscheduler`
```bash
nb plugin install nonebot_plugin_apscheduler
```
:::tip 提示
`nb-cli` 默认通过 `pypi` 安装,你可以添加命令参数 `-i [mirror]``--index [mirror]` 以使用镜像源安装。
:::
### 通过 poetry
执行以下命令以添加 `nonebot_plugin_apscheduler`
```bash
poetry add nonebot-plugin-apscheduler
```
:::tip 提示
由于稍后我们将使用 `nonebot.require()` 方法进行导入,所以无需额外的 `nonebot.load_plugin()`
:::
## 快速上手
1. 在需要设置定时任务的插件中,通过 `nonebot.require``nonebot_plugin_apscheduler` 导入 `scheduler` 对象
2. 在该对象的基础上,根据 `APScheduler` 的使用方法进一步配置定时任务
将上述步骤归纳为最小实现的代码如下:
```python
from nonebot import require
scheduler = require('nonebot_plugin_apscheduler').scheduler
@scheduler.scheduled_job('cron', hour='*/2', id='xxx', args=[1], kwargs={arg2: 2})
async def run_every_2_hour(arg1, arg2):
pass
scheduler.add_job(run_every_day_from_program_start, "interval", days=1, id="xxx")
```
## 分步进行
### 导入 scheduler 对象
为了使插件能够实现定时任务,需要先将 `scheduler` 对象导入插件。
`nonebot2` 提供了 `nonebot.require` 方法来实现导入其他插件的内容,此处我们使用这个方法来导入 `scheduler` 对象。
`nonebot` 使用的 `scheduler` 对象为 `AsyncScheduler`
> 使用该方法传入的插件本身也需要有对应实现,关于该方法的更多介绍可以参阅 [这里](./export-and-require.md)
```python
from nonebot import require
scheduler = require('nonebot_plugin_apscheduler').scheduler
```
### 编写定时任务
由于本部分为标准的通过 `APScheduler` 配置定时任务,有关指南请参阅 [APScheduler 官方文档](https://apscheduler.readthedocs.io/en/latest/userguide.html#adding-jobs)。
### 配置插件选项
根据项目的 `.env` 文件设置,向 `.env.*``bot.py` 文件添加 `nonebot_plugin_apscheduler` 的可选配置项
:::warning 注意
`.env.*` 文件的编写应遵循 nonebot2 对 `.env.*` 文件的编写要求
:::
#### `apscheduler_autostart`
类型:`bool`
默认值:`True`
是否自动启动 `APScheduler`
对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true`
##### 在 `.env` 中添加
```bash
APSCHEDULER_AUTOSTART=true
```
##### 在 `bot.py` 中添加
```python
nonebot.init(apscheduler_autostart=True)
```
#### `apscheduler_config`
类型:`dict`
默认值:`{"apscheduler.timezone": "Asia/Shanghai"}`
`APScheduler` 相关配置。修改/增加其中配置项需要确保 `prefix: apscheduler`
对于 `APScheduler` 的相关配置,请参阅 [scheduler-config](https://apscheduler.readthedocs.io/en/latest/userguide.html#scheduler-config) 和 [BaseScheduler](https://apscheduler.readthedocs.io/en/latest/modules/schedulers/base.html#apscheduler.schedulers.base.BaseScheduler)
> 官方文档在绝大多数时候能提供最准确和最具时效性的指南
##### 在 `.env` 中添加
```bash
APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"}
```
##### 在 `bot.py` 中添加
```python
nonebot.init(apscheduler_config={
"apscheduler.timezone": "Asia/Shanghai"
})
```

View File

@@ -10,18 +10,24 @@
* [nonebot.config](config.html)
* [nonebot.plugin](plugin.html)
* [nonebot.message](message.html)
* [nonebot.matcher](matcher.html)
* [nonebot.handler](handler.html)
* [nonebot.rule](rule.html)
* [nonebot.permission](permission.html)
* [nonebot.sched](sched.html)
* [nonebot.log](log.html)
@@ -40,7 +46,16 @@
* [nonebot.drivers.fastapi](drivers/fastapi.html)
* [nonebot.drivers.quart](drivers/quart.html)
* [nonebot.adapters](adapters/)
* [nonebot.adapters.cqhttp](adapters/cqhttp.html)
* [nonebot.adapters.ding](adapters/ding.html)
* [nonebot.adapters.mirai](adapters/mirai.html)

View File

@@ -0,0 +1,481 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters 模块
## 协议适配基类
各协议请继承以下基类,并使用 `driver.register_adapter` 注册适配器
## _class_ `Bot`
基类:`abc.ABC`
Bot 基类。用于处理上报消息,并提供 API 调用接口。
### `driver`
Driver 对象
### `config`
Config 配置对象
### `_calling_api_hook`
* **类型**
`Set[T_CallingAPIHook]`
* **说明**
call_api 时执行的函数
### `_called_api_hook`
* **类型**
`Set[T_CalledAPIHook]`
* **说明**
call_api 后执行的函数
### _abstract_ `__init__(connection_type, self_id, *, websocket=None)`
* **参数**
* `connection_type: str`: http 或者 websocket
* `self_id: str`: 机器人 ID
* `websocket: Optional[WebSocket]`: Websocket 连接对象
### `connection_type`
连接类型
### `self_id`
机器人 ID
### `websocket`
Websocket 连接对象
### _abstract property_ `type`
Adapter 类型
### _classmethod_ `register(driver, config)`
* **说明**
register 方法会在 driver.register_adapter 时被调用,用于初始化相关配置
### _abstract async classmethod_ `check_permission(driver, connection_type, headers, body)`
* **说明**
检查连接请求是否合法的函数,如果合法则返回当前连接 `唯一标识符`,通常为机器人 ID如果不合法则抛出 `RequestDenied` 异常。
* **参数**
* `driver: Driver`: Driver 对象
* `connection_type: str`: 连接类型
* `headers: dict`: 请求头
* `body: Optional[bytes]`: 请求数据WebSocket 连接该部分为 None
* **返回**
* `str`: 连接唯一标识符
* **异常**
* `RequestDenied`: 请求非法
### _abstract async_ `handle_message(message)`
* **说明**
处理上报消息的函数,转换为 `Event` 事件后调用 `nonebot.message.handle_event` 进一步处理事件。
* **参数**
* `message: dict`: 收到的上报消息
### _abstract async_ `_call_api(api, **data)`
* **说明**
`adapter` 实际调用 api 的逻辑实现函数,实现该方法以调用 api。
* **参数**
* `api: str`: API 名称
* `**data`: API 数据
### _async_ `call_api(api, **data)`
* **说明**
调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
* **参数**
* `api: str`: API 名称
* `self_id: Optional[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_ `MessageSegment`
基类:`abc.ABC`, `Mapping`
消息段基类
### `type`
* 类型: `str`
* 说明: 消息段类型
### `data`
* 类型: `Dict[str, Union[str, list]]`
* 说明: 消息段数据
## _class_ `Message`
基类:`list`, `abc.ABC`
消息数组
### `__init__(message=None, *args, **kwargs)`
* **参数**
* `message: Union[str, list, dict, MessageSegment, Message, Any]`: 消息内容
### `append(obj)`
* **说明**
添加一个消息段到消息数组末尾
* **参数**
* `obj: Union[str, MessageSegment]`: 要添加的消息段
### `extend(obj)`
* **说明**
拼接一个消息数组或多个消息段到消息数组末尾
* **参数**
* `obj: Union[Message, Iterable[MessageSegment]]`: 要添加的消息数组
### `reduce()`
* **说明**
缩减消息数组,即按 MessageSegment 的实现拼接相邻消息段
### `extract_plain_text()`
* **说明**
提取消息内纯文本消息
## _class_ `Event`
基类:`abc.ABC`, `pydantic.main.BaseModel`
Event 基类。提供获取关键信息的方法,其余信息可直接获取。
### _abstract_ `get_type()`
* **说明**
获取事件类型的方法,类型通常为 NoneBot 内置的四种类型。
* **返回**
* `Literal["message", "notice", "request", "meta_event"]`
* 其他自定义 `str`
### _abstract_ `get_event_name()`
* **说明**
获取事件名称的方法。
* **返回**
* `str`
### _abstract_ `get_event_description()`
* **说明**
获取事件描述的方法,通常为事件具体内容。
* **返回**
* `str`
### `get_log_string()`
* **说明**
获取事件日志信息的方法,通常你不需要修改这个方法,只有当希望 NoneBot 隐藏该事件日志时,可以抛出 `NoLogException` 异常。
* **返回**
* `str`
* **异常**
* `NoLogException`
### _abstract_ `get_user_id()`
* **说明**
获取事件主体 id 的方法,通常是用户 id 。
* **返回**
* `str`
### _abstract_ `get_session_id()`
* **说明**
获取会话 id 的方法,用于判断当前事件属于哪一个会话,通常是用户 id、群组 id 组合。
* **返回**
* `str`
### _abstract_ `get_message()`
* **说明**
获取事件消息内容的方法。
* **返回**
* `Message`
### `get_plaintext()`
* **说明**
获取消息纯文本的方法,通常不需要修改,默认通过 `get_message().extract_plain_text` 获取。
* **返回**
* `str`
### _abstract_ `is_tome()`
* **说明**
获取事件是否与机器人有关的方法。
* **返回**
* `bool`

View File

@@ -0,0 +1,581 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.cqhttp 模块
## CQHTTP (OneBot) v11 协议适配
协议详情请看: [CQHTTP](https://github.com/howmanybots/onebot/blob/master/README.md) | [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md)
# NoneBot.adapters.cqhttp.config 模块
## _class_ `Config`
CQHTTP 配置类
* **配置项**
* `access_token` / `cqhttp_access_token`: CQHTTP 协议授权令牌
* `secret` / `cqhttp_secret`: CQHTTP HTTP 上报数据签名口令
# NoneBot.adapters.cqhttp.utils 模块
## `escape(s, *, escape_comma=True)`
* **说明**
对字符串进行 CQ 码转义。
* **参数**
* `s: str`: 需要转义的字符串
* `escape_comma: bool`: 是否转义逗号(`,`)。
## `unescape(s)`
* **说明**
对字符串进行 CQ 码去转义。
* **参数**
* `s: str`: 需要转义的字符串
# NoneBot.adapters.cqhttp.exception 模块
## _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]`: 错误码
# NoneBot.adapters.cqhttp.bot 模块
## _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._base.Bot`](README.md#nonebot.adapters._base.Bot)
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 调用失败
# NoneBot.adapters.cqhttp.message 模块
## _class_ `MessageSegment`
基类:`abc.ABC`, `Mapping`
CQHTTP 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
## _class_ `Message`
基类:[`nonebot.adapters._base.Message`](README.md#nonebot.adapters._base.Message)
CQHTTP 协议 Message 适配。
# NoneBot.adapters.cqhttp.permission 模块
## `PRIVATE`
* **说明**: 匹配任意私聊消息类型事件
## `PRIVATE_FRIEND`
* **说明**: 匹配任意好友私聊消息类型事件
## `PRIVATE_GROUP`
* **说明**: 匹配任意群临时私聊消息类型事件
## `PRIVATE_OTHER`
* **说明**: 匹配任意其他私聊消息类型事件
## `GROUP`
* **说明**: 匹配任意群聊消息类型事件
## `GROUP_MEMBER`
* **说明**: 匹配任意群员群聊消息类型事件
:::warning 警告
该权限通过 event.sender 进行判断且不包含管理员以及群主!
:::
## `GROUP_ADMIN`
* **说明**: 匹配任意群管理员群聊消息类型事件
## `GROUP_OWNER`
* **说明**: 匹配任意群主群聊消息类型事件
# NoneBot.adapters.cqhttp.event 模块
## _class_ `Event`
基类:[`nonebot.adapters._base.Event`](README.md#nonebot.adapters._base.Event)
CQHTTP 协议事件,字段与 CQHTTP 一致。各事件字段参考 [CQHTTP 文档](https://github.com/howmanybots/onebot/blob/master/README.md)
## _class_ `MessageEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
消息事件
### `to_me`
* **说明**
消息是否与机器人有关
* **类型**
`bool`
### `reply`
* **说明**
消息中提取的回复消息,内容为 `get_msg` API 返回结果
* **类型**
`Optional[Reply]`
## _class_ `PrivateMessageEvent`
基类:`nonebot.adapters.cqhttp.event.MessageEvent`
私聊消息
## _class_ `GroupMessageEvent`
基类:`nonebot.adapters.cqhttp.event.MessageEvent`
群消息
## _class_ `NoticeEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
通知事件
## _class_ `GroupUploadNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群文件上传事件
## _class_ `GroupAdminNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群管理员变动
## _class_ `GroupDecreaseNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群成员减少事件
## _class_ `GroupIncreaseNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群成员增加事件
## _class_ `GroupBanNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群禁言事件
## _class_ `FriendAddNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
好友添加事件
## _class_ `GroupRecallNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群消息撤回事件
## _class_ `FriendRecallNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
好友消息撤回事件
## _class_ `NotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
提醒事件
## _class_ `PokeNotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NotifyEvent`
戳一戳提醒事件
## _class_ `LuckyKingNotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NotifyEvent`
群红包运气王提醒事件
## _class_ `HonorNotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NotifyEvent`
群荣誉变更提醒事件
## _class_ `RequestEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
请求事件
## _class_ `FriendRequestEvent`
基类:`nonebot.adapters.cqhttp.event.RequestEvent`
加好友请求事件
## _class_ `GroupRequestEvent`
基类:`nonebot.adapters.cqhttp.event.RequestEvent`
加群请求/邀请事件
## _class_ `MetaEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
元事件
## _class_ `LifecycleMetaEvent`
基类:`nonebot.adapters.cqhttp.event.MetaEvent`
生命周期元事件
## _class_ `HeartbeatMetaEvent`
基类:`nonebot.adapters.cqhttp.event.MetaEvent`
心跳元事件
## `get_event_model(event_name)`
* **说明**
根据事件名获取对应 `Event Model``FallBack Event Model` 列表
* **返回**
* `List[Type[Event]]`

View File

@@ -0,0 +1,334 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.ding 模块
## 钉钉群机器人 协议适配
协议详情请看: [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)
# NoneBot.adapters.ding.config 模块
## _class_ `Config`
钉钉配置类
* **配置项**
* `access_token` / `ding_access_token`: 钉钉令牌
* `secret` / `ding_secret`: 钉钉 HTTP 上报数据签名口令
# NoneBot.adapters.ding.exception 模块
## _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_ `NetworkError`
基类:[`nonebot.exception.NetworkError`](../exception.md#nonebot.exception.NetworkError), `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
网络错误。
* **参数**
* `retcode: Optional[int]`: 错误码
## _exception_ `SessionExpired`
基类:`nonebot.adapters.ding.exception.ApiNotAvailable`, `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
发消息的 session 已经过期。
# NoneBot.adapters.ding.bot 模块
## _class_ `Bot`
基类:[`nonebot.adapters._base.Bot`](README.md#nonebot.adapters._base.Bot)
钉钉 协议 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_ `call_api(api, event=None, **data)`
* **说明**
调用 钉钉 协议 API
* **参数**
* `api: str`: API 名称
* `event: Optional[MessageEvent]`: Event 对象
* `**data: Any`: API 参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
### _async_ `send(event, message, at_sender=False, webhook=None, secret=None, **kwargs)`
* **说明**
根据 `event` 向触发事件的主体发送消息。
* **参数**
* `event: Event`: Event 对象
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `at_sender: bool`: 是否 @ 事件主体
* `webhook: Optional[str]`: 该条消息将调用的 webhook 地址。不传则将使用 sessionWebhook若其也不存在该条消息不发送使用自定义 webhook 时注意你设置的安全方式如加关键词IP地址加签等等。
* `secret: Optional[str]`: 如果你使用自定义的 webhook 地址,推荐使用加签方式对消息进行验证,将 机器人安全设置页面加签一栏下面显示的SEC开头的字符串 传入这个参数即可。
* `**kwargs`: 覆盖默认参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ValueError`: 缺少 `user_id`, `group_id`
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
# NoneBot.adapters.ding.message 模块
## _class_ `MessageSegment`
基类:`abc.ABC`, `Mapping`
钉钉 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
### _static_ `atAll()`
@全体
### _static_ `atMobiles(*mobileNumber)`
@指定手机号人员
### _static_ `atDingtalkIds(*dingtalkIds)`
@指定 id@ 默认会在消息段末尾。
所以你可以在消息中使用 @{senderId} 占位,发送出去之后 @ 就会出现在占位的位置:
``python
message = MessageSegment.text(f"@{event.senderId},你好")
message += MessageSegment.atDingtalkIds(event.senderId)
``
### _static_ `text(text)`
发送 `text` 类型消息
### _static_ `image(picURL)`
发送 `image` 类型消息
### _static_ `extension(dict_)`
"标记 text 文本的 extension 属性,需要与 text 消息段相加。
### _static_ `code(code_language, code)`
"发送 code 消息段
### _static_ `markdown(title, text)`
发送 `markdown` 类型消息
### _static_ `actionCardSingleBtn(title, text, singleTitle, singleURL)`
发送 `actionCardSingleBtn` 类型消息
### _static_ `actionCardMultiBtns(title, text, btns, hideAvatar=False, btnOrientation='1')`
发送 `actionCardMultiBtn` 类型消息
* **参数**
* `btnOrientation`: 0按钮竖直排列 1按钮横向排列
* `btns`: [{ "title": title, "actionURL": actionURL }, ...]
### _static_ `feedCard(links)`
发送 `feedCard` 类型消息
* **参数**
* `links`: [{ "title": xxx, "messageURL": xxx, "picURL": xxx }, ...]
## _class_ `Message`
基类:[`nonebot.adapters._base.Message`](README.md#nonebot.adapters._base.Message)
钉钉 协议 Message 适配。
# NoneBot.adapters.ding.event 模块
## _class_ `Event`
基类:[`nonebot.adapters._base.Event`](README.md#nonebot.adapters._base.Event)
钉钉协议事件。各事件字段参考 [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)
## _class_ `ConversationType`
基类:`str`, `enum.Enum`
An enumeration.
## _class_ `MessageEvent`
基类:`nonebot.adapters.ding.event.Event`
消息事件
## _class_ `PrivateMessageEvent`
基类:`nonebot.adapters.ding.event.MessageEvent`
私聊消息事件
## _class_ `GroupMessageEvent`
基类:`nonebot.adapters.ding.event.MessageEvent`
群消息事件

File diff suppressed because it is too large Load Diff

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`
基类:`nonebot.config.BaseConfig`
运行环境配置。大小写不敏感。
将会从 `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[str]`
* **默认值**: `set()`
* **说明**
机器人超级用户。
* **示例**
```default
SUPERUSERS=["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,318 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers 模块
## 后端驱动适配基类
各驱动请继承以下基类
## _class_ `Driver`
基类:`abc.ABC`
Driver 基类。将后端框架封装,以满足适配器使用。
### `_adapters`
* **类型**
`Dict[str, Type[Bot]]`
* **说明**
已注册的适配器列表
### `_ws_connection_hook`
* **类型**
`Set[T_WebSocketConnectionHook]`
* **说明**
WebSocket 连接建立时执行的函数
### `_ws_disconnection_hook`
* **类型**
`Set[T_WebSocketDisconnectionHook]`
* **说明**
WebSocket 连接断开时执行的函数
### _abstract_ `__init__(env, config)`
* **参数**
* `env: Env`: 包含环境信息的 Env 对象
* `config: Config`: 包含配置信息的 Config 对象
### `env`
* **类型**
`str`
* **说明**
环境名称
### `config`
* **类型**
`Config`
* **说明**
配置对象
### `_clients`
* **类型**
`Dict[str, Bot]`
* **说明**
已连接的 Bot
### `register_adapter(name, adapter, **kwargs)`
* **说明**
注册一个协议适配器
* **参数**
* `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)`
注册一个在驱动停止时运行的函数
### `on_bot_connect(func)`
* **说明**
装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。
* **函数参数**
* `bot: Bot`: 当前连接上的 Bot 对象
### `on_bot_disconnect(func)`
* **说明**
装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。
* **函数参数**
* `bot: Bot`: 当前连接上的 Bot 对象
### `_bot_connect(bot)`
在 WebSocket 连接成功后,调用该函数来注册 bot 对象
### `_bot_disconnect(bot)`
在 WebSocket 连接断开后,调用该函数来注销 bot 对象
### _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_ `WebSocket`
基类:`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,135 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.fastapi 模块
## FastAPI 驱动适配
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)
## _class_ `Config`
基类:`pydantic.env_settings.BaseSettings`
FastAPI 驱动框架设置,详情参考 FastAPI 文档
### `fastapi_openapi_url`
* **类型**
`Optional[str]`
* **说明**
`openapi.json` 地址,默认为 `None` 即关闭
### `fastapi_docs_url`
* **类型**
`Optional[str]`
* **说明**
`swagger` 地址,默认为 `None` 即关闭
### `fastapi_redoc_url`
* **类型**
`Optional[str]`
* **说明**
`redoc` 地址,默认为 `None` 即关闭
### `fastapi_reload_dirs`
* **类型**
`List[str]`
* **说明**
`debug` 模式下重载监控文件夹列表,默认为 uvicorn 默认值
## _class_ `Driver`
基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver)
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

View File

@@ -0,0 +1,62 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.quart 模块
## Quart 驱动适配
后端使用方法请参考: [Quart 文档](https://pgjones.gitlab.io/quart/index.html)
## _class_ `Driver`
基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver)
Quart 驱动框架
* **上报地址**
* `/{adapter name}/http`: HTTP POST 上报
* `/{adapter name}/ws`: WebSocket 上报
### _property_ `type`
驱动名称: `quart`
### _property_ `server_app`
`Quart` 对象
### _property_ `asgi`
`Quart` 对象
### _property_ `logger`
fastapi 使用的 logger
### `on_startup(func)`
参考文档: [Startup and Shutdown](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
### `on_shutdown(func)`
参考文档: [Startup and Shutdown](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 Quart

View File

@@ -0,0 +1,214 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.exception 模块
## 异常
下列文档中的异常是所有 NoneBot 运行时可能会抛出的。
这些异常并非所有需要用户处理,在 NoneBot 内部运行时被捕获,并进行对应操作。
## _exception_ `NoneBotException`
基类:`Exception`
* **说明**
所有 NoneBot 发生的异常基类。
## _exception_ `IgnoredException`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
* **参数**
* `reason`: 忽略事件的原因
## _exception_ `ParserExit`
基类:`nonebot.exception.NoneBotException`
* **说明**
`shell command` 处理消息失败时返回的异常
* **参数**
* `status`
* `message`
## _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_ `NoLogException`
基类:`Exception`
* **说明**
指示 NoneBot 对当前 `Event` 进行处理但不显示 Log 信息,可在 `get_log_string` 时抛出
## _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,111 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.handler 模块
## 事件处理函数
该模块实现事件处理函数的封装,以实现动态参数等功能。
## _class_ `Handler`
基类:`object`
事件处理函数类
### `__init__(func)`
装饰事件处理函数以便根据动态参数运行
### `func`
* **类型**
`T_Handler`
* **说明**
事件处理函数
### `signature`
* **类型**
`inspect.Signature`
* **说明**
事件处理函数签名
### _property_ `bot_type`
* **类型**
`Union[Type["Bot"], inspect.Parameter.empty]`
* **说明**
事件处理函数接受的 Bot 对象类型
### _property_ `event_type`
* **类型**
`Optional[Union[Type[Event], inspect.Parameter.empty]]`
* **说明**
事件处理函数接受的 event 类型 / 不需要 event 参数
### _property_ `state_type`
* **类型**
`Optional[Union[T_State, inspect.Parameter.empty]]`
* **说明**
事件处理函数是否接受 state 参数
### _property_ `matcher_type`
* **类型**
`Optional[Union[Type["Matcher"], inspect.Parameter.empty]]`
* **说明**
事件处理函数是否接受 matcher 参数

View File

@@ -40,16 +40,3 @@ NoneBot 使用 [loguru](https://github.com/Delgan/loguru) 来记录日志信息
```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

@@ -7,7 +7,7 @@ sidebarDepth: 0
## 事件响应器
该模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行 对话 。
该模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行对话 。
## `matchers`
@@ -157,7 +157,7 @@ sidebarDepth: 0
* **类型**
`dict`
`T_State`
@@ -167,12 +167,27 @@ sidebarDepth: 0
### `_default_state_factory`
* **类型**
`Optional[T_State]`
* **说明**
事件响应器默认工厂函数
### `_default_parser`
* **类型**
`Optional[ArgsParser]`
`Optional[T_ArgsParser]`
@@ -182,6 +197,36 @@ sidebarDepth: 0
### `_default_type_updater`
* **类型**
`Optional[T_TypeUpdater]`
* **说明**
事件响应器类型更新函数
### `_default_permission_updater`
* **类型**
`Optional[T_PermissionUpdater]`
* **说明**
事件响应器权限更新函数
### `__init__()`
实例化 Matcher 以便运行
@@ -202,7 +247,7 @@ sidebarDepth: 0
### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, default_state_factory=None, expire_time=None)`
* **说明**
@@ -214,7 +259,7 @@ sidebarDepth: 0
* **参数**
* `type_: str`: 事件响应器类型,与 `event.type` 一致时触发,空字符串表示任意
* `type_: str`: 事件响应器类型,与 `event.get_type()` 一致时触发,空字符串表示任意
* `rule: Optional[Rule]`: 匹配规则
@@ -223,7 +268,7 @@ sidebarDepth: 0
* `permission: Optional[Permission]`: 权限
* `handlers: Optional[List[Handler]]`: 事件处理函数列表
* `handlers: Optional[List[T_Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器,即触发一次后删除
@@ -238,7 +283,10 @@ sidebarDepth: 0
* `module: Optional[str]`: 事件响应器所在模块名称
* `default_state: Optional[dict]`: 默认状态 `state`
* `default_state: Optional[T_State]`: 默认状态 `state`
* `default_state_factory: Optional[T_StateFactory]`: 默认状态 `state` 的工厂函数
* `expire_time: Optional[datetime]`: 事件响应器最终有效时间点,过时即被删除
@@ -296,7 +344,7 @@ sidebarDepth: 0
* `event: Event`: 上报事件
* `state: dict`: 当前状态
* `state: T_State`: 当前状态
@@ -319,7 +367,39 @@ sidebarDepth: 0
* **参数**
* `func: ArgsParser`: 参数解析函数
* `func: T_ArgsParser`: 参数解析函数
### _classmethod_ `type_updater(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认响应事件类型更新函数
* **参数**
* `func: T_TypeUpdater`: 响应事件类型更新函数
### _classmethod_ `permission_updater(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认会话权限更新函数
* **参数**
* `func: T_PermissionUpdater`: 会话权限更新函数
@@ -373,11 +453,11 @@ sidebarDepth: 0
* `prompt: Optional[Union[str, Message, MessageSegment]]`: 在参数不存在时向用户发送的消息
* `args_parser: Optional[ArgsParser]`: 可选参数解析函数,空则使用默认解析函数
* `args_parser: Optional[T_ArgsParser]`: 可选参数解析函数,空则使用默认解析函数
### _async classmethod_ `send(message)`
### _async classmethod_ `send(message, **kwargs)`
* **说明**
@@ -392,8 +472,11 @@ sidebarDepth: 0
* `message: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `finish(message=None)`
### _async classmethod_ `finish(message=None, **kwargs)`
* **说明**
@@ -408,8 +491,11 @@ sidebarDepth: 0
* `message: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `pause(prompt=None)`
### _async classmethod_ `pause(prompt=None, **kwargs)`
* **说明**
@@ -424,8 +510,11 @@ sidebarDepth: 0
* `prompt: Union[str, Message, MessageSegment]`: 消息内容
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### _async classmethod_ `reject(prompt=None)`
### _async classmethod_ `reject(prompt=None, **kwargs)`
* **说明**
@@ -440,46 +529,13 @@ sidebarDepth: 0
* `prompt: Union[str, Message, MessageSegment]`: 消息内容
## _class_ `MatcherGroup`
基类:`object`
事件响应器组合,统一管理。用法同 `Matcher`
* `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api
### `__init__(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, default_state=None, expire_time=None)`
### `stop_propagation()`
* **说明**
创建一个事件响应器组合,参数为默认值,与 `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: T_State`: 当前 State
## `event_postprocessor(func)`
* **说明**
事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
* **参数**
事件后处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前事件运行前 State
## `run_preprocessor(func)`
* **说明**
运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。
* **参数**
运行预处理函数接收四个参数。
* `matcher: Matcher`: 当前要运行的事件响应器
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 State
## `run_postprocessor(func)`
* **说明**
运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。
* **参数**
运行后处理函数接收五个参数。
* `matcher: Matcher`: 运行完毕的事件响应器
* `exception: Optional[Exception]`: 事件响应器运行错误(如果存在)
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 State
## _async_ `handle_event(bot, event)`
* **说明**
处理一个事件。调用该函数以实现分发事件。
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* **示例**
```python
import asyncio
asyncio.create_task(handle_event(bot, event))
```

View File

@@ -28,13 +28,13 @@ sidebarDepth: 0
* `on_endswith` => `nonebot.plugin.on_endswith`
* `on_keyword` => `nonebot.plugin.on_keyword`
* `on_command` => `nonebot.plugin.on_command`
* `on_regex` => `nonebot.plugin.on_regex`
* `on_regex` => `nonebot.plugin.on_regex`
* `on_shell_command` => `nonebot.plugin.on_shell_command`
* `on_regex` => `nonebot.plugin.on_regex`
@@ -43,18 +43,39 @@ sidebarDepth: 0
* `CommandGroup` => `nonebot.plugin.CommandGroup`
* `Matchergroup` => `nonebot.plugin.MatcherGroup`
* `load_plugin` => `nonebot.plugin.load_plugin`
* `load_plugins` => `nonebot.plugin.load_plugins`
* `load_all_plugins` => `nonebot.plugin.load_all_plugins`
* `load_from_json` => `nonebot.plugin.load_from_json`
* `load_from_toml` => `nonebot.plugin.load_from_toml`
* `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()`

View File

@@ -50,72 +50,14 @@ sidebarDepth: 0
* **参数**
* `*user: int`: 白名单
* `*user: str`: 白名单
* `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

View File

@@ -0,0 +1,266 @@
---
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, T_State], Awaitable[bool]]`: **异步** RuleChecker
### `checkers`
* **说明**
存储 `RuleChecker`
* **类型**
* `Set[Callable[[Bot, Event, T_State], Awaitable[bool]]]`
### _async_ `__call__(bot, event, state)`
* **说明**
检查是否符合所有规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 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 提示
命令内容与后续消息间无需空格!
:::
## _class_ `ArgumentParser`
基类:`argparse.ArgumentParser`
* **说明**
`shell_like` 命令参数解析器,解析出错时不会退出程序。
## `shell_command(*cmds, parser=None)`
* **说明**
支持 `shell_like` 解析参数的命令形式匹配,根据配置里提供的 `command_start`, `command_sep` 判断消息是否为命令。
可以通过 `state["_prefix"]["command"]` 获取匹配成功的命令(例:`("test",)`),通过 `state["_prefix"]["raw_command"]` 获取匹配成功的原始命令文本(例:`"/test"`)。
可以通过 `state["argv"]` 获取用户输入的原始参数列表
添加 `parser` 参数后, 可以自动处理消息并将结果保存在 `state["args"]` 中。
* **参数**
* `*cmds: Union[str, Tuple[str, ...]]`: 命令内容
* `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象
* **示例**
使用默认 `command_start`, `command_sep` 配置,更多示例参考 `argparse` 标准库文档。
```python
from nonebot.rule import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-a", action="store_true")
rule = shell_command("ls", parser=parser)
```
:::tip 提示
命令内容与后续消息间无需空格!
:::
## `regex(regex, flags=0)`
* **说明**
根据正则表达式进行匹配。
可以通过 `state["_matched"]` `state["_matched_groups"]` `state["_matched_dict"]`
获取正则表达式匹配成功的文本。
* **参数**
* `regex: str`: 正则表达式
* `flags: Union[int, re.RegexFlag]`: 正则标志
:::tip 提示
正则表达式匹配使用 search 而非 match如需从头匹配请使用 `r"^xxx"` 来确保匹配开头
:::
## `to_me()`
* **说明**
通过 `event.is_tome()` 判断事件是否与机器人有关
* **参数**
*

View File

@@ -0,0 +1,278 @@
---
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 模块导入。
## `T_State`
* **类型**
`Dict[Any, Any]`
* **说明**
事件处理状态 State 类型
## `T_StateFactory`
* **类型**
`Callable[[Bot, Event], Awaitable[T_State]]`
* **说明**
事件处理状态 State 类工厂函数
## `T_WebSocketConnectionHook`
* **类型**
`Callable[[Bot], Awaitable[None]]`
* **说明**
WebSocket 连接建立时执行的函数
## `T_WebSocketDisconnectionHook`
* **类型**
`Callable[[Bot], Awaitable[None]]`
* **说明**
WebSocket 连接断开时执行的函数
## `T_CallingAPIHook`
* **类型**
`Callable[[Bot, str, Dict[str, Any]], Awaitable[None]]`
* **说明**
`bot.call_api` 时执行的函数
## `T_CalledAPIHook`
* **类型**
`Callable[[Bot, Optional[Exception], str, Dict[str, Any], Any], Awaitable[None]]`
* **说明**
`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result
## `T_EventPreProcessor`
* **类型**
`Callable[[Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件预处理函数 EventPreProcessor 类型
## `T_EventPostProcessor`
* **类型**
`Callable[[Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件预处理函数 EventPostProcessor 类型
## `T_RunPreProcessor`
* **类型**
`Callable[[Matcher, Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件响应器运行前预处理函数 RunPreProcessor 类型
## `T_RunPostProcessor`
* **类型**
`Callable[[Matcher, Optional[Exception], Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件响应器运行前预处理函数 RunPostProcessor 类型,第二个参数为运行时产生的错误(如果存在)
## `T_RuleChecker`
* **类型**
`Callable[[Bot, Event, T_State], Union[bool, Awaitable[bool]]]`
* **说明**
RuleChecker 即判断是否响应事件的处理函数。
## `T_PermissionChecker`
* **类型**
`Callable[[Bot, Event], Union[bool, Awaitable[bool]]]`
* **说明**
RuleChecker 即判断是否响应消息的处理函数。
## `T_Handler`
* **类型**
* `Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
* `Callable[[Bot, Event], Union[Awaitable[None], Awaitable[NoReturn]]]`
* `Callable[[Bot, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
* `Callable[[Bot], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
Handler 即事件的处理函数。
## `T_ArgsParser`
* **类型**
`Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
ArgsParser 即消息参数解析函数,在 Matcher.got 获取参数时被运行。
## `T_TypeUpdater`
* **类型**
`Callable[[Bot, Event, T_State, str], Awaitable[str]]`
* **说明**
TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。默认会更新为 `message`
## `T_PermissionUpdater`
* **类型**
`Callable[[Bot, Event, T_State, Permission], Awaitable[Permission]]`
* **说明**
PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。默认会更新为当前事件的触发对象。

View File

@@ -52,6 +52,28 @@ sidebarDepth: 0
## `logger_wrapper`
* **说明**
用于打印 adapter 的日志。
* **Log 参数**
* `level: Literal['WARNING', 'DEBUG', 'INFO']`: 日志等级
* `message: str`: 日志信息
* `exception: Optional[Exception]`: 异常信息
## _class_ `DataclassEncoder`
基类:`json.encoder.JSONEncoder`

View File

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

View File

@@ -2,7 +2,7 @@
到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。
在上一章节中,我们创建了默认的项目结构,其中 `.env`, `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。
在上一章节中,我们创建了默认的项目结构,其中 `.env` `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。
:::danger 警告
请勿将敏感信息写入配置文件并提交至开源仓库!
@@ -13,19 +13,33 @@
NoneBot 在启动时将会从系统环境变量或者 `.env` 文件中寻找变量 `ENVIRONMENT` (大小写不敏感),默认值为 `prod`
这将引导 NoneBot 从系统环境变量或者 `.env.{ENVIRONMENT}` 文件中进一步加载具体配置。
现在,我们在 `.env` 文件中写入当前环境信息
`.env` 文件是基础环境配置文件,该文件中的配置项在不同环境下都会被加载,但会被 `.env.{ENVIRONMENT}` 文件中的配置所覆盖。
现在,我们在 `.env` 文件中写入当前环境信息:
```bash
# .env
ENVIRONMENT=dev
CUSTOM_CONFIG=common config # 这个配置项在任何环境中都会被加载
```
如你所想,之后 NoneBot 就会从 `.env.dev` 文件中加载环境变量。
## .env.\* 文件
详细配置文件,使用 [pydantic](https://pydantic-docs.helpmanual.io/) 加载配置。在 NoneBot 初始化时可以指定忽略 `.env` 中的环境信息转而加载某个配置文件: `nonebot.init(_env_file=".env.dev")`
NoneBot 使用 [pydantic](https://pydantic-docs.helpmanual.io/) 进行配置管理,会从 `.env.{ENVIRONMENT}` 文件中获悉环境配置
可以在 NoneBot 初始化时指定加载某个环境配置文件: `nonebot.init(_env_file=".env.dev")`,这将忽略你在 `.env` 中设置的 `ENVIRONMENT`
:::warning 提示
由于 `pydantic` 使用 JSON 加载配置项,请确保配置项值为 JSON 能够解析的数据。如果 JSON 解析失败将作为字符串处理。
由于 `pydantic` 使用 JSON 解析配置项,请确保配置项值为 JSON 格式的数据。如
```bash
list=["123456789", "987654321", 1]
test={"hello": "world"}
```
如果配置项值解析失败将作为字符串处理。
:::
示例及说明:
@@ -46,6 +60,10 @@ CUSTOM_CONFIG2= # 留空则从系统环境变量读取,如不存在则为空
详细的配置项参考 [Config Reference](../api/config.md) 。
## 系统环境变量
如果在系统环境变量中定义了配置,则一样会被读取。
## bot.py 文件
配置项也可以在 NoneBot 初始化时传入。此处可以传入任意合法 Python 变量。当然也可以在初始化完成后修改或新增。
@@ -65,4 +83,4 @@ config.custom_config4 = "new config after init"
## 优先级
`bot.py init` > `env file` > `system env`
`bot.py` 文件( `nonebot.init` ) > 系统环境变量 > `.env` `.env.*` 文件

View File

@@ -0,0 +1,107 @@
# CQHTTP 协议使用指南
## 安装 NoneBot CQHTTP 适配器
```bash
pip install nonebot-adapter-cqhttp
```
## 配置 CQHTTP 协议端(以 QQ 为例)
单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。
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. 生成默认配置文件并修改默认配置
```hjson{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: 1
bucket_size: 1
}
ignore_invalid_cqcode: false
force_fragmented: false
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: ws://you_websocket_api.server
reverse_event_url: ws://you_websocket_event.server
reverse_reconnect_interval: 3000
}
]
post_message_format: array
use_sso_address: false
debug: false
log_level: ""
web_ui: {
enabled: false
host: 127.0.0.1
web_ui_port: 9999
web_input: false
}
}
```
其中 `ws://127.0.0.1:8080/cqhttp/ws` 中的 `127.0.0.1` 和 `8080` 应分别对应 nonebot 配置的 HOST 和 PORT。
`cqhttp` 是前述 `register_adapter` 时传入的第一个参数,代表设置的 `CQHTTPBot` 适配器的路径,你可以对不同的适配器设置不同路径以作区别。
## 历史性的第一次对话
一旦新的配置文件正确生效之后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!
```
这表示 CQHTTP 协议端已经成功地使用 CQHTTP 协议连接上了 NoneBot。
现在,尝试向你的机器人账号发送如下内容:
```default
/echo 你好,世界
```
到这里如果一切 OK你应该会收到机器人给你回复了 `你好,世界`。这一历史性的对话标志着你已经成功地运行了一个 NoneBot 的最小实例,开始了编写更强大的 QQ 机器人的创意之旅!
<ClientOnly>
<Messenger :messages="[{ position: 'right', msg: '/echo 你好,世界' }, { position: 'left', msg: '你好,世界' }]"/>
</ClientOnly>

View File

@@ -0,0 +1,197 @@
# 事件处理
在上一章中,我们已经注册了事件响应器,现在我们可以正式编写事件处理逻辑了!
## [事件处理函数](../api/typing.md#handler)
```python{1,2,8,9}
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: T_State):
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: T_State):
state["key"] = "hello"
@matcher.got("key2", prompt="{key}!")
async def handle2(bot: Bot, event: Event, state: T_State):
pass
```
`args_parser` 为参数处理函数,在这里传入一个新的函数以覆盖默认的参数处理。详情参照 [args_parser](#参数处理函数-args-parser)
特别的,这些装饰器都可以套娃使用:
```python
@matcher.got("key1")
@matcher.got("key2")
async def handle(bot: Bot, event: Event, state: T_State):
pass
```
### 事件处理函数参数
事件处理函数类型为:
- `Callable[[Bot, Event, T_State, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Event, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, T_State, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Event], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot], Union[Awaitable[None], Awaitable[NoReturn]]]`
简单说就是:除了 `bot` 参数,其他都是可选的。
以下函数都是合法的事件处理函数(仅列举常用的):
```python
async def handle(bot: Bot, event: Event, state: T_State):
pass
async def handle(bot: Bot, event: Event, state: T_State, matcher: Matcher):
pass
async def handle(bot: Bot, event: Event):
pass
async def handle(bot: Bot, state: T_State):
pass
async def handle(bot: Bot):
pass
```
:::danger 警告
函数的参数名固定不能修改!
:::
参数分别为:
1. [nonebot.adapters.Bot](../api/adapters/#class-bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
2. [nonebot.adapters.Event](../api/adapters/#class-event): 即上报事件对象,可以获取到上报的所有信息。
3. [state](../api/typing.md#t-state): 状态字典,可以存储任意的信息,其中还包含一些特殊的值以获取 NoneBot 内部处理时的一些信息,如:
- `state["_current_key"]`: 存储当前 `got` 获取的参数名
- `state["_prefix"]`, `state["_suffix"]`: 存储当前 TRIE 匹配的前缀/后缀,可以通过该值获取用户命令的原始命令
:::tip 提示
NoneBot 会对不同类型的参数进行不同的操作,详情查看 [事件处理函数重载](../advanced/overloaded-handlers.md)
:::
### 参数处理函数 args_parser
在使用 `got` 获取用户输入参数时需要对用户的消息进行处理以转换为我们所需要的信息。在默认情况下NoneBot 会把用户的消息字符串原封不动的赋值给 `state[key]` 。可以通过以下两种方式修改默认处理逻辑:
- `@matcher.args_parser` 装饰器:直接装饰一个函数作为参数处理器
- `got(key, prompt, args_parser)`:直接把函数作为参数传入
参数处理函数类型为:`Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`,即:
```python
async def parser(bot: Bot, event: Event, state: T_State):
state[state["_current_key"]] = str(event.get_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: T_State):
print(state["_current_key"], ":", str(event.get_message()))
state[state["_current_key"]] = str(event.get_message())
@matcher.handle()
async def first_receive(bot: Bot, event: Event, state: T_State):
# 获取用户原始命令,如:/test
print(state["_prefix"]["raw_command"])
# 处理用户输入参数,如:/test arg1 arg2
raw_args = str(event.get_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: T_State):
# 在这里对参数进行验证
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,148 @@
# 注册事件响应器
好了,现在插件已经创建完毕,我们可以开始编写实际代码了,下面将以一个简易单文件天气查询插件为例。
在插件目录下 `weather.py` 中添加如下代码:
```python
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
weather = on_command("天气", rule=to_me(), priority=5)
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: T_State):
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{5}
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.get_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-plugin-test` 可以在网页端查看当前所有事件响应器的执行流程,有助理解事件响应流程!
```bash
nb plugin install nonebot_plugin_test
```
:::
### 阻断 block
当有任意事件响应器发出了阻止事件传递信号时,该事件将不再会传递给下一优先级,直接结束处理。
NoneBot 内置的事件响应器中,所有 `message` 类的事件响应器默认会阻断事件传递,其他则不会。
在部分情况中,可以使用 `matcher.stop_propagation()` 方法动态阻止事件传播,该方法需要 `handler` 在参数中获取 `matcher` 实例后调用方法。
## 自定义 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
from nonebot.typing import T_State
async def async_checker(bot: Bot, event: Event, state: T_State) -> bool:
return True
def sync_checker(bot: Bot, event: Event, state: T_State) -> bool:
return True
def check(arg1, arg2):
async def _checker(bot: Bot, event: Event, state: T_State) -> bool:
return bool(arg1 + arg2)
return Rule(_checker)
```
`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 BaseSettings
class Config(BaseSettings):
# 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

@@ -1,19 +1,15 @@
# 创建一个完整的项目
上一章中我们已经运行了一个最小的 NoneBot 实例,在这一章,我们将从零开始一个完整的项目。
上一章中我们已经运行了一个简单的 NoneBot 实例,在这一章,我们将从零开始一个完整的项目。
## 目录结构
首先,我们可以使用 `nb-cli` 或者自行创建项目目录:
可以使用 `nb-cli` 或者自行创建完整的项目目录:
```bash
pip install nonebot2[cli]
# pip install nb-cli
nb create
```
这将创建默认的目录结构
<!-- prettier-ignore-start -->
:::vue
AweSome-Bot
@@ -38,18 +34,24 @@ AweSome-Bot
## 启动 Bot
如果你使用 `nb-cli`
:::warning 提示
如果您使用如 `VSCode` / `PyCharm` 等 IDE 启动 nonebot请检查 IDE 当前工作空间目录是否与当前侧边栏打开目录一致。
* 在二者不一致的环境下可能导致 nonebot 读取配置文件和插件等不符合预期
:::
通过 `nb-cli`
```bash
nb run [--file=bot.py] [--app=app]
```
者使用
```bash
python bot.py
```
:::tip 提示
如果在 bot 入口文件内定义了 asgi server `nb-cli` 将会为你启动**冷重载模式**
如果在 bot 入口文件内定义了 asgi server `nb-cli` 将会为你启动**冷重载模式**(当文件发生变动时自动重启 NoneBot 实例)
:::

View File

@@ -0,0 +1,181 @@
# 钉钉机器人使用指南
基于企业机器人的 outgoing回调机制用户@机器人之后,钉钉会将消息内容 POST 到开发者的消息接收地址。开发者解析出消息内容、发送者身份,根据企业的业务逻辑,组装响应的消息内容返回,钉钉会将响应内容发送到群里。
::: warning 只有企业内部机器人支持接收消息
普通的机器人尚不支持应答机制,该机制指的是群里成员在聊天@机器人的时候,钉钉回调指定的服务地址,即 Outgoing 机器人。
:::
首先你需要有钉钉机器人的相关概念,请参阅相关文档:
- [群机器人概述](https://developers.dingtalk.com/document/app/overview-of-group-robots)
- [开发企业内部机器人](https://developers.dingtalk.com/document/app/develop-enterprise-internal-robots)
钉钉官方机器人教程Java
- [开发一个钉钉机器人](https://developers.dingtalk.com/document/tutorial/create-a-robot)
## 安装 NoneBot 钉钉 适配器
```bash
pip install nonebot-adapter-ding
```
## 关于 DingAdapter 的说明
你需要显式的注册 ding 这个适配器:
```python{2,6}
import nonebot
from nonebot.adapters.ding import Bot as DingBot
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter("ding", DingBot)
nonebot.load_builtin_plugins()
if __name__ == "__main__":
nonebot.run()
```
注册适配器的目的是将 `/ding` 这个路径挂载到程序上,并且和 DingBot 适配器关联起来。之后钉钉把收到的消息回调到 `http://xx.xxx.xxx.xxx:{port}/ding` 时Nonebot 才知道要用什么适配器去处理该消息。
## 第一个命令
因为 Nonebot 可以根据你的命令处理函数的类型注解来选择使用什么 Adapter 进行处理,所以你如果需要使用钉钉相关的功能,你的 handler 中 `bot` 类型的注解需要是 DingBot 及其父类。
对于 Event 来说也是如此Event 也可以根据标注来判断,比如一个 handler 的 event 标注位 `PrivateMessageEvent`,那这个 handler 只会处理私聊消息。
举个栗子:
```python
test = on_command("test", to_me())
@test.handle()
async def test_handler1(bot: DingBot, event: PrivateMessageEvent):
await test.finish("PrivateMessageEvent")
@test.handle()
async def test_handler2(bot: DingBot, event: GroupMessageEvent):
await test.finish("GroupMessageEvent")
```
这样 Nonebot 就会根据不同的类型注解使用不同的 handler 来处理消息。
可以查看 Nonebot 官方的这个例子:<https://github.com/nonebot/nonebot2/tree/dev/tests>,更详细的了解一个 Bot 的结构。
## 多种消息格式
发送 markdown 消息:
```python
@markdown.handle()
async def markdown_handler(bot: DingBot):
message = MessageSegment.markdown(
"Hello, This is NoneBot",
"#### NoneBot \n> Nonebot 是一款高性能的 Python 机器人框架\n> ![screenshot](https://v2.nonebot.dev/logo.png)\n> [GitHub 仓库地址](https://github.com/nonebot/nonebot2) \n"
)
await markdown.finish(message)
```
可以按自己的需要发送原生的格式消息(需要使用 `MessageSegment` 包裹,可以很方便的实现 @ 等操作):
```python
@raw.handle()
async def raw_handler(bot: DingBot, event: MessageEvent):
message = MessageSegment.raw({
"msgtype": "text",
"text": {
"content": f"@{event.senderId},你好"
},
})
message += MessageSegment.atDingtalkIds(event.senderId)
await raw.send(message)
```
其他消息格式请查看 [钉钉适配器的 MessageSegment](https://github.com/nonebot/nonebot2/blob/dev/nonebot/adapters/ding/message.py#L8),里面封装了很多有关消息的方法,比如 `code`、`image`、`feedCard` 等。
## 发送到特定群聊
钉钉也支持通过 Webhook 的方式直接将消息推送到某个群聊([参考链接](https://developers.dingtalk.com/document/app/custom-robot-access/title-zob-eyu-qse)),你可以在机器人的设置中看到当前群的 Webhook 地址。
![机器人所在群的 Webhook 地址](./images/ding/webhook.png)
获取到Webhook地址后用户可以向这个地址发起HTTP POST 请求,即可实现给该钉钉群发送消息。
对于这种通过 Webhook 推送的消息钉钉需要开发者进行安全方面的设置目前有3种安全设置方式请根据需要选择一种如下
1. **自定义关键词:** 最多可以设置10个关键词消息中至少包含其中1个关键词才可以发送成功。
例如添加了一个自定义关键词:监控报警,则这个机器人所发送的消息,必须包含监控报警这个词,才能发送成功。
2. **加签:** 发送请求时带上验签的值,可以在机器人设置里看到密钥。
![加签密钥](./images/ding/jiaqian.png)
3. **IP地址** 设定后只有来自IP地址范围内的请求才会被正常处理。支持两种设置方式IP地址和IP地址段暂不支持IPv6地址白名单。
如果你选择 1/3 两种安全设置,你需要自己确认当前网络和发送的消息能被钉钉接受,然后使用 `bot.send` 的时候将 webhook 地址传入 webhook 参数即可。
如我设置了 `打卡` 为关键词:
```python
message = MessageSegment.text("打卡成功XXXXXX")
await hello.send(
message,
webhook=
"https://oapi.dingtalk.com/robot/send?access_token=XXXXXXXXXXXXXX",
)
```
对于第二种加签方式,你可以在 `bot.send` 的时候把 `secret` 参数传进去Nonebot 内部会自动帮你计算发送该消息的签名并发送,如:
这里的 `secret` 参数就是加签选项给出的那个密钥。
```python
message = MessageSegment.raw({
"msgtype": "text",
"text": {
"content": 'hello from webhook,一定要注意安全方式的鉴权哦,否则可能发送失败的'
},
})
message += MessageSegment.atDingtalkIds(event.senderId)
await hello.send(
message,
webhook="https://oapi.dingtalk.com/robot/send?access_token=XXXXXXXXXXXXXX",
secret="SECXXXXXXXXXXXXXXXXXXXXXXXXX",
)
```
然后就可以发送成功了。
![测试 Webhook 发送](images/ding/test_webhook.png)
## 创建机器人并连接
在钉钉官方文档 [「开发企业内部机器人 -> 步骤一:创建机器人应用」](https://developers.dingtalk.com/document/app/develop-enterprise-internal-robots/title-ufs-4gh-poh) 中有详细介绍,这里就省去创建的步骤,介绍一下如何连接上程序。
### 本地开发机器人
在本地开发机器人的时候可能没有公网 IP钉钉官方给我们提供一个 [内网穿透工具](https://developers.dingtalk.com/document/resourcedownload/http-intranet-penetration?pnamespace=app),方便开发测试。
::: tip
究其根源这是一个魔改版的 ngrok钉钉提供了一个服务器。
本工具不保证稳定性,仅适用于开发测试阶段,禁止当作公网域名使用。如线上应用使用本工具造成稳定性问题,后果由自己承担。如使用本工具传播违法不良信息,钉钉将追究法律责任。
:::
官方文档里已经讲了如何使用。我们再以 Windows终端使用 Powershell 为例,来演示一下。
1. 将仓库 clone 到本地,打开 `windows_64` 文件夹。
2. 执行 `.\ding.exe -config="./ding.cfg" -subdomain=rcnb 8080` 就可以将 8080 端口暴露到公网中。
你访问 <http://rcnb.vaiwan.com/xxxxx> 都会映射到 <http://127.0.0.1:8080/xxxxx>。
假设我们的机器人监听的端口是 `2333`,并且已经注册了钉钉适配器。那我们就执行 `.\ding.exe -config="./ding.cfg" -subdomain=rcnb 2333`,然后在机器人的后台设置 POST 的地址:`http://rcnb.vaiwan.com/ding`。
这样钉钉接收到消息之后就会 POST 消息到 `http://rcnb.vaiwan.com/ding` 上,然后这个服务会把消息再转发到我们本地的开发服务器上。
### 生产模式
生产模式你的机器需要有一个公网 IP然后到机器人的后台设置 POST 的地址就好了。
## 示例
关于钉钉机器人能做啥,你可以查看 `https://github.com/nonebot/nonebot2/blob/dev/tests/test_plugins/test_ding.py`,里面有一些例子。

View File

@@ -0,0 +1,8 @@
# 结语
至此,相信你已经能够写出一个基础的插件了。这里给出几个小提示:
- 请千万注意事件处理器的优先级设定
- 在匹配规则中请勿使用耗时极长的函数
如果「指南」还不能满足你,前往 [进阶](../advanced/README.md) 查看更多的功能信息。

View File

@@ -0,0 +1,87 @@
# 开始使用
一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备工作。
## 最小实例
如果你已经按照推荐方式安装了 `nb-cli`,使用它创建一个空项目:
```bash
nb create
```
根据引导进行项目配置,完成后会在当前目录下创建一个项目目录,项目目录内包含 `bot.py`
如果未安装 `nb-cli`,使用你最熟悉的编辑器或 IDE创建一个名为 `bot.py` 的文件,内容如下(这里以 CQHTTP 适配器为例):
```python{4,6,7,10}
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 内置的 CQHTTP 协议适配组件
`register_adapter` 的第一个参数我们传入了一个字符串,该字符串将会在后文 [配置 CQHTTP 协议端](#配置-cqhttp-协议端-以-qq-为例) 时使用。
3. 加载 NoneBot 内置的插件
4. 在地址 `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)
```
## 配置协议端上报
在 `bot.py` 文件中使用 `register_adapter` 注册协议适配之后即可配置协议端来完成与 NoneBot 的通信,详细配置方法参考:
- [配置 CQHTTP](./cqhttp-guide.md)
- [配置钉钉](./ding-guide.md)
- [配置 mirai-api-http](./mirai-guide.md)
NoneBot 接受的上报地址与 `Driver` 有关,默认使用的 `FastAPI Driver` 所接受的上报地址有:
- `/{adapter name}/`: HTTP POST 上报
- `/{adapter name}/http/`: HTTP POST 上报
- `/{adapter name}/ws`: WebSocket 上报
- `/{adapter name}/ws/`: WebSocket 上报
:::warning 注意
如果到这一步你没有在 NoneBot 看到连接成功日志,比较常见的出错点包括:
- NoneBot 监听 `0.0.0.0`,然后在协议端上报配置中填了 `ws://0.0.0.0:8080/***/ws`
- 在 Docker 容器内运行协议端,并通过 `127.0.0.1` 访问宿主机上的 NoneBot
- 想从公网访问,但没有修改云服务商的安全组策略或系统防火墙
- NoneBot 所监听的端口存在冲突,已被其它程序占用
- 弄混了 NoneBot 的 `host`、`port` 参数与协议端上报配置中的 `host`、`port` 参数
- `ws://` 错填为 `http://`
- 协议端或 NoneBot 启动时遭到外星武器干扰
请尝试重启协议端 NoneBot、更换端口、修改防火墙、重启系统、仔细阅读前面的文档及提示、更新协议端 和 NoneBot 到最新版本等方式来解决。
:::

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

@@ -0,0 +1,109 @@
# 安装
## 安装 NoneBot
:::warning 注意
请确保你的 Python 版本 >= 3.7。
:::
:::warning 注意
请在安装 NoneBot v2 之前卸载 NoneBot v1
```bash
pip uninstall nonebot
```
:::
### (推荐安装方式)通过脚手架安装
1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境
2. 使用 `pip` 或 其他包管理工具 安装 `nb-cli``nonebot2` 会作为其依赖被一起安装
```bash
pip install nb-cli
```
3. 点个 star 吧
nonebot2: [![nonebot2](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)
4. 如果有疑问,可以加群交流(点击链接直达)
[![QQ Chat](https://img.shields.io/badge/QQ%E7%BE%A4-768887710-orange?style=social)](https://jq.qq.com/?_wv=1027&k=5OFifDh)
[![Telegram Chat](https://img.shields.io/badge/telegram-cqhttp-blue?style=social)](https://t.me/cqhttp)
### (纯净安装)不使用脚手架
```bash
pip install nonebot2
# 也可以通过 poetry 安装
poetry add nonebot2
```
如果你需要使用最新的(可能**尚未发布**的)特性,可以直接从 GitHub 仓库安装:
:::warning 注意
直接从 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` 在创建项目时根据你的选择自动安装,也可以自行使用 `pip` 安装
```bash
pip install nonebot-adapter-<adapter-name>
```
```bash
# 列出所有的适配器
nb adapter list
```
## 安装插件
插件可以通过 `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-LocalStore](https://github.com/nonebot/plugin-localstore) 本地数据文件存储插件
- [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,125 @@
# 加载插件
在 [创建一个完整的项目](creating-a-project) 一章节中,我们已经创建了插件目录 `awesome_bot/plugins`,现在我们在机器人入口文件中加载它。当然,你也可以单独加载一个插件。
## 加载内置插件
`bot.py` 文件中添加以下行:
```python{8}
import nonebot
from nonebot.adapters.cqhttp import Bot
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter("cqhttp", Bot) # 注册 CQHTTP 的 Adapter
nonebot.load_builtin_plugins() # 加载 nonebot 内置插件
app = nonebot.get_asgi()
if __name__ == "__main__":
nonebot.run()
```
::: warning
目前, 内建插件仅支持 CQHTTP 的 Adapter
如果您使用的是其他 Adapter, 请移步该 Adapter 相应的文档
:::
这将会加载 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,234 @@
# Mirai-API-HTTP 协议使用指南
::: warning
Mirai-API-HTTP 的适配现在仍然处于早期阶段, 可能没有进行过充分的测试
在生产环境中请谨慎使用
:::
::: tip
为了你的使用之旅更加顺畅, 我们建议您在配置之前具有以下的前置知识
- 对服务端/客户端(C/S)模型的基本了解
- 对 Web 服务配置基础的认知
-`YAML`语法的一点点了解
:::
::: danger
Mirai-API-HTTP 的适配器以 [AGPLv3 许可](https://opensource.org/licenses/AGPL-3.0) 单独开源
这意味着在使用该适配器时需要 **以该许可开源您的完整程序代码**
:::
**为了便捷起见, 以下内容均以缩写 `MAH` 代替 `mirai-api-http`**
## 安装 NoneBot Mirai 适配器
```bash
pip install nonebot-adapter-mirai
```
## 配置 MAH 客户端
正如你可能刚刚在[CQHTTP 协议使用指南](./cqhttp-guide.md)中所读到的:
> 单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。
这次, 我们将采用在实现上有别于 OneBotCQHTTP协议的另外一种无头 QQ API 协议, 即 MAH
为了配置 MAH 端, 我们现在需要移步到[MAH 的项目地址](https://github.com/project-mirai/mirai-api-http), 来看看它是如何配置的
根据[项目提供的 README](https://github.com/project-mirai/mirai-api-http/blob/056beedba31d6ad06426997a1d3fde861a7f8ba3/README.md),配置 MAH 大概需要以下几步
1. 下载并安装 Java 运行环境, 你可以有以下几种选择:
- [由 Oracle 提供的 Java 运行环境](https://java.com/zh-CN/download/manual.jsp) **在没有特殊需求的情况下推荐**
- [由 Zulu 编译的 OpenJRE 环境](https://www.azul.com/downloads/zulu-community/?version=java-8-lts&architecture=x86-64-bit&package=jre)
2. 下载[Mirai Console Loader](https://github.com/iTXTech/mirai-console-loader)
- 请按照文档 README 中的步骤下载并安装
3. 安装 MAH:
- 在 Mirai Console Loader 目录下执行该指令
- ```shell
./mcl --update-package net.mamoe:mirai-api-http --channel stable --type plugin
```
注意: 该指令的前缀`./mcl`可能根据操作系统以及使用 java 环境的不同而变化
4. 修改配置文件
::: tip
在此之前, 你可能需要了解我们为 MAH 设计的两种通信方式
- 正向 Websocket
- NoneBot 作为纯粹的客户端,通过 websocket 监听事件下发
- 优势
1. 网络配置简单, 特别是在使用 Docker 等网络隔离的容器时
2. 在初步测试中连接性较好
- 劣势
1. 与 NoneBot 本身的架构不同, 可能稳定性较差
2. 需要在注册 adapter 时显式指定 qq, 对于需要开源的程序来讲不利
- POST 消息上报
- NoneBot 在接受消息上报时作为服务端, 发送消息时作为客户端
- 优势
1. 与 NoneBot 本身架构相符, 性能和稳定性较强
2. 无需在任何地方指定 QQ, 即插即用
- 劣势
1. 由于同时作为客户端和服务端, 配置较为复杂
2. 在测试中网络连接性较差 (未确认原因)
:::
- 这是当使用正向 Websocket 时的配置举例
- MAH 的`setting.yml`文件
- ```yaml
# 省略了部分无需修改的部分
host: "0.0.0.0" # 监听地址
port: 8080 # 监听端口
authKey: 1234567890 # 访问密钥, 最少八位
enableWebsocket: true # 必须为true
```
- `.env`文件
- ```shell
MIRAI_AUTH_KEY=1234567890
MIRAI_HOST=127.0.0.1 # 当MAH运行在本机时
MIRAI_PORT=8080 # MAH的监听端口
```
- `bot.py`文件
- ```python
import nonebot
from nonebot.adapters.mirai import WebsocketBot
nonebot.init()
nonebot.get_driver().register_adapter('mirai-ws', WebsocketBot, qq=12345678) # qq参数需要填在mah中登录的qq
nonebot.load_builtin_plugins() # 加载 nonebot 内置插件
nonebot.run()
```
- 这是当使用 POST 消息上报时的配置文件
- MAH 的`setting.yml`文件
- ```yaml
# 省略了部分无需修改的部分
host: '0.0.0.0' # 监听地址
port: 8080 # 监听端口
authKey: 1234567890 # 访问密钥, 最少八位
## 消息上报
report:
enable: true # 必须为true
groupMessage:
report: true # 群消息上报
friendMessage:
report: true # 好友消息上报
tempMessage:
report: true # 临时会话上报
eventMessage:
report: true # 事件上报
destinations:
- 'http://127.0.0.1:2333/mirai/http' #上报地址, 请按照实际情况修改
# 上报时的额外Header
extraHeaders: {}
```
- `.env`文件
- ```shell
HOST=127.0.0.1 # 当MAH运行在本机时
PORT=2333
MIRAI_AUTH_KEY=1234567890
MIRAI_HOST=127.0.0.1 # 当MAH运行在本机时
MIRAI_PORT=8080 # MAH的监听端口
```
- `bot.py`文件
- ```python
import nonebot
from nonebot.adapters.mirai import Bot
nonebot.init()
nonebot.get_driver().register_adapter('mirai', Bot)
nonebot.load_builtin_plugins() # 加载 nonebot 内置插件
nonebot.run()
```
## 历史性的第一次对话
现在, 先启动 NoneBot, 再启动 MAH
如果你的配置文件一切正常, 你将在控制台看到类似于下列的日志
```log
02-01 18:25:12 [INFO] nonebot | NoneBot is initializing...
02-01 18:25:12 [INFO] nonebot | Current Env: prod
02-01 18:25:12 [DEBUG] nonebot | Loaded Config: {'driver': 'nonebot.drivers.fastapi', 'host': IPv4Address('127.0.0.1'), 'port': 8080, 'debug': True, 'api_root': {}, 'api_timeout': 30.0, 'access_token': None, 'secret': None, 'superusers': set(), 'nickname': set(), 'command_start': {'/'}, 'command_sep': {'.'}, 'session_expire_timeout': datetime.timedelta(seconds=120), 'mirai_port': 8080, 'environment': 'prod', 'mirai_auth_key': 12345678, 'mirai_host': '127.0.0.1'}
02-01 18:25:12 [DEBUG] nonebot | Succeeded to load adapter "mirai"
02-01 18:25:12 [INFO] nonebot | Succeeded to import "nonebot.plugins.echo"
02-01 18:25:12 [INFO] nonebot | Running NoneBot...
02-01 18:25:12 [DEBUG] nonebot | Loaded adapters: mirai
02-01 18:25:12 [INFO] uvicorn | Started server process [183155]
02-01 18:25:12 [INFO] uvicorn | Waiting for application startup.
02-01 18:25:12 [INFO] uvicorn | Application startup complete.
02-01 18:25:12 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:2333 (Press CTRL+C to quit)
02-01 18:25:14 [INFO] uvicorn | 127.0.0.1:37794 - "POST /mirai/http HTTP/1.1" 204
02-01 18:25:14 [DEBUG] nonebot | MIRAI | received message {'type': 'BotOnlineEvent', 'qq': 1234567}
02-01 18:25:14 [INFO] nonebot | MIRAI 1234567 | [BotOnlineEvent]: {'self_id': 1234567, 'type': 'BotOnlineEvent', 'qq': 1234567}
02-01 18:25:14 [DEBUG] nonebot | Checking for matchers in priority 1...
```
恭喜你, 你的配置已经成功!
现在, 我们可以写一个简单的插件来测试一下
```python
from nonebot.plugin import on_keyword, on_command
from nonebot.rule import to_me
from nonebot.adapters.mirai import Bot, MessageEvent
message_test = on_keyword({'reply'}, rule=to_me())
@message_test.handle()
async def _message(bot: Bot, event: MessageEvent):
text = event.get_plaintext()
await bot.send(event, text, at_sender=True)
command_test = on_command('miecho')
@command_test.handle()
async def _echo(bot: Bot, event: MessageEvent):
text = event.get_plaintext()
await bot.send(event, text, at_sender=True)
```
它具有两种行为
- 在指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称的情况下 (即 [Rule: to_me](../api/rule.md#to-me)), 如果消息内包含 `reply` 字段, 则该消息会被机器人重复一次
- 在执行指令`miecho xxx`时, 机器人会发送回参数`xxx`
至此, 你已经初步掌握了如何使用 Mirai Adapter

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": "/store"
},
{
"text": "更新日志",
"link": "/changelog"
}
],
"sidebarDepth": 2,
"sidebar": {
"/guide/": [
{
"title": "指南",
"path": "",
"title": "开始",
"collapsable": false,
"sidebar": "auto",
"children": [
@@ -32,8 +44,52 @@
"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"
]
},
{
"title": "协议适配",
"collapsable": false,
"sidebar": "auto",
"children": [
"cqhttp-guide",
"ding-guide",
"mirai-guide"
]
}
],
"/advanced/": [
{
"title": "进阶",
"collapsable": false,
"sidebar": "auto",
"children": [
"",
"scheduler",
"permission",
"runtime-hook",
"export-and-require",
"overloaded-handlers"
]
},
{
"title": "发布",
"collapsable": false,
"sidebar": "auto",
"children": [
"publish-plugin"
]
}
],
@@ -51,10 +107,22 @@
"title": "nonebot.config 模块",
"path": "config"
},
{
"title": "nonebot.plugin 模块",
"path": "plugin"
},
{
"title": "nonebot.message 模块",
"path": "message"
},
{
"title": "nonebot.matcher 模块",
"path": "matcher"
},
{
"title": "nonebot.handler 模块",
"path": "handler"
},
{
"title": "nonebot.rule 模块",
"path": "rule"
@@ -63,10 +131,6 @@
"title": "nonebot.permission 模块",
"path": "permission"
},
{
"title": "nonebot.sched 模块",
"path": "sched"
},
{
"title": "nonebot.log 模块",
"path": "log"
@@ -91,6 +155,10 @@
"title": "nonebot.drivers.fastapi 模块",
"path": "drivers/fastapi"
},
{
"title": "nonebot.drivers.quart 模块",
"path": "drivers/quart"
},
{
"title": "nonebot.adapters 模块",
"path": "adapters/"
@@ -98,6 +166,14 @@
{
"title": "nonebot.adapters.cqhttp 模块",
"path": "adapters/cqhttp"
},
{
"title": "nonebot.adapters.ding 模块",
"path": "adapters/ding"
},
{
"title": "nonebot.adapters.mirai 模块",
"path": "adapters/mirai"
}
]
}

View File

@@ -1,9 +1,9 @@
---
home: true
heroImage: /logo.png
tagline: An asynchronous QQ bot framework.
tagline: 跨平台 Python 异步机器人框架
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 - 2021 NoneBot Team
---

View File

@@ -0,0 +1,177 @@
# 深入
## 它如何工作?
如同[概览](../guide/README.md)所言:
> NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。
`Nonebot2` 是一个可以对机器人上报的事件进行处理并完成具体功能的机器人框架,在这里,我们将简要讲述它的工作内容。
**便捷起见,以下内容对 `Nonebot2` 会被称为 `nonebot`,与 `Nonebot2` 交互的机器人实现会被称为 `协议端`**
在实际应用中,`nonebot` 会充当一个高性能,轻量级的 Python 微服务框架。协议端可以通过 `http`, `websocket` 等方式与之通信,这个通信往往是双向的:一方面,协议端可以上报数据给 `nonebot``nonebot` 会处理数据并返回响应给协议端;另一方面,`nonebot` 可以主动推送数据给协议端。而 `nonebot` 便是围绕双向通信进行工作的。
在开始工作之前,`nonebot` 需要进行准备工作:
1. **运行 `nonebot.init` 初始化函数**,它会读取配置文件,并初始化 `nonebot` 和后端驱动 `driver` 对象。
2. **注册协议适配器 `adapter`**
3. **加载插件**
准备工作完成后,`nonebot` 会利用 `uvicorn` 启动,并运行 `on_startup` 钩子函数。
随后,倘若一个协议端与 `nonebot` 进行了连接,`nonebot` 的后端驱动 `driver` 就会将 `adapter` 实例化为 `bot``nonebot` 便会利用 `bot` 开始工作,它的工作内容分为两个方面:
1. **事件处理**`bot` 会将协议端上报的数据转化为 `事件`(`Event`),之后 `nonebot` 会根据一套既定流程来处理 `事件`
2. **调用 `API`**, 在**事件处理**的过程中,`nonebot` 可以通过 `bot` 调用协议端指定的 `API` 来获取更多数据,或者反馈响应给协议端; `nonebot` 也可以通过调用 `API` 向协议端主动请求数据或者主动推送数据。
在**指南**模块, 我们已经叙述了[如何配置 nonebot](../guide/basic-configuration.md), [如何注册协议适配器](../guide/getting-started.md)[如何加载插件](../guide/loading-a-plugin.md), 在这里便不再赘述。
下面,我们将对**事件处理** **调用 API**进行说明。
## 事件处理
我们可以先看事件处理的流程图:
![handle-event](../guide/images/Handle-Event.png)
在流程图里,我们可以看到,`nonebot` 会有三个阶段来处理事件:
1. **driver 处理上报数据**
2. **adapter 处理原始数据**
3. **nonebot 处理 Event**
我们将顺序说明这三个阶段。其中,会将第三个阶段拆分成**概念解释****处理 Event****特殊异常处理**三个部分来说明。
### driver 处理上报数据
1. 协议端会通过 `websocket` 或者 `http` 等方式与 `nonebot` 的后端驱动 `driver` 连接,`driver` 会根据之前注册的 `adapter` 和配置文件的内容来进行鉴权,从而获得这个连接的唯一识别 id `self-id`,随后 `adapter` 就会利用 `self-id` 实例化为 `bot` 对象。
::: tip
需要注意的是,如果协议端通过 `websocket``nonebot` 连接,这个步骤只会在建立连接时进行,并在之后运行 `on_bot_connect` 钩子函数;通过 `http` 方式连接时,会在协议端每次上报数据时都进行这个步骤。
:::
::: warning
连接之前必须要注册 `adapter`
:::
::: warning
`self-id` 是帐号的唯一识别 ID这意味着不能出现相同的 `self-id`
:::
2. `driver` 会将接收到的数据转交给 `bot` 对象进一步处理。
### adapter 处理原始数据
1. `bot` 会利用事先定义好的 `Event Model` 对上报的数据进行分析处理,将数据转化为 `nonebot` 可以处理的 `Event` 对象。
::: tip
`adapter` 在转换数据格式的同时可以进行一系列的特殊操作,例如 `CQHTTP` 会对 `reply` 信息进行提取。
:::
2. `Event` 会传入 `nonebot` 做进一步处理。
### nonebot 处理 Event
在讲述这个阶段之前,我们需要先对几个概念进行解释。
#### 概念解释
1. **hook**,或者说**钩子函数**,它们可以在 `nonebot` 处理 `Event` 的不同时刻进行拦截,修改或者扩展,在 `nonebot` 中,钩子函数分为 `事件预处理hook``运行预处理hook``运行后处理hook``事件后处理hook`
::: tip
关于`hook`的更多信息,可以查阅[这里](./runtime-hook.md)
:::
2. **Matcher**与**matcher**,在**指南**中,我们讲述了[如何注册事件响应器](../guide/creating-a-matcher),这里的事件响应器或者说 `Matcher` 并不是一个具体的实例 `instance`,而是一个具有特定属性的类 `class`。只有当 `Matcher` **响应事件**时,才会实例化为具体的 `instance`,也就是 `matcher``matcher` 可以认为是 `nonebot` 处理 `Event` 的基本单位,运行 `matcher``nonebot`工作的主要内容。
3. **handler**,或者说**事件处理函数**, 它们可以认为是 `nonebot` 处理 `Event` 的最小单位。在不考虑 `hook` 的情况下,**运行 matcher 就是顺序运行 matcher.handlers**,这句话换种表达方式就是,`handler` 只有添加到 `matcher.handlers` 时,才可以参与到 `nonebot` 的工作中来。
::: tip
如何让 `handler` 添加到 `matcher.handlers`
一方面,我们可以参照[这里](../guide/creating-a-handler)利用装饰器来添加;另一方面,我们在用 `on()` 或者 `on_*()` 注册事件响应器时,可以添加 `handlers=[handler1, handler2, ...]` 这样的关键词参数来添加。
:::
#### 处理 Event
1. **执行事件预处理 hook** `nonebot` 接收到 `Event` 后,会传入到 `事件预处理hook` 中进行处理。
::: warning
需要注意的是,执行多个 `事件预处理hook` 时并无顺序可言,它们是**并行运行**的。这个原则同样适用于其他的 `hook`
:::
2. **按优先级升序选出同一优先级的 Matcher**`nonebot` 提供了一个全局字典 `matchers`,这个字典的 `key` 是优先级 `priority``value` 是一个 `list`,里面存放着同一优先级的 `Matcher`。在注册 `Matcher` 时,它和优先级 `priority` 会添加到里面。
在执行 `事件预处理hook` 后,`nonebot` 会对 `matchers``key` 升序排序并选择出当前最小优先级的 `Matcher`
3. **根据 Matcher 定义的 Rule, Permission 判断是否运行**,在选出 `Matcher` 后,`nonebot` 会将 `bot``Event` 传入到 `Matcher.check_rule``Matcher.check_perm` 两个函数中,两个函数分别对 Matcher 定义的 Rule, Permission 进行 check当 check 通过后,这个 `Matcher` 就会响应事件。但是当同一个优先级的所有 `Matcher` 均没有响应时,`nonebot` 会返回到上一个步骤,选择出下一优先级的 `Matcher`
4. **实例化 matcher 并执行运行预处理 hook**,当 `Matcher` 响应事件后,它便会实例化为 `matcher`,并执行 `运行预处理hook`
5. **顺序运行 matcher 的所有 handlers**`运行预处理hook` 执行完毕后,便会运行 `matcher`,也就是**顺序运行**它的 `handlers`
::: tip
`matcher` 运行 `handlers` 的顺序是: 先运行该 `matcher` 的类 `Matcher` 注册时添加的 `handlers`(如果有的话),再按照装饰器装饰顺序运行装饰的 `handlers`
:::
6. **执行运行后处理 hook**`matcher``handlers` 运行完毕后,会执行 `运行后处理hook`
7. **判断是否停止事件传播**`nonebot` 会根据当前优先级所有 `matcher``block` 参数或者 `StopPropagation` 异常判断是否停止传播 `Event`,如果事件没有停止传播,`nonebot` 便会返回到第 2 步, 选择出下一优先级的 `Matcher`
8. **执行事件后处理 hook**,在 `Event` 停止传播或执行完所有响应的 `Matcher` 后,`nonebot` 会执行 `事件后处理hook`
`事件后处理hook` 执行完毕后,当前`Event`的处理周期就顺利结束了。
#### 特殊异常处理
在这个阶段,`nonebot` 规定了几个特殊的异常,当 `nonebot` 捕获到它们时,会用特定的行为来处理它们。
1. **IgnoredException**
这个异常可以在 `事件预处理hook``运行预处理hook` 抛出。
`事件预处理hook` 抛出它时,`nonebot` 会忽略当前的 `Event`,不进行处理。
`运行预处理hook` 抛出它时,`nonebot` 会忽略当前的 `matcher`,结束当前 `matcher` 的运行。
::: warning
`hook` 需要抛出这个异常时,要写明原因。
:::
2. **PausedException**
这个异常可以在 `handler` 中由 `Matcher.pause` 抛出。
`nonebot` 捕获到它时,会停止运行当前 `handler` 并结束当前 `matcher` 的运行,并将后续的 `handler` 交给一个临时 `Matcher` 来响应当前交互用户的下一个消息事件,当临时 `Matcher` 响应时,临时 `Matcher` 会运行后续的 handlers。
3. **RejectedException**
这个异常可以在 `handler` 中由 `Matcher.reject` 抛出。
`nonebot` 捕获到它时,会停止运行当前 `handler` 并结束当前 `matcher` 的运行,并将当前 handler 和后续 `handler` 交给一个临时 `Matcher` 来响应当前交互用户的下一个消息事件,当临时 `Matcher` 响应时,临时 `Matcher` 会运行当前 `handler` 和后续的 `handler`
4. **FinishedException**
这个异常可以在 `handler` 中由 `Matcher.finish` 抛出。
`nonebot` 捕获到它时,会停止运行当前 `handler` 并结束当前 `matcher` 的运行。
5. **StopPropagation**
这个异常一般会在执行 `运行后处理hook` 后抛出。
`nonebot` 捕获到它时, 会停止传播当前 `Event`,不再寻找下一优先级的 `Matcher`,直接执行 `事件后处理hook`
## 调用 API
`nonebot` 可以通过 `bot` 来调用 `API` `API` 可以向协议端发送数据,也可以向协议端请求更多的数据。
::: tip
不同 `adapter` 规定了不同的 API对应的 API 列表请参照协议规范。
:::
一般来说,我们可以用 `bot.*` 来调用 `API`(\*是 `API``action` 或者 `endpoint`)。
对于发送消息而言,一方面可以调用既有的 API另一方面 `nonebot` 实现了两个便捷方法,`bot.send(event, message, **kwargs)` 方法和可以在 `handler` 中使用的 `Matcher.send(message, **kwargs)` 方法,来向事件主体发送消息。

View File

@@ -0,0 +1,117 @@
# 跨插件访问
由于 `nonebot2` 独特的插件加载机制,在使用 python 原有的 import 机制来进行插件之间的访问时,很可能会有奇怪的或者意料以外的情况发生。为了避免这种情况的发生,您可以有两种方法来实现跨插件访问:
1. 将插件间的要使用的公共代码剥离出来,作为公共文件或者文件夹,提供给插件加以调用。
2. 使用 `nonebot2` 提供的 `export``require` 机制,来实现插件间的互相调用。
第一种方法比较容易理解和实现,这里不再赘述,但需要注意的是,请不要将公共文件或者公共文件夹作为**插件**被 `nonebot2` 加载。
下面将介绍第二种方法—— `export``require` 机制:
## 使用 export 和 require
现在,假定有两个插件 `pluginA``pluginB`,需要在 `pluginB` 中调用 `pluginA` 中的一个变量 `varA` 和一个函数 `funcA`
在上面的条件中涉及到了两种操作:一种是在 `pluginA``导出对象` 操作;而另一种是在 `pluginB``导入对象` 操作。在 `nonebot2` 中,`导出对象` 的操作用 `export` 机制来实现,`导入对象` 的操作用 `require` 机制来实现。下面,我们将逐一进行介绍。
:::warning 警告
使用这个方法进行跨插件访问时,**需要先加载`导出对象`的插件,再加载`导入对象`的插件。**
:::
### 使用 export
`pluginA` 中,我们调用 `export` 机制 `导出对象`
`export` 机制调用前,我们需要保证导出的对象已经被定义,比如:
```python
varA = "varA"
def funcA():
return "funcA"
```
在确保定义之后,我们可以从 `nonebot.plugin` 导入 `export()` 方法, `export()` 方法会返回一个特殊的字典 `export`
```python
from nonebot.plugin import export
export=export()
```
这个字典可以用来装载导出的对象,它的 key 是对象导出后的命名value 是对象本身,我们可以直接创建新的 `key` - `value` 对导出对象:
```python
export.vA = varA
export.fA = funcA
```
除此之外,也支持 `嵌套` 导出对象:
```python
export.sub.vA = varA
export.sub.fA = funcA
```
特别地,对于 `函数对象` 而言,`export` 支持用 `装饰器` 的方法来导出,因此,我们可以这样定义 `funcA`
```python
@export.sub
def funcA():
return "funcA"
```
或者:
```python
@export
def funcA():
return "funcA"
```
通过 `装饰器` 的方法导出函数时,命名固定为函数的命名,也就是说,上面的两个例子等同于:
```python
export.sub.funcA = funcA
export.funcA = funcA
```
这样,我们就成功导出 `varA``funcA` 对象了。
下面我们将介绍如何在 `pluginB` 中导入这些对象。
### 使用 require
`pluginB` 中,我们调用 `require` 机制 `导入对象`
:::warning 警告
在导入来自其他插件的对象时, 请确保导出该对象的插件在引用该对象的插件之前加载。如果该插件并未被加载,则会尝试加载,加载失败则会返回 `None`
:::
我们可以从 `nonebot.plugin` 中导入 `require()` 方法:
```python
from nonebot.plugin import require
```
`require()` 方法的参数是插件名, 它会返回在指定插件中,用 `export()` 方法创建的字典。
```python
require_A = require('pluginA')
```
在之前,这个字典已经存入了 `'vA'` - `varA`, `'fA'` - `funcA``'funcA'` - `funcA` 这样的 `key` - `value` 对。因此在这里我们直接用 `属性` 的方法来获取导入对象:
```python
varA = require_A.vA
funcA = require_A.fA or require_A.funcA
```
这样,我们就在 `pluginB` 中成功导入了 `varA``funcA` 对象了。

View File

@@ -0,0 +1,64 @@
# 事件处理函数重载
当我们在编写 `nonebot2` 应用时,常常会遇到这样一个问题:该怎么让同一类型的不同事件执行不同的响应逻辑?又或者如何让不同的 `adapter` 针对同一类型的事件作出不同响应?
针对这个问题, `nonebot2` 提供一个便捷而高效的解决方案:事件处理函数重载机制。简单地说,`handler` (事件处理函数) 会根据其参数的 `type hints` ([PEP484 类型标注](https://www.python.org/dev/peps/pep-0484/)) 来对相对应的 `adapter``Event` 进行响应,并且会忽略不符合其参数类型标注的情况。
必须要注意的是,该机制利用了 `inspect` 标准库获取到了事件处理函数的 `singnature` (签名) ,进一步获取到参数名称和类型标注。故而,我们在编写 `handler` 时,参数的名称和类型标注必须要符合 `T_Handler` 规定,详情可以参看 **指南** 中的[事件处理](../guide/creating-a-handler)。
::: tip 提示
如果想了解更多关于 `inspect` 标准库的信息,可以查看[官方文档](https://docs.python.org/zh-cn/3.9/library/inspect.html)。
:::
下面,我们会以 `CQHTTP` 中的 `群聊消息事件``私聊消息事件` 为例,对该机制的应用进行简单的介绍。
## 一个例子
首先,我们需要导入需要的方法、类型。
```python
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, PrivateMessageEvent
```
之后,我们可以注册一个 `Matcher` 来响应 `消息事件`
```python
matcher = on_command("testoverload")
```
最后, 我们编写不同的 `handler` 并编写不同的类型标注来实现事件处理函数重载:
```python
@matcher.handle()
async def _(bot: Bot, event: GroupMessageEvent):
await matcher.send("群聊消息事件响应成功!")
@matcher.handle()
async def _(bot: Bot, event: PrivateMessageEvent):
await matcher.send("私聊消息事件响应成功!")
```
此时,我们可以在群聊或私聊中对我们的机器人发送 `testoverload` ,它会在不同的场景做出不同的应答。
这样一个简单的事件处理函数重载就完成了。
## 进阶
事件处理函数重载机制同样支持被 `matcher.got` 等装饰器装饰的函数。 例如:
```python
@matcher.got("key1", prompt="群事件提问")
async def _(bot: Bot, event: GroupMessageEvent):
await matcher.send("群聊消息事件响应成功!")
@matcher.got("key2", prompt="私聊事件提问")
async def _(bot: Bot, event: PrivateMessageEvent):
await matcher.send("私聊消息事件响应成功!")
```
只有触发事件符合的函数才会触发装饰器。

View File

@@ -0,0 +1,90 @@
# 权限控制
**权限控制**是机器人在实际应用中需要解决的重点问题之一,`Nonebot` 提供了十分完善且灵活的权限控制机制—— `Permission` 机制。接下来我们将对这个机制进行简单的说明。
## 应用
如同 `Rule` 一样, `Permission` 可以在[注册事件响应器](../guide/creating-a-matcher)时添加 `permission` 参数来加以应用,这样 `Nonebot` 会在事件响应时检测事件主体的权限。下面我们以 `SUPERUSER` 为例,对该机制的应用做一下介绍。
```python
from nonebot.permission import SUPERUSER
from nonebot.adapters import Bot
from nonebot import on_command
matcher = on_command("测试超管", permission=SUPERUSER)
@matcher.handle()
async def _(bot: Bot):
await matcher.send("超管命令测试成功")
@matcher.got("key1", "超管提问")
async def _(bot: Bot, event: Event):
await matcher.send("超管命令got成功")
```
在这段代码中,我们事件响应器指定了 `SUPERUSER` 这样一个权限,那么机器人只会响应超级管理员的 `测试超管` 命令,并且会响应该超级管理员的连续对话。
::: tip 提示
在这里需要强调的是,`Permission``Rule` 的表现并不相同, `Rule` 只会在初次响应时生效,在余下的对话中并没有限制事件;但是 `Permission` 会持续生效,在连续对话中会一直对事件主体加以限制。
:::
## 进阶
`Permission` 除了可以在注册事件响应器时加以应用,还可以在编写事件处理函数 `handler` 时主动调用,我们可以利用这个特性在一个 `handler` 里对不同权限的事件主体进行区别响应,下面我们以 `CQHTTP` 中的 `GROUP_ADMIN` (普通管理员非群主)和 `GROUP_OWNER` 为例,说明下怎么进行主动调用。
```python
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot
from nonebot.adapters.cqhttp import GroupMessageEvent
from nonebot.adapters.cqhttp import GROUP_ADMIN, GROUP_OWNER
matcher = on_command("测试权限")
@matcher.handle()
async def _(bot: Bot, event: GroupMessageEvent):
if await GROUP_ADMIN(bot, event):
await matcher.send("管理员测试成功")
elif await GROUP_OWNER(bot, event):
await matcher.send("群主测试成功")
else:
await matcher.send("群员测试成功")
```
在这段代码里,我们并没有对命令的权限指定,这个命令会响应所有在群聊中的 `测试权限` 命令,但是在 `handler` 里,我们对两个 `Permission` 进行主动调用,从而可以对不同的角色进行不同的响应。
## 自定义
如同 `Rule` 一样, `Permission` 也是由非负数个 `PermissionChecker` 组成的,但只需其中一个返回 `True` 时就会匹配成功。下面则是 `PermissionChecker``Permission` 示例:
```python
from nonebot.adapters import Bot, Event
from nonebot.permission import Permission
async def async_checker(bot: Bot, event: Event) -> bool:
return True
def sync_checker(bot: Bot, event: Event) -> bool:
return True
def check(arg1, arg2):
async def _checker(bot: Bot, event: Event) -> bool:
return bool(arg1 + arg2)
return Permission(_checker)
```
`Permission``PermissionChecker` 之间可以使用 `或 |` 互相组合:
```python
from nonebot.permission import Permission
Permission(async_checker1) | sync_checker | async_checker2
```
同样地,如果想用 `Permission(*checkers)` 包裹构造 `Permission` ,函数必须是异步的;但是在利用 `或 |` 符号连接构造时, `Nonebot` 会自动包裹同步函数为异步函数。

View File

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

View File

@@ -0,0 +1,163 @@
# 钩子函数
[`钩子编程`](https://zh.wikipedia.org/wiki/%E9%92%A9%E5%AD%90%E7%BC%96%E7%A8%8B)
> 钩子编程hooking也称作“挂钩”是计算机程序设计术语指通过拦截软件模块间的函数调用、消息传递、事件传递来修改或扩展操作系统、应用程序或其他软件组件的行为的各种技术。处理被拦截的函数调用、事件、消息的代码被称为钩子hook
`nonebot2` 中有一系列预定义的钩子函数,分为两类:`全局钩子函数``事件钩子函数` ,这些钩子函数可以用装饰器的形式来使用。
## 全局钩子函数
全局钩子函数是指 `nonebot2` 针对其本身运行过程的钩子函数。
这些钩子函数是由其后端驱动 `driver`来运行的,故需要先获得全局 `driver` 对象:
```python
from nonebot import get_driver
driver=get_driver()
```
共分为六种函数:
### 启动准备
这个钩子函数会在 `nonebot2` 启动时运行。
```python
@driver.on_startup
async def do_something():
pass
```
### 终止处理
这个钩子函数会在 `nonebot2` 终止时运行。
```python
@driver.on_shutdown
async def do_something():
pass
```
### bot 连接处理
这个钩子函数会在 `bot` 通过 `websocket` 连接到 `nonebot2` 时运行。
```python
@driver.on_bot_connect
async def do_something(bot: Bot):
pass
```
### bot 断开处理
这个钩子函数会在 `bot` 断开与 `nonebot2``websocket` 连接时运行。
```python
@driver.on_bot_disconnect
async def do_something(bot: Bot):
pass
```
### bot api 调用钩子
这个钩子函数会在 `Bot` 调用 API 时运行。
```python
from nonebot.adapters import Bot
@Bot.on_calling_api
async def handle_api_call(bot: Bot, api: str, data: Dict[str, Any]):
pass
```
### bot api 调用后钩子
这个钩子函数会在 `Bot` 调用 API 后运行。
```python
from nonebot.adapters import Bot
@Bot.on_called_api
async def handle_api_result(bot: Bot, exception: Optional[Exception], api: str, data: Dict[str, Any], result: Any):
pass
```
## 事件处理钩子
这些钩子函数指的是影响 `nonebot2` 进行 `事件处理` 的函数。
:::tip 提示
关于 `事件处理` 的流程,可以在[这里](./README)查阅。
:::
:::warning 注意
1.在事件处理钩子函数中,与 `matcher` 运行状态相关的函数将不可用,如 `matcher.finish()`
2.如果需要在事件处理钩子函数中打断整个对话的执行,请参考以下范例:
```python
from nonebot.exception import IgnoredException
@event_preprocessor
async def do_something(bot: Bot, event: Event, state: T_State):
raise IgnoredException("reason")
```
:::
共分为四种函数:
### 事件预处理
这个钩子函数会在 `Event` 上报到 `nonebot2` 时运行
```python
from nonebot.message import event_preprocessor
@event_preprocessor
async def do_something(bot: Bot, event: Event, state: T_State):
pass
```
### 事件后处理
这个钩子函数会在 `nonebot2` 处理 `Event` 后运行
```python
from nonebot.message import event_postprocessor
@event_postprocessor
async def do_something(bot: Bot, event: Event, state: T_State):
pass
```
### 运行预处理
这个钩子函数会在 `nonebot2`运行 `matcher` 前运行。
```python
from nonebot.message import run_preprocessor
@run_preprocessor
async def do_something(matcher: Matcher, bot: Bot, event: Event, state: T_State):
pass
```
### 运行后处理
这个钩子函数会在 `nonebot2`运行 `matcher` 后运行。
```python
from nonebot.message import run_postprocessor
@run_postprocessor
async def do_something(matcher: Matcher, exception: Optional[Exception], bot: Bot, event: Event, state: T_State):
pass
```

View File

@@ -0,0 +1,135 @@
# 定时任务
[`APScheduler`](https://apscheduler.readthedocs.io/en/latest/index.html) —— Advanced Python Scheduler
> Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline.
## 从 NoneBot v1 迁移
`APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [商店](https://v2.nonebot.dev/store.html) 中找到它。
相比于 `nonebot` v1`nonebot` v2 只需要安装插件并修改 `scheduler` 的导入方式即可完成迁移。
## 安装插件
### 通过 nb-cli
如正在使用 `nb-cli` 构建项目,你可以从插件市场复制安装命令或手动输入以下命令以添加 `nonebot_plugin_apscheduler`
```bash
nb plugin install nonebot_plugin_apscheduler
```
:::tip 提示
`nb-cli` 默认通过 `pypi` 安装,你可以添加命令参数 `-i [mirror]``--index [mirror]` 以使用镜像源安装。
:::
### 通过 poetry
执行以下命令以添加 `nonebot_plugin_apscheduler`
```bash
poetry add nonebot-plugin-apscheduler
```
:::tip 提示
由于稍后我们将使用 `nonebot.require()` 方法进行导入,所以无需额外的 `nonebot.load_plugin()`
:::
## 快速上手
1. 在需要设置定时任务的插件中,通过 `nonebot.require``nonebot_plugin_apscheduler` 导入 `scheduler` 对象
2. 在该对象的基础上,根据 `APScheduler` 的使用方法进一步配置定时任务
将上述步骤归纳为最小实现的代码如下:
```python
from nonebot import require
scheduler = require("nonebot_plugin_apscheduler").scheduler
@scheduler.scheduled_job("cron", hour="*/2", id="xxx", args=[1], kwargs={"arg2": 2})
async def run_every_2_hour(arg1, arg2):
pass
scheduler.add_job(run_every_day_from_program_start, "interval", days=1, id="xxx")
```
## 分步进行
### 导入 scheduler 对象
为了使插件能够实现定时任务,需要先将 `scheduler` 对象导入插件。
`nonebot2` 提供了 `nonebot.require` 方法来实现导入其他插件的内容,此处我们使用这个方法来导入 `scheduler` 对象。
`nonebot` 使用的 `scheduler` 对象为 `AsyncScheduler`
> 使用该方法传入的插件本身也需要有对应实现,关于该方法的更多介绍可以参阅 [这里](./export-and-require.md)
```python
from nonebot import require
scheduler = require("nonebot_plugin_apscheduler").scheduler
```
### 编写定时任务
由于本部分为标准的通过 `APScheduler` 配置定时任务,有关指南请参阅 [APScheduler 官方文档](https://apscheduler.readthedocs.io/en/latest/userguide.html#adding-jobs)。
### 配置插件选项
根据项目的 `.env` 文件设置,向 `.env.*``bot.py` 文件添加 `nonebot_plugin_apscheduler` 的可选配置项
:::warning 注意
`.env.*` 文件的编写应遵循 nonebot2 对 `.env.*` 文件的编写要求
:::
#### `apscheduler_autostart`
类型:`bool`
默认值:`True`
是否自动启动 `APScheduler`
对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true`
##### 在 `.env` 中添加
```bash
APSCHEDULER_AUTOSTART=true
```
##### 在 `bot.py` 中添加
```python
nonebot.init(apscheduler_autostart=True)
```
#### `apscheduler_config`
类型:`dict`
默认值:`{"apscheduler.timezone": "Asia/Shanghai"}`
`APScheduler` 相关配置。修改/增加其中配置项需要确保 `prefix: apscheduler`
对于 `APScheduler` 的相关配置,请参阅 [scheduler-config](https://apscheduler.readthedocs.io/en/latest/userguide.html#scheduler-config) 和 [BaseScheduler](https://apscheduler.readthedocs.io/en/latest/modules/schedulers/base.html#apscheduler.schedulers.base.BaseScheduler)
> 官方文档在绝大多数时候能提供最准确和最具时效性的指南
##### 在 `.env` 中添加
```bash
APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"}
```
##### 在 `bot.py` 中添加
```python
nonebot.init(apscheduler_config={
"apscheduler.timezone": "Asia/Shanghai"
})
```

View File

@@ -0,0 +1,67 @@
# NoneBot Api Reference
* **模块索引**
* [nonebot](nonebot.html)
* [nonebot.config](config.html)
* [nonebot.plugin](plugin.html)
* [nonebot.message](message.html)
* [nonebot.matcher](matcher.html)
* [nonebot.handler](handler.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.drivers.quart](drivers/quart.html)
* [nonebot.drivers.aiohttp](drivers/aiohttp.html)
* [nonebot.adapters](adapters/)
* [nonebot.adapters.cqhttp](adapters/cqhttp.html)
* [nonebot.adapters.ding](adapters/ding.html)
* [nonebot.adapters.mirai](adapters/mirai.html)
* [nonebot.adapters.feishu](adapters/feishu.html)

View File

@@ -0,0 +1,501 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters 模块
## 协议适配基类
各协议请继承以下基类,并使用 `driver.register_adapter` 注册适配器
## _class_ `Bot`
基类:`abc.ABC`
Bot 基类。用于处理上报消息,并提供 API 调用接口。
### `driver`
Driver 对象
### `config`
Config 配置对象
### `_calling_api_hook`
* **类型**
`Set[T_CallingAPIHook]`
* **说明**
call_api 时执行的函数
### `_called_api_hook`
* **类型**
`Set[T_CalledAPIHook]`
* **说明**
call_api 后执行的函数
### `__init__(self_id, request)`
* **参数**
* `self_id: str`: 机器人 ID
* `request: HTTPConnection`: request 连接对象
### `self_id`
机器人 ID
### `request`
连接信息
### _abstract property_ `type`
Adapter 类型
### _classmethod_ `register(driver, config, **kwargs)`
* **说明**
`register` 方法会在 `driver.register_adapter` 时被调用,用于初始化相关配置
### _abstract async classmethod_ `check_permission(driver, request)`
* **说明**
检查连接请求是否合法的函数,如果合法则返回当前连接 `唯一标识符`,通常为机器人 ID如果不合法则抛出 `RequestDenied` 异常。
* **参数**
* `driver: Driver`: Driver 对象
* `request: HTTPConnection`: request 请求详情
* **返回**
* `Optional[str]`: 连接唯一标识符,`None` 代表连接不合法
* `Optional[HTTPResponse]`: HTTP 上报响应
### _abstract async_ `handle_message(message)`
* **说明**
处理上报消息的函数,转换为 `Event` 事件后调用 `nonebot.message.handle_event` 进一步处理事件。
* **参数**
* `message: bytes`: 收到的上报消息
### _abstract async_ `_call_api(api, **data)`
* **说明**
`adapter` 实际调用 api 的逻辑实现函数,实现该方法以调用 api。
* **参数**
* `api: str`: API 名称
* `**data`: API 数据
### _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`
### _classmethod_ `on_calling_api(func)`
* **说明**
调用 api 预处理。
* **参数**
* `bot: Bot`: 当前 bot 对象
* `api: str`: 调用的 api 名称
* `data: Dict[str, Any]`: api 调用的参数字典
### _classmethod_ `on_called_api(func)`
* **说明**
调用 api 后处理。
* **参数**
* `bot: Bot`: 当前 bot 对象
* `exception: Optional[Exception]`: 调用 api 时发生的错误
* `api: str`: 调用的 api 名称
* `data: Dict[str, Any]`: api 调用的参数字典
* `result: Any`: api 调用的返回
## _class_ `MessageSegment`
基类:`Mapping`, `abc.ABC`, `Generic`[`nonebot.adapters._base.TM`]
消息段基类
### `type`
* 类型: `str`
* 说明: 消息段类型
### `data`
* 类型: `Dict[str, Union[str, list]]`
* 说明: 消息段数据
## _class_ `Message`
基类:`List`[`nonebot.adapters._base.TMS`], `abc.ABC`
消息数组
### `__init__(message=None, *args, **kwargs)`
* **参数**
* `message: Union[str, list, dict, MessageSegment, Message, Any]`: 消息内容
### `append(obj)`
* **说明**
添加一个消息段到消息数组末尾
* **参数**
* `obj: Union[str, MessageSegment]`: 要添加的消息段
### `extend(obj)`
* **说明**
拼接一个消息数组或多个消息段到消息数组末尾
* **参数**
* `obj: Union[Message, Iterable[MessageSegment]]`: 要添加的消息数组
### `extract_plain_text()`
* **说明**
提取消息内纯文本消息
## _class_ `Event`
基类:`abc.ABC`, `pydantic.main.BaseModel`
Event 基类。提供获取关键信息的方法,其余信息可直接获取。
### _abstract_ `get_type()`
* **说明**
获取事件类型的方法,类型通常为 NoneBot 内置的四种类型。
* **返回**
* `Literal["message", "notice", "request", "meta_event"]`
* 其他自定义 `str`
### _abstract_ `get_event_name()`
* **说明**
获取事件名称的方法。
* **返回**
* `str`
### _abstract_ `get_event_description()`
* **说明**
获取事件描述的方法,通常为事件具体内容。
* **返回**
* `str`
### `get_log_string()`
* **说明**
获取事件日志信息的方法,通常你不需要修改这个方法,只有当希望 NoneBot 隐藏该事件日志时,可以抛出 `NoLogException` 异常。
* **返回**
* `str`
* **异常**
* `NoLogException`
### _abstract_ `get_user_id()`
* **说明**
获取事件主体 id 的方法,通常是用户 id 。
* **返回**
* `str`
### _abstract_ `get_session_id()`
* **说明**
获取会话 id 的方法,用于判断当前事件属于哪一个会话,通常是用户 id、群组 id 组合。
* **返回**
* `str`
### _abstract_ `get_message()`
* **说明**
获取事件消息内容的方法。
* **返回**
* `Message`
### `get_plaintext()`
* **说明**
获取消息纯文本的方法,通常不需要修改,默认通过 `get_message().extract_plain_text` 获取。
* **返回**
* `str`
### _abstract_ `is_tome()`
* **说明**
获取事件是否与机器人有关的方法。
* **返回**
* `bool`

View File

@@ -0,0 +1,686 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.cqhttp 模块
## CQHTTP (OneBot) v11 协议适配
协议详情请看: [CQHTTP](https://github.com/howmanybots/onebot/blob/master/README.md) | [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md)
# NoneBot.adapters.cqhttp.config 模块
## _class_ `Config`
CQHTTP 配置类
* **配置项**
* `access_token` / `cqhttp_access_token`: CQHTTP 协议授权令牌
* `secret` / `cqhttp_secret`: CQHTTP HTTP 上报数据签名口令
* `ws_urls` / `cqhttp_ws_urls`: CQHTTP 正向 Websocket 连接 Bot ID、目标 URL 字典
# NoneBot.adapters.cqhttp.utils 模块
## `escape(s, *, escape_comma=True)`
* **说明**
对字符串进行 CQ 码转义。
* **参数**
* `s: str`: 需要转义的字符串
* `escape_comma: bool`: 是否转义逗号(`,`)。
## `unescape(s)`
* **说明**
对字符串进行 CQ 码去转义。
* **参数**
* `s: str`: 需要转义的字符串
# NoneBot.adapters.cqhttp.exception 模块
## _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]`: 错误码
# NoneBot.adapters.cqhttp.bot 模块
## _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._base.Bot`](README.md#nonebot.adapters._base.Bot)
CQHTTP 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
### _property_ `type`
* 返回: `"cqhttp"`
### _async classmethod_ `check_permission(driver, request)`
* **说明**
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 调用失败
# NoneBot.adapters.cqhttp.message 模块
## _class_ `MessageSegment`
基类:[`nonebot.adapters._base.MessageSegment`](README.md#nonebot.adapters._base.MessageSegment)[`Message`]
CQHTTP 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
### _classmethod_ `get_message_class()`
### `is_text()`
### _static_ `anonymous(ignore_failure=None)`
### _static_ `at(user_id)`
### _static_ `contact(type_, id)`
### _static_ `contact_group(group_id)`
### _static_ `contact_user(user_id)`
### _static_ `dice()`
### _static_ `face(id_)`
### _static_ `forward(id_)`
### _static_ `image(file, type_=None, cache=True, proxy=True, timeout=None)`
### _static_ `json(data)`
### _static_ `location(latitude, longitude, title=None, content=None)`
### _static_ `music(type_, id_)`
### _static_ `music_custom(url, audio, title, content=None, img_url=None)`
### _static_ `node(id_)`
### _static_ `node_custom(user_id, nickname, content)`
### _static_ `poke(type_, id_)`
### _static_ `record(file, magic=None, cache=None, proxy=None, timeout=None)`
### _static_ `reply(id_)`
### _static_ `rps()`
### _static_ `shake()`
### _static_ `share(url='', title='', content=None, image=None)`
### _static_ `text(text)`
### _static_ `video(file, cache=None, proxy=None, timeout=None)`
### _static_ `xml(data)`
### `type`
* 类型: `str`
* 说明: 消息段类型
### `data`
* 类型: `Dict[str, Union[str, list]]`
* 说明: 消息段数据
## _class_ `Message`
基类:[`nonebot.adapters._base.Message`](README.md#nonebot.adapters._base.Message)[`nonebot.adapters.cqhttp.message.MessageSegment`]
CQHTTP 协议 Message 适配。
### _classmethod_ `get_segment_class()`
### `extract_plain_text()`
# NoneBot.adapters.cqhttp.permission 模块
## `PRIVATE`
* **说明**: 匹配任意私聊消息类型事件
## `PRIVATE_FRIEND`
* **说明**: 匹配任意好友私聊消息类型事件
## `PRIVATE_GROUP`
* **说明**: 匹配任意群临时私聊消息类型事件
## `PRIVATE_OTHER`
* **说明**: 匹配任意其他私聊消息类型事件
## `GROUP`
* **说明**: 匹配任意群聊消息类型事件
## `GROUP_MEMBER`
* **说明**: 匹配任意群员群聊消息类型事件
:::warning 警告
该权限通过 event.sender 进行判断且不包含管理员以及群主!
:::
## `GROUP_ADMIN`
* **说明**: 匹配任意群管理员群聊消息类型事件
## `GROUP_OWNER`
* **说明**: 匹配任意群主群聊消息类型事件
# NoneBot.adapters.cqhttp.event 模块
## _class_ `Event`
基类:[`nonebot.adapters._base.Event`](README.md#nonebot.adapters._base.Event)
CQHTTP 协议事件,字段与 CQHTTP 一致。各事件字段参考 [CQHTTP 文档](https://github.com/howmanybots/onebot/blob/master/README.md)
## _class_ `MessageEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
消息事件
### `to_me`
* **说明**
消息是否与机器人有关
* **类型**
`bool`
### `reply`
* **说明**
消息中提取的回复消息,内容为 `get_msg` API 返回结果
* **类型**
`Optional[Reply]`
## _class_ `PrivateMessageEvent`
基类:`nonebot.adapters.cqhttp.event.MessageEvent`
私聊消息
## _class_ `GroupMessageEvent`
基类:`nonebot.adapters.cqhttp.event.MessageEvent`
群消息
## _class_ `NoticeEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
通知事件
## _class_ `GroupUploadNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群文件上传事件
## _class_ `GroupAdminNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群管理员变动
## _class_ `GroupDecreaseNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群成员减少事件
## _class_ `GroupIncreaseNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群成员增加事件
## _class_ `GroupBanNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群禁言事件
## _class_ `FriendAddNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
好友添加事件
## _class_ `GroupRecallNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
群消息撤回事件
## _class_ `FriendRecallNoticeEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
好友消息撤回事件
## _class_ `NotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NoticeEvent`
提醒事件
## _class_ `PokeNotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NotifyEvent`
戳一戳提醒事件
## _class_ `LuckyKingNotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NotifyEvent`
群红包运气王提醒事件
## _class_ `HonorNotifyEvent`
基类:`nonebot.adapters.cqhttp.event.NotifyEvent`
群荣誉变更提醒事件
## _class_ `RequestEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
请求事件
## _class_ `FriendRequestEvent`
基类:`nonebot.adapters.cqhttp.event.RequestEvent`
加好友请求事件
## _class_ `GroupRequestEvent`
基类:`nonebot.adapters.cqhttp.event.RequestEvent`
加群请求/邀请事件
## _class_ `MetaEvent`
基类:`nonebot.adapters.cqhttp.event.Event`
元事件
## _class_ `LifecycleMetaEvent`
基类:`nonebot.adapters.cqhttp.event.MetaEvent`
生命周期元事件
## _class_ `HeartbeatMetaEvent`
基类:`nonebot.adapters.cqhttp.event.MetaEvent`
心跳元事件
## `get_event_model(event_name)`
* **说明**
根据事件名获取对应 `Event Model``FallBack Event Model` 列表
* **返回**
* `List[Type[Event]]`

View File

@@ -0,0 +1,334 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.ding 模块
## 钉钉群机器人 协议适配
协议详情请看: [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)
# NoneBot.adapters.ding.config 模块
## _class_ `Config`
钉钉配置类
* **配置项**
* `access_token` / `ding_access_token`: 钉钉令牌
* `secret` / `ding_secret`: 钉钉 HTTP 上报数据签名口令
# NoneBot.adapters.ding.exception 模块
## _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_ `NetworkError`
基类:[`nonebot.exception.NetworkError`](../exception.md#nonebot.exception.NetworkError), `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
网络错误。
* **参数**
* `retcode: Optional[int]`: 错误码
## _exception_ `SessionExpired`
基类:`nonebot.adapters.ding.exception.ApiNotAvailable`, `nonebot.adapters.ding.exception.DingAdapterException`
* **说明**
发消息的 session 已经过期。
# NoneBot.adapters.ding.bot 模块
## _class_ `Bot`
基类:[`nonebot.adapters._base.Bot`](README.md#nonebot.adapters._base.Bot)
钉钉 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
### _property_ `type`
* 返回: `"ding"`
### _async classmethod_ `check_permission(driver, request)`
* **说明**
钉钉协议鉴权。参考 [鉴权](https://ding-doc.dingtalk.com/doc#/serverapi2/elzz1p)
### _async_ `call_api(api, event=None, **data)`
* **说明**
调用 钉钉 协议 API
* **参数**
* `api: str`: API 名称
* `event: Optional[MessageEvent]`: Event 对象
* `**data: Any`: API 参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
### _async_ `send(event, message, at_sender=False, webhook=None, secret=None, **kwargs)`
* **说明**
根据 `event` 向触发事件的主体发送消息。
* **参数**
* `event: Event`: Event 对象
* `message: Union[str, Message, MessageSegment]`: 要发送的消息
* `at_sender: bool`: 是否 @ 事件主体
* `webhook: Optional[str]`: 该条消息将调用的 webhook 地址。不传则将使用 sessionWebhook若其也不存在该条消息不发送使用自定义 webhook 时注意你设置的安全方式如加关键词IP地址加签等等。
* `secret: Optional[str]`: 如果你使用自定义的 webhook 地址,推荐使用加签方式对消息进行验证,将 机器人安全设置页面加签一栏下面显示的SEC开头的字符串 传入这个参数即可。
* `**kwargs`: 覆盖默认参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `ValueError`: 缺少 `user_id`, `group_id`
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
# NoneBot.adapters.ding.message 模块
## _class_ `MessageSegment`
基类:[`nonebot.adapters._base.MessageSegment`](README.md#nonebot.adapters._base.MessageSegment)[`Message`]
钉钉 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
### _static_ `atAll()`
@全体
### _static_ `atMobiles(*mobileNumber)`
@指定手机号人员
### _static_ `atDingtalkIds(*dingtalkIds)`
@指定 id@ 默认会在消息段末尾。
所以你可以在消息中使用 @{senderId} 占位,发送出去之后 @ 就会出现在占位的位置:
``python
message = MessageSegment.text(f"@{event.senderId},你好")
message += MessageSegment.atDingtalkIds(event.senderId)
``
### _static_ `text(text)`
发送 `text` 类型消息
### _static_ `image(picURL)`
发送 `image` 类型消息
### _static_ `extension(dict_)`
标记 text 文本的 extension 属性,需要与 text 消息段相加。
### _static_ `code(code_language, code)`
发送 code 消息段
### _static_ `markdown(title, text)`
发送 `markdown` 类型消息
### _static_ `actionCardSingleBtn(title, text, singleTitle, singleURL)`
发送 `actionCardSingleBtn` 类型消息
### _static_ `actionCardMultiBtns(title, text, btns, hideAvatar=False, btnOrientation='1')`
发送 `actionCardMultiBtn` 类型消息
* **参数**
* `btnOrientation`: 0按钮竖直排列 1按钮横向排列
* `btns`: `[{ "title": title, "actionURL": actionURL }, ...]`
### _static_ `feedCard(links)`
发送 `feedCard` 类型消息
* **参数**
* `links`: `[{ "title": xxx, "messageURL": xxx, "picURL": xxx }, ...]`
## _class_ `Message`
基类:[`nonebot.adapters._base.Message`](README.md#nonebot.adapters._base.Message)[`nonebot.adapters.ding.message.MessageSegment`]
钉钉 协议 Message 适配。
# NoneBot.adapters.ding.event 模块
## _class_ `Event`
基类:[`nonebot.adapters._base.Event`](README.md#nonebot.adapters._base.Event)
钉钉协议事件。各事件字段参考 [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)
## _class_ `ConversationType`
基类:`str`, `enum.Enum`
An enumeration.
## _class_ `MessageEvent`
基类:`nonebot.adapters.ding.event.Event`
消息事件
## _class_ `PrivateMessageEvent`
基类:`nonebot.adapters.ding.event.MessageEvent`
私聊消息事件
## _class_ `GroupMessageEvent`
基类:`nonebot.adapters.ding.event.MessageEvent`
群消息事件

View File

@@ -0,0 +1,246 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.adapters.feishu 模块
# NoneBot.adapters.feishu.config 模块
## _class_ `Config`
钉钉配置类
* **配置项**
* `app_id` / `feishu_app_id`: 飞书开放平台后台“凭证与基础信息”处给出的 App ID
* `app_secret` / `feishu_app_secret`: 飞书开放平台后台“凭证与基础信息”处给出的 App Secret
* `encrypt_key` / `feishu_encrypt_key`: 飞书开放平台后台“事件订阅”处设置的 Encrypt Key
* `verification_token` / `feishu_verification_token`: 飞书开放平台后台“事件订阅”处设置的 Verification Token
* `tenant_access_token` / `feishu_tenant_access_token`: 请求飞书 API 后返回的租户密钥
# NoneBot.adapters.feishu.exception 模块
## _exception_ `ActionFailed`
基类:[`nonebot.exception.ActionFailed`](../exception.md#nonebot.exception.ActionFailed), `nonebot.adapters.feishu.exception.FeishuAdapterException`
* **说明**
API 请求返回错误信息。
* **参数**
* `retcode: Optional[int]`: 错误码
## _exception_ `NetworkError`
基类:[`nonebot.exception.NetworkError`](../exception.md#nonebot.exception.NetworkError), `nonebot.adapters.feishu.exception.FeishuAdapterException`
* **说明**
网络错误。
* **参数**
* `retcode: Optional[int]`: 错误码
# NoneBot.adapters.feishu.bot 模块
## `_check_at_me(bot, event)`
* **说明**
检查消息开头或结尾是否存在 @机器人,去除并赋值 `event.reply`, `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._base.Bot`](README.md#nonebot.adapters._base.Bot)
飞书 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
### _async_ `handle_message(message)`
* **说明**
处理事件并转换为 [Event](#class-event)
### _async_ `call_api(api, **data)`
* **说明**
调用 飞书 协议 API
* **参数**
* `api: str`: API 名称
* `**data: Any`: API 参数
* **返回**
* `Any`: API 调用返回数据
* **异常**
* `NetworkError`: 网络错误
* `ActionFailed`: API 调用失败
# NoneBot.adapters.feishu.message 模块
## _class_ `MessageSegment`
基类:[`nonebot.adapters._base.MessageSegment`](README.md#nonebot.adapters._base.MessageSegment)[`Message`]
飞书 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。
## _class_ `Message`
基类:[`nonebot.adapters._base.Message`](README.md#nonebot.adapters._base.Message)[`nonebot.adapters.feishu.message.MessageSegment`]
飞书 协议 Message 适配。
## _class_ `MessageSerializer`
基类:`object`
飞书 协议 Message 序列化器。
## _class_ `MessageDeserializer`
基类:`object`
飞书 协议 Message 反序列化器。
# NoneBot.adapters.feishu.event 模块
## _class_ `Event`
基类:[`nonebot.adapters._base.Event`](README.md#nonebot.adapters._base.Event)
飞书协议事件。各事件字段参考 [飞书文档](https://open.feishu.cn/document/ukTMukTMukTM/uYDNxYjL2QTM24iN0EjN/event-list)
## `get_event_model(event_name)`
* **说明**
根据事件名获取对应 `Event Model``FallBack Event Model` 列表
* **返回**
* `List[Type[Event]]`

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,311 @@
---
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`
基类:`nonebot.config.BaseConfig`
运行环境配置。大小写不敏感。
将会从 `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`
配置格式为 `<module>[:<class>]`,默认类名为 `Driver`
### `host`
* **类型**: `IPvAnyAddress`
* **默认值**: `127.0.0.1`
* **说明**
NoneBot 的 HTTP 和 WebSocket 服务端监听的 IP/主机名。
### `port`
* **类型**: `int`
* **默认值**: `8080`
* **说明**
NoneBot 的 HTTP 和 WebSocket 服务端监听的端口。
### `debug`
* **类型**: `bool`
* **默认值**: `False`
* **说明**
是否以调试模式运行 NoneBot。
### `log_level`
* **类型**: `Union[int, str]`
* **默认值**: `None`
* **说明**
配置 NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称,参考 [loguru 日志等级](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。
* **示例**
```default
LOG_LEVEL=25
LOG_LEVEL=INFO
```
### `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[str]`
* **默认值**: `set()`
* **说明**
机器人超级用户。
* **示例**
```default
SUPERUSERS=["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,529 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers 模块
## 后端驱动适配基类
各驱动请继承以下基类
## _class_ `Driver`
基类:`abc.ABC`
Driver 基类。
### `_adapters`
* **类型**
`Dict[str, Type[Bot]]`
* **说明**
已注册的适配器列表
### `_bot_connection_hook`
* **类型**
`Set[T_BotConnectionHook]`
* **说明**
Bot 连接建立时执行的函数
### `_bot_disconnection_hook`
* **类型**
`Set[T_BotDisconnectionHook]`
* **说明**
Bot 连接断开时执行的函数
### `__init__(env, config)`
* **参数**
* `env: Env`: 包含环境信息的 Env 对象
* `config: Config`: 包含配置信息的 Config 对象
### `env`
* **类型**
`str`
* **说明**
环境名称
### `config`
* **类型**
`Config`
* **说明**
配置对象
### `_clients`
* **类型**
`Dict[str, Bot]`
* **说明**
已连接的 Bot
### _property_ `bots`
* **类型**
`Dict[str, Bot]`
* **说明**
获取当前所有已连接的 Bot
### `register_adapter(name, adapter, **kwargs)`
* **说明**
注册一个协议适配器
* **参数**
* `name: str`: 适配器名称,用于在连接时进行识别
* `adapter: Type[Bot]`: 适配器 Class
* `**kwargs`: 其他传递给适配器的参数
### _abstract property_ `type`
驱动类型名称
### _abstract property_ `logger`
驱动专属 logger 日志记录器
### _abstract_ `run(*args, **kwargs)`
* **说明**
启动驱动框架
* **参数**
* `*args`
* `**kwargs`
### _abstract_ `on_startup(func)`
注册一个在驱动启动时运行的函数
### _abstract_ `on_shutdown(func)`
注册一个在驱动停止时运行的函数
### `on_bot_connect(func)`
* **说明**
装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。
* **函数参数**
* `bot: Bot`: 当前连接上的 Bot 对象
### `on_bot_disconnect(func)`
* **说明**
装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。
* **函数参数**
* `bot: Bot`: 当前连接上的 Bot 对象
### `_bot_connect(bot)`
在 WebSocket 连接成功后,调用该函数来注册 bot 对象
### `_bot_disconnect(bot)`
在 WebSocket 连接断开后,调用该函数来注销 bot 对象
## _class_ `ForwardDriver`
基类:`nonebot.drivers.Driver`
Forward Driver 基类。将客户端框架封装,以满足适配器使用。
### _abstract_ `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### _abstract_ `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
## _class_ `ReverseDriver`
基类:`nonebot.drivers.Driver`
Reverse Driver 基类。将后端框架封装,以满足适配器使用。
### _abstract property_ `server_app`
驱动 APP 对象
### _abstract property_ `asgi`
驱动 ASGI 对象
## _class_ `HTTPConnection`
基类:`abc.ABC`
### `http_version`
One of `"1.0"`, `"1.1"` or `"2"`.
### `scheme`
URL scheme portion (likely `"http"` or `"https"`).
### `path`
HTTP request target excluding any query string,
with percent-encoded sequences and UTF-8 byte sequences
decoded into characters.
### `query_string`
URL portion after the `?`, percent-encoded.
### `headers`
A dict of name-value pairs,
where name is the header name, and value is the header value.
Order of header values must be preserved from the original HTTP request;
order of header names is not important.
Header names must be lowercased.
### _abstract property_ `type`
Connection type.
## _class_ `HTTPRequest`
基类:`nonebot.drivers.HTTPConnection`
HTTP 请求封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
### `method`
The HTTP method name, uppercased.
### `body`
Body of the request.
Optional; if missing defaults to `b""`.
### _property_ `type`
Always `http`
## _class_ `HTTPResponse`
基类:`object`
HTTP 响应封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
### `status`
HTTP status code.
### `body`
HTTP body content.
Optional; if missing defaults to `None`.
### `headers`
A dict of name-value pairs,
where name is the header name, and value is the header value.
Order must be preserved in the HTTP response.
Header names must be lowercased.
Optional; if missing defaults to an empty dict.
### _property_ `type`
Always `http`
## _class_ `WebSocket`
基类:`nonebot.drivers.HTTPConnection`, `abc.ABC`
WebSocket 连接封装。参考 [asgi websocket scope](https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope)。
### _property_ `type`
Always `websocket`
### _abstract property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _abstract async_ `accept()`
接受 WebSocket 连接请求
### _abstract async_ `close(code)`
关闭 WebSocket 连接请求
### _abstract async_ `receive()`
接收一条 WebSocket text 信息
### _abstract async_ `receive_bytes()`
接收一条 WebSocket binary 信息
### _abstract async_ `send(data)`
发送一条 WebSocket text 信息
### _abstract async_ `send_bytes(data)`
发送一条 WebSocket binary 信息
## _class_ `HTTPPollingSetup`
基类:`object`
### `adapter`
协议适配器名称
### `self_id`
机器人 ID
### `url`
URL
### `method`
HTTP method
### `body`
HTTP body
### `headers`
HTTP headers
### `http_version`
HTTP version
### `poll_interval`
HTTP 轮询间隔
## _class_ `WebSocketSetup`
基类:`object`
### `adapter`
协议适配器名称
### `self_id`
机器人 ID
### `url`
URL
### `headers`
HTTP headers
### `reconnect_interval`
WebSocket 重连间隔

View File

@@ -0,0 +1,101 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.aiohttp 模块
## AIOHTTP 驱动适配
本驱动仅支持客户端连接
## _class_ `Driver`
基类:[`nonebot.drivers.ForwardDriver`](README.md#nonebot.drivers.ForwardDriver)
AIOHTTP 驱动框架
### _property_ `type`
驱动名称: `aiohttp`
### _property_ `logger`
aiohttp driver 使用的 logger
### `on_startup(func)`
* **说明**
注册一个启动时执行的函数
* **参数**
* `func: Callable[[], Awaitable[None]]`
### `on_shutdown(func)`
* **说明**
注册一个停止时执行的函数
* **参数**
* `func: Callable[[], Awaitable[None]]`
### `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
### `run(*args, **kwargs)`
启动 aiohttp driver
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)

View File

@@ -0,0 +1,174 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.fastapi 模块
## FastAPI 驱动适配
本驱动同时支持服务端以及客户端连接
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)
## _class_ `Config`
基类:`pydantic.env_settings.BaseSettings`
FastAPI 驱动框架设置,详情参考 FastAPI 文档
### `fastapi_openapi_url`
* **类型**
`Optional[str]`
* **说明**
`openapi.json` 地址,默认为 `None` 即关闭
### `fastapi_docs_url`
* **类型**
`Optional[str]`
* **说明**
`swagger` 地址,默认为 `None` 即关闭
### `fastapi_redoc_url`
* **类型**
`Optional[str]`
* **说明**
`redoc` 地址,默认为 `None` 即关闭
### `fastapi_reload_dirs`
* **类型**
`List[str]`
* **说明**
`debug` 模式下重载监控文件夹列表,默认为 uvicorn 默认值
## _class_ `Driver`
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver), [`nonebot.drivers.ForwardDriver`](README.md#nonebot.drivers.ForwardDriver)
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)
### `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 FastAPI
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)

View File

@@ -0,0 +1,89 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.quart 模块
## Quart 驱动适配
后端使用方法请参考: [Quart 文档](https://pgjones.gitlab.io/quart/index.html)
## _class_ `Config`
基类:`pydantic.env_settings.BaseSettings`
Quart 驱动框架设置
### `quart_reload_dirs`
* **类型**
`List[str]`
* **说明**
`debug` 模式下重载监控文件夹列表,默认为 uvicorn 默认值
## _class_ `Driver`
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver)
Quart 驱动框架
* **上报地址**
* `/{adapter name}/http`: HTTP POST 上报
* `/{adapter name}/ws`: WebSocket 上报
### _property_ `type`
驱动名称: `quart`
### _property_ `server_app`
`Quart` 对象
### _property_ `asgi`
`Quart` 对象
### _property_ `logger`
Quart 使用的 logger
### `on_startup(func)`
参考文档: [Startup and Shutdown](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
### `on_shutdown(func)`
参考文档: [Startup and Shutdown](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 Quart
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)

View File

@@ -11,11 +11,22 @@ sidebarDepth: 0
这些异常并非所有需要用户处理,在 NoneBot 内部运行时被捕获,并进行对应操作。
## _exception_ `IgnoredException`
## _exception_ `NoneBotException`
基类:`Exception`
* **说明**
所有 NoneBot 发生的异常基类。
## _exception_ `IgnoredException`
基类:`nonebot.exception.NoneBotException`
* **说明**
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
@@ -29,9 +40,30 @@ sidebarDepth: 0
## _exception_ `ParserExit`
基类:`nonebot.exception.NoneBotException`
* **说明**
`shell command` 处理消息失败时返回的异常
* **参数**
* `status`
* `message`
## _exception_ `PausedException`
基类:`Exception`
基类:`nonebot.exception.NoneBotException`
* **说明**
@@ -49,7 +81,7 @@ sidebarDepth: 0
## _exception_ `RejectedException`
基类:`Exception`
基类:`nonebot.exception.NoneBotException`
* **说明**
@@ -67,7 +99,7 @@ sidebarDepth: 0
## _exception_ `FinishedException`
基类:`Exception`
基类:`nonebot.exception.NoneBotException`
* **说明**
@@ -83,26 +115,9 @@ sidebarDepth: 0
## _exception_ `ExpiredException`
基类:`Exception`
* **说明**
指示 NoneBot 当前 `Matcher` 已失效。
* **用法**
`Matcher` 运行前检查时抛出。
## _exception_ `StopPropagation`
基类:`Exception`
基类:`nonebot.exception.NoneBotException`
* **说明**
@@ -117,11 +132,40 @@ sidebarDepth: 0
## _exception_ `ApiNotAvailable`
## _exception_ `AdapterException`
基类:`nonebot.exception.NoneBotException`
* **说明**
代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception`
* **参数**
* `adapter_name: str`: 标识 adapter
## _exception_ `NoLogException`
基类:`Exception`
* **说明**
指示 NoneBot 对当前 `Event` 进行处理但不显示 Log 信息,可在 `get_log_string` 时抛出
## _exception_ `ApiNotAvailable`
基类:`nonebot.exception.AdapterException`
* **说明**
在 API 连接不可用时抛出。
@@ -130,7 +174,7 @@ sidebarDepth: 0
## _exception_ `NetworkError`
基类:`Exception`
基类:`nonebot.exception.AdapterException`
* **说明**
@@ -141,16 +185,9 @@ sidebarDepth: 0
## _exception_ `ActionFailed`
基类:`Exception`
基类:`nonebot.exception.AdapterException`
* **说明**
API 请求成功返回数据,但 API 操作失败。
* **参数**
* `retcode`: 错误代码

View File

@@ -0,0 +1,111 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.handler 模块
## 事件处理函数
该模块实现事件处理函数的封装,以实现动态参数等功能。
## _class_ `Handler`
基类:`object`
事件处理函数类
### `__init__(func)`
装饰事件处理函数以便根据动态参数运行
### `func`
* **类型**
`T_Handler`
* **说明**
事件处理函数
### `signature`
* **类型**
`inspect.Signature`
* **说明**
事件处理函数签名
### _property_ `bot_type`
* **类型**
`Union[Type["Bot"], inspect.Parameter.empty]`
* **说明**
事件处理函数接受的 Bot 对象类型
### _property_ `event_type`
* **类型**
`Optional[Union[Type[Event], inspect.Parameter.empty]]`
* **说明**
事件处理函数接受的 event 类型 / 不需要 event 参数
### _property_ `state_type`
* **类型**
`Optional[Union[T_State, inspect.Parameter.empty]]`
* **说明**
事件处理函数是否接受 state 参数
### _property_ `matcher_type`
* **类型**
`Optional[Union[Type["Matcher"], inspect.Parameter.empty]]`
* **说明**
事件处理函数是否接受 matcher 参数

View File

@@ -0,0 +1,42 @@
---
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
```

View File

@@ -0,0 +1,586 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.matcher 模块
## 事件响应器
该模块实现事件响应器的创建与运行,并提供一些快捷方法来帮助用户更好的与机器人进行对话 。
## `matchers`
* **类型**
`Dict[int, List[Type[Matcher]]]`
* **说明**
用于存储当前所有的事件响应器
## _class_ `Matcher`
基类:`object`
事件响应器类
### `module`
* **类型**
`Optional[ModuleType]`
* **说明**
事件响应器所在模块
### `plugin_name`
* **类型**
`Optional[str]`
* **说明**
事件响应器所在插件名
### `module_name`
* **类型**
`Optional[str]`
* **说明**
事件响应器所在模块名
### `module_prefix`
* **类型**
`Optional[str]`
* **说明**
事件响应器所在模块前缀
### `type`
* **类型**
`str`
* **说明**
事件响应器类型
### `rule`
* **类型**
`Rule`
* **说明**
事件响应器匹配规则
### `permission`
* **类型**
`Permission`
* **说明**
事件响应器触发权限
### `priority`
* **类型**
`int`
* **说明**
事件响应器优先级
### `block`
* **类型**
`bool`
* **说明**
事件响应器是否阻止事件传播
### `temp`
* **类型**
`bool`
* **说明**
事件响应器是否为临时
### `expire_time`
* **类型**
`Optional[datetime]`
* **说明**
事件响应器过期时间点
### `_default_state`
* **类型**
`T_State`
* **说明**
事件响应器默认状态
### `_default_state_factory`
* **类型**
`Optional[T_State]`
* **说明**
事件响应器默认工厂函数
### `_default_parser`
* **类型**
`Optional[T_ArgsParser]`
* **说明**
事件响应器默认参数解析函数
### `_default_type_updater`
* **类型**
`Optional[T_TypeUpdater]`
* **说明**
事件响应器类型更新函数
### `_default_permission_updater`
* **类型**
`Optional[T_PermissionUpdater]`
* **说明**
事件响应器权限更新函数
### `__init__()`
实例化 Matcher 以便运行
### `handlers`
* **类型**
`List[Handler]`
* **说明**
事件响应器拥有的事件处理函数列表
### _classmethod_ `new(type_='', rule=None, permission=None, handlers=None, temp=False, priority=1, block=False, *, module=None, expire_time=None, default_state=None, default_state_factory=None, default_parser=None, default_type_updater=None, default_permission_updater=None)`
* **说明**
创建一个新的事件响应器,并存储至 [matchers](#matchers)
* **参数**
* `type_: str`: 事件响应器类型,与 `event.get_type()` 一致时触发,空字符串表示任意
* `rule: Optional[Rule]`: 匹配规则
* `permission: Optional[Permission]`: 权限
* `handlers: Optional[List[T_Handler]]`: 事件处理函数列表
* `temp: bool`: 是否为临时事件响应器,即触发一次后删除
* `priority: int`: 响应优先级
* `block: bool`: 是否阻止事件向更低优先级的响应器传播
* `module: Optional[str]`: 事件响应器所在模块名称
* `default_state: Optional[T_State]`: 默认状态 `state`
* `default_state_factory: Optional[T_StateFactory]`: 默认状态 `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: T_State`: 当前状态
* **返回**
* `bool`: 是否满足匹配规则
### _classmethod_ `args_parser(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认参数解析函数
* **参数**
* `func: T_ArgsParser`: 参数解析函数
### _classmethod_ `type_updater(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认响应事件类型更新函数
* **参数**
* `func: T_TypeUpdater`: 响应事件类型更新函数
### _classmethod_ `permission_updater(func)`
* **说明**
装饰一个函数来更改当前事件响应器的默认会话权限更新函数
* **参数**
* `func: T_PermissionUpdater`: 会话权限更新函数
### _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[T_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
### `stop_propagation()`
* **说明**
阻止事件传播

View File

@@ -0,0 +1,143 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.message 模块
## 事件处理
NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供了多个插槽以进行事件的预处理等。
## `event_preprocessor(func)`
* **说明**
事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
* **参数**
事件预处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 State
## `event_postprocessor(func)`
* **说明**
事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
* **参数**
事件后处理函数接收三个参数。
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前事件运行前 State
## `run_preprocessor(func)`
* **说明**
运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。
* **参数**
运行预处理函数接收四个参数。
* `matcher: Matcher`: 当前要运行的事件响应器
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 State
## `run_postprocessor(func)`
* **说明**
运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。
* **参数**
运行后处理函数接收五个参数。
* `matcher: Matcher`: 运行完毕的事件响应器
* `exception: Optional[Exception]`: 事件响应器运行错误(如果存在)
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 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,324 @@
---
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_shell_command` => `nonebot.plugin.on_shell_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_all_plugins` => `nonebot.plugin.load_all_plugins`
* `load_from_json` => `nonebot.plugin.load_from_json`
* `load_from_toml` => `nonebot.plugin.load_from_toml`
* `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_bot(self_id=None)`
* **说明**
当提供 self_id 时,此函数是 get_bots()[self_id] 的简写;当不提供时,返回一个 Bot。
* **参数**
* `self_id: Optional[str]`: 用来识别 Bot 的 ID
* **返回**
* `Bot`: Bot 对象
* **异常**
* `KeyError`: 对应 ID 的 Bot 不存在
* `ValueError`: 全局 Driver 对象尚未初始化 (nonebot.init 尚未调用)
* `ValueError`: 没有传入 ID 且没有 Bot 可用
* **用法**
```python
assert nonebot.get_bot('12345') == nonebot.get_bots()['12345']
another_unspecified_bot = nonebot.get_bot()
```
## `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,137 @@
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.permission 模块
## 权限
每个 `Matcher` 拥有一个 `Permission` ,其中是 **异步** `PermissionChecker` 的集合,只要有一个 `PermissionChecker` 检查结果为 `True` 时就会继续运行。
:::tip 提示
`PermissionChecker` 既可以是 async function 也可以是 sync function
:::
## _class_ `Permission`
基类:`object`
* **说明**
`Matcher` 规则类,当事件传递时,在 `Matcher` 运行前进行检查。
* **示例**
```python
Permission(async_function) | sync_function
# 等价于
from nonebot.utils import run_sync
Permission(async_function, run_sync(sync_function))
```
### `__init__(*checkers)`
* **参数**
* `*checkers: Callable[[Bot, Event], Awaitable[bool]]`: **异步** PermissionChecker
### `checkers`
* **说明**
存储 `PermissionChecker`
* **类型**
* `Set[Callable[[Bot, Event], Awaitable[bool]]]`
### _async_ `__call__(bot, event)`
* **说明**
检查是否满足某个权限
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* **返回**
* `bool`
## `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=None)`
* **说明**
`event``session_id` 在白名单内且满足 perm
* **参数**
* `*user: str`: 白名单
* `perm: Optional[Permission]`: 需要同时满足的权限
## `SUPERUSER`
* **说明**: 匹配任意超级用户消息类型事件

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,266 @@
---
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, T_State], Awaitable[bool]]`: **异步** RuleChecker
### `checkers`
* **说明**
存储 `RuleChecker`
* **类型**
* `Set[Callable[[Bot, Event, T_State], Awaitable[bool]]]`
### _async_ `__call__(bot, event, state)`
* **说明**
检查是否符合所有规则
* **参数**
* `bot: Bot`: Bot 对象
* `event: Event`: Event 对象
* `state: T_State`: 当前 State
* **返回**
* `bool`
## `startswith(msg, ignorecase=False)`
* **说明**
匹配消息开头
* **参数**
* `msg: str`: 消息开头字符串
## `endswith(msg, ignorecase=False)`
* **说明**
匹配消息结尾
* **参数**
* `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 提示
命令内容与后续消息间无需空格!
:::
## _class_ `ArgumentParser`
基类:`argparse.ArgumentParser`
* **说明**
`shell_like` 命令参数解析器,解析出错时不会退出程序。
## `shell_command(*cmds, parser=None)`
* **说明**
支持 `shell_like` 解析参数的命令形式匹配,根据配置里提供的 `command_start`, `command_sep` 判断消息是否为命令。
可以通过 `state["_prefix"]["command"]` 获取匹配成功的命令(例:`("test",)`),通过 `state["_prefix"]["raw_command"]` 获取匹配成功的原始命令文本(例:`"/test"`)。
可以通过 `state["argv"]` 获取用户输入的原始参数列表
添加 `parser` 参数后, 可以自动处理消息并将结果保存在 `state["args"]` 中。
* **参数**
* `*cmds: Union[str, Tuple[str, ...]]`: 命令内容
* `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象
* **示例**
使用默认 `command_start`, `command_sep` 配置,更多示例参考 `argparse` 标准库文档。
```python
from nonebot.rule import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-a", action="store_true")
rule = shell_command("ls", parser=parser)
```
:::tip 提示
命令内容与后续消息间无需空格!
:::
## `regex(regex, flags=0)`
* **说明**
根据正则表达式进行匹配。
可以通过 `state["_matched"]` `state["_matched_groups"]` `state["_matched_dict"]`
获取正则表达式匹配成功的文本。
* **参数**
* `regex: str`: 正则表达式
* `flags: Union[int, re.RegexFlag]`: 正则标志
:::tip 提示
正则表达式匹配使用 search 而非 match如需从头匹配请使用 `r"^xxx"` 来确保匹配开头
:::
## `to_me()`
* **说明**
通过 `event.is_tome()` 判断事件是否与机器人有关
* **参数**
*

View File

@@ -0,0 +1,278 @@
---
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 模块导入。
## `T_State`
* **类型**
`Dict[Any, Any]`
* **说明**
事件处理状态 State 类型
## `T_StateFactory`
* **类型**
`Callable[[Bot, Event], Awaitable[T_State]]`
* **说明**
事件处理状态 State 类工厂函数
## `T_BotConnectionHook`
* **类型**
`Callable[[Bot], Awaitable[None]]`
* **说明**
Bot 连接建立时执行的函数
## `T_BotDisconnectionHook`
* **类型**
`Callable[[Bot], Awaitable[None]]`
* **说明**
Bot 连接断开时执行的函数
## `T_CallingAPIHook`
* **类型**
`Callable[[Bot, str, Dict[str, Any]], Awaitable[None]]`
* **说明**
`bot.call_api` 时执行的函数
## `T_CalledAPIHook`
* **类型**
`Callable[[Bot, Optional[Exception], str, Dict[str, Any], Any], Awaitable[None]]`
* **说明**
`bot.call_api` 后执行的函数,参数分别为 bot, exception, api, data, result
## `T_EventPreProcessor`
* **类型**
`Callable[[Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件预处理函数 EventPreProcessor 类型
## `T_EventPostProcessor`
* **类型**
`Callable[[Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件预处理函数 EventPostProcessor 类型
## `T_RunPreProcessor`
* **类型**
`Callable[[Matcher, Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件响应器运行前预处理函数 RunPreProcessor 类型
## `T_RunPostProcessor`
* **类型**
`Callable[[Matcher, Optional[Exception], Bot, Event, T_State], Awaitable[None]]`
* **说明**
事件响应器运行前预处理函数 RunPostProcessor 类型,第二个参数为运行时产生的错误(如果存在)
## `T_RuleChecker`
* **类型**
`Callable[[Bot, Event, T_State], Union[bool, Awaitable[bool]]]`
* **说明**
RuleChecker 即判断是否响应事件的处理函数。
## `T_PermissionChecker`
* **类型**
`Callable[[Bot, Event], Union[bool, Awaitable[bool]]]`
* **说明**
RuleChecker 即判断是否响应消息的处理函数。
## `T_Handler`
* **类型**
* `Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
* `Callable[[Bot, Event], Union[Awaitable[None], Awaitable[NoReturn]]]`
* `Callable[[Bot, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
* `Callable[[Bot], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
Handler 即事件的处理函数。
## `T_ArgsParser`
* **类型**
`Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
* **说明**
ArgsParser 即消息参数解析函数,在 Matcher.got 获取参数时被运行。
## `T_TypeUpdater`
* **类型**
`Callable[[Bot, Event, T_State, str], Awaitable[str]]`
* **说明**
TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。默认会更新为 `message`
## `T_PermissionUpdater`
* **类型**
`Callable[[Bot, Event, T_State, Permission], Awaitable[Permission]]`
* **说明**
PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。默认会更新为当前事件的触发对象。

View File

@@ -0,0 +1,85 @@
---
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.encoder.JSONEncoder`
* **说明**
在JSON序列化 `Message` (List[Dataclass]) 时使用的 `JSONEncoder`
## `logger_wrapper(logger_name)`
* **说明**
用于打印 adapter 的日志。
* **Log 参数**
* `level: Literal['WARNING', 'DEBUG', 'INFO']`: 日志等级
* `message: str`: 日志信息
* `exception: Optional[Exception]`: 异常信息

View File

@@ -0,0 +1,31 @@
# 概览
<!-- :::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.3 以上版本**
## 特色
NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义**,并且可以作为插件进行**替换/添加**
- 提供使用简易的脚手架
- 提供丰富的官方插件
- 提供可添加/替换的驱动以及协议选项
- 基于异步 I/O
- 同时支持 HTTP 和反向 WebSocket 通信方式
- 支持多个机器人账号负载均衡
- 提供直观的交互式会话接口
- 提供可自定义的权限控制机制
- 多种方式渲染要发送的消息内容,使对话足够自然

View File

@@ -0,0 +1,86 @@
# 基本配置
到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。
在上一章节中,我们创建了默认的项目结构,其中 `.env``.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。
:::danger 警告
请勿将敏感信息写入配置文件并提交至开源仓库!
:::
## .env 文件
NoneBot 在启动时将会从系统环境变量或者 `.env` 文件中寻找变量 `ENVIRONMENT` (大小写不敏感),默认值为 `prod`
这将引导 NoneBot 从系统环境变量或者 `.env.{ENVIRONMENT}` 文件中进一步加载具体配置。
`.env` 文件是基础环境配置文件,该文件中的配置项在不同环境下都会被加载,但会被 `.env.{ENVIRONMENT}` 文件中的配置所覆盖。
现在,我们在 `.env` 文件中写入当前环境信息:
```bash
# .env
ENVIRONMENT=dev
CUSTOM_CONFIG=common config # 这个配置项在任何环境中都会被加载
```
如你所想,之后 NoneBot 就会从 `.env.dev` 文件中加载环境变量。
## .env.\* 文件
NoneBot 使用 [pydantic](https://pydantic-docs.helpmanual.io/) 进行配置管理,会从 `.env.{ENVIRONMENT}` 文件中获悉环境配置。
可以在 NoneBot 初始化时指定加载某个环境配置文件: `nonebot.init(_env_file=".env.dev")`,这将忽略你在 `.env` 中设置的 `ENVIRONMENT`
:::warning 提示
由于 `pydantic` 使用 JSON 解析配置项,请确保配置项值为 JSON 格式的数据。如:
```bash
list=["123456789", "987654321", 1]
test={"hello": "world"}
```
如果配置项值解析失败将作为字符串处理。
:::
示例及说明:
```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` 文件( `nonebot.init` ) > 系统环境变量 > `.env` `.env.*` 文件

View File

@@ -0,0 +1,117 @@
# CQHTTP 协议使用指南
## 安装 NoneBot CQHTTP 适配器
```bash
pip install nonebot-adapter-cqhttp
```
## 配置 CQHTTP 协议端(以 QQ 为例)
单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。
QQ 协议端举例:
- [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) (基于 [MiraiGo](https://github.com/Mrs4s/MiraiGo))
- [onebot-kotlin](https://github.com/yyuueexxiinngg/onebot-kotlin)
- [Mirai](https://github.com/mamoe/mirai) + [onebot-mirai](https://github.com/yyuueexxiinngg/onebot-kotlin)
- [Mirai](https://github.com/mamoe/mirai) + [Mirai Native](https://github.com/iTXTech/mirai-native) + [CQHTTP](https://github.com/richardchien/coolq-http-api)
- [node-onebot](https://github.com/takayama-lily/node-onebot) (基于 [abot](https://github.com/takayama-lily/abot), [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. 生成默认配置文件并修改默认配置
### 选项 1 反向 WebSocket 连接
```yml{2,3,6,10}
account:
uin: 机器人QQ号
password: "机器人密码"
message:
post-format: array
servers:
- ws-reverse:
universal: ws://127.0.0.1:8080/cqhttp/ws
```
其中 `ws://127.0.0.1:8080/cqhttp/ws` 中的 `127.0.0.1` 和 `8080` 应分别对应 nonebot 配置的 HOST 和 PORT。
`cqhttp` 是前述 `register_adapter` 时传入的第一个参数,代表设置的 `CQHTTPBot` 适配器的路径,你可以对不同的适配器设置不同路径以作区别。
### 选项 2 HTTP POST 上报
```yml{2,3,6,11}
account:
uin: 机器人QQ号
password: "机器人密码"
message:
post-format: array
servers:
- http:
post:
- url: "http://127.0.0.1:8080/cqhttp/http"
secret: ""
```
其中 `ws://127.0.0.1:8080/cqhttp/http` 中的 `127.0.0.1` 和 `8080` 应分别对应 nonebot 配置的 HOST 和 PORT。
`cqhttp` 是前述 `register_adapter` 时传入的第一个参数,代表设置的 `CQHTTPBot` 适配器的路径,你可以对不同的适配器设置不同路径以作区别。
### 选项 3 正向 WebSocket 连接
```yml{2,3,6,10,11}
account:
uin: 机器人QQ号
password: "机器人密码"
message:
post-format: array
servers:
- ws:
host: 127.0.0.1
port: 6700
```
NoneBot 配置
```dotenv
CQHTTP_WS_URLS={"机器人QQ号": "ws://127.0.0.1:6700/"}
```
其中 `ws://127.0.0.1:6700/` 中的 `127.0.0.1` 和 `6700` 应分别对应 go-cqhttp 配置的 HOST 和 PORT。
正向连接可以选择支持客户端连接方式的 `Driver` 来进行连接,请根据需求进行选择:
- `nonebot.drivers.fastapi`: 同时支持正向和反向
- `nonebot.drivers.aiohttp`: 仅支持正向
## 历史性的第一次对话
一旦新的配置文件正确生效之后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!
```
这表示 CQHTTP 协议端已经成功地使用 CQHTTP 协议连接上了 NoneBot。
现在,尝试向你的机器人账号发送如下内容:
```default
/echo 你好,世界
```
到这里如果一切 OK你应该会收到机器人给你回复了 `你好,世界`。这一历史性的对话标志着你已经成功地运行了一个 NoneBot 的最小实例,开始了编写更强大的 QQ 机器人的创意之旅!
<ClientOnly>
<Messenger :messages="[{ position: 'right', msg: '/echo 你好,世界' }, { position: 'left', msg: '你好,世界' }]"/>
</ClientOnly>

View File

@@ -0,0 +1,197 @@
# 事件处理
在上一章中,我们已经注册了事件响应器,现在我们可以正式编写事件处理逻辑了!
## [事件处理函数](../api/typing.md#handler)
```python{1,2,8,9}
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: T_State):
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: T_State):
state["key"] = "hello"
@matcher.got("key2", prompt="{key}!")
async def handle2(bot: Bot, event: Event, state: T_State):
pass
```
`args_parser` 为参数处理函数,在这里传入一个新的函数以覆盖默认的参数处理。详情参照 [args_parser](#参数处理函数-args-parser)
特别的,这些装饰器都可以套娃使用:
```python
@matcher.got("key1")
@matcher.got("key2")
async def handle(bot: Bot, event: Event, state: T_State):
pass
```
### 事件处理函数参数
事件处理函数类型为:
- `Callable[[Bot, Event, T_State, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Event, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, T_State, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Event], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot, Matcher], Union[Awaitable[None], Awaitable[NoReturn]]]`
- `Callable[[Bot], Union[Awaitable[None], Awaitable[NoReturn]]]`
简单说就是:除了 `bot` 参数,其他都是可选的。
以下函数都是合法的事件处理函数(仅列举常用的):
```python
async def handle(bot: Bot, event: Event, state: T_State):
pass
async def handle(bot: Bot, event: Event, state: T_State, matcher: Matcher):
pass
async def handle(bot: Bot, event: Event):
pass
async def handle(bot: Bot, state: T_State):
pass
async def handle(bot: Bot):
pass
```
:::danger 警告
函数的参数名固定不能修改!
:::
参数分别为:
1. [nonebot.adapters.Bot](../api/adapters/#class-bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
2. [nonebot.adapters.Event](../api/adapters/#class-event): 即上报事件对象,可以获取到上报的所有信息。
3. [state](../api/typing.md#t-state): 状态字典,可以存储任意的信息,其中还包含一些特殊的值以获取 NoneBot 内部处理时的一些信息,如:
- `state["_current_key"]`: 存储当前 `got` 获取的参数名
- `state["_prefix"]`, `state["_suffix"]`: 存储当前 TRIE 匹配的前缀/后缀,可以通过该值获取用户命令的原始命令
:::tip 提示
NoneBot 会对不同类型的参数进行不同的操作,详情查看 [事件处理函数重载](../advanced/overloaded-handlers.md)
:::
### 参数处理函数 args_parser
在使用 `got` 获取用户输入参数时需要对用户的消息进行处理以转换为我们所需要的信息。在默认情况下NoneBot 会把用户的消息字符串原封不动的赋值给 `state[key]` 。可以通过以下两种方式修改默认处理逻辑:
- `@matcher.args_parser` 装饰器:直接装饰一个函数作为参数处理器
- `got(key, prompt, args_parser)`:直接把函数作为参数传入
参数处理函数类型为:`Callable[[Bot, Event, T_State], Union[Awaitable[None], Awaitable[NoReturn]]]`,即:
```python
async def parser(bot: Bot, event: Event, state: T_State):
state[state["_current_key"]] = str(event.get_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: T_State):
print(state["_current_key"], ":", str(event.get_message()))
state[state["_current_key"]] = str(event.get_message())
@matcher.handle()
async def first_receive(bot: Bot, event: Event, state: T_State):
# 获取用户原始命令,如:/test
print(state["_prefix"]["raw_command"])
# 处理用户输入参数,如:/test arg1 arg2
raw_args = str(event.get_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: T_State):
# 在这里对参数进行验证
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,148 @@
# 注册事件响应器
好了,现在插件已经创建完毕,我们可以开始编写实际代码了,下面将以一个简易单文件天气查询插件为例。
在插件目录下 `weather.py` 中添加如下代码:
```python
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
weather = on_command("天气", rule=to_me(), priority=5)
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, event: Event, state: T_State):
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{5}
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.get_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-plugin-test` 可以在网页端查看当前所有事件响应器的执行流程,有助理解事件响应流程!
```bash
nb plugin install nonebot_plugin_test
```
:::
### 阻断 block
当有任意事件响应器发出了阻止事件传递信号时,该事件将不再会传递给下一优先级,直接结束处理。
NoneBot 内置的事件响应器中,所有 `message` 类的事件响应器默认会阻断事件传递,其他则不会。
在部分情况中,可以使用 `matcher.stop_propagation()` 方法动态阻止事件传播,该方法需要 `handler` 在参数中获取 `matcher` 实例后调用方法。
## 自定义 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
from nonebot.typing import T_State
async def async_checker(bot: Bot, event: Event, state: T_State) -> bool:
return True
def sync_checker(bot: Bot, event: Event, state: T_State) -> bool:
return True
def check(arg1, arg2):
async def _checker(bot: Bot, event: Event, state: T_State) -> bool:
return bool(arg1 + arg2)
return Rule(_checker)
```
`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 BaseSettings
class Config(BaseSettings):
# 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
在该文件中编写数据库模型。

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