2023-11-17 01:44:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Plugins\Telegram\Commands;
|
|
|
|
|
2023-12-04 07:40:49 -05:00
|
|
|
use App\Exceptions\ApiException;
|
2023-11-17 01:44:01 -05:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Plugins\Telegram\Telegram;
|
|
|
|
|
|
|
|
class UnBind extends Telegram {
|
|
|
|
public $command = '/unbind';
|
|
|
|
public $description = '将Telegram账号从网站解绑';
|
|
|
|
|
|
|
|
public function handle($message, $match = []) {
|
|
|
|
if (!$message->is_private) return;
|
2025-01-12 02:31:51 -05:00
|
|
|
if (!isset($message->args[0])) {
|
|
|
|
$user = User::where('telegram_id', $message->chat_id)->first();
|
|
|
|
} else {
|
|
|
|
$chat = User::where('telegram_id', $message->chat_id)->first();
|
|
|
|
if (!$chat) return;
|
|
|
|
if (!($chat->is_admin || $chat->is_staff)) return;
|
|
|
|
if (strpos($message->args[0], '@') !== true) {
|
|
|
|
$user = User::where('email', $message->args[0])->first();
|
|
|
|
} else {
|
|
|
|
$user = User::where('telegram_id', $message->args[0])->first();
|
|
|
|
}
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
$user->telegram_id = NULL;
|
|
|
|
if (!$user->save()) {
|
2023-12-06 15:01:32 -05:00
|
|
|
throw new ApiException('解绑失败');
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
$telegramService->sendMessage($message->chat_id, '解绑成功', 'markdown');
|
|
|
|
}
|
|
|
|
}
|