diff --git a/app/Http/Controllers/Api/TG/HookController.php b/app/Http/Controllers/Api/TG/HookController.php index 1f8c5c5e..4a0b0628 100755 --- a/app/Http/Controllers/Api/TG/HookController.php +++ b/app/Http/Controllers/Api/TG/HookController.php @@ -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'); } diff --git a/app/Models/ArticleCache.php b/app/Models/ArticleCache.php new file mode 100755 index 00000000..b6fb39ae --- /dev/null +++ b/app/Models/ArticleCache.php @@ -0,0 +1,24 @@ +toArray(); +// +// foreach ($aSelf as &$aSelfRow) { +// unset($aSelfRow["content"]); +// } +// +// return $aSelf; +// } + + +} diff --git a/app/Services/TG/Hook/Mod/Article.php b/app/Services/TG/Hook/Mod/Article.php index cba93caa..f7080cac 100644 --- a/app/Services/TG/Hook/Mod/Article.php +++ b/app/Services/TG/Hook/Mod/Article.php @@ -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 }} diff --git a/routes/web.php b/routes/web.php index b372f30d..713be80a 100755 --- a/routes/web.php +++ b/routes/web.php @@ -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