mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	bot add getLatestUrl
This commit is contained in:
		| @@ -3,7 +3,9 @@ | ||||
| namespace App\Http\Controllers\Client; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Services\ServerService; | ||||
| use App\Services\UserService; | ||||
| use App\Utils\Clash; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Models\Server; | ||||
| use Symfony\Component\Yaml\Yaml; | ||||
| @@ -20,44 +22,20 @@ class AppController extends Controller | ||||
|         $user = $request->user; | ||||
|         $userService = new UserService(); | ||||
|         if ($userService->isAvailable($user)) { | ||||
|             $servers = Server::where('show', 1) | ||||
|                 ->orderBy('sort', 'ASC') | ||||
|                 ->get(); | ||||
|             foreach ($servers as $item) { | ||||
|                 $groupId = json_decode($item['group_id']); | ||||
|                 if (in_array($user->group_id, $groupId)) { | ||||
|                     array_push($server, $item); | ||||
|                 } | ||||
|             } | ||||
|             $serverService = new ServerService(); | ||||
|             $servers = $serverService->getAllServers($user); | ||||
|         } | ||||
|         $config = Yaml::parseFile(base_path() . '/resources/rules/app.clash.yaml'); | ||||
|         $proxy = []; | ||||
|         $proxies = []; | ||||
|         foreach ($server as $item) { | ||||
|             $array = []; | ||||
|             $array['name'] = $item->name; | ||||
|             $array['type'] = 'vmess'; | ||||
|             $array['server'] = $item->host; | ||||
|             $array['port'] = $item->port; | ||||
|             $array['uuid'] = $user->uuid; | ||||
|             $array['alterId'] = $user->v2ray_alter_id; | ||||
|             $array['cipher'] = 'auto'; | ||||
|             if ($item->tls) { | ||||
|                 $tlsSettings = json_decode($item->tlsSettings); | ||||
|                 $array['tls'] = true; | ||||
|                 if (isset($tlsSettings->allowInsecure)) $array['skip-cert-verify'] = ($tlsSettings->allowInsecure ? true : false ); | ||||
|             } | ||||
|             if ($item->network == 'ws') { | ||||
|                 $array['network'] = $item->network; | ||||
|                 if ($item->networkSettings) { | ||||
|                     $wsSettings = json_decode($item->networkSettings); | ||||
|                     if (isset($wsSettings->path)) $array['ws-path'] = $wsSettings->path; | ||||
|                     if (isset($wsSettings->headers->Host)) $array['ws-headers'] = [ | ||||
|                         'Host' => $wsSettings->headers->Host | ||||
|                     ]; | ||||
|                 } | ||||
|             } | ||||
|             array_push($proxy, $array); | ||||
|  | ||||
|         foreach ($servers['vmess'] as $item) { | ||||
|             array_push($proxy, Clash::buildVmess($user->uuid, $item)); | ||||
|             array_push($proxies, $item->name); | ||||
|         } | ||||
|  | ||||
|         foreach ($servers['trojan'] as $item) { | ||||
|             array_push($proxy, Clash::buildTrojan($user->uuid, $item)); | ||||
|             array_push($proxies, $item->name); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -29,6 +29,8 @@ class TelegramController extends Controller | ||||
|                     break; | ||||
|                 case '/traffic': $this->traffic(); | ||||
|                     break; | ||||
|                 case '/getLatestUrl': $this->getLatestUrl(); | ||||
|                     break; | ||||
|                 default: $this->help(); | ||||
|             } | ||||
|         } catch (\Exception $e) { | ||||
| @@ -84,7 +86,8 @@ class TelegramController extends Controller | ||||
|         $telegramService = new TelegramService(); | ||||
|         $commands = [ | ||||
|             '/bind 订阅地址 - 绑定你的' . config('v2board.app_name', 'V2Board') . '账号', | ||||
|             '/traffic - 查询流量信息' | ||||
|             '/traffic - 查询流量信息', | ||||
|             '/getLatestUrl - 获取最新的' . config('v2board.app_name', 'V2Board') . '网址' | ||||
|         ]; | ||||
|         $text = implode(PHP_EOL, $commands); | ||||
|         $telegramService->sendMessage($msg->chat_id, "你可以使用以下命令进行操作:\n\n$text", 'markdown'); | ||||
| @@ -108,4 +111,17 @@ class TelegramController extends Controller | ||||
|         $text = "🚥流量查询\n———————————————\n计划流量:`{$transferEnable}`\n已用上行:`{$up}`\n已用下行:`{$down}`\n剩余流量:`{$remaining}`"; | ||||
|         $telegramService->sendMessage($msg->chat_id, $text, 'markdown'); | ||||
|     } | ||||
|  | ||||
|     private function getLatestUrl() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         $user = User::where('telegram_id', $msg->chat_id)->first(); | ||||
|         $telegramService = new TelegramService(); | ||||
|         $text = sprintf( | ||||
|             "%s的最新网址是:%s", | ||||
|             config('v2board.app_name', 'V2Board'), | ||||
|             config('v2board.app_url') | ||||
|         ); | ||||
|         $telegramService->sendMessage($msg->chat_id, $text, 'markdown'); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user