no message
This commit is contained in:
parent
889ccad6ad
commit
01b8e3cd12
@ -11,6 +11,32 @@ use App\Models\Hook as ModelHook;
|
||||
|
||||
final class HookController
|
||||
{
|
||||
|
||||
private $sCustomText = '';
|
||||
// private $sType = '';
|
||||
// private $sCmdName = '';
|
||||
|
||||
// private $sCustomCmd = '';
|
||||
// private $sCustomFunc = '';
|
||||
// private $aCustomOption = [];
|
||||
// private $bCustomLock = false;
|
||||
|
||||
public function cmd_ffq_article()
|
||||
{
|
||||
$sUpdate = file_get_contents("php://input");
|
||||
$aUpdate = json_decode($sUpdate, true);
|
||||
$sText = &$aUpdate["message"]["text"] ?? "没有text";
|
||||
// tomd($sText, 1);
|
||||
if (!str_starts_with($sText, '/')) {
|
||||
// $this->sCustomCmd = "article";
|
||||
// $this->sCustomFunc = "cache";
|
||||
// $this->aCustomOption[1] = "ffq";
|
||||
$this->sCustomText = "/article#cache__ffq"." ".$sText;
|
||||
}
|
||||
|
||||
return $this->cmd();
|
||||
}
|
||||
|
||||
public function cmd()
|
||||
{
|
||||
|
||||
@ -34,7 +60,21 @@ final class HookController
|
||||
throw new \Exception(json_encode($aUpdate));
|
||||
}
|
||||
|
||||
$sText = &$aUpdate["message"]["text"];
|
||||
if ($this->sCustomText) {
|
||||
$sText = $this->sCustomText;
|
||||
} else {
|
||||
$sText = &$aUpdate["message"]["text"] ?? "没有text";
|
||||
}
|
||||
// tomd($sText, 1);
|
||||
// if ($this->sCustomCmd) {
|
||||
// $sText =
|
||||
// }
|
||||
|
||||
// if ($this->sType == "article") {
|
||||
// if (!str_starts_with($sText, '/')) {
|
||||
// $sText = "/article#cache__".$sCmdName." ".$sText;
|
||||
// }
|
||||
// }
|
||||
|
||||
// hook优先
|
||||
// 非is_hook,并且,首字符非/
|
||||
@ -52,7 +92,7 @@ final class HookController
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//tomd($sText, 1);
|
||||
@$aArg = explode(" ", $sText) ?? [];
|
||||
@$aOption = explode("__", $aArg[0]) ?? [];
|
||||
|
||||
@ -68,7 +108,19 @@ final class HookController
|
||||
$sClass = $aCmd[0] ?? false;
|
||||
$sFunc = $aCmd[1] ?? false;
|
||||
// }
|
||||
|
||||
|
||||
// if ($this->sCustomCmd) {
|
||||
// $sClass = $this->sCustomCmd;
|
||||
// }
|
||||
//
|
||||
// if ($this->sCustomFunc) {
|
||||
// $sFunc = $this->sCustomFunc;
|
||||
// }
|
||||
//
|
||||
// if ($this->aCustomOption) {
|
||||
// $aOption = $this->aCustomOption;
|
||||
// }
|
||||
|
||||
if (strpos($sClass, "dove$") !== false) {
|
||||
$sClass = "dove";
|
||||
$sFunc = "go";
|
||||
@ -125,7 +177,7 @@ final class HookController
|
||||
} catch (\Throwable $e) {
|
||||
$sMessage = "错误(文件: " . $e->getFile() . ",行: " . $e->getLine() . "): " . $e->getMessage();
|
||||
|
||||
$oTGHttp->send($sMessage, $aUpdate);
|
||||
$oTGHttp->send($sMessage, $sUpdate);
|
||||
|
||||
// Http::response(200, 'error');
|
||||
}
|
||||
|
||||
24
app/Models/ArticleCache.php
Executable file
24
app/Models/ArticleCache.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleCache extends Model
|
||||
{
|
||||
protected $table = 'article_cache';
|
||||
public $timestamps = false;
|
||||
|
||||
// public static function _listKey()
|
||||
// {
|
||||
// $aSelf = self::all()->toArray();
|
||||
//
|
||||
// foreach ($aSelf as &$aSelfRow) {
|
||||
// unset($aSelfRow["content"]);
|
||||
// }
|
||||
//
|
||||
// return $aSelf;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Services\TG\Hook\Mod;
|
||||
|
||||
use App\Models\Article as ModelArticle;
|
||||
use App\Models\ArticleCache as ModelArticleCache;
|
||||
use App\Services\TG\Hook\Dog;
|
||||
|
||||
class Article extends Base {
|
||||
@ -26,4 +27,60 @@ class Article extends Base {
|
||||
|
||||
}
|
||||
|
||||
public function cache($aParam)
|
||||
{
|
||||
|
||||
$sContent = implode(' ', $aParam["aArg"]);
|
||||
|
||||
$oModelArticleCache = new ModelArticleCache();
|
||||
$oModelArticleCache->content = $sContent;
|
||||
$oModelArticleCache->created_at = time();
|
||||
$r = $oModelArticleCache->save();
|
||||
|
||||
}
|
||||
|
||||
public function saveFFQ($aParam)
|
||||
{
|
||||
$aParam["aArg"][1] = "ffq_tg";
|
||||
|
||||
return $this->save($aParam);
|
||||
}
|
||||
|
||||
public function save($aParam)
|
||||
{
|
||||
$sFrom = $aParam["aArg"][1] ?? false;
|
||||
|
||||
if (!$sFrom) {
|
||||
return "需要from";
|
||||
}
|
||||
|
||||
if ($aParam["aArg"][1] == '?') {
|
||||
return "/article#save [from]";
|
||||
}
|
||||
|
||||
$oModelArticleCache = ModelArticleCache::orderBy('id', 'asc')->get();
|
||||
|
||||
if ($sFrom == "ffq" || $sFrom == "ffq_tg") {
|
||||
|
||||
$sArticle = '';
|
||||
|
||||
foreach ($oModelArticleCache as $oModelArticleCacheRow) {
|
||||
$sArticle .= $oModelArticleCacheRow->content;
|
||||
}
|
||||
|
||||
$oModelArticle = new ModelArticle();
|
||||
$oModelArticle->from_type = "ffq_tg";
|
||||
$oModelArticle->to_type = "vp_md";
|
||||
$oModelArticle->title = "test";
|
||||
$oModelArticle->content = $sArticle;
|
||||
$oModelArticle->code = "ffq_tg:".uniqid();
|
||||
$r = $oModelArticle->save();
|
||||
}
|
||||
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//{{ $site.title }}
|
||||
|
||||
@ -40,6 +40,7 @@ Route::get('/test4', [SakaiController::class, 'test4']);
|
||||
Route::get('/test5', [SakaiController::class, 'test5']);
|
||||
|
||||
Route::any('/api/tg/hook', [HookController::class, 'cmd']);
|
||||
Route::any('/api/tg/hook/cmd_ffq_article', [HookController::class, 'cmd_ffq_article']);
|
||||
|
||||
//Route::get('/', [ArticleListController::class, 'fn']);
|
||||
//Route::get('/fn', [ArticleListController::class, 'fn']); // 免费节点list
|
||||
|
||||
Loading…
Reference in New Issue
Block a user