Compare commits

..

419 Commits

Author SHA1 Message Date
crazywhalecc
f33956f585 increment build number (build 667) 2023-01-04 16:11:58 +00:00
Jerry
5f0de0d513 Merge pull request #242 from zhamao-robot/onebot-file-transfer
添加 OneBot 12 文件上传和下载工具
2023-01-05 00:10:50 +08:00
Jerry
9c97d4a41c Merge pull request #241 from zhamao-robot/add-prompt-message
重构新的 waitMessage 到 prompt
2023-01-05 00:10:31 +08:00
crazywhalecc
cd4b7df1d7 add onebot file downloader and uploader 2023-01-04 23:21:41 +08:00
crazywhalecc
926b77a429 add prompt for bot context 2023-01-04 23:09:58 +08:00
crazywhalecc
7c30ba6b03 increment build number (build 666) 2023-01-04 13:39:30 +00:00
Jerry
cd85bd087c Merge pull request #240 from zhamao-robot/beta5-update
Beta5 系列升级内容(包含 Redis、sendAction 协程、reply 模式、修复 data 报错)
2023-01-04 21:38:17 +08:00
crazywhalecc
53ae4b1ed7 add bot context resume procedure 2023-01-04 21:24:29 +08:00
crazywhalecc
e526a94520 fix data error bug 2023-01-04 21:24:04 +08:00
crazywhalecc
d708485918 add match reply mode 2023-01-04 21:23:25 +08:00
crazywhalecc
c73a3e85aa add coroutine waiting result for sendAction 2023-01-04 21:22:54 +08:00
crazywhalecc
61ddf9515c cs fix 2023-01-04 20:44:13 +08:00
crazywhalecc
5b98480950 add redis wrapper 2023-01-04 20:43:03 +08:00
sunxyw
25fa833495 fix doxygen sudo permission (#239) 2023-01-04 16:54:46 +08:00
sunxyw
4b2af374f5 increment build number (build 665) 2023-01-04 08:45:21 +00:00
sunxyw
6238224e8c add postgres support (#236) 2023-01-04 16:44:26 +08:00
Jerry
fe890025c5 Merge pull request #237 from zhamao-robot/update-readme
更新首页介绍
2023-01-04 16:36:49 +08:00
sunxyw
78612b6e58 fix doxygen permission (#238) 2023-01-04 16:36:37 +08:00
Jerry
4957731760 Update README.md 2023-01-04 16:28:01 +08:00
sunxyw
fba39219cf increment build number (build 664) 2023-01-04 08:20:12 +00:00
sunxyw
b5329aef7c update api docs 2023-01-04 08:19:53 +00:00
sunxyw
4d6fc097c2 Merge pull request #235 from zhamao-robot/chore-updates
修复一些小问题和添加 GitAttributes
2023-01-04 16:18:53 +08:00
sunxyw
863c2d8c7a add workflow timeout limit 2023-01-04 15:33:38 +08:00
sunxyw
3596d6077d fix php8.0 coroutine fail 2023-01-04 15:26:41 +08:00
sunxyw
ed40799fe3 add .gitattributes 2023-01-04 14:42:27 +08:00
sunxyw
32afd38ad4 update bin permission 2023-01-04 14:36:25 +08:00
sunxyw
e0049fc7da increment build number (build 663) 2023-01-04 05:46:56 +00:00
sunxyw
f8c4bc01bc Merge pull request #234 from zhamao-robot/fix-some-tests
暂时停用网络请求测试并修复文件系统测试
2023-01-04 13:46:09 +08:00
sunxyw
0c13cded89 fix test result printer (#233) 2023-01-04 13:45:48 +08:00
sunxyw
690f8aed10 add cron support (#232) 2023-01-04 13:45:24 +08:00
sunxyw
5d473eddcf mark network io test as incomplete 2023-01-03 23:55:58 +08:00
sunxyw
2d6896adde fix FileSystemTest no perm 2023-01-03 23:35:38 +08:00
crazywhalecc
8f8002608e increment build number (build 662) 2023-01-03 10:39:03 +00:00
Jerry
9c3e6ce8bd Merge pull request #231 from zhamao-robot/fix-route-bug
修复 Route 注解无法正常解析的 Bug
2023-01-03 18:38:19 +08:00
Jerry
3a04c98f62 Update README.md 2023-01-03 13:29:05 +08:00
crazywhalecc
e8c8bd0ba7 fix route not working bug 2023-01-03 01:05:22 +08:00
crazywhalecc
939b02fdbc increment build number (build 661) 2023-01-02 17:05:14 +00:00
Jerry
cd52bfbfa5 Merge pull request #230 from zhamao-robot/redis
新增 Redis 支持
2023-01-03 01:04:34 +08:00
crazywhalecc
c78b7fa2b0 add redis support 2023-01-03 00:50:31 +08:00
crazywhalecc
e5b3509ebf update config for redis 2023-01-03 00:49:44 +08:00
crazywhalecc
d45d34430d refactor console table output things 2023-01-03 00:49:06 +08:00
crazywhalecc
26e172680d add sql validation 2023-01-03 00:48:31 +08:00
crazywhalecc
429eae64c6 increment build number (build 660) 2023-01-02 15:24:51 +00:00
Jerry
19aab968ae Merge pull request #229 from zhamao-robot/refactor-annotation
重构注解解析器和优化部分代码
2023-01-02 23:23:58 +08:00
crazywhalecc
7d9a8a5ee1 simplify and refactor the rest some code 2023-01-02 23:17:23 +08:00
crazywhalecc
1abdfc761d add dependency checker for plugin manager 2023-01-02 23:16:32 +08:00
crazywhalecc
43634974fc refactor annotation parser 2023-01-02 23:16:08 +08:00
crazywhalecc
5893d18149 change v3.sh comment 2023-01-02 23:15:19 +08:00
crazywhalecc
a145814923 to beta5 2023-01-02 23:15:07 +08:00
crazywhalecc
366b49ca82 add windows installation document 2023-01-02 23:14:44 +08:00
crazywhalecc
dbbc6f75d8 add level for Init 2023-01-02 23:14:30 +08:00
crazywhalecc
316c29628a add bat 2023-01-02 23:14:11 +08:00
sunxyw
11cd4ef56e increment build number (build 659) 2023-01-02 15:10:19 +00:00
sunxyw
fe8b38f968 Merge pull request #228 from zhamao-robot/refactor-command-manual
重构命令手册插件
2023-01-02 23:09:10 +08:00
sunxyw
8477bf153f fix CommandManualPlugin blocking annotations 2023-01-02 23:07:50 +08:00
sunxyw
2f94f5258d adjust StaticManualFactory method visibility 2023-01-02 23:01:40 +08:00
sunxyw
eb05cea443 fix reversed priority 2023-01-02 23:01:39 +08:00
sunxyw
af26086019 refactor command manual 2023-01-02 23:01:39 +08:00
Jerry
a0950a4be3 Merge pull request #227 from zhamao-robot/update-v3-sh
update v3.sh update script
2023-01-02 17:29:37 +08:00
crazywhalecc
9f970857ae update v3.sh update script 2023-01-02 17:22:40 +08:00
sunxyw
1a1fc8c558 increment build number (build 658) 2023-01-01 12:55:49 +00:00
sunxyw
fd7b9928ba Merge pull request #226 from zhamao-robot/add-build-command
添加 Phar 构建命令
2023-01-01 20:54:52 +08:00
sunxyw
da1bbee24c add built-in php support 2023-01-01 16:04:02 +08:00
sunxyw
3086bcdf6d simplify file filtering 2023-01-01 00:18:27 +08:00
sunxyw
50d6e75e71 add phar compression 2022-12-31 23:57:56 +08:00
sunxyw
413d783d53 use built-in default value 2022-12-31 23:01:00 +08:00
sunxyw
85240c753b add build command 2022-12-31 22:59:03 +08:00
crazywhalecc
c2c5433220 increment build number (build 657) 2022-12-31 13:05:23 +00:00
Jerry
5cd28964e6 Merge pull request #225 from zhamao-robot/refactor-config-config
重构配置类配置
2022-12-31 21:04:28 +08:00
crazywhalecc
d87b7dc0f7 increment build number (build 656) 2022-12-31 12:55:21 +00:00
Jerry
1d27091558 Merge pull request #224 from zhamao-robot/edge-bug-fix
边缘 Bug 修复
2022-12-31 20:53:35 +08:00
crazywhalecc
3dafbf4fbd increment build number (build 655) 2022-12-31 12:50:11 +00:00
Jerry
3a78f5e2b1 Merge pull request #223 from zhamao-robot/fix-ob12-cmd-bug
修复有关 BotCommand 的 Bug
2022-12-31 20:29:16 +08:00
sunxyw
3f26648a3c fix ZMRequestTest wrong assertion 2022-12-31 20:22:55 +08:00
sunxyw
a62e950870 add more path to cs-fix 2022-12-31 20:12:45 +08:00
sunxyw
aee7fa332a refactor config config 2022-12-31 20:12:20 +08:00
crazywhalecc
c1a0fae6e6 add interactive chat box docs 2022-12-31 19:57:49 +08:00
crazywhalecc
ed31edcc5c add some comments 2022-12-31 19:39:50 +08:00
crazywhalecc
4aea90cb39 add multiple bot support 2022-12-31 19:39:08 +08:00
crazywhalecc
a58c3aadab remove debug logger 2022-12-31 19:27:06 +08:00
Jerry
f2fb40b67c Merge pull request #222 from zhamao-robot/psr-simple-cache
将 KV 库接口调整为 PSR-16
2022-12-31 19:25:00 +08:00
crazywhalecc
18df76f650 fix AnnotationHandler return callback not working for BotCommand 2022-12-31 19:12:29 +08:00
crazywhalecc
dce126136b fix BotCommand prefix bug 2022-12-31 19:11:39 +08:00
crazywhalecc
d32f7b0ff8 update to beta4 version 2022-12-31 19:10:50 +08:00
crazywhalecc
d55362e190 update global functions for KV 2022-12-31 19:08:52 +08:00
crazywhalecc
6bcedea720 cs fix 2022-12-31 19:04:57 +08:00
Jerry
ccc801e6cb Merge pull request #221 from zhamao-robot/docs-update-1
更新部分文档
2022-12-31 19:03:07 +08:00
crazywhalecc
a2404482a3 change to psr-16 2022-12-31 19:02:41 +08:00
crazywhalecc
4c41dd09d2 update some docs 2022-12-31 18:12:28 +08:00
crazywhalecc
ab83194bbe Merge remote-tracking branch 'origin/main' 2022-12-31 17:42:18 +08:00
crazywhalecc
6013571267 update README.md and docs test activate 2022-12-31 17:41:20 +08:00
Jerry
2636bc2e35 Merge pull request #220 from zhamao-robot/update-workflows
根据最新的分支命名更新 Workflows
2022-12-31 17:37:01 +08:00
crazywhalecc
a2b013402b update workflows for newest 3.0 branch 2022-12-31 17:29:26 +08:00
Jerry
206f041d29 Merge pull request #219 from zhamao-robot/update-v3-docs-build
升级 v3 文档构建发布路径
2022-12-31 17:20:18 +08:00
crazywhalecc
ce885a7a61 update 3.0 docs build path 2022-12-31 17:19:23 +08:00
crazywhalecc
b0d0d5eba9 update 3.0 docs build path 2022-12-31 17:19:05 +08:00
sunxyw
d45c4e24fd switch hook to captainhook (#218) 2022-12-31 17:17:03 +08:00
crazywhalecc
49fffcc464 update 3.0 docs build path 2022-12-31 17:15:18 +08:00
crazywhalecc
e89d5ad1ac increment build number (build 654) 2022-12-31 08:14:31 +00:00
Jerry
11aed8c6be Merge pull request #217 from zhamao-robot/light-cache-update
新增全新的 LightCache
2022-12-31 16:13:37 +08:00
crazywhalecc
46d2f895e2 increment build number (build 653) 2022-12-31 07:45:20 +00:00
crazywhalecc
ed6b65eb88 cs fix 2022-12-31 15:45:09 +08:00
Jerry
8efb63a334 Merge pull request #216 from zhamao-robot/zm-request-update
新增 ZMRequest
2022-12-31 15:44:15 +08:00
crazywhalecc
13b5c44627 let getDriver() method always work 2022-12-31 15:36:33 +08:00
crazywhalecc
2a3c953c36 add ZMRequest support 2022-12-31 15:35:19 +08:00
crazywhalecc
fd8b3721ae add LightCache support 2022-12-31 15:27:09 +08:00
Jerry
3734f5d476 Merge pull request #215 from zhamao-robot/add-v3-sh
添加 v3 版本的一键安装脚本
2022-12-31 11:21:01 +08:00
crazywhalecc
088f963ad1 add v3.sh (and test my mac gpg) 2022-12-30 17:38:33 +08:00
crazywhalecc
c8a6bc69d3 increment build number (build 652) 2022-12-30 08:32:09 +00:00
Jerry
8584cc647c Merge pull request #214 from zhamao-robot/bot-action-and-some-update
拆分 Bot 动作到 Trait 以及更新一些类型强化的代码
2022-12-30 16:31:02 +08:00
crazywhalecc
d8ac604592 increment build number (build 651) 2022-12-30 08:16:55 +00:00
Jerry
9acb5e760b Merge pull request #213 from zhamao-robot/container-coroutine-support
让容器支持协程
2022-12-30 16:15:56 +08:00
crazywhalecc
96879bf415 update some doc and types 2022-12-30 16:15:22 +08:00
crazywhalecc
d7e815d670 fix windows CtrlC capture bug 2022-12-30 16:13:57 +08:00
crazywhalecc
dfcb8a4550 separate bot action method to BotActionTrait 2022-12-30 16:13:25 +08:00
crazywhalecc
96fa6b105c add coroutine for container 2022-12-30 11:30:29 +08:00
crazywhalecc
b86f51ab46 increment build number (build 650) 2022-12-30 03:23:40 +00:00
Jerry
8473a1152d Merge pull request #211 from zhamao-robot/fix-bot-context-not-sync
修复 BotContext 不同步问题
2022-12-30 11:22:43 +08:00
Jerry
65acfaa0bd Merge pull request #212 from zhamao-robot/add-event-docs
加(一些)事件文档
2022-12-30 10:06:34 +08:00
sunxyw
c58e08998a add event docs 2022-12-29 17:52:21 +08:00
sunxyw
9cf905421e fix bot context not sync 2022-12-29 14:58:18 +08:00
sunxyw
c65694402f increment build number (build 649) 2022-12-28 14:06:04 +00:00
sunxyw
0d24ae6192 add command manual plugin (#210) 2022-12-28 22:05:03 +08:00
sunxyw
383e0e22af increment build number (build 648) 2022-12-27 12:40:06 +00:00
sunxyw
87840930e0 use solution repository instead of built-in (#209)
* use solution repository instead of built-in

* suppress static analysis
2022-12-27 20:39:24 +08:00
sunxyw
05b3321af7 add windows entry binary (#208) 2022-12-27 15:39:36 +08:00
crazywhalecc
19e380d1fb increment build number (build 647) 2022-12-26 13:01:15 +00:00
Jerry
d1f69556b7 Merge pull request #206 from zhamao-robot/v3-beta2
发布 beta2
2022-12-26 21:00:22 +08:00
crazywhalecc
80ba34351c update to beta2 2022-12-26 20:02:47 +08:00
sunxyw
81a5e48b26 renew docs (#205) 2022-12-26 18:31:27 +08:00
crazywhalecc
aa28675016 increment build number (build 646) 2022-12-26 07:33:05 +00:00
Jerry
f8ecfa2745 Merge pull request #203 from zhamao-robot/bot-command-enhancement
完善 BotCommand 和 CommandArgument 的解析
2022-12-26 15:32:06 +08:00
crazywhalecc
efda3f4408 enhancement for BotCommand and CommandArgument 2022-12-26 03:19:53 +08:00
crazywhalecc
a5b29ac398 increment build number (build 645) 2022-12-25 19:17:43 +00:00
Jerry
73151db726 Merge pull request #202 from zhamao-robot/plugin-make-command
添加插件生成功能
2022-12-26 03:17:00 +08:00
crazywhalecc
aab57ce216 add PHPDoc 2022-12-25 23:20:57 +08:00
crazywhalecc
f140784a50 add PHPDoc 2022-12-25 23:19:49 +08:00
crazywhalecc
579269cb5b add plugin make command 2022-12-25 23:11:10 +08:00
sunxyw
ed5a9c6c12 add HttpEventListener test (#200) 2022-12-25 19:29:44 +08:00
sunxyw
ca430123c9 increment build number (build 644) 2022-12-25 11:08:18 +00:00
sunxyw
bc68aff654 Merge pull request #201 from zhamao-robot/change-container-impl
切换容器实现为 PHP-DI
2022-12-25 19:07:34 +08:00
sunxyw
19e3280e29 adjust container listening event level 2022-12-25 18:21:58 +08:00
sunxyw
a813e80b32 add class alias support 2022-12-25 18:15:07 +08:00
sunxyw
05b3446f59 change container to php-di 2022-12-25 17:42:32 +08:00
crazywhalecc
60ce722010 increment build number (build 643) 2022-12-24 08:57:41 +00:00
Jerry
1fc329c670 Merge pull request #197 from zhamao-robot/catcode-add-text-options
新增 CatCode encode 时选择是否编码文本的参数
2022-12-24 16:56:50 +08:00
crazywhalecc
4035ffcffb strict types 2022-12-24 16:19:26 +08:00
sunxyw
b41871a2a2 refactor config test (#199) 2022-12-24 15:46:13 +08:00
sunxyw
a44a7e86d7 Merge pull request #192 from zhamao-robot/move-api-docs-to-doxygen
用 Doxygen 替代 API Docs
2022-12-24 14:41:11 +08:00
sunxyw
716734d26f fix docs link target 2022-12-24 14:39:03 +08:00
sunxyw
b3e97febe1 adjust .gitignore 2022-12-24 14:36:27 +08:00
sunxyw
520db4b550 add doxy preview 2022-12-24 14:36:26 +08:00
sunxyw
c6c3efade4 fix typo 2022-12-24 14:36:26 +08:00
sunxyw
0b7f5f9f05 change api link to external 2022-12-24 14:36:26 +08:00
sunxyw
33a14dee8b move api docs to doxygen 2022-12-24 14:36:25 +08:00
crazywhalecc
bddc54b93d increment build number (build 642) 2022-12-24 05:59:33 +00:00
Jerry
2e0f5e2c51 Merge pull request #198 from zhamao-robot/v3-fix-class-psr-4
修复 getClassesPsr4 中默认过滤方法的路径 Bug
2022-12-24 13:58:28 +08:00
sunxyw
2c6f6067ca increment build number (build 641) 2022-12-24 05:35:58 +00:00
sunxyw
dcf41091ef add event provider test (#195) 2022-12-24 13:34:53 +08:00
crazywhalecc
8040a329cb fix getClassesPsr4 default ignore dir bug 2022-12-24 01:42:56 +08:00
crazywhalecc
6e43d4092f add CatCode text encode options 2022-12-24 01:38:15 +08:00
sunxyw
0ac2985fc1 increment build number (build 640) 2022-12-23 14:57:18 +00:00
sunxyw
1e037b9610 Merge pull request #194 from zhamao-robot/add-tests
添加些许测试
2022-12-23 22:56:33 +08:00
sunxyw
38b70db2dc add more FileSystemTest 2022-12-23 22:43:25 +08:00
sunxyw
b35d546555 add phpstan extension for prophecy 2022-12-23 20:26:35 +08:00
sunxyw
5e3d07abe6 add FileSystemTest 2022-12-23 20:23:07 +08:00
sunxyw
1d131871f1 add CatCode test 2022-12-23 17:35:19 +08:00
sunxyw
5e8f80b626 enhance test run (#193) 2022-12-23 17:16:08 +08:00
sunxyw
9128efbaa1 increment build number (build 639) 2022-12-20 17:26:49 +00:00
sunxyw
3545e1173e Merge pull request #190 from zhamao-robot/fix-init-command-dir
修复相对路径问题
2022-12-21 01:25:49 +08:00
sunxyw
9bf95223a1 fix user command dir path 2022-12-21 01:19:45 +08:00
sunxyw
3f2bd69002 fix global define bootstrapper relative path 2022-12-21 00:38:37 +08:00
sunxyw
4554bbc85b remove internal files from extract list 2022-12-21 00:34:24 +08:00
sunxyw
8901c31631 fix command loader relative path 2022-12-21 00:28:20 +08:00
sunxyw
61ece52edc fix init command dir 2022-12-21 00:13:53 +08:00
crazywhalecc
fb936e97ac remove prefer for composer 2022-12-20 23:49:41 +08:00
crazywhalecc
8ca4f7400a increment build number (build 638) 2022-12-20 15:46:29 +00:00
Jerry
61b48676ae Merge pull request #188 from zhamao-robot/v3-beta1
Beta 1 发布
2022-12-20 23:45:43 +08:00
crazywhalecc
257e59b79f remove debug log 2022-12-20 23:42:29 +08:00
crazywhalecc
c19791c31d remove debug log 2022-12-20 23:41:58 +08:00
crazywhalecc
c99747c1f6 add class alias helper generate command 2022-12-20 23:36:43 +08:00
crazywhalecc
a9b6989966 Merge remote-tracking branch 'origin/v3-beta1' into v3-beta1
# Conflicts:
#	src/Globals/global_class_alias.php
2022-12-20 23:22:55 +08:00
crazywhalecc
c9bf0fb13c prerelease of beta1 2022-12-20 23:19:55 +08:00
sunxyw
04247048d4 increment build number (build 637) 2022-12-20 15:05:27 +00:00
sunxyw
b2a6c2f5e0 add container class_alias support (#189) 2022-12-20 23:04:26 +08:00
crazywhalecc
865c306e14 prerelease of beta1 2022-12-20 20:10:40 +08:00
sunxyw
588fc919d9 increment build number (build 636) 2022-12-19 12:23:38 +00:00
sunxyw
8ff7da4d23 PHP80 小修 (#187)
* migrate-php80

fix styles
fix static analyse

* fix some bugs
2022-12-19 20:22:47 +08:00
sunxyw
da516b487d update readme test badge src (#186) 2022-12-19 15:20:01 +08:00
crazywhalecc
06615cbb29 increment build number (build 635) 2022-12-19 06:02:03 +00:00
crazywhalecc
463ee0cced update api docs 2022-12-19 06:01:59 +00:00
Jerry
208ccd6642 Merge pull request #185 from zhamao-robot/plugin-update-post
完善插件加载系统
2022-12-19 14:01:02 +08:00
crazywhalecc
cd2bb1b570 add plugin loader support 2022-12-19 01:45:27 +08:00
crazywhalecc
52a195aca2 fix DBException syntax error 2022-12-19 01:43:47 +08:00
crazywhalecc
fbc3cf00a2 increment build number (build 634) 2022-12-18 12:14:53 +00:00
crazywhalecc
ede5f456a8 update api docs 2022-12-18 12:14:51 +00:00
Jerry
2633e91d4d Merge pull request #184 from zhamao-robot/plugin-update-pre
插件和 OneBot 12 适配器前置内容
2022-12-18 20:13:50 +08:00
crazywhalecc
39b3a74d34 refactor with php-libonebot factory classes 2022-12-18 18:33:51 +08:00
crazywhalecc
3ecd224ce6 separate onebot 12 adapter things 2022-12-18 18:31:35 +08:00
sunxyw
49c7033eaa update dependencies (#180)
* update dependencies

* revert swoole-helper update
2022-12-18 15:58:48 +08:00
crazywhalecc
20ca848df9 increment build number (build 633) 2022-12-17 16:42:49 +00:00
crazywhalecc
5b0e3ed636 update api docs 2022-12-17 16:42:47 +00:00
Jerry
14840715bc Merge pull request #181 from zhamao-robot/8.0-upgrade
兼容 8.x PHP 一些改动
2022-12-18 00:41:56 +08:00
crazywhalecc
ed4537e5d5 update some strict parameters and separate easter eggs 2022-12-18 00:17:28 +08:00
crazywhalecc
58d4b4427d update default download native php to 8.1 2022-12-18 00:15:55 +08:00
crazywhalecc
8c6aba9361 rename Instant to ZM 2022-12-18 00:15:34 +08:00
crazywhalecc
1173949bba rename Instant to ZM 2022-12-18 00:15:19 +08:00
crazywhalecc
279956456c remove unused files 2022-12-18 00:11:54 +08:00
crazywhalecc
3f8c557a96 add requirement tokenizer 2022-12-18 00:11:33 +08:00
sunxyw
ff93201ab1 increment build number (build 632) 2022-12-17 16:00:09 +00:00
sunxyw
cd94539e99 update api docs 2022-12-17 16:00:07 +00:00
sunxyw
adc1d176e3 Merge pull request #179 from zhamao-robot/migrate-symfony-console-v6
迁移 Symfony Console V6
2022-12-17 23:59:19 +08:00
sunxyw
44c25f7fdd make commands lazily loaded 2022-12-17 22:30:19 +08:00
sunxyw
3806983bc2 change commands definition to attribute 2022-12-17 21:53:24 +08:00
sunxyw
c6f877700e add contributing document (#178) 2022-12-17 19:45:04 +08:00
sunxyw
c2fb90dfc7 increment build number (build 631) 2022-12-17 11:43:42 +00:00
sunxyw
ca61e6a238 update api docs 2022-12-17 11:43:41 +00:00
sunxyw
9399e54da8 Merge pull request #176 from zhamao-robot/docker-compose-support
增加 Docker Compose 支持
2022-12-17 19:42:42 +08:00
sunxyw
385f217b96 remove symfony/polyfill-php80 2022-12-17 16:29:28 +08:00
sunxyw
65bb6a2473 improve Command phpdoc 2022-12-17 16:27:49 +08:00
sunxyw
a430cf59c4 add docker init to InitCommand 2022-12-16 21:58:19 +08:00
sunxyw
4bf328ef67 refactor InitCommand 2022-12-16 18:05:51 +08:00
sunxyw
ebb724415d split InitException to SingletonViolationException 2022-12-16 17:59:12 +08:00
sunxyw
daa07dcb2b add docker compose support 2022-12-16 15:29:10 +08:00
sunxyw
635f081437 increment build number (build 630) 2022-11-18 07:22:16 +00:00
sunxyw
c7b4ca2a82 Merge pull request #173 from zhamao-robot/advance-exception
改进异常
2022-11-18 15:21:33 +08:00
sunxyw
b5c91531fa fix comment position 2022-11-18 15:16:48 +08:00
sunxyw
8199e91ce0 remove todo from InterruptException 2022-11-17 21:11:11 +08:00
sunxyw
44c32c1711 fix styles 2022-11-15 23:14:31 +08:00
sunxyw
5a3da43640 fix unused argument 2022-11-15 23:11:24 +08:00
sunxyw
352f3e920e deprecate ZMKnownException 2022-11-15 21:51:15 +08:00
sunxyw
5f4a00c77e refactor ZMException 2022-11-15 21:48:46 +08:00
crazywhalecc
aeea6f5dc1 increment build number (build 629) 2022-11-14 02:10:52 +00:00
Jerry
ea74a531b4 Merge pull request #172 from zhamao-robot/orgianze-bootstrap
重新组织 Bootstraper
2022-11-14 10:09:52 +08:00
sunxyw
02003b2bd3 reduce useless method 2022-11-12 01:15:40 +08:00
sunxyw
723dfd30a2 fix styles 2022-11-08 17:33:25 +08:00
sunxyw
aa29dc99f3 orgianze bootstrapper 2022-11-08 17:28:07 +08:00
crazywhalecc
74ba4d0145 increment build number (build 628) 2022-11-06 02:15:29 +00:00
crazywhalecc
5705f5227f update api docs 2022-11-06 02:15:28 +00:00
Jerry
3bb34b46ee Merge pull request #170 from zhamao-robot/proxy-server
添加代理、升级到 PHP8.0
2022-11-06 10:14:47 +08:00
crazywhalecc
4d0ea99f47 fix posix killer 2022-11-04 12:35:17 +08:00
sunxyw
fe70c07113 Merge pull request #171 from zhamao-robot/update-workflow
更新Workflow
2022-11-04 11:36:49 +08:00
sunxyw
27c6bf1864 add PHP8.2 support 2022-11-03 17:37:52 +08:00
sunxyw
f4ded4c6d7 drop PHP7.4 support 2022-11-03 17:36:09 +08:00
sunxyw
4a2c7f5ecb bump fkirc/skip-duplicate-actions to v5 2022-11-03 17:35:38 +08:00
crazywhalecc
7a051380e2 fix php version requirements 2022-11-03 10:36:08 +08:00
crazywhalecc
35dec947df add proxy server command and update lowest version of PHP >= 8.0 2022-11-03 10:18:17 +08:00
crazywhalecc
6b34427855 increment build number (build 627) 2022-10-02 10:35:36 +00:00
crazywhalecc
59a9f30089 update api docs 2022-10-02 10:35:35 +00:00
Jerry Ma
779564ebb6 Merge pull request #169 from zhamao-robot/state-and-windows
add state and ctrl+C support for windows
2022-10-02 18:34:49 +08:00
crazywhalecc
a4f992b9e5 add state and ctrl+C support for windows 2022-09-26 22:44:41 +08:00
sunxyw
cf3f09600b increment build number (build 626) 2022-09-23 14:12:45 +00:00
sunxyw
83c1d63408 update api docs 2022-09-23 14:12:42 +00:00
sunxyw
43337c34c8 fix config upstream changes (#168) 2022-09-23 22:11:26 +08:00
crazywhalecc
bb431ccf53 increment build number (build 625) 2022-09-23 09:09:14 +00:00
crazywhalecc
ba69cc93ee update api docs 2022-09-23 09:09:12 +00:00
Jerry Ma
406de8f4df Merge pull request #167 from zhamao-robot/fix-relative-path-check-in-windows
修复 isRelativePath 在 Windows 环境判断相反的 Bug
2022-09-23 17:08:13 +08:00
crazywhalecc
fd05fe6e25 fix 2022-09-23 12:50:44 +08:00
sunxyw
10a0ee9142 increment build number (build 624) 2022-09-11 11:33:47 +00:00
sunxyw
836d4dc1ef Merge pull request #165 from zhamao-robot/refactor-workflow
重构 Workflow
2022-09-11 19:32:56 +08:00
sunxyw
a18fcdb21e adjust workflow php version 2022-09-10 16:04:15 +08:00
sunxyw
6c9cd06e4a simplify incrememt build number 2022-09-09 21:03:51 +08:00
sunxyw
44c1ac054c avoid duplicate workflow runs 2022-09-09 20:55:44 +08:00
sunxyw
9d77d60887 fix styles 2022-09-09 18:59:46 +08:00
sunxyw
8f7fd97ebe refactor workflow 2022-09-09 18:54:55 +08:00
sunxyw
87e3b2249c increment build number (build 623) 2022-08-28 06:12:39 +00:00
sunxyw
5e12af77a4 drop config array access support (#163) 2022-08-28 14:12:01 +08:00
sunxyw
47244373d7 add custom phpunit printer (#164) 2022-08-28 13:03:58 +08:00
sunxyw
a72530598a increment build number (build 622) 2022-08-27 18:20:38 +00:00
sunxyw
2679facf24 update api docs 2022-08-27 18:20:37 +00:00
sunxyw
cf9db4b0d4 add config trace (#159)
* add config trace

* fix config tracer bug
2022-08-28 02:19:26 +08:00
crazywhalecc
f341c8585e increment build number (build 621) 2022-08-27 12:34:51 +00:00
crazywhalecc
28f7b47034 update api docs 2022-08-27 12:34:50 +00:00
Jerry Ma
99954f9140 Merge pull request #162 from zhamao-robot/windows-support-relative-path
FileSystem.php isRelativePath() 对 Windows 的兼容性
2022-08-27 20:34:02 +08:00
Jerry Ma
85b21d63ed Merge pull request #161 from zhamao-robot/fix-config-overwrite-bug
修复 Framework 中 Config 重写的 Bug
2022-08-27 20:33:48 +08:00
Jerry Ma
ef443d9912 Merge pull request #160 from zhamao-robot/sqlite-support
Sqlite 支持
2022-08-27 20:33:36 +08:00
crazywhalecc
db2b22c822 FileSystem.php isRelativePath() compatibility for windows 2022-08-27 20:03:22 +08:00
crazywhalecc
24156884e4 fix config overwrite bug in framework init 2022-08-27 19:56:29 +08:00
crazywhalecc
6413567353 change global config for database 2022-08-27 19:51:09 +08:00
crazywhalecc
84f84dad40 add sqlite extensions for github action 2022-08-27 19:50:40 +08:00
crazywhalecc
dd01653da9 add SQLiteDriver.php and change MySQLDriver.php 2022-08-27 19:47:45 +08:00
crazywhalecc
085472a12c refactor MySQL component to support SQLite at the same time 2022-08-27 19:45:23 +08:00
crazywhalecc
e9b6965678 remove redundant library 2022-08-27 19:39:02 +08:00
sunxyw
1a9680c09a increment build number (build 620) 2022-08-27 08:26:49 +00:00
sunxyw
40f8fe22ee update api docs 2022-08-27 08:26:48 +00:00
sunxyw
be6002dd64 Merge pull request #157 from zhamao-robot/fix-config-loading
修正&改进配置加载
2022-08-27 16:25:43 +08:00
sunxyw
96ebb770b6 add environment aliases 2022-08-27 01:12:38 +08:00
sunxyw
9bcdb254c9 increment build number (build 619) 2022-08-26 16:54:30 +00:00
sunxyw
87e71f1eb8 add repl command (#155) 2022-08-27 00:53:45 +08:00
sunxyw
451ce104c5 fix config loading 2022-08-27 00:42:43 +08:00
sunxyw
7920711988 increment build number (build 618) 2022-08-23 15:43:41 +00:00
sunxyw
6e78f2caf2 update api docs 2022-08-23 15:43:37 +00:00
sunxyw
2727b056eb Merge pull request #146 from zhamao-robot/refactor-config
基于 LibOB Config 类重构 ZMConfig
2022-08-23 23:42:30 +08:00
sunxyw
975d0e3540 allow multiple set config 2022-08-23 18:18:20 +08:00
sunxyw
eb7e700e7c replace legacy config 2022-08-23 18:02:00 +08:00
sunxyw
18892a14c2 ready to replace legacy config 2022-08-23 17:51:20 +08:00
sunxyw
6cbde80a1c delete outdated config classes 2022-08-23 17:36:45 +08:00
sunxyw
6fc875aa72 fix windows compatibility 2022-08-23 16:00:55 +08:00
sunxyw
29f5c3c758 change confusing name global to default 2022-08-23 15:59:55 +08:00
sunxyw
afa6411004 add array replace feature 2022-08-23 15:37:31 +08:00
crazywhalecc
67526c30da increment build number (build 617) 2022-08-22 13:39:34 +00:00
Jerry Ma
dc67dbc489 Merge pull request #152 from zhamao-robot/more-windows-support
add phpunit windows support
2022-08-22 21:38:21 +08:00
crazywhalecc
05ac2feebd add windows exit code support 2022-08-22 21:32:00 +08:00
crazywhalecc
6f30c04899 fix php 7.4 stuck bug 2022-08-22 21:27:23 +08:00
crazywhalecc
dfce8e9749 remove default mysql host 2022-08-22 21:22:49 +08:00
crazywhalecc
aae326133b cs-fix 2022-08-22 21:03:33 +08:00
crazywhalecc
15383a6b92 add phpunit windows support 2022-08-22 20:54:14 +08:00
sunxyw
5d8a1deb35 add yaml and toml config support 2022-08-22 17:15:10 +08:00
sunxyw
b09d12aad5 add config patch support 2022-08-22 17:02:50 +08:00
sunxyw
488acc3e69 fix incorrect onebot namespace 2022-08-22 16:30:45 +08:00
sunxyw
32534c870d add clearer exception 2022-08-22 16:29:27 +08:00
sunxyw
74af1516ac add get file load type test 2022-08-22 16:12:50 +08:00
sunxyw
07b2f175f3 add more test cases 2022-08-22 16:12:49 +08:00
sunxyw
1a1c65afce fix code styles 2022-08-22 16:12:49 +08:00
sunxyw
90282b858e fix inappropriate config group name 2022-08-22 16:12:49 +08:00
sunxyw
f819922d8a add basic usable config 2022-08-22 16:12:48 +08:00
sunxyw
aa8fdf557e add load order to config 2022-08-22 16:12:48 +08:00
sunxyw
4896cf0ad3 simply refactor ZMConfig 2022-08-22 16:12:47 +08:00
crazywhalecc
2e61e2a366 increment build number (build 616) 2022-08-22 07:46:48 +00:00
Jerry Ma
172a7444c9 Merge pull request #151 from zhamao-robot/windows-support
修复对 Windows 环境开发的支持
2022-08-22 15:45:57 +08:00
crazywhalecc
3ea5b16487 increment build number (build 615) 2022-08-22 07:39:45 +00:00
crazywhalecc
e83a169fd6 update api docs 2022-08-22 07:39:44 +00:00
Jerry Ma
53c1c0103c Merge pull request #149 from zhamao-robot/feature/class-alias
添加类别名
2022-08-22 15:38:49 +08:00
crazywhalecc
e467402a15 fix typo 2022-08-22 15:32:29 +08:00
crazywhalecc
d5fc16dccb change arg pass 2022-08-22 15:23:41 +08:00
crazywhalecc
3be84edb5a remove swoole pdo proxy 2022-08-22 13:37:48 +08:00
crazywhalecc
fe3bb22311 add windows development support 2022-08-22 13:35:07 +08:00
sunxyw
86c2cf96a9 fix gendoc incompatibility (#150) 2022-08-22 13:06:48 +08:00
crazywhalecc
67ba8340cc cs fix 2022-08-21 20:17:05 +08:00
crazywhalecc
ac69640253 add alias 2022-08-21 20:15:55 +08:00
crazywhalecc
64965bcc93 increment build number (build 614) 2022-08-21 08:42:32 +00:00
Jerry Ma
2eb73f3746 Merge pull request #148 from zhamao-robot/feature/mysql
完善 MySQL 连接池和组件
2022-08-21 16:41:22 +08:00
crazywhalecc
8f761c31e3 reset PHPDoc 2022-08-21 16:25:05 +08:00
crazywhalecc
528b61862a remove deprecated php version for integration-test 2022-08-21 16:20:21 +08:00
crazywhalecc
c7003a7139 add mysql support 2022-08-21 16:08:20 +08:00
crazywhalecc
75e65b082e fix middleware closure reference not working 2022-08-21 16:07:01 +08:00
crazywhalecc
22d38b783d update function name, add --print-process-pid option 2022-08-21 16:05:58 +08:00
crazywhalecc
ebdada57a6 add bot crafting command 2022-08-21 16:04:20 +08:00
crazywhalecc
28f8850013 increment build number (build 613) 2022-08-20 11:00:45 +00:00
Jerry Ma
540977c637 Merge pull request #147 from zhamao-robot/refactor/phpunit-test-rebuild
Refactor/phpunit test rebuild
2022-08-20 18:59:50 +08:00
crazywhalecc
4ba74e9f3e refactor phpunit-swoole to phpunit-zm and move old test cases 2022-08-20 17:49:33 +08:00
crazywhalecc
cecdb1681c increment build number (build 612) 2022-08-15 07:07:37 +00:00
crazywhalecc
2947da2a00 update api docs 2022-08-15 07:07:36 +00:00
crazywhalecc
da6000b4da fix container and coroutine 2022-08-15 15:06:45 +08:00
crazywhalecc
8be7207c3c increment build number (build 611) 2022-08-14 10:16:55 +00:00
crazywhalecc
0a806a74b1 update api docs 2022-08-14 10:16:53 +00:00
crazywhalecc
d56f9d6e6e fix param for annotation handler 2022-08-14 18:15:45 +08:00
crazywhalecc
dc742763a8 add pipeline feature for middleware 2022-08-14 18:15:45 +08:00
crazywhalecc
0b9b87ba23 upgrade cs-check php version 2022-08-14 18:15:45 +08:00
crazywhalecc
346be22ea9 change comment 2022-08-14 18:15:45 +08:00
crazywhalecc
b2c95d96b1 refactor all base things 2022-08-14 18:15:45 +08:00
crazywhalecc
1c801bb205 remove mkdocs config 2022-08-14 18:15:45 +08:00
crazywhalecc
163d240a9c change LICENSE copyright 2022-08-14 18:15:45 +08:00
crazywhalecc
19fc3a6d40 add PhpStorm meta config 2022-08-14 18:15:45 +08:00
crazywhalecc
4c9bc002f4 update composer.json 2022-08-14 18:15:45 +08:00
crazywhalecc
b3a5d50ba8 rename bin/start to bin/zhamao 2022-08-14 18:15:45 +08:00
crazywhalecc
f7919129b6 patch 2.x new features on 3.0 2022-08-14 18:15:45 +08:00
crazywhalecc
dccb1d91e2 update docs 2022-08-14 18:15:45 +08:00
crazywhalecc
41b058aeaf update to 3.0.0-alpha2 (build 610): refactor driver 2022-08-14 18:15:45 +08:00
sunxyw
f2a12634a4 increment build number (build 609) 2022-07-09 11:51:35 +00:00
sunxyw
8d33f45388 update api docs 2022-07-09 11:51:33 +00:00
sunxyw
cb7e230214 Merge pull request #135 from zhamao-robot/replace-console-with-logger
替换 zhamao/console 为 zhamao/logger
2022-07-09 19:50:18 +08:00
sunxyw
badd05a014 skip unfit tests for now 2022-06-09 00:25:17 +08:00
sunxyw
47ffe9a2ec temporarily fix logger infinite loop 2022-06-09 00:20:58 +08:00
sunxyw
4fe74eb5fe replace console with logger 2022-06-08 23:14:25 +08:00
sunxyw
1c40896dc0 increment build number (build 608) 2022-05-31 08:34:45 +00:00
sunxyw
872b4ce1c6 update api docs 2022-05-31 08:34:43 +00:00
sunxyw
c0fed1a391 Merge pull request #133 from zhamao-robot/fix-adapter-overflow
修复 OneBot11Adapter 无限回调溢出及其他小补丁
2022-05-31 16:33:40 +08:00
sunxyw
d1f584e490 fix phpstan false positive in ModuleUnpacker 2022-05-31 00:58:44 +08:00
sunxyw
79f5011d58 fix adapter overflow 2022-05-31 00:52:15 +08:00
sunxyw
e350edd41f fix container example command not working 2022-05-31 00:51:53 +08:00
sunxyw
23a6e56478 fix logger constructor 2022-05-31 00:51:26 +08:00
sunxyw
80050f11f2 increment build number (build 607) 2022-05-28 09:33:44 +00:00
sunxyw
25c46cc978 update api docs 2022-05-28 09:33:43 +00:00
sunxyw
458c42ae7c optimize container services register (#129)
* optimize container services register

* fix ConnectionObject not exists

* fix phpdoc
2022-05-28 17:33:01 +08:00
sunxyw
febeeadc7b increment build number (build 606) 2022-05-24 06:37:35 +00:00
sunxyw
044643559d Merge pull request #131 from zhamao-robot/refactor-framework-entry
轻量重构 Framework 类
2022-05-24 14:36:35 +08:00
sunxyw
782e668abf improve remote terminal logging 2022-05-23 11:54:07 +08:00
sunxyw
fa6af88566 fix dynamic logger call 2022-05-23 11:52:02 +08:00
sunxyw
c106c4fc2a cleanup framework class logging 2022-05-23 11:52:01 +08:00
sunxyw
09780f64de refactor framework class logging 2022-05-23 11:52:01 +08:00
sunxyw
81d4558b2f add master support for logger 2022-05-23 11:52:01 +08:00
sunxyw
3de0e37fd5 increment build number (build 605) 2022-05-23 01:52:21 +00:00
sunxyw
fcfd2f8ba5 update api docs 2022-05-23 01:52:19 +00:00
sunxyw
7e7e461237 remove deprecated global functions (#130) 2022-05-23 09:51:26 +08:00
sunxyw
2afab030bd increment build number (build 604) 2022-05-16 15:28:58 +00:00
sunxyw
5cbeee6e86 add logging config (#127) 2022-05-16 23:28:02 +08:00
sunxyw
87bbffefc3 increment build number (build 603) 2022-05-15 17:53:12 +00:00
sunxyw
a2877cab70 Merge pull request #126 from zhamao-robot/add-phpstan-extensions
添加 PHPStan 相关扩展
2022-05-16 01:52:30 +08:00
sunxyw
4f10b6dbc3 fix use of deprecated methods 2022-05-15 16:40:12 +08:00
sunxyw
24a213a8ff drop use of deprecated DBAL iterator 2022-05-15 16:39:26 +08:00
sunxyw
cf21044cf7 add phpunit extensions 2022-05-15 16:38:37 +08:00
crazywhalecc
289a5d7051 increment build number (build 602) 2022-05-14 17:17:29 +00:00
crazywhalecc
b5ae76d298 update api docs 2022-05-14 17:17:27 +00:00
Jerry Ma
598cf60e10 Merge pull request #125 from zhamao-robot/v3-refactor-command
框架V3部分重构
2022-05-15 01:16:39 +08:00
crazywhalecc
c4ca2103e4 fix phpunit-swoole class name 2022-05-15 00:16:01 +08:00
crazywhalecc
4b55a3e525 add $ZM_CUSTOM_PHP_PATH env support 2022-05-14 23:52:37 +08:00
crazywhalecc
376b81f841 change another table printer 2022-05-14 23:51:47 +08:00
crazywhalecc
ee6035c59a add openswoole support 2022-05-14 23:51:17 +08:00
crazywhalecc
a757330788 move process state related function to ProcessManager 2022-05-14 23:43:15 +08:00
crazywhalecc
bf141202f8 change worker start message 2022-05-14 23:42:15 +08:00
crazywhalecc
1be3127177 use zhamao/logger table printer instead 2022-05-14 23:41:24 +08:00
crazywhalecc
c74a43cd74 remove and refactor daemon/server command, add useful messages 2022-05-14 23:40:22 +08:00
crazywhalecc
1b520d3c96 add zhamao/logger dependency 2022-05-14 23:20:58 +08:00
sunxyw
b7418a2a3a fix increment build number wrong branch 2022-05-10 17:55:06 +08:00
Jerry Ma
eee67cdb53 Merge pull request #124 from zhamao-robot/refactor-zmconfig
重构 ZMConfig
2022-05-10 17:04:20 +08:00
crazywhalecc
1d70bc4ed7 change risky test 2022-05-10 16:03:37 +08:00
crazywhalecc
d06b0dd6d6 change include_once to require 2022-05-10 14:53:23 +08:00
crazywhalecc
cbbac0554e fix Console debug for ZMConfig get 2022-05-10 01:04:18 +08:00
crazywhalecc
5f16766997 update errcode docs 2022-05-10 00:32:42 +08:00
crazywhalecc
dcd6cae0f6 add global function is_assoc_array 2022-05-10 00:32:20 +08:00
crazywhalecc
cc43993d5b MessageUtilTest use smaller image to boost 2022-05-10 00:31:40 +08:00
crazywhalecc
2478ffe331 fix WorkerStop read global config bug 2022-05-10 00:31:03 +08:00
crazywhalecc
18ae960f86 refactor ZMConfig 2022-05-10 00:30:33 +08:00
sunxyw
fcb226e357 increment build number (build 601) 2022-05-09 16:53:51 +08:00
sunxyw
58c04b7a7b fix incorrect build branch 2022-05-09 16:42:34 +08:00
sunxyw
a6401fa9ef add adapter feature (#121) 2022-05-09 16:39:09 +08:00
sunxyw
2481124ada update workflows for future develop (#123)
* update workflows for future develop

* fix updated build id path
2022-05-09 16:36:32 +08:00
crazywhalecc
488fde47e5 create 3.x main branch and move VERSION constants 2022-05-08 21:15:16 +08:00
570 changed files with 12465 additions and 34243 deletions

21
.gitattributes vendored Normal file
View File

@@ -0,0 +1,21 @@
# Exclude build/test files from archive (reduce package size)
/.github export-ignore
/.phive export-ignore
/build export-ignore
/docs export-ignore
/ext export-ignore
/resources export-ignore
/tests export-ignore
/tests_old export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/captainhook.json export-ignore
/install-runtime.sh export-ignore
/package.json export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
# Configure diff output
*.php diff=php

43
.github/workflows/coding-style.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
name: Code Style
on:
push:
pull_request:
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: same_content_newer
skip_after_successful_duplicate: true
paths: '["src/**", "tests/**"]'
do_not_skip: '["workflow_dispatch", "schedule"]'
cs-fix:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Code Style
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup PHP
uses: sunxyw/workflows/setup-environment@main
with:
php-version: 8.0
php-extensions: swoole, posix, json
operating-system: ubuntu-latest
use-cache: true
- name: Code Style
uses: sunxyw/workflows/coding-style@main

View File

@@ -3,7 +3,7 @@ name: Increment Build Number
on:
pull_request:
branches:
- master
- main
types:
- closed
paths:
@@ -16,54 +16,46 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
- name: Setup PHP
uses: "shivammathur/setup-php@v2"
uses: sunxyw/workflows/setup-environment@main
with:
php-version: '8.1'
extensions: swoole, posix, json
php-version: 8.1
php-extensions: swoole, posix, json
operating-system: ubuntu-latest
use-cache: true
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Prepare Doxygen
id: prepare-doxygen
continue-on-error: true
run: bin/prepare-doxygen before
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Generate Doxygen
if: steps.prepare-doxygen.outcome == 'success'
uses: mattnotmitt/doxygen-action@v1.9.5
- name: Cache dependencies
uses: actions/cache@v2
- name: Finishing Doxygen
if: steps.prepare-doxygen.outcome == 'success'
run: bin/prepare-doxygen after
- name: Commit API Docs
uses: stefanzweifel/git-auto-commit-action@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: "composer install --prefer-dist --no-progress --optimize-autoloader"
- name: Generate API Docs
id: generate-api-docs
continue-on-error: true
run: bin/gendoc
- name: Commit api docs
if: steps.generate-api-docs.outcome == 'success'
continue-on-error: true
run: |
git config --global user.name 'Github Build Bot'
git config --global user.email 'noreply@github.com'
git add docs
git commit -m "update api docs"
git push
commit_message: update api docs
branch: ${{ github.base_ref }}
- name: Increment build number
run: sed -i -r 's/(.*)(\VERSION_ID\s=\s)([0-9]+)(.*)/echo "\1\2$((\3+1))\4"/ge' src/ZM/ConsoleApplication.php
id: increment-build-number
run: |
sed -i -r 's/(.*)(\VERSION_ID\s=\s)([0-9]+)(.*)/echo "\1\2$((\3+1))\4"/ge' src/ZM/Framework.php
BUILD_ID=$(cat src/ZM/Framework.php | grep "VERSION_ID = " | sed 's/[^0-9]//g')
echo "::set-output name=build_id::$BUILD_ID"
- name: Commit build number
run: |
BUILD_ID=$(cat src/ZM/ConsoleApplication.php | grep "VERSION_ID = " | sed 's/[^0-9]//g')
git config --global user.name 'Github Build Bot'
git config --global user.email 'noreply@github.com'
git add src/ZM/ConsoleApplication.php
git commit -m "increment build number (build $BUILD_ID)"
git push
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: increment build number (build ${{ steps.increment-build-number.outputs.build_id }})
branch: ${{ github.base_ref }}

View File

@@ -1,101 +0,0 @@
name: Integration and Style Test
on:
push:
branches:
- master
paths:
- '**/**.php'
pull_request:
branches:
- master
types:
- opened
- synchronize
- reopened
- ready_for_review
- review_requested
paths:
- '**/**.php'
jobs:
integration:
name: Integration Test (PHP ${{ matrix.php-versions }}) (OS ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ "ubuntu-latest", "macos-latest" ]
php-versions: [ "7.2", "7.3", "7.4", "8.0", "8.1" ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: "shivammathur/setup-php@v2"
with:
php-version: ${{ matrix.php-versions }}
extensions: swoole, posix, json
env:
SWOOLE_CONFIGURE_OPTS: --enable-openssl
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Validate composer.json
run: "composer validate --strict"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: "composer install --prefer-dist --no-progress --optimize-autoloader"
- name: Run Static Analysis
run: "composer analyse"
- name: Run PHPUnit
run: "composer test"
cs-check:
name: PHP CS Fixer Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP 7.2
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.2"
extensions: swoole, posix, json
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Validate composer.json
run: "composer validate --strict"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: "composer install --prefer-dist --no-progress --optimize-autoloader"
- name: Run PHP CS Fixer Check
run: "composer cs-fix -- --dry-run --diff"

43
.github/workflows/static-analysis.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
name: Static Analysis
on:
push:
pull_request:
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: same_content_newer
skip_after_successful_duplicate: true
paths: '["src/**", "tests/**"]'
do_not_skip: '["workflow_dispatch", "schedule"]'
analyse:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Static Analysis
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup PHP
uses: sunxyw/workflows/setup-environment@main
with:
php-version: 8.0
php-extensions: swoole, posix, json
operating-system: ubuntu-latest
use-cache: true
- name: Static Analysis
uses: sunxyw/workflows/static-analysis@main

55
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,55 @@
name: Test
on:
push:
branches:
- main
- develop
- '*-dev*'
pull_request:
types:
- opened
- reopened
- review_requested
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: same_content_newer
skip_after_successful_duplicate: true
paths: '["src/**", "tests/**", "bin/phpunit-zm"]'
do_not_skip: '["workflow_dispatch", "schedule"]'
test:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
strategy:
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-latest ]
php-version: [ 8.0, 8.1, 8.2 ]
name: PHP ${{ matrix.php-version }} Test (${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup PHP
uses: sunxyw/workflows/setup-environment@main
with:
php-version: ${{ matrix.php-version }}
php-extensions: swoole, posix, json
operating-system: ${{ matrix.operating-system }}
use-cache: true
- name: Test
uses: sunxyw/workflows/test@main

View File

@@ -2,7 +2,7 @@ name: Docs and Script Auto Deploy
on:
push:
branches:
- master
- main
paths:
- 'docs/**'
- 'ext/**'
@@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Deploy docs to GitHub Pages
uses: jenkey2011/vuepress-deploy@master
@@ -32,12 +32,20 @@ jobs:
SOURCE: "deploy/"
REMOTE_HOST: ${{ secrets.ZHAMAO_XIN_HOST }}
REMOTE_USER: ${{ secrets.ZHAMAO_XIN_USER }}
TARGET: ${{ secrets.ZHAMAO_XIN_TARGET }}
TARGET: ${{ secrets.FRAMEWORK_ZHAMAO_XIN_TARGET }}
- name: deploy script file
uses: wlixcc/SFTP-Deploy-Action@v1.0
uses: wlixcc/SFTP-Deploy-Action@v1.2
with:
username: ${{ secrets.ZHAMAO_XIN_USER }}
server: ${{ secrets.ZHAMAO_XIN_HOST }}
ssh_private_key: ${{ secrets.ZHAMAO_XIN_PRIVATE_KEY }}
local_path: './ext/go.sh'
remote_path: ${{ secrets.ZHAMAO_XIN_MAIN_TARGET }}
- name: deploy script file
uses: wlixcc/SFTP-Deploy-Action@v1.2
with:
username: ${{ secrets.ZHAMAO_XIN_USER }}
server: ${{ secrets.ZHAMAO_XIN_HOST }}
ssh_private_key: ${{ secrets.ZHAMAO_XIN_PRIVATE_KEY }}
local_path: './ext/v3.sh'
remote_path: ${{ secrets.ZHAMAO_XIN_MAIN_TARGET }}

9
.gitignore vendored
View File

@@ -7,7 +7,9 @@
/tmp/
/temp/
/site/
/plugins/
/doxy/
/walle/
# 框架审计文件
audit.log
@@ -78,3 +80,8 @@ package-lock.json
### ASDF ###
/.tool-version
.DS_Store
### PHP CS Fixer ###
.php-cs-fixer.cache

View File

@@ -6,80 +6,71 @@ declare(strict_types=1);
* @since 2.7.0
*/
$rules = [
'@PSR12' => true,
'@Symfony' => true,
'@PhpCsFixer' => true,
'array_syntax' => [
'syntax' => 'short',
],
'list_syntax' => [
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one',
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'constant_case' => [
'case' => 'lower',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_static_reference' => true,
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => false,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
'phpdoc_summary' => false,
'php_unit_test_class_requires_covers' => false,
'global_namespace_import' => false,
'phpdoc_order' => false,
];
if (PHP_VERSION_ID > 70400) {
$rules['no_useless_concat_operator'] = false;
}
// 'no_useless_concat_operator' => false,
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules($rules)
->setRules([
'@PSR12' => true,
'@Symfony' => true,
'@PhpCsFixer' => true,
'array_syntax' => [
'syntax' => 'short',
],
'list_syntax' => [
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one',
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'constant_case' => [
'case' => 'lower',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_static_reference' => true,
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => false,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
'phpdoc_summary' => false,
'php_unit_test_class_requires_covers' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
)
->setUsingCache(false);
->in(__DIR__ . '/config')
->in(__DIR__ . '/bin')
);

11
.phpstorm.meta.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace PHPSTORM_META {
use OneBot\V12\Object\Event\OneBotEvent;
use ZM\Context\Context;
override(Context::__call(0), map([
'getBotEvent' => OneBotEvent::class,
]));
}

View File

@@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Reload Zhamao Server" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="./zhamao server:reload &amp;&amp; exit" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>

View File

@@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Zhamao Server" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="./zhamao server" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="./zhamao" />
<option name="SCRIPT_OPTIONS" value="server" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>

View File

@@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run watcher" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="bin/watcher" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>

View File

@@ -1,17 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Stop Zhamao Server" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="./zhamao server:stop &amp;&amp; exit" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>

68
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,68 @@
# 炸毛框架贡献指南
首先很高兴你愿意读这篇文章,因为我们需要更多的开发者来帮助我们开发和维护。
如果你还没加入我们的 [QQ 群670821194][qq-group],我们建议你加入一下,以便和其他开发者实时交流和协作。
## 测试
我们目前采用 PHPUnit 作为测试框架,如果你编写了新的功能或改变了现有的行为,我们希望你可以编写相应的测试代码。
## 提交变更
请使用 [GitHub Pull Request][new-pr] 提交你的更改,并附上恰当的说明(例如一个简明的列表列出所作的改动)。
同时,请不要忘记在提交前执行代码格式检查 `composer cs-fix` 和静态分析检查 `composer analyse`
。虽然我们的自动化流程会在你推送到仓库后自动运行检查,但我仍然建议你提前在本地运行,以节省可能的修改成本。
对了,请尽量为你的每个函数、方法加上 PHPDoc 注释。
## 具体贡献流程
#### **你发现了个 BUG**
- **如果你发现的是安全漏洞,请不要在 GitHub 上回报!** 请直接联系 [@crazywhalecc](https://github.com/crazywhalecc)。
- **确保该问题还没被其他人回报。** 你可以在 [Issue 列表][issues] 中搜索相关关键词来检查。
- 如果你没能找到一个已有的 Issue 来描述你遇到的问题,[请新建一个 Issue][new-issue]。请务必包含**标题和清晰的描述**
,尽可能多的相关信息,以及一个**代码示例**或者一个**可执行的测试用例**,来描述你遇到的问题。
- 如果可以的话,请使用相关的 Issue 模板来创建 Issue。
#### **你修复了个 BUG**
- 在 GitHub 上提交一个 Pull Request。
- 确保 PR 的描述清楚地描述了问题和解决方案。如果有相关的 Issue请在 PR 描述中包含 Issue 编号。
#### **你想添加新功能或改变现有功能?**
- 虽然你可以直接提交 PR但我们建议你先与我们的开发者讨论你的想法以避免你的努力白费。你可以在 [QQ 群][qq-group]
中与我们的开发者交流,或者在 [GitHub Issue][issues] 中提出你的想法。
- 如果你的想法被采纳,你可以在 GitHub 上[提交一个 Pull Request][new-pr]。
#### **你对源码有疑问?**
- 你可以在 [QQ 群][qq-group] 中与我们的开发者讨论,或者你也可以在 [GitHub Issue][issues] 中提出你的疑问。
#### **你想为文档做贡献?**
- 非常欢迎^^
- 你可以直接[提交一个 Pull Request][new-pr]。
炸毛框架是由志愿开发者共同维护的项目。我们欢迎你加入我们的开发。
感谢~ :heart: :heart: :heart:
炸毛框架开发团队
[issues]: https://github.com/zhamao-robot/zhamao-framework/issues
[new-pr]: https://github.com/zhamao-robot/zhamao-framework/pull/new/master
[new-issue]: https://github.com/zhamao-robot/zhamao-framework/issues/new
[qq-group]: https://jq.qq.com/?_wv=1027&k=KdIGy0UK

View File

@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Copyright 2022 CrazyBot Developer Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@@ -1,15 +1,15 @@
<div align="center">
<img src="https://cdn.jsdelivr.net/gh/zhamao-robot/zhamao-framework/resources/images/logo_trans.png" width = "150" height = "150" alt="炸毛框架"><br>
<h2>炸毛框架</h2>
炸毛框架 (zhamao-framework) 是一个协程高性能的聊天机器人 + Web 服务器开发框架<br><br>
炸毛框架 (zhamao-framework) 是一个高性能的聊天机器人 + Web 服务器开发框架<br><br>
<p align="center">
<a href="https://onebot.dev/">
<img src="https://img.shields.io/badge/OneBot-11-black?style=flat-square" alt="OneBot">
<img src="https://img.shields.io/badge/OneBot-12-black?style=flat-square" alt="OneBot">
</a>
<a href="https://github.com/zhamao-robot/zhamao-framework/actions">
<img src="https://img.shields.io/github/workflow/status/zhamao-robot/zhamao-framework/Integration%20and%20Style%20Test?label=Test&style=flat-square" alt="Integration Test">
<img src="https://img.shields.io/github/actions/workflow/status/zhamao-robot/zhamao-framework/test.yml?branch=v3-develop&label=Test&style=flat-square" alt="Integration Test">
</a>
<a href="https://packagist.org/packages/zhamao/framework">
@@ -24,19 +24,8 @@
<img src="https://img.shields.io/github/license/zhamao-robot/zhamao-framework?label=License&style=flat-square" alt="开源协议">
</a>
<a href="https://wpa.qq.com/msgrd?v=3&uin=627577391&site=qq&menu=yes">
<img src="https://img.shields.io/badge/作者QQ-627577391-orange?style=flat-square" alt="作者QQ">
</a>
<br>
<br>
<a href="https://github.com/zhamao-robot/zhamao-framework/search?q=AnnotationBase">
<img src="https://img.shields.io/github/search/zhamao-robot/zhamao-framework/AnnotationBase?label=Annotations&style=flat-square" alt="注解数量">
</a>
<a href="https://github.com/zhamao-robot/zhamao-framework/search?q=TODO">
<img src="https://img.shields.io/github/search/zhamao-robot/zhamao-framework/TODO?label=TODO&style=flat-square" alt="TODO">
<img src="https://img.shields.io/github/search/zhamao-robot/zhamao-framework/TODO?label=TODO%20Counter&style=flat-square" alt="TODO">
</a>
</p>
@@ -46,44 +35,38 @@
**如果有愿意一起开发框架本身的开发者,请提出 PR 或 Issue 参与开发!如果对框架本身的核心设计有更好的想法,可与作者成立开发组(目前仅 2 人),参与 OneBot V12 生态和框架本身的开发。**
**3.0已进入Alpha阶段**
**相关正在进行的版本任务见 Projects 一栏!**
## 简介
炸毛框架使用 PHP 编写,采用 Swoole 扩展为基础,主要面向 API 服务,聊天机器人OneBot 兼容的 QQ 机器人对接),包含 Websocket、HTTP
炸毛框架使用 PHP 编写,主要面向 API 服务,聊天机器人,包含 Websocket、HTTP
等监听和请求库,用户代码采用模块化处理,使用注解可以方便地编写各类功能。
框架主要用途为 HTTP 服务器,机器人搭建框架。尤其对于 QQ 机器人消息处理较为方便和全面,提供了众多会话机制和内部调用机制,可以以各种方式设计你自己的模块
框架主要用途为 HTTP 服务器,机器人搭建框架。尤其对于聊天机器人消息处理较为方便和全面,提供了众多会话机制和内部调用机制,可以以各种方式设计你自己的插件
```php
/**
* @CQCommand("你好")
*/
public function hello() {
ctx()->reply("你好,我是炸毛!"); // 简单的命令式回复
#[\BotCommand('你好')]
public function hello(\BotContext $ctx) {
$ctx->reply("你好,我是炸毛!"); // 简单的命令式回复
}
/**
* @RequestMapping("/index")
*/
#[\Route('/index')]
public function index() {
return "<h1>hello!</h1>"; // 快速的 HTTP 服务开发
}
```
> 从 2.7.0 版本开始,框架已支持同时使用 Annotation 和原生 Attribute 注解,供开发者根据需要自由选用。
## 开始
框架目前支持 Linux、WSL、macOS 环境直接运行,上述环境可直接使用下方一键安装脚本。
框架目前支持 Linux、WSL、macOS、Windows 环境直接运行,其中 Linux、macOS 环境可直接使用下方一键安装脚本。
> 如果你想在其他环境安装部署,可使用 Docker、Cygwin,详见文档。
> 如果你想在其他环境安装部署,可使用 Docker 快速部署或手动安装环境后安装框架,详见文档。
```bash
# 检测PHP环境、安装框架
bash <(curl -fsSL https://zhamao.xin/go.sh)
# Linux、macOS 下一键检测 PHP 环境、安装框架
bash <(curl -fsSL https://zhamao.xin/v3.sh)
# 启动框架
cd zhamao-app
cd zhamao-v3
./zhamao server
```
@@ -92,17 +75,17 @@ cd zhamao-app
```bash
# 脚本默认会检测系统的PHP如果想直接跳过检测安装独立的PHP版本则添加此环境变量
export ZM_NO_LOCAL_PHP="yes"
# 脚本如果安装独立版本PHP默认版本为8.0,如果想使用其他版本,则添加此环境变量指定版本
export ZM_DOWN_PHP_VERSION="8.1"
# 脚本如果安装独立版本PHP默认版本为8.1,如果想使用其他版本,则添加此环境变量指定版本
export ZM_DOWN_PHP_VERSION="8.2"
# 脚本默认会将框架在当前目录下的 `zhamao-app` 目录进行安装,如果想使用其他目录,则添加此环境变量
export ZM_CUSTOM_DIR="my-custom-app"
# 脚本默认会对本项目使用阿里云国内加速镜像如果想使用packagist源则添加此环境变量
export ZM_COMPOSER_PACKAGIST="yes"
# 执行完前面的环境变量再执行一键安装脚本,就可以实现自定义参数!
bash <(curl -fsSL https://zhamao.xin/go.sh)
bash <(curl -fsSL https://zhamao.xin/v3.sh)
```
关于其他安装方式,请参阅[文档](https://framework.zhamao.xin/guide/installation.html) 。
关于其他安装方式,请参阅 [文档](https://framework.zhamao.xin/guide/installation.html) 。
## 文档
@@ -113,28 +96,20 @@ bash <(curl -fsSL https://zhamao.xin/go.sh)
## 特点
- 原生支持多个机器人客户端同时连接
- 使用 Swoole 多工作进程机制和协程加持,尽可能简单的情况下提升了性能
- 灵活的注解事件绑定机制,可同时使用 Annotation 和原生 Attribute 注解
- 易用的上下文,模块内随处可
- 采用模块化编写,可自由搭配其他 Composer 组件,也可单文件面向过程编写
- 完善的插件系统,可编写插件后打包或分发,供他人使
- 采用插件化编写,可自由搭配其他 Composer 组件,也可单文件面向过程编写
- 支持模块打包、热加载,分享模块更方便
- 常驻内存,全局缓存变量随处使用,提供多种缓存方案
- 自带 MySQL、Redis 等数据库连接池等数据库连接方案
- 自带 MySQL、SQLite、Redis 等数据库连接池
- 本身为 HTTP 服务器、WebSocket 服务器,可以构建属于自己的 HTTP API 接口
- 静态文件服务器,可将前端合并到一起
- 自带 PHP + Swoole 环境无需手动编译安装by [crazywhalecc/static-php-cli](https://github.com/crazywhalecc/static-php-cli)
## 下载源码
框架源码可直接克隆本仓库进行编辑,如果你在国内,访问 GitHub 和克隆仓库比较慢,可以将 `github.com` 替换为 `fgit.zhamao.me` 进行加速。
例如:`git clone https://fgit.zhamao.me/zhamao-robot/zhamao-framework.git --depth 1`
- 可选自带 PHP 环境无需手动编译安装by [crazywhalecc/static-php-cli](https://github.com/crazywhalecc/static-php-cli)
## 贡献和捐赠
如果你在使用过程中发现任何问题,可以提交 Issue 或自行 Fork 后修改并提交 Pull Request。
目前项目仅人维护,耗费精力较大,所以非常欢迎对框架的贡献。
目前项目仅人维护,耗费精力较大,所以非常欢迎对框架的贡献。
本项目为作者闲暇时间开发,如果觉得好用,不妨进行捐助~你的捐助会让我更加有动力完善插件,感谢你的支持!
@@ -152,12 +127,11 @@ bash <(curl -fsSL https://zhamao.xin/go.sh)
作者的炸毛机器人已从2018年初起稳定运行了**五年**,并且持续迭代。
欢迎随时在 HTTP-API 插件群里提问,当然更好的话可以加作者 QQ[627577391](http://wpa.qq.com/msgrd?v=3&uin=627577391&site=qq&menu=yes)
或提交 [Issue](https://github.com/zhamao-robot/zhamao-framework/issues/new/choose) 进行疑难解答。
可以提交 [Issue](https://github.com/zhamao-robot/zhamao-framework/issues/new/choose) 或 [加群(670821194)](https://jq.qq.com/?_wv=1027&k=YkNI3AIr) 进行疑难解答。
本项目在更新内容时,请及时关注 GitHub 动态,更新前请将自己的模块代码做好备份。
本项目在更新内容时,请及时关注 GitHub 动态,更新前请将自己的插件或项目代码做好备份。
项目框架采用 Apache-2.0 协议开源,在分发或重写修改等操作时需遵守协议。项目模块部分(`Module` 文件夹) 在非借鉴框架内代码时可不遵守 Apache-2.0 协议进行分发和修改(声明版权)。
项目框架采用 Apache-2.0 协议开源,在分发或重写修改等操作时需遵守协议。项目插件部分(`src/Globals``src/ZM` 文件夹外的其他文件夹) 在非借鉴框架内代码时可不遵守 Apache-2.0 协议进行分发和修改(声明版权)。
**注意**:在你使用 mirai 等 `AGPL-3.0` 协议的机器人软件与框架连接时,使用本框架需要将你编写或修改的部分使用 `AGPL-3.0` 协议重新分发。
@@ -167,6 +141,6 @@ bash <(curl -fsSL https://zhamao.xin/go.sh)
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/PhpStorm.svg" width="300">
感谢 [php-libonebot](https://github.com/botuniverse/php-libonebot) 开发者 @sunxyw 中为项目开发规范化提出的一些建议。
感谢开发者 @sunxyw 中为项目开发规范化提出的一些建议。
<!-- ![star](https://starchart.cc/zhamao-robot/zhamao-framework.svg) -->
![star](https://starchart.cc/zhamao-robot/zhamao-framework.svg)

View File

@@ -1,401 +0,0 @@
#!/usr/bin/env php
<?php
/**
* 决定是否忽略该类
*
* @param ReflectionClass $class 准备生成的类的反射类
*/
function should_ignore_class(ReflectionClass $class): bool
{
// 注解类
if (($doc = $class->getDocComment()) && strpos($doc, '@Annotation') !== false) {
return true;
}
if (str_ends_with($class->getName(), 'Exception')) {
return true;
}
if (str_contains($class->getName(), '_')) {
return true;
}
return false;
}
if (PHP_VERSION_ID < 70400) {
echo 'PHP 版本必须为 7.4 或以上';
exit(1);
}
function check_composer_executable(string $composer): bool
{
passthru($composer . ' --version 2>/dev/null', $exit_code);
return $exit_code === 0;
}
function find_valid_root(string $current_dir, int $max_loop): string
{
if ($max_loop <= 0) {
return '';
}
if (!file_exists($current_dir . '/composer.json')) {
return find_valid_root(dirname($current_dir), $max_loop - 1);
}
return $current_dir;
}
$root = find_valid_root(getcwd(), 3);
if (empty($root)) {
echo '找不到有效的根目录';
exit(1);
}
echo '根目录: ' . $root . PHP_EOL;
chdir($root);
if (!is_dir($root . '/src/ZM')) {
echo '源码目录不存在';
exit(1);
}
$phpdoc_package_temp_installed = false;
if (file_exists($root . '/vendor/jasny/phpdoc-parser/composer.json')) {
echo '正在使用现有的 PHPDoc 解析库' . PHP_EOL;
} else {
echo 'PHPDoc 解析库不存在,正在尝试安装...' . PHP_EOL;
echo '本次生成完成后将会自动移除' . PHP_EOL;
$composers = [
'runtime/composer', 'composer', 'php composer.phar',
];
foreach ($composers as $composer) {
if (check_composer_executable($composer)) {
echo '正在使用 ' . $composer . ' 安装 PHPDoc 解析库,请稍候...' . PHP_EOL;
passthru("{$composer} require --quiet jasny/phpdoc-parser", $exit_code);
if ($exit_code === 0) {
$phpdoc_package_temp_installed = true;
break;
}
}
}
if (!$phpdoc_package_temp_installed) {
echo '安装失败请手动安装composer require jasny/phpdoc-parser' . PHP_EOL;
exit(1);
}
}
// 从这里开始是主要生成逻辑
require_once $root . '/vendor/autoload.php';
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
use Jasny\PhpdocParser\Tag\Summery;
use ZM\Console\Console;
$opts = getopt('', ['show-warnings', 'show-debug']);
if (array_key_exists('show-warnings', $opts)) {
$show_warnings = true;
} else {
$show_warnings = false;
}
Console::init(array_key_exists('show-debug', $opts) ? 4 : 2);
$errors = [];
$warnings = [];
// 获取源码目录的文件遍历器
$fs = new \RecursiveDirectoryIterator($root . '/src/ZM', FilesystemIterator::SKIP_DOTS);
// 初始化文档解析器
$parser = new PhpdocParser(PhpDocumentor::tags()->with([
new Summery(),
]));
$metas = [];
$class_count = 0;
$method_count = 0;
function error(string $message)
{
global $errors;
$errors[] = $message;
Console::error($message);
}
function warning(string $message)
{
global $warnings, $show_warnings;
$warnings[] = $message;
if ($show_warnings) {
Console::warning($message);
}
}
/**
* 获取类的元数据
*
* 包括类的注释、方法的注释、参数、返回值等
*/
function get_class_metas(string $class_name, PhpdocParser $parser): array
{
// 尝试获取反射类
try {
$class = new \ReflectionClass($class_name);
} catch (\ReflectionException $e) {
error('无法获取类 ' . $class_name . ' 的反射类');
return [];
}
// 判断是否略过该类
if (should_ignore_class($class)) {
return [];
}
$metas = [];
// 遍历类方法
foreach ($class->getMethods() as $method) {
if ($method->getDeclaringClass()->getName() !== $class_name) {
continue;
}
Console::verbose('正在解析方法:' . $class_name . '::' . $method->getName());
// 获取方法的注释并解析
$doc = $method->getDocComment();
if (!$doc) {
warning('找不到文档:' . $class_name . '::' . $method->getName());
continue;
}
try {
$meta = $parser->parse($doc);
} catch (\Exception $e) {
error('解析失败:' . $class_name . '::' . $method->getName() . '' . $e->getMessage());
continue;
}
// 少数情况解析后会带有 */,需要去除
array_walk_recursive($meta, static function (&$item) {
if (is_string($item)) {
$item = trim(str_replace('*/', '', $item));
}
});
// 对比反射方法获取的参数和注释声明的参数
$parameters = $method->getParameters();
$params_in_doc = $meta['params'] ?? [];
foreach ($parameters as $parameter) {
$parameter_name = $parameter->getName();
// 不存在则添加进参数列表中
if (!isset($params_in_doc[$parameter_name])) {
$params_in_doc[$parameter_name] = [
'type' => $parameter->getType()?->getName(),
'description' => '',
];
}
}
// 确保所有参数都有对应的类型和描述
foreach ($params_in_doc as &$param) {
if (!isset($param['type'])) {
$param['type'] = 'mixed';
}
if (!isset($param['description'])) {
$param['description'] = '';
}
}
// 清除引用
unset($param);
$meta['params'] = $params_in_doc;
// 设定方法默认返回值
if (!isset($meta['return'])) {
$meta['return'] = [
'type' => $method->getReturnType()?->getName() ?: 'mixed',
'description' => '',
];
}
// 设定默认描述
if (!isset($meta['return']['description'])) {
$meta['return']['description'] = '';
}
$metas[$method->getName()] = $meta;
}
return $metas;
}
/**
* 将方法的元数据转换为 Markdown 格式
*
* @param string $method 方法名
* @param array $meta 元数据
*/
function convert_meta_to_markdown(string $method, array $meta): string
{
// 方法名作为标题
$markdown = '## ' . $method . "\n\n";
// 构造方法代码块
$markdown .= '```php' . "\n";
// TODO: 适配 private 等修饰符
$markdown .= 'public function ' . $method . '(';
$params = [];
// 添加参数
foreach ($meta['params'] as $param_name => $param_meta) {
$params[] = sprintf('%s $%s', $param_meta['type'] ?? 'mixed', $param_name);
}
$markdown .= implode(', ', $params) . ')';
// 添加返回值
$markdown .= ': ' . $meta['return']['type'];
$markdown .= "\n```\n\n";
// 方法描述
$markdown .= '### 描述' . "\n\n";
$markdown .= ($meta['description'] ?? '作者很懒,什么也没有说') . "\n\n";
// 参数
if (count($meta['params'])) {
$markdown .= '### 参数' . "\n\n";
$markdown .= '| 名称 | 类型 | 描述 |' . "\n";
$markdown .= '| -------- | ---- | ----------- |' . "\n";
foreach ($meta['params'] as $param_name => $param_meta) {
$markdown .= '| ' . $param_name . ' | ' . $param_meta['type'] . ' | ' . $param_meta['description'] . ' |' . "\n";
}
$markdown .= "\n";
}
// 返回值
$markdown .= '### 返回' . "\n\n";
$markdown .= '| 类型 | 描述 |' . "\n";
$markdown .= '| ---- | ----------- |' . "\n";
$markdown .= '| ' . $meta['return']['type'] . ' | ' . $meta['return']['description'] . ' |' . "\n";
return $markdown;
}
function generate_sidebar_config(string $title, array $items): array
{
return [
'title' => $title,
'collapsable' => true,
'children' => $items,
];
}
Console::info('开始生成!');
// 遍历类并将元数据添加至数组中
foreach (new \RecursiveIteratorIterator($fs) as $file) {
if (!$file->isFile()) {
continue;
}
$path = $file->getPathname();
// 过滤不包含类的文件
$tokens = token_get_all(file_get_contents($path));
$found = false;
foreach ($tokens as $k => $token) {
if (!is_array($token)) {
continue;
}
if ($token[0] === T_CLASS && $tokens[$k - 2][0] !== T_NEW) {
$found = true;
break;
}
if ($k >= 100) {
break;
}
}
if (!$found) {
continue;
}
// 获取完整类名
$path = ltrim($path, $root . '/');
$class = str_replace(['.php', 'src/', '/'], ['', '', '\\'], $path);
Console::verbose('正在解析类:' . $class);
$meta = get_class_metas($class, $parser);
// 忽略不包含任何方法的类
if (empty($meta)) {
continue;
}
$metas[$class] = $meta;
++$class_count;
$method_count += count($meta);
}
// 将元数据转换为 Markdown
$markdown = [];
foreach ($metas as $class => $class_metas) {
$markdown[$class] = [];
// 将类名作为页面大标题
$markdown[$class]['class'] = '# ' . $class;
foreach ($class_metas as $method => $meta) {
$markdown[$class][$method] = convert_meta_to_markdown($method, $meta);
}
}
// 生成文档
$docs = $root . '/docs/api/';
foreach ($markdown as $class => $methods) {
$file = $docs . str_replace('\\', '/', $class) . '.md';
// 确保目录存在
if (!file_exists(dirname($file)) && !mkdir($concurrent_directory = dirname($file), 0777, true) && !is_dir($concurrent_directory)) {
throw new \RuntimeException(sprintf('无法建立目录 %s', $concurrent_directory));
}
Console::verbose('正在生成文档:' . $file);
$text = implode("\n\n", $methods);
file_put_contents($file, $text);
}
// 生成文档目录
$children = array_keys($markdown);
$children = str_replace('\\', '/', $children);
$class_tree = [];
foreach ($children as $child) {
$parent = dirname($child);
$class_tree[$parent][] = $child;
}
ksort($class_tree);
$config = 'module.exports = [';
foreach ($class_tree as $parent => $children) {
$encode = json_encode(generate_sidebar_config($parent, $children));
$encode = str_replace('\/', '/', $encode);
$config .= $encode . ',';
}
$config = rtrim($config, ',');
$config .= ']';
$file = $root . '/docs/.vuepress/api.js';
file_put_contents($file, $config);
if (count($warnings)) {
Console::warning('生成过程中发现 ' . count($warnings) . ' 次警告');
if (!$show_warnings) {
Console::info('生成器默认忽略了警告,你可以通过 gendoc --show-warnings 来查看警告');
}
}
if (count($errors)) {
Console::error('生成过程中发现错误:');
foreach ($errors as $error) {
Console::error($error);
}
}
Console::success('API 文档生成完毕');
Console::success(sprintf('共生成 %d 个类,共 %d 个方法', $class_count, $method_count));
// 完成生成,进行善后
if ($phpdoc_package_temp_installed) {
echo '正在移除 PHPDoc 解析库,请稍候...' . PHP_EOL;
passthru('composer remove --quiet jasny/phpdoc-parser', $exit_code);
if ($exit_code !== 0) {
echo '移除失败请手动移除composer remove jasny/phpdoc-parser' . PHP_EOL;
}
echo '移除完成';
}
exit(0);

View File

@@ -1,111 +0,0 @@
#!/usr/bin/env php
<?php
/** For Swoole coroutine tests */
// 如果改成 true则会在终端显示所有炸毛框架的 Log
const ZM_TEST_LOG_DEBUG = false;
use PHPUnit\Runner\Version;
use PHPUnit\TextUI\TestRunner;
use Swoole\Coroutine;
use ZM\Annotation\Swoole\OnStart;
use ZM\Command\RunServerCommand;
use ZM\Console\Console;
use ZM\ConsoleApplication;
use ZM\Event\EventManager;
use ZM\Framework;
use ZM\Store\ZMAtomic;
use ZM\Utils\ZMUtil;
$root = dirname(__DIR__);
Coroutine::set([
'log_level' => SWOOLE_LOG_INFO,
'trace_flags' => 0,
]);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (PHP_VERSION_ID <= 70100) {
fwrite(
STDERR,
sprintf(
'This version of PHPUnit is supported on PHP 7.1 and above.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);
exit(1);
}
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'Asia/Shanghai');
}
require $root . '/vendor/autoload.php';
const ZM_VERSION_ID = ConsoleApplication::VERSION_ID;
const ZM_VERSION = ConsoleApplication::VERSION;
// 模拟define
const ZM_PROCESS_MASTER = 1;
const ZM_PROCESS_MANAGER = 2;
const ZM_PROCESS_WORKER = 4;
const ZM_PROCESS_USER = 8;
const ZM_PROCESS_TASKWORKER = 16;
define('FRAMEWORK_ROOT_DIR', $root);
define('WORKING_DIR', $root);
const SOURCE_ROOT_DIR = WORKING_DIR;
define('LOAD_MODE', is_dir(SOURCE_ROOT_DIR . '/src/ZM') ? 0 : 1);
chdir(__DIR__ . '/../');
$options = array_map(function ($x) {
return $x->getDefault();
}, RunServerCommand::exportDefinition()->getOptions());
$options['disable-safe-exit'] = true;
$options['worker-num'] = 1;
$options['private-mode'] = true;
$options['log-error'] = true;
spl_autoload_register(static function ($class) {
$map = [
TestRunner::class => 'vendor/phpunit/phpunit/src/TextUI/TestRunner.php',
Version::class => 'vendor/phpunit/phpunit/src/Runner/Version.php',
];
if (isset($map[$class])) {
$source = file_get_contents(SOURCE_ROOT_DIR . '/' . $map[$class]);
$source = str_replace(['#StandWith', 'Ukraine', 'declare(strict_types=1);'], '', $source);
eval('?>' . $source);
}
}, true, true);
Console::setLevel(0);
$framework = new Framework($options);
$start = new OnStart();
$start->method = function () {
try {
Console::setLevel(ZM_TEST_LOG_DEBUG ? 4 : 0);
$retcode = PHPUnit\TextUI\Command::main(false);
} finally {
Console::setLevel(0);
ZMUtil::stop(($retcode ?? 1) !== 0);
}
};
EventManager::addEvent(OnStart::class, $start);
$framework->start();
Swoole\Event::wait();
if (ZMAtomic::get('stop_signal')->get() === 2) {
exit(1);
}

65
bin/phpunit-zm Executable file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/env php
<?php
/** For Swoole coroutine tests */
// 如果改成 true则会在终端显示所有炸毛框架的 Log
const ZM_TEST_LOG_DEBUG = false;
use OneBot\Driver\Event\Process\WorkerStartEvent;
use PHPUnit\TextUI\Command;
use Swoole\Atomic;
use Tests\ZMResultPrinter;
use ZM\Command\Server\ServerStartCommand;
use ZM\Event\EventProvider;
use ZM\Framework;
use ZM\Logger\ConsoleLogger;
use ZM\Store\MockAtomic;
// 引入自动加载
require $_composer_autoload_path ?? dirname(__DIR__) . '/vendor/autoload.php';
// 声明一个全局的原子计数,用于保存整个进程的退出状态码
global $_swoole_atomic;
// Windows 没有 Swoole所以就使用了一个假的原子计数器反正 Windows 只有单进程
$_swoole_atomic = class_exists('\\Swoole\\Atomic') ? new Atomic() : new MockAtomic();
// 注册 Logger 等级
ob_logger_register(new ConsoleLogger(ZM_TEST_LOG_DEBUG ? 'debug' : 'error'));
// 使用框架自身的 EventProvider
global $ob_event_provider;
$ob_event_provider = new EventProvider();
// 注册一个最低级别的 WorkerStart 事件,用于在框架的事件初始化之后开始运行 PHPUnit
ob_event_provider()->addEventListener(WorkerStartEvent::getName(), function () {
register_shutdown_function(function () {
$error = error_get_last();
// 下面这段代码的作用就是,不是错误引发的退出时照常退出即可
if (($error['type'] ?? 0) != 0) {
logger()->emergency(zm_internal_errcode('E00027') . 'Internal fatal error: ' . $error['message'] . ' at ' . $error['file'] . "({$error['line']})");
}
Framework::getInstance()->stop();
});
$_SERVER['argv'][] = '--printer';
$_SERVER['argv'][] = ZMResultPrinter::class;
try {
// 不退出,而是返回 code
$retcode = Command::main(false);
} finally {
global $_swoole_atomic;
$_swoole_atomic->set($retcode ?? 0);
Framework::getInstance()->stop($retcode ?? 0);
}
}, 1);
try {
$options = ServerStartCommand::exportOptionArray();
$options['driver'] = 'workerman';
$options['worker-num'] = 1;
$options['private-mode'] = true;
(new Framework($options))->init()->start();
exit($_swoole_atomic->get());
} catch (Throwable $e) {
echo $e->getMessage() . PHP_EOL;
exit(1);
}

3
bin/phpunit-zm.bat Normal file
View File

@@ -0,0 +1,3 @@
@echo off
php %~dp0phpunit-zm %*

76
bin/prepare-doxygen Executable file
View File

@@ -0,0 +1,76 @@
#!/usr/bin/env php
<?php
function find_valid_root(string $current_dir, int $max_loop): string
{
if ($max_loop <= 0) {
return '';
}
if (!file_exists($current_dir . '/composer.json')) {
return find_valid_root(dirname($current_dir), $max_loop - 1);
}
return $current_dir;
}
$root = find_valid_root(getcwd(), 3);
if (empty($root)) {
echo '找不到有效的根目录';
exit(1);
}
chdir($root);
require_once $root . '/vendor/autoload.php';
// 获取参数,可为 before 或 after
$param = $argv[1] ?? 'before';
if ($param === 'before') {
// Doxyfile file source: https://pastebin.com/raw/N8tJ9kWE
// Posted by: sunxyw
// 从剪贴板获取 Doxyfile 内容并保存到临时文件
logger()->info('正在获取 Doxyfile 内容');
$doxyfile = file_get_contents('https://pastebin.com/raw/N8tJ9kWE');
$doxyfile = str_replace('<zm_version>', \ZM\Framework::VERSION, $doxyfile);
file_put_contents('Doxyfile', $doxyfile);
// 应用 Awesome 样式
// 来源https://github.com/jothepro/doxygen-awesome-css.git
// 优先使用本地文件
logger()->info('正在应用 Awesome 样式');
\ZM\Store\FileSystem::createDir('doxy/css');
if (
file_exists('doxy/css/doxygen-awesome.css') &&
(md5_file('doxy/css/doxygen-awesome.css') === '326a1447f9693d1b3876f59de837a7c0')
) {
logger()->info('本地 Awesome 样式文件已存在,跳过下载');
} else {
logger()->info('正在下载 Awesome 样式文件');
$cmd = [
'git clone https://github.com/jothepro/doxygen-awesome-css.git doxy/css',
'cd doxy/css',
'git checkout v2.1.0',
'cd ../..',
];
$cmd = implode(' && ', $cmd);
exec($cmd);
}
} elseif ($param === 'after') {
// 删除临时文件
unlink('Doxyfile');
// 清除旧文档
exec('rm -rf docs/.vuepress/public/doxy');
// 授予目录权限doxy/html
exec('sudo chmod -R 644 doxy/html');
// 移动新文档到 docs 目录
exec('mv doxy/html docs/.vuepress/public/doxy');
logger()->info('文档生成完成');
} else {
logger()->error('参数错误');
exit(1);
}

View File

@@ -5,7 +5,10 @@
# author: crazywhalecc
# since: 2.5.0
if [ -f "$(pwd)/runtime/php" ]; then
if [ "$ZM_CUSTOM_PHP_PATH" != "" ]; then
echo "* Using PHP executable: ""$ZM_CUSTOM_PHP_PATH"
executable="$ZM_CUSTOM_PHP_PATH"
elif [ -f "$(pwd)/runtime/php" ]; then
executable="$(pwd)/runtime/php"
echo "* Framework started with built-in php."
else
@@ -18,12 +21,6 @@ else
fi
fi
result=$(echo "$1" | grep -E "module|build")
if [ "$result" != "" ]; then
executable="$executable -d phar.readonly=off"
fi
if [ -f "$(pwd)/src/entry.php" ]; then
$executable "$(pwd)/src/entry.php" $@
elif [ -f "$(pwd)/vendor/zhamao/framework/src/entry.php" ]; then

27
bin/zhamao.bat Normal file
View File

@@ -0,0 +1,27 @@
@echo off
@REM Check if ZM_CUSTOM_PHP_PATH is set
IF /i "%ZM_CUSTOM_PHP_PATH%" neq "" (
@REM Set the path to the custom PHP
echo "* Using custom PHP executable: %ZM_CUSTOM_PHP_PATH%"
SET executable=%ZM_CUSTOM_PHP_PATH%
) ELSE IF exist ./runtime/php.exe (
@REM Set the path to the built-in PHP
echo "* Using built-in PHP executable"
SET executable=.\runtime\php.exe
) ELSE (
@REM Set the path to the system PHP
echo "* Using system PHP executable"
SET executable=php
)
IF exist src/entry.php (
@REM Run the PHP entry point
%executable% src/entry.php %*
) ELSE IF exist vendor/zhamao/framework/src/entry.php (
@REM Run the PHP entry point
%executable% vendor/zhamao/framework/src/entry.php %*
) ELSE (
@REM No entry point found
echo "[ErrCode:E00015] Cannot find zhamao-framework entry file!"
exit /b 1
)

47
captainhook.json Normal file
View File

@@ -0,0 +1,47 @@
{
"pre-push": {
"enabled": true,
"actions": [
{
"action": "composer analyse"
},
{
"action": "composer test"
}
]
},
"pre-commit": {
"enabled": true,
"actions": [
{
"action": "composer cs-fix -- --config=.php-cs-fixer.php --dry-run --diff {$STAGED_FILES|of-type:php}",
"conditions": [
{
"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType",
"args": ["php"]
}
]
}
]
},
"post-change": {
"enabled": true,
"actions": [
{
"action": "composer install",
"options": [],
"conditions": [
{
"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileChanged\\Any",
"args": [
[
"composer.json",
"composer.lock"
]
]
}
]
}
]
}
}

View File

@@ -13,34 +13,42 @@
}
],
"require": {
"php": "^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1",
"php": "^8.0 || ^8.1 || ^8.2",
"ext-json": "*",
"ext-posix": "*",
"ext-tokenizer": "*",
"doctrine/dbal": "^2.13.1",
"dragonmantank/cron-expression": "^3.3",
"jelix/version": "^2.0",
"koriym/attributes": "^1.0",
"nunomaduro/collision": "^6.3",
"onebot/libonebot": "^0.5",
"php-di/php-di": "^7",
"psr/container": "^2.0",
"psy/psysh": "^0.11.2",
"symfony/console": "~6.0 || ~5.0 || ~4.0 || ~3.0",
"psr/simple-cache": "^3.0",
"psy/psysh": "^0.11.8",
"symfony/console": "^6.0",
"symfony/polyfill-ctype": "^1.19",
"symfony/polyfill-mbstring": "^1.19",
"symfony/polyfill-php80": "^1.16",
"symfony/routing": "~6.0 || ~5.0 || ~4.0 || ~3.0",
"zhamao/config": "^1.0",
"zhamao/connection-manager": "^1.0",
"zhamao/console": "^1.0",
"zhamao/request": "^1.1"
"symfony/routing": "~6.0 || ~5.0 || ~4.0"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.8",
"captainhook/captainhook": "^5.12",
"friendsofphp/php-cs-fixer": "^3.2 != 3.7.0",
"jangregor/phpstan-prophecy": "^1.0",
"jetbrains/phpstorm-attributes": "^1.0",
"mikey179/vfsstream": "^1.6",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpunit/phpunit": "^8.5 || ^9.0",
"roave/security-advisories": "dev-latest",
"swoole/ide-helper": "^4.5"
},
"replace": {
"symfony/polyfill-php80": "*"
},
"suggest": {
"ext-ctype": "Use C/C++ extension instead of polyfill will be more efficient",
"ext-mbstring": "Use C/C++ extension instead of polyfill will be more efficient",
@@ -48,47 +56,37 @@
"ext-redis": "If you use Redis in framework, you will need this extension",
"league/climate": "Display columns and status in terminal"
},
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"ZM\\": "src/ZM"
},
"files": [
"src/ZM/global_functions.php"
"src/Globals/global_functions.php",
"src/Globals/global_defines_app.php",
"src/Globals/global_class_alias.php"
]
},
"autoload-dev": {
"psr-4": {
"Module\\": "src/Module",
"Custom\\": "src/Custom",
"Tests\\": "tests"
}
},
"bin": [
"bin/gendoc",
"bin/phpunit-swoole",
"bin/start"
"bin/phpunit-zm",
"bin/zhamao",
"bin/zhamao.bat"
],
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"optimize-autoloader": true,
"sort-packages": true
},
"extra": {
"hooks": {
"post-merge": "composer install",
"pre-commit": [
"echo committing as $(git config user.name)",
"composer cs-fix -- --diff"
],
"pre-push": [
"composer cs-fix -- --dry-run --diff",
"composer analyse"
]
},
"zm": {
"exclude-annotation-path": [
"src/ZM",
@@ -97,11 +95,9 @@
}
},
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add"
],
"post-autoload-dump": "vendor/bin/captainhook install -f -s",
"analyse": "phpstan analyse --memory-limit 300M",
"cs-fix": "php-cs-fixer fix",
"test": "bin/phpunit-swoole --no-coverage"
"cs-fix": "PHP_CS_FIXER_FUTURE_MODE=1 php-cs-fixer fix",
"test": "bin/phpunit-zm --no-coverage"
}
}

28
config/config.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* Config 配置类的配置文件
* 由于 Config 类是第一批被加载的类,因此本文件存在以下限制:
* 1. 只能使用 PHP 格式
* 2. 无法利用容器及依赖注入
* 3. 必须存在于本地,无法使用远程配置(后续版本可能会支持)
*/
return [
'repository' => [
\OneBot\Config\Repository::class, // 配置仓库,须实现 \OneBot\Config\RepositoryInterface 接口
[], // 传入的参数,依序传入构造函数
],
'loader' => [
\OneBot\Config\Loader\DelegateLoader::class, // 配置加载器,须实现 \OneBot\Config\LoaderInterface 接口
[], // 传入的参数,依序传入构造函数
],
'source' => [
'extensions' => ['php', 'yaml', 'yml', 'json', 'toml'], // 配置文件扩展名
'paths' => [
SOURCE_ROOT_DIR . '/config', // 配置文件所在目录
// 可以添加多个配置文件目录
],
],
];

28
config/container.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use OneBot\Driver\Driver;
use OneBot\Driver\Process\ProcessManager;
use Psr\Log\LoggerInterface;
use ZM\Framework;
/*
* 这里是容器的配置文件,你可以在这里配置容器的绑定和其他一些参数。
* 选用的容器是 PHP-DI你可以在这里查看文档https://php-di.org/doc/
* 我们建议你在使用容器前先阅读以下章节:
* - 基本使用方式https://php-di.org/doc/container.html
* - 注册绑定方式https://php-di.org/doc/php-definitions.html#definition-types
* - 最佳使用实践https://php-di.org/doc/best-practices.html
* 同时,你也可以选择查阅我们(炸毛框架)的相关文档,其会包含一些简单的使用方法和示例。
* 关于框架在不同事件(或周期中)默认注册的绑定,请参阅我们的文档,或直接查看 {@see \ZM\Container\ContainerRegistrant}
*/
return [
// 这里定义的是全局容器的绑定,不建议在此处直接调用框架、应用内部的类或方法,因为这些类可能还没有被加载或初始化
// 你可以使用匿名函数来延迟加载
'definitions' => [
'worker_id' => fn () => ProcessManager::getProcessId(),
Driver::class => fn () => Framework::getInstance()->getDriver(),
LoggerInterface::class => fn () => logger(),
],
];

View File

@@ -1,154 +1,125 @@
<?php
/** @noinspection PhpComposerExtensionStubsInspection */
declare(strict_types=1);
/* bind host */
$config['host'] = '0.0.0.0';
/* 启动框架的底层驱动(原生支持 swoole、workerman 两种) */
$config['driver'] = 'workerman';
/* bind port */
$config['port'] = 20001;
/* 框架开到公网或外部的HTTP访问链接通过 DataProvider::getFrameworkLink() 获取 */
$config['http_reverse_link'] = 'http://127.0.0.1:' . $config['port'];
/* 框架是否启动debug模式当debug模式为true时启用热更新需要安装inotify扩展 */
$config['debug_mode'] = false;
/* 存放框架内文件数据的目录 */
$config['zm_data'] = realpath(WORKING_DIR) . '/zm_data/';
/* 存放各个模块配置文件的目录 */
$config['config_dir'] = $config['zm_data'] . 'config/';
/* 存放崩溃和运行日志的目录 */
$config['crash_dir'] = $config['zm_data'] . 'crash/';
/* 对应swoole的server->set参数 */
$config['swoole'] = [
'log_file' => $config['crash_dir'] . 'swoole_error.log',
// 'worker_num' => swoole_cpu_num(), //如果你只有一个 OneBot 实例连接到框架并且代码没有复杂的CPU密集计算则可把这里改为1使用全局变量
'dispatch_mode' => 2, // 包分配原则,见 https://wiki.swoole.com/#/server/setting?id=dispatch_mode
'max_coroutine' => 300000,
'max_wait_time' => 5,
// 'task_worker_num' => 4,
// 'task_enable_coroutine' => true
/* 要启动的服务器监听端口及协议 */
$config['servers'] = [
[
'host' => '0.0.0.0',
'port' => 20001,
'type' => 'websocket',
],
[
'host' => '0.0.0.0',
'port' => 20002,
'type' => 'http',
'flag' => 20002,
],
];
/* 一些框架与框架运行时设置的调整 */
/* Workerman 驱动相关配置 */
$config['workerman_options'] = [
'worker_num' => 1, // 如果你只有一个 OneBot 实例连接到框架并且代码没有复杂的CPU密集计算则可把这里改为1使用全局变量
];
/* Swoole 驱动相关配置 */
$config['swoole_options'] = [
'coroutine_hook_flags' => SWOOLE_HOOK_ALL & (~SWOOLE_HOOK_CURL), // 协程 Hook 内容
'swoole_set' => [
'worker_num' => 1, // 如果你只有一个 OneBot 实例连接到框架并且代码没有复杂的CPU密集计算则可把这里改为1使用全局变量
'dispatch_mode' => 2, // 包分配原则,见 https://wiki.swoole.com/#/server/setting?id=dispatch_mode
'max_coroutine' => 300000, // 允许最大的协程数
'max_wait_time' => 5, // 安全退出模式下允许等待 Worker 的最长秒数
// 'task_worker_num' => 4, // 启动 TaskWorker 进程的数量(默认不启动)
// 'task_enable_coroutine' => true // TaskWorker 是否开启协程
],
'swoole_server_mode' => SWOOLE_PROCESS, // Swoole Server 启动模式,默认为 SWOOLE_PROCESS
];
/* 默认存取炸毛数据的目录相对目录时代表WORKING_DIR下的目录绝对目录按照绝对目录来 */
$config['data_dir'] = WORKING_DIR . '/zm_data';
/* 框架本体运行时的一些可调配置 */
$config['runtime'] = [
'swoole_coroutine_hook_flags' => SWOOLE_HOOK_ALL & (~SWOOLE_HOOK_CURL),
'swoole_server_mode' => SWOOLE_PROCESS,
'middleware_error_policy' => 1,
'reload_delay_time' => 800,
'global_middleware_binding' => [],
'save_console_log_file' => false, // 改为目标路径,则将 Console 输出的日志保存到文件
'annotation_reader_ignore' => [ // 设置注解解析器忽略的注解名或命名空间,防止解析到不该解析的
'name' => [
'mixin',
],
'namespace' => [],
],
'inside_table_size' => 65536 // 内部表字符串最大长度需要2的倍数
// 正常不要低于65536如果群数量过多可能出现会size不够。若swoole日志出现WARNING TableRow::set_value(): [key=wait_api,field=value]string value is too long可以将该值往大设置。
'timezone' => 'Asia/Shanghai',
];
/* 轻量字符串缓存,默认开启 */
$config['light_cache'] = [
'size' => 512, // 最多允许储存的条数需要2的倍数
'max_strlen' => 32768, // 单行字符串最大长度需要2的倍数
'hash_conflict_proportion' => 0.6, // Hash冲突率越大越好但是需要的内存更多
'persistence_path' => $config['zm_data'] . '_cache.json',
'auto_save_interval' => 900,
];
/* 大容量跨进程变量存储2.2.0可用) */
$config['worker_cache'] = [
'worker' => 0,
'transaction_timeout' => 30000,
];
/* MySQL数据库连接信息host留空则启动时不创建sql连接池 */
$config['mysql_config'] = [
'host' => '',
'port' => 3306,
'unix_socket' => null,
'username' => 'root',
'password' => '123456',
'dbname' => '',
'charset' => 'utf8mb4',
'pool_size' => 64,
'options' => [
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
],
];
/* Redis连接信息host留空则启动时不创建Redis连接池 */
$config['redis_config'] = [
'host' => '',
'port' => 6379,
'timeout' => 1,
'db_index' => 0,
'auth' => '',
];
/* onebot连接约定的token */
$config['access_token'] = '';
/* HTTP服务器固定请求头的返回 */
$config['http_header'] = [
'Server' => 'zhamao-framework',
'Content-Type' => 'text/html; charset=utf-8',
];
/* HTTP服务器在指定状态码下回复的页面默认 */
$config['http_default_code_page'] = [
'404' => '404.html',
];
/* zhamao-framework在框架启动时初始化的atomic们 */
$config['init_atomics'] = [
// 'custom_atomic_name' => 0, //自定义添加的Atomic
];
/* 终端日志显示等级0-4 */
$config['info_level'] = 2;
/* 上下文接口类 implemented from ContextInterface */
$config['context_class'] = \ZM\Context\Context::class;
/* 静态文件访问 */
$config['static_file_server'] = [
'status' => false,
'document_root' => realpath(__DIR__ . '/../') . '/resources/html',
'document_index' => [
'index.html',
/* 允许加载插件形式 */
$config['plugin'] = [
'enable' => true,
'load_dir' => 'plugins',
];
/* 内部默认启用的插件 */
$config['native_plugin'] = [
'onebot12' => true, // OneBot v12 协议支持
'onebot12-ban-other-ws' => true, // OneBot v12 协议支持,禁止其他 WebSocket 连接
'command-manual' => true,
];
/* 静态文件读取器 */
$config['file_server'] = [
'enable' => true,
'document_root' => $config['data_dir'] . '/public/',
'document_index' => 'index.html',
'document_code_page' => [
'404' => '404.html',
'500' => '500.html',
],
];
/* 机器人解析模块关闭后无法使用如CQCommand等注解(上面的modules即将废弃) */
$config['onebot'] = [
'status' => true,
'single_bot_mode' => false,
'message_level' => 99,
'message_convert_string' => true,
'message_command_policy' => 'interrupt',
/* MySQL 和 SQLite3 数据库连接配置,框架将自动生成连接池,支持多个连接池 */
$config['database'] = [
'sqlite_db1' => [
'enable' => false,
'type' => 'sqlite',
'dbname' => 'a.db',
'pool_size' => 10,
],
'default' => [
'enable' => false,
'type' => 'mysql',
'host' => '127.0.0.1', // 填写数据库服务器地址后才会创建数据库连接
'port' => 3306,
'username' => 'root',
'password' => 'ZhamaoTEST',
'dbname' => 'zm',
'charset' => 'utf8mb4',
'pool_size' => 64,
],
];
/* 一个远程简易终端使用nc直接连接即可但是不建议开放host为0.0.0.0(远程连接) */
$config['remote_terminal'] = [
'status' => false,
'host' => '127.0.0.1',
'port' => 20002,
'token' => '',
/* Redis 连接配置,框架将自动生成连接池,支持多个连接 */
$config['redis'] = [
'default' => [
'enable' => false,
'host' => '127.0.0.1',
'port' => 6379,
'index' => 0,
'auth' => '',
'pool_size' => 10,
],
];
/* 模块(插件)加载器的相关设置 */
$config['module_loader'] = [
'enable_hotload' => false,
'load_path' => $config['zm_data'] . 'modules',
/* KV 数据库的配置 */
$config['kv'] = [
'use' => \LightCache::class, // 默认在单进程模式下使用 LightCache多进程需要使用 ZMRedis
'light_cache_dir' => $config['data_dir'] . '/lc', // 默认的 LightCache 保存持久化数据的位置
'light_cache_autosave_time' => 600, // LightCache 自动保存时间(秒)
'redis_config' => 'default',
];
return $config;

152
config/global_old.php Normal file
View File

@@ -0,0 +1,152 @@
<?php
/** @noinspection PhpComposerExtensionStubsInspection */
declare(strict_types=1);
/* bind host */
$config['host'] = '0.0.0.0';
/* bind port */
$config['port'] = 20001;
/* 框架开到公网或外部的HTTP访问链接通过 DataProvider::getFrameworkLink() 获取 */
$config['http_reverse_link'] = 'http://127.0.0.1:' . $config['port'];
/* 框架是否启动debug模式当debug模式为true时启用热更新需要安装inotify扩展 */
$config['debug_mode'] = false;
/* 存放框架内文件数据的目录 */
$config['zm_data'] = realpath(WORKING_DIR) . '/zm_data/';
/* 存放各个模块配置文件的目录 */
$config['config_dir'] = $config['zm_data'] . 'config/';
/* 存放崩溃和运行日志的目录 */
$config['crash_dir'] = $config['zm_data'] . 'crash/';
/* 对应swoole的server->set参数 */
$config['swoole'] = [
'log_file' => $config['crash_dir'] . 'swoole_error.log',
// 'worker_num' => swoole_cpu_num(), //如果你只有一个 OneBot 实例连接到框架并且代码没有复杂的CPU密集计算则可把这里改为1使用全局变量
'dispatch_mode' => 2, // 包分配原则,见 https://wiki.swoole.com/#/server/setting?id=dispatch_mode
'max_coroutine' => 300000,
'max_wait_time' => 5,
// 'task_worker_num' => 4,
// 'task_enable_coroutine' => true
];
/* 一些框架与框架运行时设置的调整 */
$config['runtime'] = [
'swoole_coroutine_hook_flags' => SWOOLE_HOOK_ALL & (~SWOOLE_HOOK_CURL),
'swoole_server_mode' => SWOOLE_PROCESS,
'middleware_error_policy' => 1,
'reload_delay_time' => 800,
'global_middleware_binding' => [],
'save_console_log_file' => false, // 改为目标路径,则将 Console 输出的日志保存到文件
'annotation_reader_ignore' => [ // 设置注解解析器忽略的注解名或命名空间,防止解析到不该解析的
'name' => [
'mixin',
],
'namespace' => [],
],
];
/* 轻量字符串缓存,默认开启 */
$config['light_cache'] = [
'size' => 512, // 最多允许储存的条数需要2的倍数
'max_strlen' => 32768, // 单行字符串最大长度需要2的倍数
'hash_conflict_proportion' => 0.6, // Hash冲突率越大越好但是需要的内存更多
'persistence_path' => $config['zm_data'] . '_cache.json',
'auto_save_interval' => 900,
];
/* 大容量跨进程变量存储2.2.0可用) */
$config['worker_cache'] = [
'worker' => 0,
'transaction_timeout' => 30000,
];
/* MySQL数据库连接信息host留空则启动时不创建sql连接池 */
$config['mysql_config'] = [
'host' => '',
'port' => 3306,
'unix_socket' => null,
'username' => 'root',
'password' => '123456',
'dbname' => '',
'charset' => 'utf8mb4',
'pool_size' => 64,
'options' => [
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
],
];
/* Redis连接信息host留空则启动时不创建Redis连接池 */
$config['redis_config'] = [
'host' => '',
'port' => 6379,
'timeout' => 1,
'db_index' => 0,
'auth' => '',
];
/* onebot连接约定的token */
$config['access_token'] = '';
/* HTTP服务器固定请求头的返回 */
$config['http_header'] = [
'Server' => 'zhamao-framework',
'Content-Type' => 'text/html; charset=utf-8',
];
/* HTTP服务器在指定状态码下回复的页面默认 */
$config['http_default_code_page'] = [
'404' => '404.html',
];
/* zhamao-framework在框架启动时初始化的atomic们 */
$config['init_atomics'] = [
// 'custom_atomic_name' => 0, //自定义添加的Atomic
];
/* 终端日志显示等级0-4 */
$config['info_level'] = 2;
/* 上下文接口类 implemented from ContextInterface */
$config['context_class'] = \ZM\Context\Context::class;
/* 静态文件访问 */
$config['static_file_server'] = [
'status' => false,
'document_root' => realpath(__DIR__ . '/../') . '/resources/html',
'document_index' => [
'index.html',
],
];
/* 机器人解析模块关闭后无法使用如CQCommand等注解(上面的modules即将废弃) */
$config['onebot'] = [
'status' => true,
'single_bot_mode' => false,
'message_level' => 99,
'message_convert_string' => true,
'message_command_policy' => 'interrupt',
];
/* 一个远程简易终端使用nc直接连接即可但是不建议开放host为0.0.0.0(远程连接) */
$config['remote_terminal'] = [
'status' => false,
'host' => '127.0.0.1',
'port' => 20002,
'token' => '',
];
/* 模块(插件)加载器的相关设置 */
$config['module_loader'] = [
'enable_hotload' => false,
'load_path' => $config['zm_data'] . 'modules',
];
return $config;

96
docker-compose.yml Normal file
View File

@@ -0,0 +1,96 @@
version: "3.9"
services:
bot:
build:
context: docker/zhamao
dockerfile: ./Dockerfile
container_name: zhamao-bot
depends_on:
- database-postgres
- database-redis
networks:
- bot-net
ports:
- "20001-20005:20001-20005/tcp"
volumes:
- ".:/bot"
walle-q:
build:
context: docker/walle-q
dockerfile: ./Dockerfile
container_name: zhamao-bot-walle-q
depends_on:
- bot
networks:
- bot-net
volumes:
- "./docker/volumes/walle-q-data:/bot"
database-postgres:
container_name: zhamao-bot-db-postgres
env_file:
- docker/environment.env
image: postgres:14.4-alpine
networks:
- bot-net
ports:
- "5432:5432/tcp"
restart: always
volumes:
- "./docker/volumes/postgres-data:/var/lib/postgresql/data"
- "./docker/volumes/postgres-init:/docker-entrypoint-initdb.d"
database-redis:
command:
- redis-server
- --requirepass
- "$${REDIS_PASSWORD}"
container_name: zhamao-bot-db-redis
env_file:
- docker/environment.env
image: redis:7.0-alpine
networks:
- bot-net
ports:
- "6379:6379/tcp"
restart: always
volumes:
- "./docker/volumes/redis-data:/data"
db-admin-adminer:
container_name: zhamao-bot-dbadmin-adminer
depends_on:
database-postgres:
condition: service_started
database-redis:
condition: service_started
env_file:
- docker/environment.env
image: adminer:latest
networks:
- bot-net
ports:
- "15432:8080/tcp"
profiles:
- with-adminer
db-admin-redis-insight:
container_name: zhamao-bot-dbadmin-redis-insight
depends_on:
database-postgres:
condition: service_started
database-redis:
condition: service_started
image: redislabs/redisinsight:latest
networks:
- bot-net
ports:
- "16379:8001/tcp"
profiles:
- with-adminer
networks:
bot-net:
name: bot-net

2
docker/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/volumes
environment.env

View File

@@ -0,0 +1,7 @@
REDIS_PASSWORD={{$REDIS_PASSWORD}}
POSTGRES_USER={{$DB_ROOT_USER}}
POSTGRES_PASSWORD={{$DB_ROOT_PASSWORD}}
POSTGRES_APPLICATION_USER={{$DB_USER}}
POSTGRES_APPLICATION_USER_PASSWORD={{$DB_PASSWORD}}
POSTGRES_APPLICATION_DATABASE={{$DB_NAME}}

14
docker/walle-q/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM alpine:latest
MAINTAINER sunxyw <me@sunxyw.xyz>
RUN apk add --no-cache curl
RUN mkdir -p /bot && \
curl -fsSL https://github.com/onebot-walle/walle-q/releases/latest/download/walle-q-i686-linux-musl.tar.gz -O && \
tar -zxvf walle-q-i686-linux-musl.tar.gz -C /bot && \
rm -rf walle-q-i686-linux-musl.tar.gz && \
chmod +x /bot/walle-q-i686-linux-musl
ENV TZ=Asia/Shanghai
ENTRYPOINT [ "/bot/walle-q-i686-linux-musl" ]

14
docker/zhamao/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM phpswoole/swoole:5.0-php8.1
MAINTAINER sunxyw <me@sunxyw.xyz>
WORKDIR "/bot"
ENV TZ=Asia/Shanghai
EXPOSE 20001-20005
RUN docker-php-ext-install pcntl
ENTRYPOINT [ "./zhamao" ]
CMD [ "server" ]

View File

@@ -1 +0,0 @@
module.exports = [{"title":"ZM","collapsable":true,"children":["ZM/ZMServer"]},{"title":"ZM/API","collapsable":true,"children":["ZM/API/CQ","ZM/API/ZMRobot","ZM/API/TuringAPI","ZM/API/GoCqhttpAPIV11","ZM/API/OneBotV11"]},{"title":"ZM/API/Proxies/Bot","collapsable":true,"children":["ZM/API/Proxies/Bot/AllGroupsProxy","ZM/API/Proxies/Bot/AbstractBotProxy","ZM/API/Proxies/Bot/AllBotsProxy"]},{"title":"ZM/Annotation/Swoole","collapsable":true,"children":["ZM/Annotation/Swoole/OnSwooleEventBase"]},{"title":"ZM/Command","collapsable":true,"children":["ZM/Command/CheckConfigCommand"]},{"title":"ZM/Command/Module","collapsable":true,"children":["ZM/Command/Module/ModulePackCommand","ZM/Command/Module/ModuleListCommand"]},{"title":"ZM/Container","collapsable":true,"children":["ZM/Container/BoundMethod","ZM/Container/WorkerContainer","ZM/Container/Container"]},{"title":"ZM/DB","collapsable":true,"children":["ZM/DB/UpdateBody","ZM/DB/DB","ZM/DB/InsertBody","ZM/DB/DeleteBody","ZM/DB/Table","ZM/DB/SelectBody"]},{"title":"ZM/Event","collapsable":true,"children":["ZM/Event/EventDispatcher","ZM/Event/EventTracer","ZM/Event/EventManager"]},{"title":"ZM/Event/SwooleEvent","collapsable":true,"children":["ZM/Event/SwooleEvent/OnMessage","ZM/Event/SwooleEvent/OnTask"]},{"title":"ZM/Http","collapsable":true,"children":["ZM/Http/Response"]},{"title":"ZM/Module","collapsable":true,"children":["ZM/Module/ModuleUnpacker","ZM/Module/ModuleBase","ZM/Module/ModulePacker"]},{"title":"ZM/MySQL","collapsable":true,"children":["ZM/MySQL/MySQLPool","ZM/MySQL/MySQLWrapper","ZM/MySQL/MySQLStatementWrapper","ZM/MySQL/MySQLQueryBuilder","ZM/MySQL/MySQLConnection","ZM/MySQL/MySQLStatement"]},{"title":"ZM/Store","collapsable":true,"children":["ZM/Store/LightCacheInside","ZM/Store/ZMAtomic","ZM/Store/LightCache"]},{"title":"ZM/Store/Redis","collapsable":true,"children":["ZM/Store/Redis/ZMRedis"]},{"title":"ZM/Utils","collapsable":true,"children":["ZM/Utils/CommandInfoUtil","ZM/Utils/Terminal","ZM/Utils/DataProvider","ZM/Utils/SignalListener","ZM/Utils/CoMessage","ZM/Utils/ReflectionUtil","ZM/Utils/MessageUtil","ZM/Utils/ZMUtil","ZM/Utils/HttpUtil"]},{"title":"ZM/Utils/Manager","collapsable":true,"children":["ZM/Utils/Manager/ModuleManager","ZM/Utils/Manager/WorkerManager","ZM/Utils/Manager/CronManager"]}]

View File

@@ -1,7 +1,5 @@
const apiConfig = require('./api')
module.exports = {
title: '炸毛框架v2 旧版)',
title: '炸毛框架 v3',
description: '一个高性能聊天机器人 + Web 框架',
theme: 'antdocs',
markdown: {
@@ -28,13 +26,9 @@ module.exports = {
activeHeaderLinks: false,
nav: [
{ text: '指南', link: '/guide/' },
{ text: '事件和注解', link: '/event/' },
{ text: '组件', link: '/component/' },
{ text: '进阶', link: '/advanced/' },
{ text: 'API', link: '/api/' },
{ text: 'FAQ', link: '/faq/' },
{ text: '更新日志', link: '/update/v2/' },
{ text: '炸毛框架 v3最新版', link: 'https://framework.zhamao.xin/' }
{ text: '事件', link: '/event/' },
{ text: 'API 文档', link: '/doxy/', target: '_blank' },
{ text: '炸毛框架 v2', link: 'https://docs-v2.zhamao.xin/' }
],
sidebar: {
'/guide/': [
@@ -45,147 +39,26 @@ module.exports = {
children: [
'',
'installation',
'quickstart-robot',
'quickstart-http',
'onebot-choose',
'basic-config',
'write-module',
'register-event',
'upgrade',
'errcode'
'configuration',
'structure',
'get_started',
]
}
],
'/event/': [
{
title: '事件和注解',
title: '事件',
collapsable: false,
sidebarDepth: 1,
children: [
'',
'robot-annotations',
'route-annotations',
'framework-annotations',
'bot',
'http',
'middleware',
'custom-annotations',
'event-dispatcher'
'framework',
'extend',
]
}
],
'/component/': [
'',
{
title: '聊天机器人组件',
collapsable: true,
sidebarDepth: 2,
children: [
'bot/robot-api-12',
'bot/robot-api',
'bot/cqcode',
'bot/message-util',
'bot/access-token',
'bot/turing-api',
'bot/help-generator.md',
]
},
{
title: '存储组件',
collapsable: true,
sidebarDepth: 2,
children: [
'store/light-cache',
'store/mysql',
'store/mysql-db',
'store/redis',
'store/atomics',
'store/spin-lock',
'store/data-provider'
]
},
{
title: '通用组件',
collapsable: true,
sidebarDepth: 2,
children: [
'common/context',
'common/coroutine-pool',
'common/singleton-trait',
'common/zmutil',
'common/global-functions',
'common/console',
'common/task-worker',
'common/remote-terminal',
'common/event-tracer'
]
},
{
title: 'HTTP 组件',
collapsable: true,
sidebarDepth: 2,
children: [
'http/zmrequest',
'http/route-manager'
]
},
{
title: '模块/插件管理',
collapsable: true,
sidebarDepth: 2,
children: [
'module/module-pack',
'module/module-unpack'
]
}
],
'/advanced/': [
'',
{
title: '框架高级开发',
collapsable: true,
sidebarDepth: 2,
children: [
'framework-structure',
'custom-start',
'manually-install',
'inside-class',
'multi-process',
'task-worker'
]
},
{
title: '开发实战教程',
collapsable: true,
sidebarDepth: 2,
children: [
'connect-ws-client',
'example/admin',
'example/integrate-qingyunke-chatbot',
'example/weather-bot'
]
},
],
'/api/': apiConfig,
'/faq/': [
'',
'to-v2',
'usual-question',
'address-already-in-use',
'display-deadlock',
'light-cache-wrong',
'wait-message-cqbefore'
],
'/update/': [
{
title: '更新日志',
collapsable: true,
sidebarDepth: 0,
children: [
'v2',
'v1',
'build-update'
]
},
'config'
]
}
}

View File

@@ -1 +1 @@
docs-v2.zhamao.me
framework.zhamao.me

View File

@@ -2,16 +2,22 @@
home: true
heroImage: ./logo_trans.png
actions:
- theme: brand
text: 快速上手
- text: 快速上手
link: /guide/
type: primary
size: large
- text: 快速上手v2 旧版)
link: https://docs-v2.zhamao.xin/
type: primary
ghost: true
size: large
features:
- title: 高性能
details: 基于 PHP 的 Swoole 高性能扩展,利用 WebSocket 进行与 OneBot 协议兼容的聊天机器人软件的通信,还有数据库连接池、内存缓存、多任务进程等特色,大幅增强性能。
- title: 易于开发
details: 所有功能采用模块化设计,除特殊情况外几乎所有功能都不需要修改框架内任意代码,框架采用灵活的注解进行各类事件绑定,同时支持下断点调试。
- title: 接口直观
details: 支持命令、普通文本、正则匹配、自然语言处理等多种对话解析方式,利用协程巧妙实现了直观的交互式会话模式,同时支持多种富文本的处理。
- title: 高性能
details: 基于 PHP 的 Swoole 高性能扩展,利用 WebSocket 进行与 OneBot 协议兼容的聊天机器人软件的通信,还有数据库连接池、内存缓存、多任务进程等特色,大幅增强性能。
- title: 易于开发
details: 所有功能采用模块化设计,除特殊情况外几乎所有功能都不需要修改框架内任意代码,框架采用灵活的注解进行各类事件绑定,同时支持下断点调试。
- title: 接口直观
details: 支持命令、普通文本、正则匹配、自然语言处理等多种对话解析方式,利用协程巧妙实现了直观的交互式会话模式,同时支持多种富文本的处理。
footer: |
Apache-2.0 Licensed &nbsp;|&nbsp; Copyright © 2019-2022 Zhamao Developer Team &nbsp;|&nbsp; <a href="http://beian.miit.gov.cn">沪ICP备2021010446号-1</a>
---
@@ -23,7 +29,7 @@ footer: |
此命令可一键以模板安装框架!(仅限 Linux 和 macOS
```bash
bash <(curl -fsSL https://zhamao.xin/go.sh)
bash <(curl -fsSL https://zhamao.xin/v3.sh)
```
## 运行框架

View File

@@ -1,4 +0,0 @@
# 进阶开发
在本章,下面的部分将详细说明一些具体的案例和自定义框架的操作。
> 更多进阶教程敬请期待....(或者你可以选择提 Issue 到框架 GitHub有需求就写入文档

View File

@@ -1,144 +0,0 @@
# 接入 WebSocket 客户端
炸毛框架其实从本质上讲,就是一个 HTTP + WebSocket 服务器,所以框架也支持对接其他任何 HTTP 客户端和 WebSocket 客户端,实际上炸毛框架非常适合用 WebSocket 做在线的 IM 聊天通讯,也可以方便地进行 WS 通信。这里主要说明如何对接一个自定义的 WebSocket 客户端。
## 类型指定
由于 WebSocket 连接都具有同样的性质,没有状态,所以在建立 WebSocket 连接的时候,需要客户端表明自己的身份和类型。指定客户端连接类型的方式有两种:
- `GET` 参数传递,在连接的时候,加上 GET 参数 `type` 即可。比如 js 中 WebSocket 建立时地址写:`ws://127.0.0.1:20001/?type=foo`,这时传入的连接就是 `foo` 类型。
- `Header` 传递,用户需要在建立连接时指定 HTTP 的头部信息 `X-Client-Role`,例如 `X-Client-Role: foo`,这时传入的连接就是 `foo` 类型。
以上两种方式,`Header` 方式比 `GET` 方式优先级要高,如果两者均没有指定,框架会将此连接当作 `default` 类型接入。
::: tip 提示
对于对接 OneBot 标准的机器人客户端,只要符合 OneBot 标准,即 `X-Client-Role` 会自动带上 `universal``qq` 等字样,就会自动标记为 `qq` 类型。
:::
## 逻辑编写
传入连接后,我们就能通过注解事件绑定来做我们自己想做的事情了!比如下方是传入类型为 foo 连接要做的事情
```php
<?php
namespace Module\Example;
use ZM\Annotation\Swoole\OnOpenEvent;
use ZM\Console\Console;
use ZM\ConnectionManager\ConnectionObject;
class Hello {
/**
* @OnOpenEvent("foo")
*/
public function onFooConnect(ConnectionObject $conn) {
Console::info($conn->getName()." 已连接!");
}
```
以上作用就是在终端输出 `foo 已连接!` 这个提示的。关于 `ConnectionObject` 对象,见下方。
## WS 连接对象
对于每一个 WebSocket 连接,框架内都有一个专属的操作类,有获取类型名称、保存链接参数和属性以及获取文件标识符等功能。
### getFd()
获取文件标示符,用于发送消息、接收消息等。这个参数获取的 `fd` 是 Swoole 指定的,用于发送信息等。
```php
$fd = $conn->getFd();
server()->send($fd, "hello world");
```
> WebSocket 是全双工的,所以发送和接收其实是互不干扰的,你可以不仅仅在 WebSocket 相关的上下文中,还可以比如在 HTTP 或者机器人上下文中给别的 WebSocket 客户端发请求。
### getName()
获取连接对象绑定的连接类型,例如上方提到的 `foo``default` 等。
```php
Console::info("当前连接类型:".$conn->getName()); //当前连接类型foo
```
### setName()
改变连接对象绑定的连接类型,例如从 `foo` 改为 `bar`
```php
$s = $conn->getName(); // foo
$conn->setName("bar");
$s = $conn->getName(); // bar
```
### getOptions()
获取此连接存储的所有参数,以数组形式。存储内容见下方 `setOption()`
格式:`["参数1" => {参数1的值}, "参数2" => {参数2的值}]`
### getOption()
获取此连接存储的参数,获取指定名称的,此方法拥有一个参数 `$key`,指定即可获取。
如果没有对应参数,则返回 `null`
我们在前面的机器人部分知道,框架主要是用于机器人的连接,那么机器人客户端在连接后,比如我们想知道这个机器人的 WS 连接对应的是哪个 QQ 号的机器人,我们就可以用 `getOption("connect_id")` 来获取。这个 `connect_id` 是 OneBot 标准的客户端接入后自动填入的一个参数。例如,我们想在机器人接入后打出接入机器人的 QQ 号:
```php
/**
* @OnOpenEvent("qq")
*/
public function onQQConnect($conn) {
Console::success("机器人 ".$conn->getOption("connect_id")." 已连接!"); // 机器人 123456 已连接!
}
```
### setOption()
设置连接存储的参数。参数:`setOption($key, $value)``$key` 限定为 `connect_id` 一种。(因为目前有了 LightCache所以这里暂时不提供别的 key 设定)
```php
$conn->setOption("connect_id", "asdasdasd"); // $value 最长长度为 29
```
## 发送到 WebSocket 客户端
很简单,从上面获取到 `fd` 后使用下面的方式就可以了~
```php
server()->push($conn->getFd(), "hello"); // 第二个为 string 类型的参数
```
## 从客户端接收
接收消息必须从 `@OnMessageEvent` 注解事件下接收,使用上下文 `ctx()->getFrame()` 获取消息帧。
从这里获取的 `Frame` 对象,见 [Swoole 文档 - Frame](https://wiki.swoole.com/#/websocket_server?id=swoolewebsocketframe)。
Frame 对象有四个参数:
- `$frame->fd`:获取发来帧的 fd
- `$frame->data`:数据本体
- `$frame->opcode`:数据类型 int 值,见 [Swoole 文档 - 数据帧类型](https://wiki.swoole.com/#/websocket_server?id=%e6%95%b0%e6%8d%ae%e5%b8%a7%e7%b1%bb%e5%9e%8b)
- `$frame->finish`是否发送完毕bool
下面以接收一个 json 字符串为例,并进行后续的解析:
```php
/**
* @OnMessageEvent("foo")
*/
public function onMessage() {
$frame = ctx()->getFrame();
$json_str = $frame->data; // 假设传入的是 {"key1":"value1","k2":"v2"}
$json = json_decode($json_str, true);
Console::info("key1 的值是:" . $json["key1"]);
}
```
## 关闭连接
```php
server()->close($conn->getFd());
```

View File

@@ -1,136 +0,0 @@
# 框架高级启动
## 框架下载方式
从前面的几章中,我们了解到框架有多种下载到本地的方式。
- Composer 依赖模式
- Starter 从模板创建模式(等同于 Composer 模式)
- 源码模式
- Phar Composer 依赖模式
- Phar 源码模式
### Composer 依赖模式
从 Composer 依赖加载框架是一种拉取框架的方式,这种方式的优点在于,你可以直观地感受到是如何使用框架从零开始一个完整的项目的过程。
从 Composer 依赖的启动步骤:
```bash
mkdir my-bot # 新建一个空的文件夹
cd my-bot/
composer require zhamao/framework # 从 composer 拉取后会自动部署 autoload 和 composer.json 等内容
# 使用命令初始化框架
vendor/bin/start init
# 启动框架
vendor/bin/start server
```
注意:使用 `init` 命令时,会给当前目录解压以下文件:
```php
$extract_files = [
"/config/global.php", // 全局配置文件
"/.gitignore", // git 排除文件
"/config/file_header.json", // HTTP 文件头
"/config/console_color.json", // 终端颜色主题文件
"/config/motd.txt", // 框架启动时自定义的 motd
"/src/Module/Example/Hello.php", // 框架自带的示例模块
"/src/Module/Middleware/TimerMiddleware.php", // 框架自带的函数运行时间监控中间件
"/src/Custom/global_function.php" // 用户可在这里自定义编写自己的全局函数
];
```
经过 init 解压这些文件后,你的框架就能正常运行且开始编写代码了!
### Starter 模板模式
从模板新建其实原理和 Composer 依赖模式完全一样,只不过,这个过程是使用模板仓库新建的项目,使用 Composer 自带的 `create-project` 方式创建的。starter 也是一个 GitHub 项目,见 [地址](https://github.com/zhamao-robot/zhamao-framework-starter)。
```bash
composer create-project zhamao/framework-starter my-bot/ # my-bot 是你自定义的文件夹名称,和上方相同
cd my-bot
vendor/bin/start server # 启动框架
```
Starter 模式相当于直接从 GitHub 拉取 `zhamao-framework-starter` 项目,然后执行 `composer update`
那和 Composer 依赖模式有什么区别呢?没区别!构建出来的框架和文件是一模一样的!使用 Composer 依赖模式,使用 `init` 命令后,文件会和 `zhamao-framework-starter` 仓库拉取回来的模板一模一样!(或者换句话说,这个仓库就是使用 `init` 命令生成的文件的)
那使用哪种好呢?看你自己!如果你想给你自己的已有项目套上炸毛框架,那么就推荐使用 Composer 依赖模式,如果是从 0 开始编写框架模块,则推荐使用模板模式。
### 源码模式
源码模式和以上两种方案都不一样,源码模式允许你对框架本身进行一系列修改,框架本体就可以直接运行。
Composer 依赖模式(以及模板模式)和源码模式的区别是:
- 依赖模式和模板模式是通过 library 方式引入框架的,框架本身会放在 composer 的 `vendor/` 目录下,从 composer 引入的 library 相当于子集vendor 目录下的文件最好不要手动修改(应该都知道吧),所以框架本身也只是加载了进来。
- 源码模式相当于直接从框架源码目录运行框架和模块,框架源码都在 `src/ZM` 目录下,默认的示例模块都在 `src/Module` 下,是同级目录。而此时的 `vendor/` 目录只包含了框架依赖的外部组件,例如注解解析器和 psysh 等。
源码模式可以方便地调试和修改框架本身,拉取方式很简单,用 `git clone` 或从 GitHub 下载最新版的源码包解压即可。
```bash
git clone https://github.com/zhamao-robot/zhamao-framework.git
cd zhamao-framework/
bin/start server # 第一次运行时会提示一个“框架源码模式需要在autoload文件中添加Module目录为自动加载”
composer update # 更新 autoload 文件,应用刚才上一步添加的 `src/Module` 文件夹下的模块自动加载
bin/start server # 通过源码模式启动框架
```
## 框架启动参数
框架启动时可以根据实际情况指定启动参数。
- `--debug-mode`:启用调试模式,调试模式的作用是关闭一键协程化和终端交互,减少 Swoole 本身对代码逻辑的干扰(比如执行 `shell_exec()` 报错的话可以开启这个进行调试)。
- `--log-{mode}`:设置 log 等级。支持 `--log-debug``--log-verbose``--log-info``--log-warning``--log-error`
- `--log-theme`:设置终端信息的主题。这个选项适用于多种终端信息显示的兼容,例如白色终端和不支持颜色的终端。详见 [Console - 主题设置](/component/console/#_2)。
- `--disable-coroutine`:关闭一键协程化。
- `--remote-terminal`:开启 nc 远程终端,配置文件使用全局中的 `remote_terminal` 项。也可以在全局配置中常开启status 设置为 true
- `--daemon`:以守护进程方式运行框架,此参数将直接在输出 motd 后将进程挂到 init 下运行,后台常驻。
- `--watch`:监控 `src/` 目录下的文件变化,有变化则自动重新载入代码。开启监控需要安装 PHP 扩展inotify。使用 pecl 就可以安装:`pecl install inotify`。(注:不支持 WSL 和 macOS
- `--env`:设置运行环境,设置运行环境后将优先加载指定环境的配置文件,支持 `--env=production``--env=staging``--env=development`,见 [基本配置](/guide/basic-config/#_2)。
- `--worker-num`:指定运行的工作进程数量(并不是越多越好,框架默认为 CPU 核心数),例如 `--worker-num=8`
- `--task-worker-num`:启用 TaskWorker 进程并指定数量。
- `--show-php-ver`:在启动时显示 Swoole 和 PHP 的版本。
## 守护进程操作命令
守护进程在 2.2.0 版本开始,可以使用命令行快速操作,如重启、停止、查看状态等。
注意,这里的守护进程操作命令是指 **使用 `--daemon` 方式启动的框架**,如使用 Docker、screen、tmux、systemd 等方式挂后台跑则此命令不可用!
```bash
vendor/bin/start daemon:status # 查看守护进程的状态
vendor/bin/start daemon:reload # 重载框架
vendor/bin/start daemon:stop # 停止运行守护进程的框架
```
## 独立启动其他组件
框架默认不止启动框架的 `server` 命令,还有 `init` 命令和 `simple-http-server` 命令。`init` 命令在上方 Composer 依赖模式中提到过,就是初始化各个文件的。
### 独立 HTTP 文件服务器
如果你只需要一个静态文件服务器,类似 Nginx那么框架也支持。
```bash
vendor/bin/start simple-http-server your-web-dir/ --host=0.0.0.0 --port=8080
```
- `your-web-dir` 是必填的参数。
- `--host``--port` 是可选参数,如果不填,则默认使用 `global.php` 配置文件中的配置。
### 检查配置是否更新
默认情况下(非源码模式),你可以使用命令 `vendor/bin/start check:config` 来检查你的配置文件是否需要更新部分段落。
### systemd 配置文件生成器
框架支持生成 systemd 配置文件 `zhamao.service`,生成后将文件放入 `/etc/systemd/system` 后输入 `systemctl enable zhamao.service` 即可。
命令:`vendor/bin/start systemd:generate`
注意systemd 启动的守护进程模式和使用参数 `--daemon` 不一样,请勿同时混用,直接使用上述命令生成的配置文件即可正常使用!

View File

@@ -1,229 +0,0 @@
# 编写管理员专属功能
众所周知,如果大家使用炸毛框架来开发聊天机器人的话,会比较方便。但是有些地方你一定会感觉还是欠缺了点,比如下面这样,你想编写一个只能由机器人管理员,也就是你自己,才能触发的功能:
```php
/**
* @CQCommand(match="禁言",message_type="group")
*/
public function banSomeone() {
$r1 = ctx()->getNextArg("请输入禁言的人或at他");
$r2 = ctx()->getFullArg("请输入禁言的时间(秒)");
$cq = CQ::getCQ($r1);
if ($cq !== null) {
if ($cq["type"] != "at") return "请at或者输入正确的QQ号";
$r1 = $cq["params"]["qq"];
}
// 群内禁言用户
ctx()->getRobot()->setGroupBan(ctx()->getGroupId(), $r1, $r2);
return "禁言成功!";
}
```
这时候,如果只是自己有绝对的权利,可以将自己的 QQ 号写死在注解 `@CQCommand` 中,并限定 `user_id`(假设我的 QQ 号码为 123456
```php
/**
* @CQCommand(match="禁言",message_type="group",user_id=123456)
*/
```
但是,随着时间的推移,你的机器人伙伴群可能越来越大,这个命令可能不止需要绝对的你来使用,你还要将机器人的部分权利下发给更多的伙伴,怎么办呢?注解里面只能写死的。
答案很简单这时候我们就需要用到框架提供的中间件Middleware。中间件说白了就是在事件执行前、后、过程中抛出的异常对其进行阻断和插入代码比如我们上方在触发禁言这个注解事件前首先要判断执行这个命令的是不是钦定的管理员。
## 第一步:定义中间件
首先,我们需要定义一个中间件。在框架默认提供的脚手架中,包含了一个叫 `TimerMiddleware.php` 的示例中间件,这个示例中间件的目的是非常简单的,就是判断这个注解事件运行了多长时间。假设你有一个机器人功能,这个功能下的代码需要执行很长时间,可以使用这一注解轻松将事件执行的时间打印到终端上。
关于中间件的有关说明,见 [中间件](/event/middleware)。
下面我们假设你已经阅读过中间件注解的文档了,我们着手编写一个判断指令执行者是否是指定的管理员 QQ 的中间件。为了省事和让大家方便地复现,我先在脚手架下的目录 `src/Module/Middleware/` 下新建 PHP 类文件 `AdminMiddleware.php`(和 `TimerMiddleware.php` 在同一个目录)。
```php
<?php
namespace Module\Middleware;
use ZM\Annotation\Http\HandleBefore;
use ZM\Annotation\Http\MiddlewareClass;
use ZM\Exception\ZMException;
use ZM\Http\MiddlewareInterface;
use ZM\Store\LightCache;
/**
* Class AdminMiddleware
* 示例中间件:用于动态管理一些管理员指令的中间件
* @package Module\Middleware
* @MiddlewareClass("admin")
*/
class AdminMiddleware implements MiddlewareInterface
{
/**
* @HandleBefore()
* @return bool
* @throws ZMException
*/
public function onBefore(): bool {
$r = ctx()->getUserId(); // 从上下文获取发消息的用户 QQ
$admin_list = LightCache::get("admin_list") ?? []; // 从轻量缓存获取管理员列表
return in_array($r, $admin_list); // 返回这个 QQ 是否在管理员列表中
}
}
```
其中,`@MiddlewareClass("admin")` 的意思是,定义这个类为名字叫 `admin` 的中间件,同时,所有中间件的类**必须**带上 `implements MiddlewareInterface`,统一接口形式。
`@HandleBefore()` 代表的是这个类下的这个函数onBefore被标注为这个中间件的 `onBefore` 事件,也就是说,如果有别的注解事件插入了这个 `admin` 中间件,那么执行对应注解事件前都要执行一下 `@HandleBefore` 所绑定的这个函数。而这个绑定的函数只能返回 `bool` 类型的值哦!
## 第二步:使用中间件
使用中间件很简单,在需要阻断的注解事件绑定的函数上再加一个注解就好了!我们以上方的禁言例子说明:
```php
/**
* @Middleware("admin")
* @CQCommand(match="禁言",message_type="group")
*/
```
<chat-box :my-chats="[
{type:0,content:'禁言 1234567 600'},
{type:1,content:'禁言成功!'},
{type:2,content:'假设我不在管理员名单里'},
{type:0,content:'禁言 1234567 900'},
{type:2,content:'机器人没有回复,因为中间件返回了 false不继续执行'},
]"></chat-box>
而这时候有朋友又要问了,如果我有一系列管理员命令,假设都在一个叫 `AdminFunc.php` 的模块类里,我是不是还得一个一个地给注解事件写 `@Middleware("admin")` 呢?当然不需要!如果你这个类所有的注解事件都是机器人的聊天事件(`@CQCommand``@CQMessage`)的话,可以直接给类注解这个中间件,效果等同于给每一个函数写一次中间件注解。
```php
<?php
namespace Module\Example;
use ZM\Annotation\Http\Middleware;
/**
* Class AdminFunc
* @package Module\Example
* @Middleware("admin")
*/
class AdminFunc
{
// ...这里是你的一堆注解事件的函数
}
```
## 第三步:补全代码
上面我们讲到了,中间件里面使用了 `LightCache` 轻量缓存来储存临时的管理员列表,那么我们将这部分的代码完善吧!
**src/Module/Example/AdminFunc.php**
```php
<?php
namespace Module\Example;
use ZM\Annotation\CQ\CQCommand;
use ZM\Annotation\Http\Middleware;
use ZM\API\CQ;
/**
* Class AdminFunc
* @package Module\Example
* @Middleware("admin")
*/
class AdminFunc
{
/**
* @CQCommand(match="禁言",message_type="group")
*/
public function banSomeone() {
$r1 = ctx()->getNextArg("请输入禁言的人或at他");
$r2 = ctx()->getFullArg("请输入禁言的时间(秒)");
$cq = CQ::getCQ($r1);
if ($cq !== null) {
if ($cq["type"] != "at") return "请at或者输入正确的QQ号";
$r1 = $cq["params"]["qq"];
}
// 群内禁言用户
ctx()->getRobot()->setGroupBan(ctx()->getGroupId(), $r1, $r2);
return "禁言成功!";
}
/**
* @CQCommand(match="解除禁言",message_type="group")
*/
public function unbanSomeone() {
$r1 = ctx()->getNextArg("请输入禁言的人或at他");
$cq = CQ::getCQ($r1);
if ($cq !== null) {
if ($cq["type"] != "at") return "请at或者输入正确的QQ号";
$r1 = $cq["params"]["qq"];
}
// 群内禁言用户
ctx()->getRobot()->setGroupBan(ctx()->getGroupId(), $r1, 0);
return "解除禁言成功!";
}
}
```
**src/Module/Example/AdminManager.php**
```php
<?php
namespace Module\Example;
use ZM\Annotation\CQ\CQCommand;
use ZM\Annotation\Http\Middleware;
use ZM\Annotation\Swoole\OnStart;
use ZM\Store\LightCache;
use ZM\Store\Lock\SpinLock;
class AdminManager
{
/**
* @OnStart()
*/
public function onStart() {
if (!LightCache::isset("admin_list")) { //一次性代码首次执行才会执行if
LightCache::set("admin_list", [ // 框架启动时初始化管理员列表
"123456",
"234567"
], -2); // 这里用 -2 的原因是将这一列表持久化保存,避免关闭框架后丢失
}
}
/**
* @CQCommand(match="添加管理员")
* @Middleware("admin")
*/
public function addAdmin() { //只有管理员才能添加管理员
$qq = ctx()->getNextArg("请输入要添加管理员的QQ(qq号码不可at");
SpinLock::lock("admin_list"); //如果是多进程模式的话需要加锁
$ls = LightCache::get("admin_list");
if (!in_array($qq, $ls)) $ls[] = $qq;
LightCache::set("admin_list", $ls, -2);
SpinLock::unlock("admin_list"); //如果是多进程模式的话需要加锁
return "成功添加 $qq 到管理员列表!";
}
}
```
<chat-box :my-chats="[
{type:2,content:'现在我是 123456'},
{type:0,content:'禁言 13579 60'},
{type:1,content:'禁言成功!'},
{type:0,content:'解除禁言 13579'},
{type:1,content:'解除禁言成功!'},
{type:0,content:'添加管理员 98765'},
{type:1,content:'成功添加 98765 到管理员列表!'},
{type:2,content:'现在我是98765'},
{type:0,content:'禁言 13579'},
{type:1,content:'请输入禁言的时间(秒)'},
{type:0,content:'120'},
{type:1,content:'禁言成功!'},
]"></chat-box>

View File

@@ -1,85 +0,0 @@
# 接入青云客智能聊天机器人API
作为一个群聊机器人,懂得聊天会让机器人增色不少,在大数据和 AI 热潮下,不少厂商都研发了自己的智能聊天 API例如图灵机器人、腾讯智能闲聊等大厂开发的 API 自然有着他人无可比拟的健壮性和可靠性,但是随之而来不菲的价格显然并不适合大众开发者。这时候一个免费、可用的智能聊天 API 便非常重要了,其中,青云客是少有的完全免费、无需注册的智能聊天 API提供了包括智能聊天、歌词、天气查询、笑话等多种有用功能且接入简单非常适合新手开发者尝试。
## 结果演示
![圖片](https://user-images.githubusercontent.com/31698606/158875192-108698a3-b54e-4fc0-889a-0829ca328b13.png)
## 阅读接入指南
不管接入何种服务,阅读接入指南永远都是最优先、最重要的一步,所幸青云客的接入指南十分简单,简单来说归纳为以下:
* 请求GET https://api.qingyunke.com/api.php
* 参数:
* * `key` 目前固定为 `free`
* * `appid` 目前固定为 `0`
* * `msg` 关键词,需要经过 `urlencode`
* 注意:返回结果中 `{br}` 代表换行
## 逻辑编写
阅读过后,我们便可以进行主要的编写工作了。
首先,为了机器人的性能考虑,也为了避免过分打扰群聊的聊天,我们希望机器人只有在主动触发(@AT 或者 关键词等)时才会进行智能聊天。
对于关键词匹配,我们可以使用 `@CQCommand`
```php
/**
* 智能聊天
*
* @CQCommand(start_with="机器人")
*/
public function chat()
{
// 替换掉机器人前缀,并获取消息内容
$msg = ctx()->getMessage();
$msg = str_replace('机器人', '', $msg);
if (empty(trim($msg))) {
$msg = ctx()->getFullArg('怎么了?');
}
Console::info('正在获取智能聊天回复:' . $msg);
// 请求 API 获取回复
$raw_data = file_get_contents('https://api.qingyunke.com/api.php?key=free&appid=0&msg=' . urlencode($msg));
try {
$data = json_decode($raw_data, true, 512, JSON_THROW_ON_ERROR);
} catch (\Exception $e) {
$data = ['content' => '机器人解析异常,请稍后再试'];
Console::warning('无法获取智能聊天回复:' . $e->getMessage());
}
if ($data['result'] !== 0) {
$data = ['content' => '机器人服务异常,请稍后再试'];
Console::warning('无法获取智能聊天回复:' . $raw_data);
}
Console::info('获取智能聊天回复完成:' . $data['content']);
// 将 {br} 替换为换行
$data['content'] = strtr($data['content'], ['{br}' => "\n"]);
return $data['content'];
}
```
这样我们的命令便只会在用户发送以`机器人`开头的消息时才会触发。
同时,我们也希望在 @AT 机器人时也进行回复,此时可以使用 `@CQBefore` 方法进行折中:
```php
/**
* 将 AT 机器人的消息交由智能聊天处理
*
* @CQBefore("message")
*/
public function changeAt(): bool
{
// 判断此条消息是否 AT 了机器人
if (MessageUtil::isAtMe(ctx()->getMessage(), ctx()->getRobotId())) {
// 将 AT 本身从消息中去掉
$msg = str_replace(CQ::at(ctx()->getRobotId()), '', ctx()->getMessage());
ctx()->setMessage('机器人' . trim($msg));
// 调用智能聊天
ctx()->reply($this->chat());
return false;
}
return true;
}
```

View File

@@ -1,113 +0,0 @@
# 基于词性分析和魅族天气的天气查询机器人
本文将基于 [`jieba-php`](https://github.com/fukuball/jieba-php) 中文分词库以及 [魅族天气 API](https://github.com/shichunlei/-Api/blob/master/MeizuWeather.md) 开发一个天气查询机器人。
## 结果演示
![圖片](https://user-images.githubusercontent.com/31698606/159122016-61ba9696-5786-4561-b371-827d9f1d01aa.png)
尾部的随机表情并非本教程的一部分。
## 逻辑编写
[jieba-php](https://github.com/fukuball/jieba-php) 是目前比较好用的中文分词库,虽然最近的维护并不活跃,但已足够我们的需求:
```shell
composer require fukuball/jieba-php:dev-master
```
以下代码使用了本文作者自行编写的天气查询库,需要进行引入:
```shell
composer require sunxyw/weather
```
您也可以将以下代码自行改写为直接调用魅族天气 API详情请参阅[魅族天气 API 文档](https://github.com/shichunlei/-Api/blob/master/MeizuWeather.md)。
```php
<?php
namespace Bot\Module\SmartChat;
use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Posseg;
use Sunxyw\Weather\Weather;
use ZM\Annotation\CQ\CQCommand;
use ZM\Console\Console;
class WeatherReport
{
/**
* 加载字典
*
* @OnStart(worker_id=-1)
*
* @return void
*/
public function initDictionary(): void
{
// 分词以及词性分析需要载入字典到内存
ini_set('memory_limit', '600M');
Jieba::init(['dict' => 'small']);
Posseg::init();
}
/**
* 查询天气
*
* @CQCommand(keyword="天气")
*
* @return string
*/
public function cmdQueryWeather(): string
{
// 分词并进行词性分析
$seg_list = Posseg::cut(ctx()->getMessage());
$tags = array_column($seg_list, 'tag');
// 找出词性为 ns地名的单词
$location_index = array_search('ns', $tags, true);
$location = $seg_list[$location_index]['word'];
// 此处引入了本文作者自己写的天气库
$w = new Weather();
try {
$report = $w->getWeather($location);
} catch (\InvalidArgumentException) {
return '城市输入错误';
} catch (\JsonException $e) {
Console::warning("天气查询失败:{$e->getMessage()}");
return '天气查询失败';
}
$template = <<<EOF
%s天气%s
温度:%s℃
湿度:%s%%
风向:%s %s
空气质量:%s
------------------------------
未来三天天气:
%s%s日间%s℃夜间%s℃吹%s %s
%s%s日间%s℃夜间%s℃吹%s %s
%s%s日间%s℃夜间%s℃吹%s %s
EOF;
$args = [
$report->getCity(),
$report->getRealtime()['weather'],
$report->getRealtime()['temperature'],
$report->getRealtime()['humidity'],
$report->getRealtime()['wind_direction'],
$report->getRealtime()['wind_speed'],
$report->getRealtime()['air_quality'],
];
foreach (array_slice($report->getForecastDaily(), 0, 3) as $forecast) {
$args[] = $forecast['date'];
$args[] = $forecast['weather'];
$args[] = $forecast['temperature']['day'];
$args[] = $forecast['temperature']['night'];
$args[] = $forecast['wind_direction'];
$args[] = $forecast['wind_speed'];
}
return vsprintf($template, ...$args);
}
}
```

View File

@@ -1,5 +0,0 @@
# 框架剖析
## 框架运行总结构图
![](https://static.zhamao.me/images/docs/a23d8a952cf9c88d395888d220605a4f.png)

View File

@@ -1,67 +0,0 @@
# 内部类文件手册
这个章节写明了在框架使用过程中可能涉及到的框架内部或 Swoole、其他 composer 依赖组件的内部类,这里会根据类的命名空间一一说明。
## Swoole\Http\Request
此类是 Swoole 内部的一个类,一般在收到 HTTP 请求时,在 `@RequestMapping``@OnRequestEvent()` 两个注解下可用,用作获取 GET、POST参数上传到后端的文件、Cookies 等。详见 [Swoole 文档 - Request](http://wiki.swoole.com/#/http_server?id=httprequest) 。
### 属性
- `$fd`:获取当前连接的文件描述符 ID。
- `$header``HTTP` 请求的头部信息。类型为数组,所有 `key` 均为小写。
- `$server``HTTP` 请求相关的服务器信息。
- `$cookie`:获取 Cookies。
- `$get`:获取 GET 参数。
- `$post`:获取 POST 参数。
- `$files`:获取上传的文件信息
### 方法
- `rawContent()`:获取 POST 包原始二进制内容,相当于原生 PHP 的 ` file_get_contents("php://input");`
- `getData()`:获取完整的原始 `Http` 请求报文。包括 `Http Header``Http Body`
### 示例
```php
TODO先放一放。
```
## ZM\Entity\MatchObject
此类是调用方法 `MessageUtil::matchCommand()` 返回的对象体,含有匹配成功与否和匹配到的注解相关的信息。
### 属性
- `$match``bool` 类型,返回匹配是否成功
- `$object``CQCommand` 注解类,如果匹配成功则返回对应的 `@CQCommand` 信息
- `match``array` 类型,如果匹配成功则返回匹配到的参数
```php
// 假设我有一个注解事件 @CQCommand(match="你好"),绑定的函数是 \Module\Example\Hello 下的 hello123()
$obj = MessageUtil::matchCommand("你好 我叫顺溜 我今年二十八", ctx()->getData());
/* 以下是返回信息,仅供参考
$obj->match ==> true
$obj->object ==> \ZM\Annotation\CQ\CQCommand: (
match: "你好",
pattern: "",
regex: "",
start_with: "",
end_with: "",
keyword: "",
alias: [],
message_type: "",
user_id: 0,
group_id: 0,
discuss_id: 0,
level: 20,
method: "hello123",
class: \Module\Example\Hello::class
)
$obj->match ==> [
"我叫顺溜",
"我今年二十八"
]
*/
```

View File

@@ -1,3 +0,0 @@
# 手动部署环境教程
TODO: 还没写

View File

@@ -1,72 +0,0 @@
# 框架多进程
首先对于多进程概念,对于传统 PHP 程序员可能比较陌生,唯一接触到的地方可能就是 php-fpm 等一些方式处理时间长的请求时开进程去执行。关于多进程,我觉得廖雪峰的 Python 多进程这段讲的不错:
> Unix/Linux 操作系统提供了一个`fork()`系统调用,它非常特殊。普通的函数调用,调用一次,返回一次,但是`fork()`调用一次,返回两次,因为操作系统自动把当前进程(称为父进程)复制了一份(称为子进程),然后,分别在父进程和子进程内返回。
这里面的重点在于,多进程的创建,是父进程的复制,然后两个进程接下来运行的代码和存的内容就分道扬镳了。
PHP 也是如此,框架的多进程又是怎么一回事呢?为什么要采用多进程呢?
## 作用
使用过框架的你一定知道,框架是以命令行方式运行 PHP 的,而命令行方式运行 PHP就代表要常驻内存就像 Python、Node.js 一样。而默认情况下,比如 Python 的 Flask 为单线程单进程模式,也就是说同时只能处理一个 Web 请求。但大部分情况下,比如 Node.js提供的都是异步 I/O这也就是说明它在 Web 处理请求上,可同时承接的 I/O 密集型请求会更多一些,这样在对一般的 Web 应用中 I/O 密集型场景非常有用,而且往往只需要单进程也可以承载上万的并发请求。
在炸毛框架中,因为框架基于 Swoole 构建,所以天然支持协程,而协程就是针对 I/O 操作进行一个调度,类似异步的 Node.js所以针对项目中存在太多的 SQL 语句执行、文件读写的话,炸毛框架直接上手,无需做任何修改,也可以达到很好的性能。
**但是**CPU 密集型的应用怎么办呢?假设我的 Web 应用有大量的排序、md5 运算怎么办呢?这样的阻塞,假设是一个超级大的 for 循环或者是要执行很长时间的 while 循环CPU 一直在被占用。多进程就是针对 CPU 密集型的应用说 yes 的一个方案。
![diagram](https://static.zhamao.me/images/docs/06c17ab473f17ab10523a938cdbd8760.png)
我们假设现在有 3 个请求同时访问,也就是说上面的流程需要执行 3 遍。而如果我们只有一个进程的话,最后一个请求需要等待的时间为 `2*3+5*3=21` 秒,非常耗时。
而如果有两个进程处理 3 个请求,则最后一个完成的请求就缩短了,`2+5+2+5=14` 秒。
![diagram](https://static.zhamao.me/images/docs/dbb4e32e1c77f96162d10e41f25befa4.png)
所以如果要充分利用你的服务器或者个人电脑的多核 CPU 资源,就要设置多个进程来处理。一个进程只能在一个 CPU 上运行,而设置了多进程后,就可以让多核 CPU 充分运行多个进程,所以我们给框架设置多进程的推荐数值为等同于 CPU 的核心数。
## 为什么不是多线程
因为众所周知PHP 对线程的支持比较不好,而 ZTS 版本的 PHP 又会影响传统的 Web 端 PHP 的性能,再加上 Linux 对线程的切换效率和多进程切换的效率差不多,多线程容易造成数据读写不安全等问题,故 Swoole 使用的是多进程模型。
## 框架进程模型
![diagram](https://static.zhamao.me/images/docs/46a34feb0195d6ea12da7b80750c9e71.png)
上图中,横向的时间片可以理解为并行执行,这些操作在多个 CPU 内可能同时在执行。
## 进程间隔离
众所周知,进程是程序在操作系统中的一个边界,和自己有关的一切变量、内容和代码都在自己的进程内,不同进程之间如果不使用管道等方式,是不可以互相访问的。而加上开始描述的,创建子进程是一个复制自身的过程,所以也就会有如下图的情况:
![diagram](https://static.zhamao.me/images/docs/8b43e2179a63c8d91a508d7cefcd3226.png)
我们以静态类为例,设置一个进程中的全局变量。这里就会出现,同一个静态变量在多个进程中完全不同的值的结果。此后,我们将会在 Worker 进程中执行用户的代码,如果设置 Worker 数量仅为 1 的话,那么就简单许多了,你还是可以使用全局变量或静态类来存储你想要的内容而不用担心这种多个进程变量隔离的情况(因为用户的 Web 请求处理的代码只会在一个 Worker 进程中执行)。如果像上图一样设置了多个 Worker则用户过来的比如 HTTP 请求就有可能出现在不同的 Worker 进程中,给全局变量设值就一定会造成不同步的问题。这时我们就不可以使用全局变量做数据同步(注意,我说的是数据同步)。
## 跨进程同步
跨进程同步方案中,框架给出了很多种解决方案。
- MySQL 数据库
- Redis
- LightCache 轻量缓存(共享内存)
- WorkerCache 大缓存
- ZMAtomic 跨进程原子计数器
下面的表格我将列出下方的特点和各自的优缺点:
| 类型 | 用途 | 优点 | 缺点 |
| ----------- | --------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------ |
| MySQL | 大型的传统的关系式数据都可以用数据库,你懂的 | 就是数据库的优点 | 和数据库不在同一台服务器的话网络延迟会较大,数据获取效率不高 |
| Redis | 传统的 key-value 数据库 | 数据无同步等问题,性能高 | 有网络通信延迟 |
| LightCache | 框架封装的跨进程的 key-value 存储模型 | 性能强悍,无 I/O 和网络通信 | 需要提前分配最大内存大小,最大单个值长度大小,不灵活 |
| WorkerCache | 框架封装的基于进程的 key-value 存储模型,类似 Redis | 无需提前分配最大内存大小,受限于 PHP memory_limit | 见 WorkerCache 的说明 |
::: tip WorkerCache 的说明
对于 WorkerCache 来说其实是比较特殊的进程间通信。具体来说就是WorkerCache 的原理就是将变量指定的存到一个进程中,如果是本进程读写的话直接相当于改一下全局变量,如果是其他进程读写的话,则依靠进程间通信。
所以缺点也显而易见,如果使用过程中不是命中了 WorkerCache 存储所在的进程的话,则一直会使用进程间通信,影响一定的效率。
:::

View File

@@ -1,3 +0,0 @@
# PHP 环境高级部署方式
TODO: 留个坑。

View File

@@ -1,3 +0,0 @@
# 使用 TaskWorker 进程处理密集运算
> TODO: 新开个坑有时间补上。__填坑标记__

View File

@@ -1,618 +0,0 @@
# ZM\API\CQ
## at
```php
public function at(int|string $qq): string
```
### 描述
at一下QQ用户仅在QQ群支持at全体
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| qq | int|string | 用户QQ号/ID号 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## face
```php
public function face(int|string $id): string
```
### 描述
发送QQ原生表情
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| id | int|string | 表情ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## image
```php
public function image(string $file, bool $cache, bool $flash, bool $proxy, int $timeout): string
```
### 描述
发送图片
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| file | string | 文件的路径、URL或者base64编码的图片数据 |
| cache | bool | 是否缓存默认为true |
| flash | bool | 是否闪照默认为false |
| proxy | bool | 是否使用代理默认为true |
| timeout | int | 超时时间(默认不超时) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## record
```php
public function record(string $file, bool $magic, bool $cache, bool $proxy, int $timeout): string
```
### 描述
发送语音
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| file | string | 文件的路径、URL或者base64编码的语音数据 |
| magic | bool | 是否加特技默认为false |
| cache | bool | 是否缓存默认为true |
| proxy | bool | 是否使用代理默认为true |
| timeout | int | 超时时间(默认不超时) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## video
```php
public function video(string $file, bool $cache, bool $proxy, int $timeout): string
```
### 描述
发送短视频
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| file | string | 文件的路径、URL或者base64编码的短视频数据 |
| cache | bool | 是否缓存默认为true |
| proxy | bool | 是否使用代理默认为true |
| timeout | int | 超时时间(默认不超时) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## rps
```php
public function rps(): string
```
### 描述
发送投掷骰子(只能在单条回复中单独使用)
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## dice
```php
public function dice(): string
```
### 描述
发送掷骰子表情(只能在单条回复中单独使用)
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## shake
```php
public function shake(): string
```
### 描述
戳一戳(原窗口抖动,仅支持好友消息使用)
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## poke
```php
public function poke(int|string $type, int|string $id, string $name): string
```
### 描述
发送新的戳一戳
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| type | int|string | 焯一戳类型 |
| id | int|string | 戳一戳ID号 |
| name | string | 戳一戳名称(可选) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## anonymous
```php
public function anonymous(int $ignore): string
```
### 描述
发送匿名消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| ignore | int | 是否忽略错误默认为10表示不忽略错误 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## share
```php
public function share(string $url, string $title, null|string $content, null|string $image): string
```
### 描述
发送链接分享(只能在单条回复中单独使用)
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| url | string | 分享地址 |
| title | string | 标题 |
| content | null|string | 卡片内容(可选) |
| image | null|string | 卡片图片(可选) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## contact
```php
public function contact(int|string $type, int|string $id): string
```
### 描述
发送好友或群推荐名片
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| type | int|string | 名片类型 |
| id | int|string | 好友或群ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## location
```php
public function location(float|string $lat, float|string $lon, string $title, string $content): string
```
### 描述
发送位置
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| lat | float|string | 纬度 |
| lon | float|string | 经度 |
| title | string | 标题(可选) |
| content | string | 卡片内容(可选) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## music
```php
public function music(string $type, int|string $id_or_url, null|string $audio, null|string $title, null|string $content, null|string $image): string
```
### 描述
发送音乐分享(只能在单条回复中单独使用)
qq、163、xiami为内置分享需要先通过搜索功能获取id后使用
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| type | string | 分享类型(仅限 `qq``163``xiami``custom` |
| id_or_url | int|string | 当分享类型不是 `custom`表示的是分享音乐的ID需要先通过搜索功能获取id后使用反之表示的是音乐卡片点入的链接 |
| audio | null|string | 当分享类型是 `custom`表示为音乐如mp3文件的HTTP链接地址不可为空 |
| title | null|string | 当分享类型是 `custom`表示为音乐卡片的标题建议12字以内不可为空 |
| content | null|string | 当分享类型是 `custom` 时,表示为音乐卡片的简介(可忽略) |
| image | null|string | 当分享类型是 `custom` 时,表示为音乐卡片的图片链接地址(可忽略) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## forward
```php
public function forward(int|string $id): string
```
### 描述
合并转发消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| id | int|string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## node
```php
public function node(int|string $user_id, string $nickname, string $content): string
```
### 描述
合并转发消息节点
特殊说明: 需要使用单独的API /send_group_forward_msg 发送, 并且由于消息段较为复杂, 仅支持Array形式入参。
如果引用消息和自定义消息同时出现, 实际查看顺序将取消息段顺序。
另外按 CQHTTP 文档说明, data 应全为字符串, 但由于需要接收message 类型的消息, 所以 仅限此Type的content字段 支持Array套娃
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| user_id | int|string | 转发消息id |
| nickname | string | 发送者显示名字 |
| content | string | 具体消息 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## xml
```php
public function xml(string $data): string
```
### 描述
XML消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| data | string | xml内容, xml中的value部分 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## json
```php
public function json(string $data, int $resid): string
```
### 描述
JSON消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| data | string | json内容 |
| resid | int | 0为走小程序通道其他值为富文本通道默认为0 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## _custom
```php
public function _custom(string $type_name, array $params): string
```
### 描述
返回一个自定义扩展的CQ码支持自定义类型和参数
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| type_name | string | CQ码类型名称 |
| params | array | 参数 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | CQ码 |
## decode
```php
public function decode(int|string|Stringable $msg, bool $is_content): string
```
### 描述
反转义字符串中的CQ码敏感符号
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | int|string|Stringable | 字符串 |
| is_content | bool | 如果是解码CQ码本体内容则为false默认如果是参数内的字符串则为true |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | 转义后的CQ码 |
## replace
```php
public function replace(int|string|Stringable $str): string
```
### 描述
简单反转义替换CQ码的方括号
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| str | int|string|Stringable | 字符串 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | 字符串 |
## escape
```php
public function escape(int|string|Stringable $msg, bool $is_content): string
```
### 描述
转义CQ码的特殊字符同encode
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | int|string|Stringable | 字符串 |
| is_content | bool | 如果是转义CQ码本体内容则为false默认如果是参数内的字符串则为true |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | 转义后的CQ码 |
## encode
```php
public function encode(int|string|Stringable $msg, bool $is_content): string
```
### 描述
转义CQ码的特殊字符
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | int|string|Stringable | 字符串 |
| is_content | bool | 如果是转义CQ码本体内容则为false默认如果是参数内的字符串则为true |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | 转义后的CQ码 |
## removeCQ
```php
public function removeCQ(string $msg): string
```
### 描述
移除消息中所有的CQ码并返回移除CQ码后的消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | string | 消息 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | 消息内容 |
## getCQ
```php
public function getCQ(string $msg, bool $is_object): null|array|CQObject
```
### 描述
获取消息中第一个CQ码
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | string | 消息内容 |
| is_object | bool | 是否以对象形式返回如果为False的话返回数组形式默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| null|array|CQObject | 返回的CQ码数组或对象 |
## getAllCQ
```php
public function getAllCQ(string $msg, bool $is_object): array|CQObject[]
```
### 描述
获取消息中所有的CQ码
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | string | 消息内容 |
| is_object | bool | 是否以对象形式返回如果为False的话返回数组形式默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|CQObject[] | 返回的CQ码们数组或对象 |

View File

@@ -1,130 +0,0 @@
# ZM\API\GoCqhttpAPIV11
## getGuildServiceProfile
```php
public function getGuildServiceProfile(): array|bool
```
### 描述
获取频道系统内BOT的资料
响应字段nickname, tiny_id, avatar_url
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGuildList
```php
public function getGuildList(): array|bool
```
### 描述
获取频道列表
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGuildMetaByGuest
```php
public function getGuildMetaByGuest(int|string $guild_id): array|bool
```
### 描述
通过访客获取频道元数据
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| guild_id | int|string | 频道ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGuildChannelList
```php
public function getGuildChannelList(int|string $guild_id, false $no_cache): array|bool
```
### 描述
获取子频道列表
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| guild_id | int|string | 频道ID |
| no_cache | false | 禁用缓存默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGuildMembers
```php
public function getGuildMembers(int|string $guild_id): array|bool
```
### 描述
获取频道成员列表
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| guild_id | int|string | 频道ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## sendGuildChannelMsg
```php
public function sendGuildChannelMsg(int|string $guild_id, int|string $channel_id, string $message): array|bool
```
### 描述
发送信息到子频道
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| guild_id | int|string | 频道ID |
| channel_id | int|string | 子频道ID |
| message | string | 信息内容 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |

View File

@@ -1,984 +0,0 @@
# ZM\API\OneBotV11
## get
```php
public function get(int|string $robot_id): ZMRobot
```
### 描述
获取机器人Action/API实例
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| robot_id | int|string | 机器人ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| ZMRobot | 机器人实例 |
## getRandom
```php
public function getRandom(): ZMRobot
```
### 描述
随机获取一个连接到框架的机器人实例
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| ZMRobot | 机器人实例 |
## getAllRobot
```php
public function getAllRobot(): ZMRobot[]
```
### 描述
获取所有机器人实例
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| ZMRobot[] | 机器人实例们 |
## setCallback
```php
public function setCallback(bool|Closure $callback): OneBotV11
```
### 描述
设置回调或启用协程等待API回包
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| callback | bool|Closure | 是否开启协程或设置异步回调函数如果为true则协程等待结果如果为false则异步执行并不等待结果如果为回调函数则异步执行且调用回调 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| OneBotV11 | 返回本身 |
## setPrefix
```php
public function setPrefix(int $prefix): OneBotV11
```
### 描述
设置API调用类型后缀
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| prefix | int | 设置后缀类型API_NORMAL为不加后缀API_ASYNC为异步调用API_RATE_LIMITED为加后缀并且限制调用频率 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| OneBotV11 | 返回本身 |
## sendPrivateMsg
```php
public function sendPrivateMsg(int|string $user_id, string $message, bool $auto_escape): array|bool
```
### 描述
发送私聊消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| user_id | int|string | 用户ID |
| message | string | 消息内容 |
| auto_escape | bool | 是否自动转义默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## sendGroupMsg
```php
public function sendGroupMsg(int|string $group_id, string $message, bool $auto_escape): array|bool
```
### 描述
发送群消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群组ID |
| message | string | 消息内容 |
| auto_escape | bool | 是否自动转义默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## sendMsg
```php
public function sendMsg(string $message_type, int|string $target_id, string $message, bool $auto_escape): array|bool
```
### 描述
发送消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| message_type | string | 消息类型 |
| target_id | int|string | 目标ID |
| message | string | 消息内容 |
| auto_escape | bool | 是否自动转义默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## deleteMsg
```php
public function deleteMsg(int|string $message_id): array|bool
```
### 描述
撤回消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| message_id | int|string | 消息ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getMsg
```php
public function getMsg(int|string $message_id): array|bool
```
### 描述
获取消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| message_id | int|string | 消息ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getForwardMsg
```php
public function getForwardMsg(int|string $id): array|bool
```
### 描述
获取合并转发消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| id | int|string | ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## sendLike
```php
public function sendLike(int|string $user_id, int $times): array|bool
```
### 描述
发送好友赞
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| user_id | int|string | 用户ID |
| times | int | 时间 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupKick
```php
public function setGroupKick(int|string $group_id, int|string $user_id, bool $reject_add_request): array|bool
```
### 描述
群组踢人
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| user_id | int|string | 用户ID |
| reject_add_request | bool | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupBan
```php
public function setGroupBan(int|string $group_id, int|string $user_id, int $duration): array|bool
```
### 描述
群组单人禁言
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| user_id | int|string | 用户ID |
| duration | int | 禁言时长 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupAnonymousBan
```php
public function setGroupAnonymousBan(int|string $group_id, array|int|string $anonymous_or_flag, int $duration): array|bool
```
### 描述
群组匿名用户禁言
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| anonymous_or_flag | array|int|string | 匿名禁言Flag或匿名用户对象 |
| duration | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupWholeBan
```php
public function setGroupWholeBan(int|string $group_id, bool $enable): array|bool
```
### 描述
群组全员禁言
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| enable | bool | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupAdmin
```php
public function setGroupAdmin(int|string $group_id, int|string $user_id, bool $enable): array|bool
```
### 描述
群组设置管理员
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| user_id | int|string | 用户ID |
| enable | bool | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupAnonymous
```php
public function setGroupAnonymous(int|string $group_id, bool $enable): array|bool
```
### 描述
群组匿名
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| enable | bool | 是否启用默认为true |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupCard
```php
public function setGroupCard(int|string $group_id, int|string $user_id, string $card): array|bool
```
### 描述
设置群名片(群备注)
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| user_id | int|string | 用户ID |
| card | string | 名片内容(默认为空) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupName
```php
public function setGroupName(int|string $group_id, string $group_name): array|bool
```
### 描述
设置群名
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| group_name | string | 群名 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupLeave
```php
public function setGroupLeave(int|string $group_id, bool $is_dismiss): array|bool
```
### 描述
退出群组
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| is_dismiss | bool | 是否解散默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupSpecialTitle
```php
public function setGroupSpecialTitle(int|string $group_id, int|string $user_id, string $special_title, int $duration): array|bool
```
### 描述
设置群组专属头衔
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| user_id | int|string | 用户ID |
| special_title | string | 专属头衔内容 |
| duration | int | 持续时间(默认为-1永久 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setFriendAddRequest
```php
public function setFriendAddRequest(array|int|string $flag, bool $approve, string $remark): array|bool
```
### 描述
处理加好友请求
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| flag | array|int|string | 处理加好友请求的flag |
| approve | bool | 是否同意默认为true |
| remark | string | 设置昵称(默认不设置) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setGroupAddRequest
```php
public function setGroupAddRequest(array|int|string $flag, string $sub_type, bool $approve, string $reason): array|bool
```
### 描述
处理加群请求/邀请
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| flag | array|int|string | 处理加群请求的flag |
| sub_type | string | 处理请求类型包含add和invite |
| approve | bool | 是否同意默认为true |
| reason | string | 拒绝理由(仅在拒绝时有效,默认为空) |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getLoginInfo
```php
public function getLoginInfo(): array|bool
```
### 描述
获取登录号信息
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getStrangerInfo
```php
public function getStrangerInfo(int|string $user_id, bool $no_cache): array|bool
```
### 描述
获取陌生人信息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| user_id | int|string | 用户ID |
| no_cache | bool | 是否不使用缓存默认为false |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getFriendList
```php
public function getFriendList(): array|bool
```
### 描述
获取好友列表
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGroupInfo
```php
public function getGroupInfo(int|string $group_id, bool $no_cache): array|bool
```
### 描述
获取群信息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| no_cache | bool | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGroupList
```php
public function getGroupList(): array|bool
```
### 描述
获取群列表
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGroupMemberInfo
```php
public function getGroupMemberInfo(int|string $group_id, int|string $user_id, bool $no_cache): array|bool
```
### 描述
获取群成员信息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| user_id | int|string | 用户ID |
| no_cache | bool | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGroupMemberList
```php
public function getGroupMemberList(int|string $group_id): array|bool
```
### 描述
获取群成员列表
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getGroupHonorInfo
```php
public function getGroupHonorInfo(int|string $group_id, string $type): array|bool
```
### 描述
获取群荣誉信息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| group_id | int|string | 群ID |
| type | string | 荣誉类型 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getCsrfToken
```php
public function getCsrfToken(): array|bool
```
### 描述
获取 CSRF Token
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getCredentials
```php
public function getCredentials(string $domain): array|bool
```
### 描述
获取 QQ 相关接口凭证
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| domain | string | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getRecord
```php
public function getRecord(string $file, string $out_format): array|bool
```
### 描述
获取语音
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| file | string | 文件 |
| out_format | string | 输出格式 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getImage
```php
public function getImage(string $file): array|bool
```
### 描述
获取图片
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| file | string | 文件 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## canSendImage
```php
public function canSendImage(): array|bool
```
### 描述
检查是否可以发送图片
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## canSendRecord
```php
public function canSendRecord(): array|bool
```
### 描述
检查是否可以发送语音
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getStatus
```php
public function getStatus(): array|bool
```
### 描述
获取运行状态
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getVersionInfo
```php
public function getVersionInfo(): array|bool
```
### 描述
获取版本信息
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## setRestart
```php
public function setRestart(int $delay): array|bool
```
### 描述
重启 OneBot 实现
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| delay | int | 延迟时间毫秒默认为0 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## cleanCache
```php
public function cleanCache(): array|bool
```
### 描述
清理缓存
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |
## getExtendedAPI
```php
public function getExtendedAPI(string $package_name): mixed
```
### 描述
获取内置支持的扩展API对象
现支持 go-cqhttp 的扩展API
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| package_name | string | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | 返回包的操作对象 |
## callExtendedAPI
```php
public function callExtendedAPI(string $action, array $params): array|bool
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| action | string | 动作API名称 |
| params | array | 参数 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array|bool | 返回API调用结果数组或异步API调用状态bool |

View File

@@ -1,117 +0,0 @@
# ZM\API\Proxies\Bot\AbstractBotProxy
## __construct
```php
public function __construct(AbstractBotProxy|ZMRobot $bot): mixed
```
### 描述
构造函数
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| bot | AbstractBotProxy|ZMRobot | 调用此代理的机器人实例 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## __call
```php
public function __call(string $name, array $arguments): mixed
```
### 描述
在传入的机器人实例上调用方法
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| name | string | 方法名 |
| arguments | array | 参数 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## __get
```php
public function __get(string $name): mixed
```
### 描述
获取传入的机器人实例的属性
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| name | string | 属性名 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## __set
```php
public function __set(string $name, mixed $value): mixed
```
### 描述
设置传入的机器人实例的属性
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| name | string | 属性名 |
| value | mixed | 属性值 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## __isset
```php
public function __isset(string $name): bool
```
### 描述
判断传入的机器人实例的属性是否存在
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| name | string | 属性名 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| bool | |

View File

@@ -1,24 +0,0 @@
# ZM\API\Proxies\Bot\AllBotsProxy
## __call
```php
public function __call(string $name, array $arguments): array<mixed>
```
### 描述
在所有机器人实例上调用方法
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| name | string | 方法名 |
| arguments | array | 参数 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array<mixed> | 返回一个包含所有执行结果的数组键名为机器人ID |

View File

@@ -1,24 +0,0 @@
# ZM\API\Proxies\Bot\AllGroupsProxy
## __call
```php
public function __call(string $name, array $arguments): array<mixed>
```
### 描述
在传入的机器人实例上调用方法
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| name | string | 方法名 |
| arguments | array | 参数 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| array<mixed> | 返回一个包含所有执行结果的数组,键名为群号 |

View File

@@ -1,48 +0,0 @@
# ZM\API\TuringAPI
## getTuringMsg
```php
public function getTuringMsg(string $msg, int|string $user_id, string $api): string
```
### 描述
请求图灵API返回图灵的消息
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| msg | string | 消息 |
| user_id | int|string | 用户ID |
| api | string | API Key |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| string | 图灵的回复 |
## getResultStatus
```php
public function getResultStatus(array $r): bool|string
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| r | array | 数据API回包 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| bool|string | 错误消息或成功鸥鸟 |

View File

@@ -1,46 +0,0 @@
# ZM\API\ZMRobot
## all
```php
public function all(ZM\API\Proxies\Bot\AbstractBotProxy $proxy): ZM\API\Proxies\Bot\AllBotsProxy
```
### 描述
获取一个会在所有机器人实例上执行的代理
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| proxy | ZM\API\Proxies\Bot\AbstractBotProxy | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| ZM\API\Proxies\Bot\AllBotsProxy | |
## allGroups
```php
public function allGroups(ZM\API\Proxies\Bot\AbstractBotProxy $proxy): ZM\API\Proxies\Bot\AllGroupsProxy
```
### 描述
获取一个会在所有群上执行的代理
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| proxy | ZM\API\Proxies\Bot\AbstractBotProxy | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| ZM\API\Proxies\Bot\AllGroupsProxy | |

View File

@@ -1 +0,0 @@
# ZM\Annotation\AnnotationBase

View File

@@ -1,100 +0,0 @@
# ZM\Annotation\AnnotationParser
## __construct
```php
public function __construct(): mixed
```
### 描述
AnnotationParser constructor.
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## registerMods
```php
public function registerMods(): mixed
```
### 描述
注册各个模块类的注解和模块level的排序
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## addRegisterPath
```php
public function addRegisterPath(string $path, string $indoor_name): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| path | string | 注册解析注解的路径 |
| indoor_name | string | 起始命名空间的名称 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## sortByLevel
```php
public function sortByLevel(array $events, string $class_name, string $prefix): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| events | array | 需要排序的 |
| class_name | string | 排序的类名 |
| prefix | string | 前缀 |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## verifyMiddlewares
```php
public function verifyMiddlewares(): mixed
```
### 描述
作者很懒,什么也没有说
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1 +0,0 @@
# ZM\Annotation\CQ\CQAPIResponse

View File

@@ -1,39 +0,0 @@
# ZM\Annotation\CQ\CQAfter
## getLevel
```php
public function getLevel(): mixed
```
### 描述
作者很懒,什么也没有说
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## setLevel
```php
public function setLevel(mixed $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | mixed | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1,39 +0,0 @@
# ZM\Annotation\CQ\CQBefore
## getLevel
```php
public function getLevel(): mixed
```
### 描述
作者很懒,什么也没有说
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## setLevel
```php
public function setLevel(mixed $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | mixed | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1,22 +0,0 @@
# ZM\Annotation\CQ\CQCommand
## setLevel
```php
public function setLevel(int $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1 +0,0 @@
# ZM\Annotation\CQ\CQMessage

View File

@@ -1,39 +0,0 @@
# ZM\Annotation\CQ\CQMetaEvent
## getLevel
```php
public function getLevel(): mixed
```
### 描述
作者很懒,什么也没有说
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |
## setLevel
```php
public function setLevel(int $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1,22 +0,0 @@
# ZM\Annotation\CQ\CQNotice
## setLevel
```php
public function setLevel(int $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1,22 +0,0 @@
# ZM\Annotation\CQ\CQRequest
## setLevel
```php
public function setLevel(int $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1 +0,0 @@
# ZM\Annotation\Command\TerminalCommand

View File

@@ -1,61 +0,0 @@
# ZM\Annotation\Cron\Cron
## setStatus
```php
public function setStatus(int $status): void
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| status | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| void | |
## getRecordNextTime
```php
public function getRecordNextTime(): int
```
### 描述
作者很懒,什么也没有说
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| int | |
## setRecordNextTime
```php
public function setRecordNextTime(int $record_next_time): void
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| record_next_time | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| void | |

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\Controller

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\HandleAfter

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\HandleBefore

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\HandleException

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\Middleware

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\MiddlewareClass

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\RequestMapping

View File

@@ -1 +0,0 @@
# ZM\Annotation\Http\RequestMethod

View File

@@ -1 +0,0 @@
# ZM\Annotation\Module\Closed

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnCloseEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnManagerStartEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnMessageEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnOpenEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnPipeMessageEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnRequestEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnSave

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnSetup

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnStart

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnSwooleEvent

View File

@@ -1,23 +0,0 @@
# ZM\Annotation\Swoole\OnSwooleEventBase
## setLevel
```php
public function setLevel(int $level): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| level | int | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1,17 +0,0 @@
# ZM\Annotation\Swoole\OnTask
## getRule
```php
public function getRule(): mixed
```
### 描述
作者很懒,什么也没有说
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnTaskEvent

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\OnTick

View File

@@ -1 +0,0 @@
# ZM\Annotation\Swoole\SwooleHandler

View File

@@ -1 +0,0 @@
# ZM\Command\BuildCommand

View File

@@ -1,25 +0,0 @@
# ZM\Command\CheckConfigCommand
## check
```php
public function check(mixed $remote, mixed $local, Symfony\Component\Console\Output\OutputInterface $out): mixed
```
### 描述
作者很懒,什么也没有说
### 参数
| 名称 | 类型 | 描述 |
| -------- | ---- | ----------- |
| remote | mixed | |
| local | mixed | |
| out | Symfony\Component\Console\Output\OutputInterface | |
### 返回
| 类型 | 描述 |
| ---- | ----------- |
| mixed | |

View File

@@ -1 +0,0 @@
# ZM\Command\Daemon\DaemonCommand

View File

@@ -1 +0,0 @@
# ZM\Command\Daemon\DaemonReloadCommand

View File

@@ -1 +0,0 @@
# ZM\Command\Daemon\DaemonStatusCommand

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