mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: telegram bot modularization
This commit is contained in:
		
							
								
								
									
										38
									
								
								app/Plugins/Telegram/Commands/Bind.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								app/Plugins/Telegram/Commands/Bind.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Plugins\Telegram\Commands; | ||||
|  | ||||
| use App\Models\User; | ||||
| use App\Plugins\Telegram\Telegram; | ||||
|  | ||||
| class Bind extends Telegram { | ||||
|     public $command = '/bind'; | ||||
|     public $description = '将Telegram账号绑定到网站'; | ||||
|  | ||||
|     public function handle($message, $match = []) { | ||||
|         if (!$message->is_private) return; | ||||
|         if (!isset($message->args[0])) { | ||||
|             abort(500, '参数有误,请携带订阅地址发送'); | ||||
|         } | ||||
|         $subscribeUrl = $message->args[0]; | ||||
|         $subscribeUrl = parse_url($subscribeUrl); | ||||
|         parse_str($subscribeUrl['query'], $query); | ||||
|         $token = $query['token']; | ||||
|         if (!$token) { | ||||
|             abort(500, '订阅地址无效'); | ||||
|         } | ||||
|         $user = User::where('token', $token)->first(); | ||||
|         if (!$user) { | ||||
|             abort(500, '用户不存在'); | ||||
|         } | ||||
|         if ($user->telegram_id) { | ||||
|             abort(500, '该账号已经绑定了Telegram账号'); | ||||
|         } | ||||
|         $user->telegram_id = $message->chat_id; | ||||
|         if (!$user->save()) { | ||||
|             abort(500, '设置失败'); | ||||
|         } | ||||
|         $telegramService = $this->telegramService; | ||||
|         $telegramService->sendMessage($message->chat_id, '绑定成功'); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user