mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-20 15:15:35 +08:00
update to build 385
add CQObject for CQ add after-stop action(set terminal level 0) update global.php modules, add http_proxy_server add MessageUtil.php for message parsing add RouteManager::addStaticFileRoute() for quick handling static file finish onTask function finally!! add TaskManager::runTask()
This commit is contained in:
35
src/ZM/Utils/MessageUtil.php
Normal file
35
src/ZM/Utils/MessageUtil.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace ZM\Utils;
|
||||
|
||||
|
||||
use ZM\API\CQ;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Requests\ZMRequest;
|
||||
|
||||
class MessageUtil
|
||||
{
|
||||
public static function downloadCQImage($msg, $path = null) {
|
||||
$path = $path ?? DataProvider::getDataFolder() . "images/";
|
||||
if (!is_dir($path)) mkdir($path);
|
||||
$path = realpath($path);
|
||||
if ($path === false) {
|
||||
Console::warning("指定的路径错误不存在!");
|
||||
return false;
|
||||
}
|
||||
$files = [];
|
||||
$cq = CQ::getAllCQ($msg, true);
|
||||
foreach ($cq as $v) {
|
||||
if ($v->type == "image") {
|
||||
$result = ZMRequest::downloadFile($v->params["url"], $path . "/" . $v->params["file"]);
|
||||
if ($result === false) {
|
||||
Console::warning("图片 " . $v->params["url"] . " 下载失败!");
|
||||
return false;
|
||||
}
|
||||
$files[] = $path . "/" . $v->params["file"];
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user