UnBind.php 914 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Plugins\Telegram\Commands;
  3. use App\Models\User;
  4. use App\Plugins\Telegram\Telegram;
  5. class UnBind extends Telegram {
  6. public $command = '/unbind';
  7. public $description = '将Telegram账号从网站解绑';
  8. public function handle($message, $match = []) {
  9. if (!$message->is_private) return;
  10. $user = User::where('telegram_id', $message->chat_id)->first();
  11. $telegramService = $this->telegramService;
  12. if (!$user) {
  13. $help = new Help();
  14. $help->handle($message);
  15. $telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
  16. return;
  17. }
  18. $user->telegram_id = NULL;
  19. if (!$user->save()) {
  20. abort(500, '解绑失败');
  21. }
  22. $telegramService->sendMessage($message->chat_id, '解绑成功', 'markdown');
  23. }
  24. }