no message

This commit is contained in:
hellcat 2025-05-11 10:37:57 +08:00
parent fee656d40a
commit c66c96b991
8 changed files with 403 additions and 20 deletions

View File

@ -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);
}

View File

@ -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";

11
app/Models/Book.php Executable file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
protected $table = 'book';
public $timestamps = false;
}

26
app/Models/BookHook.php Executable file
View File

@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class BookHook extends Model
{
protected $table = 'book_hook';
public $timestamps = false;
public static function _first($sType)
{
$oData = self::where("type", $sType)->first();
return $oData;
}
public static function _first_key($sType)
{
$sKey = self::where("type", $sType)->first()?->key;
return $sKey;
}
}

11
app/Models/BookOption.php Executable file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class BookOption extends Model
{
protected $table = 'book_option';
public $timestamps = false;
}

View File

@ -0,0 +1,317 @@
<?php
namespace App\Services\TG\Hook\Mod;
use App\Models\Book as ModelBook;
//use App\Models\BookOption as ModelBookOption;
use App\Models\BookHook as ModelBookHook;
class Book extends Base {
public function cd($aParam)
{
$sKey = $aParam["aArg"][1];
$oBook = ModelBook::where("key", $sKey)->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;
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Services\TG;
use App\Services\TomTool\Http as TomHttp;
class Http {
@ -20,8 +21,21 @@ class Http {
echo "<pre>";
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);
}
}

View File

@ -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
{