mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 23:55:35 +08:00
update to 2.4.4 version (build 405)
change requirements: add pcntl as required extension update docs
This commit is contained in:
@@ -118,7 +118,7 @@ dump(LightCache::getExpire("test")); // 返回 10
|
||||
|
||||
### LightCache::getExpireTS()
|
||||
|
||||
获取存储项要过期的时间戳。
|
||||
获取存储项要过期的时间戳。(2.4.3 起可用)
|
||||
|
||||
定义:`LightCache::getExpireTS(string $key)`
|
||||
|
||||
@@ -135,7 +135,7 @@ dump(LightCache::getExpire("test")); // 返回 null
|
||||
获取轻量缓存使用的总空间大小(字节)
|
||||
|
||||
```php
|
||||
LightCache::getMemoryUsage());
|
||||
LightCache::getMemoryUsage();
|
||||
```
|
||||
|
||||
轻量缓存的内存手工计算方式:(Table 结构体长度` + `KEY 长度 64 字节 + `$size`) * (1 + `$conflict_proportion`) * 列尺寸。
|
||||
|
||||
@@ -87,3 +87,29 @@ MessageUtil::splitCommand("我有 三个空格"); // ["我有","三个空格"]
|
||||
|
||||
返回:`\ZM\Entity\MatchObject` 对象,含有匹配成功与否,匹配到的注解对象,匹配到的分割词等,见 []
|
||||
|
||||
### addShortCommand()
|
||||
|
||||
快速添加一条静态消息回复命令。
|
||||
|
||||
定义:`addShortCommand($command, string $reply)`
|
||||
|
||||
参数 `$command` 为问的内容,如 `炸毛不聪明`。
|
||||
|
||||
参数 `$reply` 为回复的内容,如 `其实还是很聪明的!`。
|
||||
|
||||
这个命令推荐在 `@OnStart` 注解下使用,可以用这个来做一个动态的词库,从文件加载后使用。
|
||||
|
||||
```php
|
||||
/**
|
||||
* @OnStart()
|
||||
*/
|
||||
public function onStart() {
|
||||
MessageUtil::addShortCommand("炸毛不聪明", "其实还是很聪明的!");
|
||||
}
|
||||
```
|
||||
|
||||
<chat-box>
|
||||
) 炸毛不聪明
|
||||
( 其实还是很聪明的!
|
||||
</chat-box>
|
||||
|
||||
|
||||
86
docs/component/turing-api.md
Normal file
86
docs/component/turing-api.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# 图灵机器人 API(TuringAPI)
|
||||
|
||||
类定义:`\ZM\API\TuringAPI`
|
||||
|
||||
## 方法
|
||||
|
||||
### TuringAPI::getTuringMsg()
|
||||
|
||||
请求图灵接口,返回回复的消息。
|
||||
|
||||
定义:`getTuringMsg($msg, $user_id, $api)`
|
||||
|
||||
参数 `$msg` 为用户的消息内容,如果含有图片 CQ 码,则自动转换为图灵兼容的接口模式。
|
||||
|
||||
参数 `$user_id` 为用户 ID,一般默认给 QQ 号码就可以了,注意最好不要有特殊字符(如 `./\<>*` 等),否则会间断性调用失败。
|
||||
|
||||
参数 `$api` 为图灵机器人的 `apikey`,可以到 <http://www.turingapi.com/> 申请免费或付费的 API key。
|
||||
|
||||
在框架的示例模块中,已经写好了一个正常机器人响应图灵回复的命令,如下:
|
||||
|
||||
```php
|
||||
class Hello {
|
||||
/**
|
||||
* 图灵机器人的内置实现,在www.turingapi.com申请一个apikey填入下方变量即可。
|
||||
* @CQCommand(start_with="机器人",end_with="机器人",message_type="group")
|
||||
* @CQMessage(message_type="private",level=1)
|
||||
*/
|
||||
public function turingAPI() {
|
||||
$user_id = ctx()->getUserId();
|
||||
$api = ""; // 请在这里填入你的图灵机器人的apikey
|
||||
if ($api === "") return false; //如果没有填入apikey则此功能关闭
|
||||
if (($this->_running_annotation ?? null) instanceof CQCommand) {
|
||||
$msg = ctx()->getFullArg("我在!有什么事吗?");
|
||||
} else {
|
||||
$msg = ctx()->getMessage();
|
||||
}
|
||||
ctx()->setMessage($msg);
|
||||
if (MessageUtil::matchCommand($msg, ctx()->getData())->status === false) {
|
||||
return TuringAPI::getTuringMsg($msg, $user_id, $api);
|
||||
} else {
|
||||
QQBot::getInstance()->handle(ctx()->getData(), ctx()->getCache("level") + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应at机器人的消息
|
||||
* @CQBefore("message")
|
||||
*/
|
||||
public function changeAt() {
|
||||
if (MessageUtil::isAtMe(ctx()->getMessage(), ctx()->getRobotId())) {
|
||||
$msg = str_replace(CQ::at(ctx()->getRobotId()), "", ctx()->getMessage());
|
||||
ctx()->setMessage("机器人" . $msg);
|
||||
Console::info(ctx()->getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如上述代码,我们将申请的 apikey 填入变量 `$api` 中,启动机器人即可使用,以下是实测消息(我用自己申请的 key 做测试回复的消息)。
|
||||
|
||||
<chat-box>
|
||||
) 你咋了
|
||||
( 我没事哦,谢谢您的关心。
|
||||
) 上海天气
|
||||
( 上海:周一 03月29日,小雨 东南风转东风,最低气温14度,最高气温24度。
|
||||
^ 切换为群内
|
||||
) 机器人
|
||||
( 我在!有什么事吗?
|
||||
) 你叫啥
|
||||
( 我的名字叫炸毛,认识你很高兴呢!
|
||||
</chat-box>
|
||||
|
||||
在默认示例模块中的例子是直接可以拿来用的,这段代码同时做了对 at 的处理、以及兼容用户自定义写的其他命令的方式,下面是默认模块填好 apikey 后可以用的各种方式提问:
|
||||
|
||||
<chat-box>
|
||||
^ 切换为群内
|
||||
) 我是一条普通消息,这条机器人不会回复我
|
||||
) @机器人 你叫啥
|
||||
( 我是聪明可爱的炸毛,认识你很高兴。
|
||||
) 机器人
|
||||
( 我在!有什么事吗?
|
||||
) 一言
|
||||
( 多少事,从来急,天地转,光阴迫,一万年太久,只争朝夕。
|
||||
</chat-box>
|
||||
Reference in New Issue
Block a user