unique server_name/ link moderation

This commit is contained in:
Vladless
2024-12-04 03:02:29 +03:00
parent 2f6b85d4a6
commit 8e778eb7af
2 changed files with 8 additions and 7 deletions
+3 -4
View File
@@ -134,18 +134,17 @@ async def init_db():
await conn.close()
async def check_unique_server_name(server_name: str) -> bool:
"""
Проверяет уникальность имени сервера.
:param server_name: Имя сервера.
:return: True, если имя сервера уникально, False, если уже существует.
"""
conn = await asyncpg.connect(DATABASE_URL)
result = await conn.fetchrow(
"SELECT 1 FROM servers WHERE server_name = $1 LIMIT 1", server_name
)
result = await conn.fetchrow("SELECT 1 FROM servers WHERE server_name = $1 LIMIT 1", server_name)
await conn.close()
+5 -3
View File
@@ -4,10 +4,9 @@ from aiogram.fsm.state import State, StatesGroup
from aiogram.types import InlineKeyboardButton
from aiogram.utils.keyboard import InlineKeyboardBuilder
import asyncpg
from typing import Any
from config import DATABASE_URL
from database import get_servers_from_db, check_unique_server_name
from database import check_unique_server_name, get_servers_from_db
from filters.admin import IsAdminFilter
router = Router()
@@ -130,7 +129,6 @@ async def handle_server_name_input(message: types.Message, state: FSMContext):
await state.set_state(UserEditorState.waiting_for_api_url)
@router.message(UserEditorState.waiting_for_api_url, IsAdminFilter())
async def handle_api_url_input(message: types.Message, state: FSMContext):
api_url = message.text.strip()
@@ -152,6 +150,8 @@ async def handle_api_url_input(message: types.Message, state: FSMContext):
)
return
api_url = api_url.rstrip('/')
user_data = await state.get_data()
cluster_name = user_data.get('cluster_name')
server_name = user_data.get('server_name')
@@ -193,6 +193,8 @@ async def handle_subscription_url_input(message: types.Message, state: FSMContex
)
return
subscription_url = subscription_url.rstrip('/')
user_data = await state.get_data()
cluster_name = user_data.get('cluster_name')
server_name = user_data.get('server_name')