dd/app/Services/TG/Hook/Mod/Box.php
2025-07-03 16:25:32 +08:00

128 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services\TG\Hook\Mod;
//use App\Models\Box as ModelShip;
//use App\Services\TomTool\Http;
use App\Models\BoxGithubTag as GithubTag;
class Box extends Base {
public function github_tag_rand($aParam)
{
$sType = $aParam["aOption"][1] ?? false;
$iLimit = $aParam["aArg"][1] ?? false;
if (!$sType) {
return "要有option[1]a带中文b不带中文。";
}
if (!$iLimit) {
return "要有arg[1], 生成几个。";
}
$aGithubTag = GithubTag::all()->toArray();
shuffle($aGithubTag);
$i = 1;
$sRandTag = "";
foreach ($aGithubTag as $aGithubTagRow) {
if ($i == 1) {
$sPre = "";
} else {
$sPre = "";
}
if ($sType == "b") {
if ($aGithubTagRow["type"] == "cn") {
continue;
}
}
$sRandTag .= $sPre.$aGithubTagRow["tag"];
if ($i >= $iLimit) {
break;
} else {
$i++;
}
}
return $sRandTag;
}
public function github_tag_list()
{
$oGithubTag = GithubTag::all();
return $this->toJson($oGithubTag);
}
public function github_tag_add($aParam)
{
$sTag = $aParam["aArg"][1] ?? false;
$sType = $aParam["aArg"][2] ?? false;
if (!$sTag) {
return "需要arg[1]tag。";
}
if (!$sType) {
return "需要arg[2]cn中文en英文。";
}
$oGithubTag = new GithubTag();
$oGithubTag->tag = $sTag;
$oGithubTag->type = $sType;
$oGithubTag->save();
return $this->toJson($oGithubTag);
}
public function github_tag_set($aParam)
{
$iId = $aParam["aOption"][1] ?? false;
$sField = $aParam["aOption"][2] ?? false;
$sValue = $aParam["aArg"][1] ?? false;
if (!$iId) {
return "需要option[1]id。";
}
if (!$sField) {
return "需要option[2]field。";
}
if (!$sValue) {
return "需要arg[1]value。";
}
$oGithubTag = GithubTag::find($iId);
if (!$oGithubTag) {
return "没找到";
}
$oGithubTag->$sField = $sValue;
$oGithubTag->save();
return $this->toJson($oGithubTag);
}
public function github_tag_del($aParam)
{
$iId = $aParam["aArg"][1] ?? false;
if (!$iId) {
return "需要arg[1]id。";
}
$oGithubTag = GithubTag::find($iId);
$r = $oGithubTag->delete();
return $r;
}
}