feat: bot

This commit is contained in:
hashbro
2026-08-15 23:05:51 +08:00
parent 9049fdccad
commit 376b442880
26 changed files with 944 additions and 352 deletions
+22 -3
View File
@@ -8,7 +8,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected $fillable = [
'username', 'password', 'status', 'comment', 'chat_id', 'bot_token',
'username', 'password', 'status', 'comment', 'chat_id',
];
protected $hidden = [
@@ -42,9 +42,28 @@ class User extends Authenticatable
return $this->hasMany(Channel::class, 'user_id');
}
public function hasTelegramChat(): bool
{
return trim((string) ($this->chat_id ?? '')) !== '';
}
/** @deprecated Use hasTelegramChat(); kept for existing call sites. */
public function hasTelegramBot(): bool
{
return trim((string) ($this->bot_token ?? '')) !== ''
&& trim((string) ($this->chat_id ?? '')) !== '';
return $this->hasTelegramChat();
}
public static function findEnabledByChatId(int|string|null $chatId): ?self
{
$chatId = trim((string) $chatId);
if ($chatId === '') {
return null;
}
return static::query()
->where('status', 1)
->where('chat_id', $chatId)
->orderBy('id')
->first();
}
}