dd/app/Services/TG/Hook/Mod/Box.php
2025-07-03 20:33:12 +08:00

231 lines
5.3 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;
use App\Models\BoxCountry as ModelBoxCountry;
class Box extends Base {
public function country_test()
{
$this->oHttp->sToUrl = "https://".env("APP_WWW")."/api/freenode/country/rand";
$this->oHttp->bIsJson = true;
$this->sMethod = "get";
$r = $this->oHttp->send();
$r = json_decode($r, true);
$r = $this->toJson($r);
return $r;
}
public function country_hit($aParam)
{
$sName = $aParam["aArg"][1] ?? false;
if (!$sName) {
return "需要arg[1]name。";
}
$oCountry = ModelBoxCountry::where("name", $sName)->get();
if(!$oCountry) {
return "不存在".$sName;
}
return $this->toJson($oCountry);
}
public function country_list()
{
$oCountry = ModelBoxCountry::all()->toArray();
return $this->toJson($oCountry);
}
public function country_add($aParam)
{
$sName = $aParam["aArg"][1] ?? false;
if (!$sName) {
return "需要有arg[1]name。";
}
$oCountry = new ModelBoxCountry();
$oCountry->name = $sName;
$oCountry->save();
return $this->toJson($oCountry);
}
public function country_set($aParam)
{
$iId = $aParam["aOption"][1] ?? false;
$sField = $aParam["aArg"][1] ?? false;
$sValue = $aParam["aArg"][2] ?? false;
if (!$iId) {
return "需要option[1]id。";
}
if (!$sField) {
return "需要arg[1]field。";
}
if (!$sValue) {
return "需要arg[2]value。";
}
$oCountry = ModelBoxCountry::find($iId);
if (!$oCountry) {
return "没找到";
}
$oCountry->$sField = $sValue;
$oCountry->save();
return $this->toJson($oCountry);
}
public function country_del($aParam)
{
$iId = $aParam["aArg"][1] ?? false;
if (!$iId) {
return "需要arg[1]id。";
}
$oCountry = ModelBoxCountry::find($iId);
if (!$oCountry) {
return "没找到";
}
$r = $oCountry->delete();
return $r;
}
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()->get();
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;
}
}