From c66c96b991da766cc06f75b3bb1d4373ebba0905 Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Sun, 11 May 2025 10:37:57 +0800 Subject: [PATCH] no message --- .../Controllers/Api/TG/HookController.php | 26 +- app/Http/Controllers/SakaiController.php | 12 + app/Models/Book.php | 11 + app/Models/BookHook.php | 26 ++ app/Models/BookOption.php | 11 + app/Services/TG/Hook/Mod/Book.php | 317 ++++++++++++++++++ app/Services/TG/Http.php | 18 +- app/Services/TomTool/Http.php | 2 +- 8 files changed, 403 insertions(+), 20 deletions(-) create mode 100755 app/Models/Book.php create mode 100755 app/Models/BookHook.php create mode 100755 app/Models/BookOption.php create mode 100644 app/Services/TG/Hook/Mod/Book.php diff --git a/app/Http/Controllers/Api/TG/HookController.php b/app/Http/Controllers/Api/TG/HookController.php index eb89a933..94a02ec5 100755 --- a/app/Http/Controllers/Api/TG/HookController.php +++ b/app/Http/Controllers/Api/TG/HookController.php @@ -35,39 +35,28 @@ final class HookController $sText = $aUpdate["message"]["text"]; - // test -// $sText = "\\//Article#List ni__aaa__bbb 111 222"; -// $sText = "///\\\SaleCode#SetRate__zzxx 2"; -// $sText = "///\\\SaleCode#List"; -// $sText = "///\\\SaleCode#Find zzxx"; -// $sText = "/Article#Like__sale_code zzx"; -// $sText = "////Article#Add jxxjjjj"; -// $sText = "//\\\//Article#Del 9"; -// $sText = "/Article#Set__1__user_name xxx"; - @$aArg = explode(" ", $sText); @$aOption = explode("__", $aArg[0]); $sCmd = $this->cleanCmd($aOption[0]); -// list($sClass, $sFunc) = explode("#", $sCmd); -// $sClass = ucfirst($sClass); -// $sFunc = ucfirst($sFunc); - // 大于3个说明是hook或dove之类 $aCmd = explode("#", $sCmd); if (count($aCmd) >= 3) { $sHook = $aCmd[0]; -// $sClass = $aCmd[1]; -// $sFunc = $aCmd[2]; $sClass = $sHook; $sFunc = "go"; -// $aUpdate["subCmd"] = "/".$aCmd[1]."#".$aCmd[2]; } else { $sClass = $aCmd[0]; $sFunc = $aCmd[1]; } +// if ($sClass == "book" || $sClass == "Book") { +// if (strpos($sFunc, '/') !== false) { +// echo "字符串中包含斜杠。"; +// } +// } + $sUClass = ucfirst($sClass); $sUFunc = ucfirst($sFunc); @@ -87,6 +76,9 @@ final class HookController } else if (method_exists($sUClassPath, $sUFunc)) { $oInstans = new $sUClassPath(); $r = $oInstans->$sUFunc($aParams, $aUpdate); + } else if ($sClass == "book" || $sClass == "Book") { + $sFunc = "cd"; + $r = $oInstans->$sFunc($aParams, $aUpdate); } else { throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc); } diff --git a/app/Http/Controllers/SakaiController.php b/app/Http/Controllers/SakaiController.php index ee06a62a..6a23e4ce 100755 --- a/app/Http/Controllers/SakaiController.php +++ b/app/Http/Controllers/SakaiController.php @@ -74,6 +74,18 @@ class SakaiController $s = "/note_option#find icon_type1"; $s = "/note_option#set__icon_type 2"; $s = "/note#main"; + $s = "/book#cd ziyuan/duck"; + $s = "/book#add xxx"; + $s = "/book#key"; + $s = "/book#key_like jj"; + $s = "/book#add zzxxc"; + $s = "/book#del 2"; + $s = "/book#up 8"; + $s = "/book#down 8"; + $s = "/book#set__3 zxcv33333"; + $s = "/book#o 8"; + $s = "/book#seto__8 99991919191"; + $s = "/note#now"; $oHttp = new Http(); $oHttp->sMethod = "post"; diff --git a/app/Models/Book.php b/app/Models/Book.php new file mode 100755 index 00000000..0e5d01e2 --- /dev/null +++ b/app/Models/Book.php @@ -0,0 +1,11 @@ +first(); + + return $oData; + } + + public static function _first_key($sType) + { + $sKey = self::where("type", $sType)->first()?->key; + + return $sKey; + } + +} diff --git a/app/Models/BookOption.php b/app/Models/BookOption.php new file mode 100755 index 00000000..b0880640 --- /dev/null +++ b/app/Models/BookOption.php @@ -0,0 +1,11 @@ +orderBy("no")->get(); + + if (!$oBook) { + return "没有"; + } + + ModelBookHook::where("type", "key")->delete(); + + $oBookHook = new ModelBookHook(); + $oBookHook->key = $sKey; + $oBookHook->type = "key"; + $r = $oBookHook->save(); + + return $this->bookToStr($oBook); + } + + public function mark($aParam) + { + $iNo = $aParam["aArg"][1]; + $sType = $aParam["sType"][1] ?? false; + + if ($sType == "un") { + $iValue = 0; + } else { + $iValue = 1; + } + + $sKey = ModelBookHook::_first_key("key"); + + $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); + $oBook->mark = $iValue; + $oBook->save(); + + $aParam["aArg"][1] = $sKey; + return $this->cd($aParam); + } + + public function set($aParam) + { + $iNo = $aParam["aOption"][1]; + $sValue = $aParam["aArg"][1]; + + $sKey = ModelBookHook::_first_key("key"); + + $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); + $oBook->title = $sValue; + $oBook->save(); + + $aParam["aArg"][1] = $sKey; + return $this->cd($aParam); + } + +// public function setoa($aParam) +// { +// $iNo = $aParam["aOption"][1]; +// $sValue = $aParam["aArg"][1]; +// +// $sKey = ModelBookHook::_first_key("key"); +// +// $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); +// $oBook->title = $sValue; +// $oBook->save(); +// +// $aParam["aArg"][1] = $sKey; +// return $this->cd($aParam); +// } + + public function o($aParam) + { + + $iNo = $aParam["aArg"][1]; + + $sKey = ModelBookHook::_first_key("key"); + + $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); + + if (!$oBook) { + return "没有"; + } + + return $oBook->content; + + } + + public function seto($aParam) + { + $iNo = $aParam["aOption"][1]; + $sValue = $aParam["aArg"][1]; + + $sKey = ModelBookHook::_first_key("key"); + + $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); + $oBook->content = $sValue; + $r = $oBook->save(); + + $aParam["aArg"][1] = $sKey; + return $this->cd($aParam); + } + + public function key_all($aParam) + { + $oBook = ModelBook::select('key')->distinct()->orderBy("key")->get(); + + return $this->keyToStr($oBook); + } + + public function key_like($aParam) + { + $sLike = $aParam["aArg"][1]; + $sType = $aParam["aOption"][1] ?? "a"; // r=向右,l=向左,a=全部,默认a + + switch ($sType) { + case "a" : + $sLikeSql = "%".$sLike."%"; + break; + case "l" : + $sLikeSql = "%".$sLike; + break; + case "r" : + $sLikeSql = $sLike."%"; + break; + default : + return "???"; + } + + $oKey = ModelBook::select('key') + ->distinct() + ->where('key', 'like', $sLikeSql) // 替换为你的条件 + ->orderBy('key') + ->get(); + + return $this->keyToStr($oKey); + + } + + private function keyToStr($oKey) + { + $str = ""; + foreach ($oKey as $row) { + $str .= "\n"; + $str .= $row->key; + } + + return $str; + } + + public function add($aParam) + { + $sTitle = $aParam["aArg"][1]; + + $oKey = ModelBookHook::where("type", "key")->get(); + + if ($oKey) { + $i = 0; + foreach ($oKey as $row) { + + $oBook = ModelBook::where("key", $row->key)->orderBy("no", "desc")->first(); + if ($oBook->no) { + $iNo = (int)$oBook->no+1; + } else { + $iNo = 1; + } + + $oModelBook = new ModelBook(); + $oModelBook->title = $sTitle; + $oModelBook->key = $row->key; + $oModelBook->no = $iNo; + $oModelBook->save(); + $i++; + } + } else { + return "得先cd"; + } + + $aParam["aArg"][1] = $oKey[0]->key; + + return $this->cd($aParam); + + } + + public function del($aParam) + { + $sType = $aParam["aOption"][1] ?? "no"; // no,id + $iValue = $aParam["aArg"][1]; + + $oBookHook = ModelBookHook::where("type", "key")->first(); + if (!$oBookHook->key) { + return "先cd"; + } + + $iDelCont = ModelBook::where($sType, $iValue)->where("key", $oBookHook->key)->delete(); + +// $this->oTGHttp->send("删除".$iDelCont."条"); + $this->noReByKey($oBookHook->key); + + $aParam["aArg"][1] = $oBookHook->key; + return $this->cd($aParam); + } + + public function up($aParam) + { + $iNo = (int) $aParam["aArg"][1]; + $iNoTo = $iNo-1; + if ($iNoTo <= 0) { + return "不能小于1"; + } + + $oBookHook = ModelBookHook::_first("key"); + + // 拿到他的真实id + $iId = ModelBook::where("key", $oBookHook->key)->where("no", $iNo)->first()?->id; + + // 先所有大于noto的+1 + $oBooks = ModelBook::where("key", $oBookHook->key)->where('no', '>=', $iNoTo)->get(); + foreach ($oBooks as $row) { + $row->no += 1; + $row->save(); + } + + // 设置他 + $oModelBook = ModelBook::where("id", $iId)->first(); + $oModelBook->no = $iNoTo; + $oModelBook->save(); + + // 然后重新排序 + $this->noReByKey($oBookHook->key); + + $aParam["aArg"][1] = $oBookHook->key; + return $this->cd($aParam); + } + + public function down($aParam) + { + $iNo = (int) $aParam["aArg"][1]; + $iNoTo = $iNo+1; + + $oBookHook = ModelBookHook::_first("key"); + + // 拿到他的真实id + $iId = ModelBook::where("key", $oBookHook->key)->where("no", $iNo)->first()?->id; + + // 先所有大于noto的+1 + $oBooks = ModelBook::where("key", $oBookHook->key)->where('no', '<=', $iNoTo)->get(); + foreach ($oBooks as $row) { + $row->no -= 1; + $row->save(); + } + + // 设置他 + $oModelBook = ModelBook::where("id", $iId)->first(); + $oModelBook->no = $iNoTo; + $oModelBook->save(); + + // 然后重新排序 + $this->noReByKey($oBookHook->key); + + $aParam["aArg"][1] = $oBookHook->key; + return $this->cd($aParam); + } + + private function bookToStr($oBook) + { + + $sStr = ""; + foreach ($oBook as $row) { + $sStr .= "\n"; + $sStr .= $row->no; + + // 可以扩充 +// if ($row->content) { +// $sStr .= "::"; +// } + +// if ($row->content) { +// $sStr .= "🗞️"; +// } + + $sStr .= ":".$row->title; + + if ($row->content) { + $sStr .= " 🗞️"; + } + } + + return $sStr; + + } + + private function noReByKey($sKey) + { + $oBook = ModelBook::where("key", $sKey)->orderBy("no")->get(); + + $i = 1; + foreach ($oBook as $row) { + $row->no = $i; + $row->save(); + $i++; + } + + return $i; + } + +} diff --git a/app/Services/TG/Http.php b/app/Services/TG/Http.php index 390fd97a..832f09e0 100644 --- a/app/Services/TG/Http.php +++ b/app/Services/TG/Http.php @@ -1,6 +1,7 @@ "; echo($sMsg); } else { - $url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sMsg); - file_get_contents($url); +// $url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sMsg); +// file_get_contents($url); + + $oHttp = new TomHttp(); + $oHttp->sMethod = "post"; + $oHttp->sToUrl = "https://api.telegram.org/bot$this->sApiToken/sendMessage"; +// $oHttp->bIsJson = true; + $oHttp->aData = [ + "chat_id" => $this->sApiChatId, + "text" => $sMsg + ]; + $r = $oHttp->send(); + + tomd($r); + } } diff --git a/app/Services/TomTool/Http.php b/app/Services/TomTool/Http.php index 8cd52a65..cf07df25 100755 --- a/app/Services/TomTool/Http.php +++ b/app/Services/TomTool/Http.php @@ -9,7 +9,7 @@ class Http public $sMethod = 'get'; public $aData = []; public $sToUrl; // 必须 - public $bIsJson = false; // 默认值为 false + public $bIsJson = false; public function send($sUrl = false): string {