no message
This commit is contained in:
parent
31df328c38
commit
cd53bfaa35
25
app/Services/Cron/FreenodeWatch.php
Executable file
25
app/Services/Cron/FreenodeWatch.php
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Cron;
|
||||
|
||||
use App\Models\SiteMap as ModelSiteMap;
|
||||
use App\Services\TomTool\Telegram\Slave as TeleSlave;
|
||||
use App\Services\TomTool\HttpV2;
|
||||
|
||||
final class FreenodeWatch
|
||||
{
|
||||
static function run()
|
||||
{
|
||||
echo "\n\nFreenodeWatch::run() - 开始";
|
||||
|
||||
$sDirBase = $_ENV["dir_base"];
|
||||
|
||||
$oFnSiteList = ModelSiteMap::where("group_code", "fn_a")->get();
|
||||
|
||||
// foreach ()
|
||||
|
||||
echo "\n - ok";
|
||||
}
|
||||
}
|
||||
@ -36,6 +36,8 @@ final class Telegram
|
||||
$sPhotoUrl = $aArg["sPhotoUrl"] ?? '';
|
||||
$iPhotoWidth = $aArg["iPhotoWidth"] ?? 0;
|
||||
$iPhotoHeight = $aArg["iPhotoHeight"] ?? 0;
|
||||
$sFileUrl = $aArg["sFileUrl"] ?? '';
|
||||
$sFileName = $aArg["sFileName"] ?? '';
|
||||
$sType = $aArg["sType"] ?? '';
|
||||
|
||||
$r = TeleMaster::start()
|
||||
@ -44,6 +46,7 @@ final class Telegram
|
||||
->setBotToken($sBotToken)
|
||||
->setChatId($iChatId)
|
||||
->setPhotoUrl($sPhotoUrl, $iPhotoWidth, $iPhotoHeight)
|
||||
->setFileUrl($sFileUrl, $sFileName)
|
||||
->setType($sType)
|
||||
->send($sMsg);
|
||||
|
||||
|
||||
66
app/Services/Tg/Hook/Mod/Freenode.php
Executable file
66
app/Services/Tg/Hook/Mod/Freenode.php
Executable file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Tg\Hook\Mod;
|
||||
|
||||
use App\Services\Tg\Hook\Dog;
|
||||
//use App\Services\TomTool\Flow;
|
||||
use App\Services\TomTool\ThrowableHandler;
|
||||
//use App\Services\Cron\FreenodeMerge as CronFreenodeMerge;
|
||||
use App\Models\FreenodePool as ModelFreenodePool;
|
||||
use App\Services\TomTool\HttpV2;
|
||||
use App\Services\TomTool\Map;
|
||||
use App\Models\SiteMap as ModelSiteMap;
|
||||
use App\Services\TomTool\Telegram\slave as TeleSlave;
|
||||
|
||||
class Freenode extends Base {
|
||||
|
||||
public function __construct($aUpdate)
|
||||
{
|
||||
$this->oDog = new Dog(new ModelFreenodePool());
|
||||
$this->oDog->_setDogName("Freenode");
|
||||
$this->oDog->_setJsonField(["content"]);
|
||||
// $this->oDog->_setStrField(["content"]);
|
||||
$this->aUpdate = $aUpdate;
|
||||
}
|
||||
|
||||
public function __call($sName, $aArg)
|
||||
{
|
||||
return $this->oDog->$sName($aArg[0]);
|
||||
}
|
||||
|
||||
public function show($aParam)
|
||||
{
|
||||
$sSiteCode = $aParam["aArg"][1] ?? "cfn";
|
||||
$sClient = $aParam["aOption"][1] ?? "clash";
|
||||
|
||||
if ($sSiteCode === "?") {
|
||||
return "/show#__[client:clash] [siteCodeShort]";
|
||||
}
|
||||
|
||||
$oSite = ModelSiteMap::where("code_short", $sSiteCode)->first();
|
||||
|
||||
if (!$oSite) {
|
||||
return "没有这个site";
|
||||
}
|
||||
|
||||
$sClientSfx = Map::fnClientToSfx($sClient);
|
||||
|
||||
$sFileName = date("Ymd")."-".$sClient.".".$sClientSfx;
|
||||
$sFileUrl = "https://".$oSite->url."/sub/".$sFileName;
|
||||
// $sFileUrl = "https://clashv2rayfree.com/sub/".$sFileName; // test
|
||||
|
||||
$oFlow = TeleSlave::start("admin", "admin")
|
||||
->enableSlaveQueue(false)
|
||||
->enableAsync(false)
|
||||
->enableDetail(false)
|
||||
->setFileUrl($sFileUrl, $sSiteCode."的".$sClient.".txt")
|
||||
->send();
|
||||
|
||||
if ($oFlow->isFail()) {
|
||||
var_dump($oFlow->getResult());
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -6,6 +6,7 @@ use App\Models\BladeJctj as ModelBladeJctj;
|
||||
use App\Services\Tg\Hook\Dog;
|
||||
use App\Services\TomTool\Flow;
|
||||
use App\Services\TomTool\HttpV2;
|
||||
use App\Services\TomTool\Telegram\Slave as TeleSlave;
|
||||
|
||||
use App\Services\UrlMap;
|
||||
|
||||
@ -28,6 +29,12 @@ class Test extends Base {
|
||||
return $this->oDog->$sName($aArg[0]);
|
||||
}
|
||||
|
||||
public function t1()
|
||||
{
|
||||
TeleSlave::log()->enableSlaveQueue(false)->setFileUrl("https://master.tomshell.my/freenode/template/clash.txt")->setMsgS("fff")->send();
|
||||
echo 1;
|
||||
}
|
||||
|
||||
public function httpJson($aParam)
|
||||
{
|
||||
$sUrl = $aParam["aOption"][1] ?? '';
|
||||
|
||||
26
app/Services/TomTool/Map.php
Executable file
26
app/Services/TomTool/Map.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\TomTool;
|
||||
|
||||
class Map
|
||||
{
|
||||
public static function fnClientToSfx($sClient)
|
||||
{
|
||||
$sfx = "";
|
||||
|
||||
switch ($sClient) {
|
||||
case "clash":
|
||||
$sfx = "yaml";
|
||||
break;
|
||||
case "v2ray":
|
||||
$sfx = "txt";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return $sfx;
|
||||
}
|
||||
}
|
||||
@ -40,6 +40,9 @@ final class Master
|
||||
public int $iPhotoWidth = 0;
|
||||
public int $iPhotoHeight = 0;
|
||||
|
||||
public string $sFileUrl = '';
|
||||
public string $sFileName = '';
|
||||
|
||||
public string $sType = '';
|
||||
|
||||
public bool $enableQueue = false; // 应该用不到了
|
||||
@ -98,6 +101,13 @@ final class Master
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFileUrl(string $sFileUrl = '', string $sFileName = ''): self
|
||||
{
|
||||
$this->sFileUrl = $sFileUrl;
|
||||
$this->sFileName = $sFileName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send($sMsg = ''): Flow
|
||||
{
|
||||
if ($sMsg) {
|
||||
@ -105,7 +115,7 @@ final class Master
|
||||
}
|
||||
|
||||
if (!$this->sMsg) {
|
||||
throw new \Exception("未设置msg");
|
||||
// throw new \Exception("未设置msg");
|
||||
}
|
||||
|
||||
$this->keyBegin();
|
||||
@ -119,6 +129,7 @@ final class Master
|
||||
->setChatId($this->iChatId)
|
||||
->setMsgS($this->sMsg)
|
||||
->setPhotoUrl($this->sPhotoUrl, $this->iPhotoWidth, $this->iPhotoHeight)
|
||||
->setFileUrl($this->sFileUrl, $this->sFileName)
|
||||
->setType($this->sType)
|
||||
->send();
|
||||
}
|
||||
@ -155,6 +166,8 @@ final class Master
|
||||
"sPhotoUrl" => $this->sPhotoUrl ?? '',
|
||||
"iPhotoWidth" => $this->iPhotoWidth,
|
||||
"iPhotoHeight" => $this->iPhotoHeight,
|
||||
"sFileUrl" => $this->sFileUrl,
|
||||
"sFileName" => $this->sFileName,
|
||||
"sMsg" => $this->sMsg ?? '',
|
||||
"sType" => $this->sType ?? '',
|
||||
];
|
||||
|
||||
@ -21,6 +21,8 @@ class Sdk
|
||||
public $sPhotoUrl = '';
|
||||
public $iPhotoWidth = 0;
|
||||
public $iPhotoHeight = 0;
|
||||
public $sFileUrl = '';
|
||||
public $sFileName = '';
|
||||
public $sMsg;
|
||||
public $oApi;
|
||||
|
||||
@ -56,7 +58,13 @@ class Sdk
|
||||
$this->sPhotoUrl = $sUrl;
|
||||
$this->iPhotoWidth = $iPhotoWidth;
|
||||
$this->iPhotoHeight = $iPhotoHeight;
|
||||
// tomd($iPhotoWidth, 1);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFileUrl($sFileUrl = '', $sFileName = '')
|
||||
{
|
||||
$this->sFileUrl = $sFileUrl;
|
||||
$this->sFileName = $sFileName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -79,6 +87,8 @@ class Sdk
|
||||
|
||||
if ($this->sPhotoUrl) {
|
||||
$r = $this->oApi->sendPhoto($this->sMsgFormat);
|
||||
} else if ($this->sFileUrl) {
|
||||
$r = $this->oApi->sendDocument($this->sMsgFormat);
|
||||
} else {
|
||||
$r = $this->oApi->sendMessage($this->sMsgFormat);
|
||||
}
|
||||
@ -105,7 +115,7 @@ class Sdk
|
||||
if (!in_array($this->sMsgFormatType, self::ALLOWED_FORMATS, true)) {
|
||||
throw new \RuntimeException("不支持的格式类型: {$this->sMsgFormatType}");
|
||||
}
|
||||
// ini_set('memory_limit', '512M');
|
||||
|
||||
$method = 'msgFormat_' . $this->sMsgFormatType;
|
||||
$this->sMsgFormat = $this->$method();
|
||||
|
||||
@ -118,7 +128,7 @@ class Sdk
|
||||
|
||||
$sImg = file_get_contents($this->sPhotoUrl);
|
||||
$oImage = $oManager->read($sImg);
|
||||
// tomd($this->iPhotoWidth, 1);
|
||||
|
||||
if ($this->iPhotoWidth && $this->iPhotoHeight) {
|
||||
$oImage = $oImage->cover($this->iPhotoWidth, $this->iPhotoHeight);
|
||||
}
|
||||
@ -131,6 +141,21 @@ class Sdk
|
||||
|
||||
$this->sMsgFormat["caption"] = $this->sMsgFormat["text"];
|
||||
unset($this->sMsgFormat["text"]);
|
||||
|
||||
} else if ($this->sFileUrl) {
|
||||
|
||||
if (!$this->sFileName) {
|
||||
$sFileName = date("Y-m-d H:i:s").'.txt';
|
||||
} else {
|
||||
$sFileName = $this->sFileName;
|
||||
}
|
||||
|
||||
$sFile = InputFile::create($this->sFileUrl, $sFileName);
|
||||
|
||||
$this->sMsgFormat["document"] = $sFile;
|
||||
$this->sMsgFormat["caption"] = $this->sMsgFormat["text"];
|
||||
unset($this->sMsgFormat["text"]);
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@ -61,6 +61,9 @@ class Slave
|
||||
public int $iPhotoWidth = 0;
|
||||
public int $iPhotoHeight = 0;
|
||||
|
||||
public string $sFileUrl = '';
|
||||
public string $sFileName = '';
|
||||
|
||||
public string $sType = '';
|
||||
|
||||
public bool $enableMaster = true;
|
||||
@ -152,6 +155,14 @@ class Slave
|
||||
return $this;
|
||||
}
|
||||
|
||||
// set
|
||||
public function setFileUrl(string $sFileUrl, string $sFileName = ''): self
|
||||
{
|
||||
$this->sFileUrl = $sFileUrl;
|
||||
$this->sFileName = $sFileName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// set
|
||||
public function setType(string $sType): self
|
||||
{
|
||||
@ -233,7 +244,7 @@ class Slave
|
||||
}
|
||||
|
||||
if (!$this->sMsg) {
|
||||
throw new Exception("未设置msg");
|
||||
// throw new \Exception("未设置msg");
|
||||
}
|
||||
|
||||
if ($this->enableMaster) {
|
||||
@ -261,7 +272,6 @@ class Slave
|
||||
|
||||
private function _send_master(): Flow
|
||||
{
|
||||
// tomd(11111,1);
|
||||
$aData = $this->buildDataTom();
|
||||
|
||||
if ($this->enableSlaveQueue) {
|
||||
@ -272,7 +282,7 @@ class Slave
|
||||
$sUrlMaSterBase = $_ENV["url_master_base"] ?? "";
|
||||
|
||||
if (!$sUrlMaSterBase) {
|
||||
throw new Exception("未设置env的url_master_base");
|
||||
throw new \Exception("未设置env的url_master_base");
|
||||
}
|
||||
|
||||
$sUrlMasterPost = "https://".$sUrlMaSterBase."/api/telegram/post";
|
||||
@ -336,6 +346,8 @@ class Slave
|
||||
"iPhotoWidth" => $this->iPhotoWidth ?? 0,
|
||||
"iPhotoHeight" => $this->iPhotoHeight ?? 0,
|
||||
"sType" => $this->sType ?? '',
|
||||
"sFileUrl" => $this->sFileUrl ?? '',
|
||||
"sFileName" => $this->sFileName ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user