cleanup code, update some features

add Hitokoto API
add Closure for access_token
add working_dir() global function
adjust reply() method to .handle_quick_operation
This commit is contained in:
jerry
2021-02-24 23:37:00 +08:00
parent fb9dbed306
commit 69521a1f1f
8 changed files with 109 additions and 22 deletions

View File

@@ -11,6 +11,7 @@ use ZM\Console\Console;
use ZM\Annotation\CQ\CQCommand;
use ZM\Annotation\Http\RequestMapping;
use ZM\Event\EventDispatcher;
use ZM\Requests\ZMRequest;
use ZM\Utils\ZMUtil;
/**
@@ -45,6 +46,18 @@ class Hello
return "你好啊,我是由炸毛框架构建的机器人!";
}
/**
* 一个最基本的第三方 API 接口使用示例
* @CQCommand("一言")
*/
public function hitokoto() {
$api_result = ZMRequest::get("https://v1.hitokoto.cn/");
if ($api_result === false) return "接口请求出错,请稍后再试!";
$obj = json_decode($api_result, true);
if ($obj === null) return "接口解析出错!可能返回了非法数据!";
return $obj["hitokoto"] . "\n----「" . $obj["from"] . "";
}
/**
* 一个简单随机数的功能demo
* 问法1随机数 1 20
@@ -89,7 +102,7 @@ class Hello
* @return string
*/
public function paramGet($param) {
return "Hello, ".$param["name"];
return "Hello, " . $param["name"];
}
/**