UnBind.php 845 B

1234567891011121314151617181920212223242526
  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. $telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
  14. return;
  15. }
  16. $user->telegram_id = NULL;
  17. if (!$user->save()) {
  18. abort(500, '解绑失败');
  19. }
  20. $telegramService->sendMessage($message->chat_id, '解绑成功', 'markdown');
  21. }
  22. }