This commit is contained in:
Vladless
2024-11-11 07:42:22 +03:00
parent dab1a8d754
commit b5c8f4fa28
13 changed files with 51 additions and 43 deletions
-3
View File
@@ -12,15 +12,12 @@ RUN apt-get update && \
sed -i '/ru_RU.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen ru_RU.UTF-8
# Устанавливаем переменные окружения
ENV LANG=ru_RU.UTF-8
ENV LANGUAGE=ru_RU:ru
ENV LC_ALL=ru_RU.UTF-8
COPY . .
# Замена DATABASE_URL на значение из переменной окружения
RUN sed -i "s|DATABASE_URL = .*|DATABASE_URL = '${DATABASE_URL}'|" config.py
# dosker-compose в полной версии бота
CMD ["python", "main.py"]
-1
View File
@@ -50,7 +50,6 @@ async def link(session, server_id: str, client_id: str, email: str):
raise Exception("Не удалось получить данные клиентов.")
inbounds = response["obj"][0]
# settings = json.loads(inbounds["settings"])
stream_settings = json.loads(inbounds["streamSettings"])
tcp = stream_settings.get("network", "tcp")
+5 -4
View File
@@ -2,10 +2,6 @@ from aiogram import Bot, Dispatcher, Router
from aiogram.fsm.storage.memory import MemoryStorage
from config import API_TOKEN, FREEKASSA_ENABLE, YOOKASSA_ENABLE
from handlers import commands, notifications, profile, start
from handlers.admin import admin, admin_panel, user_editor
from handlers.keys import key_management, keys
from handlers.payment import freekassa_pay, yookassa_pay
from middlewares.admin import AdminMiddleware
from middlewares.logging import UserActivityMiddleware
@@ -14,6 +10,11 @@ storage = MemoryStorage()
dp = Dispatcher(bot=bot, storage=storage)
router = Router()
from handlers import commands, notifications, profile, start
from handlers.admin import admin, admin_panel, user_editor
from handlers.keys import key_management, keys
from handlers.payment import freekassa_pay, yookassa_pay
dp.include_router(admin.router)
dp.include_router(admin_panel.router)
-2
View File
@@ -245,7 +245,6 @@ async def handle_key_name_input(message: types.Message, state: FSMContext):
key_buttons = []
for record in user_records:
# tg_id = record["tg_id"]
balance = record["balance"]
email = record["email"]
key = record["key"]
@@ -448,7 +447,6 @@ async def process_callback_confirm_delete(callback_query: types.CallbackQuery):
)
if record:
# email = record["email"]
response_message = "Ключ успешно удален."
back_button = types.InlineKeyboardButton(
text="Назад", callback_data="view_keys"
-4
View File
@@ -45,7 +45,6 @@ async def process_callback_create_key(callback_query: CallbackQuery, state: FSMC
async def select_server(callback_query: CallbackQuery, state: FSMContext):
# selected_server_id = (await state.get_data()).get("selected_server_id")
conn = await asyncpg.connect(DATABASE_URL)
try:
@@ -92,8 +91,6 @@ async def select_server(callback_query: CallbackQuery, state: FSMContext):
@dp.callback_query(F.data == "confirm_create_new_key")
async def confirm_create_new_key(callback_query: CallbackQuery, state: FSMContext):
tg_id = callback_query.from_user.id
# data = await state.get_data()
# server_id = data.get("selected_server_id")
balance = await get_balance(tg_id)
if balance < RENEWAL_PLANS["1"]["price"]:
@@ -145,7 +142,6 @@ async def handle_key_name_input(message: Message, state: FSMContext):
finally:
await conn.close()
# data = await state.get_data()
client_id = str(uuid.uuid4())
email = key_name.lower()
current_time = datetime.utcnow()
+1 -1
View File
@@ -68,7 +68,7 @@ async def delete_key_from_db(client_id):
async def delete_key_from_server(server_id, client_id):
"""Удаление ключа с сервера"""
try:
async with login_with_credentials(
async with await login_with_credentials(
server_id, ADMIN_USERNAME, ADMIN_PASSWORD
) as session:
success = await delete_client(session, server_id, client_id)
-3
View File
@@ -390,9 +390,7 @@ async def process_callback_renew_key(callback_query: types.CallbackQuery):
)
if record:
# email = record["email"]
expiry_time = record["expiry_time"]
# current_time = datetime.utcnow().timestamp() * 1000
keyboard = types.InlineKeyboardMarkup(
inline_keyboard=[
[
@@ -474,7 +472,6 @@ async def process_callback_confirm_delete(callback_query: types.CallbackQuery):
)
if record:
# email = record["email"]
response_message = "Ключ успешно удален."
back_button = types.InlineKeyboardButton(
text="Назад", callback_data="view_keys"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 36 KiB

-8
View File
@@ -248,14 +248,6 @@ async def handle_expired_keys(bot: Bot, conn: asyncpg.Connection, current_time:
f"Время истечения ключа: {expiry_time} (дата: {expiry_date}), Текущее время: {current_date}, Оставшееся время: {time_left}."
)
# if time_left.total_seconds() <= 0:
# days_left_message = "Ключ истек"
# elif time_left.days > 0:
# days_left_message = f"Осталось дней: <b>{time_left.days}</b>"
# else:
# hours_left = time_left.seconds // 3600
# days_left_message = f"Осталось часов: <b>{hours_left}</b>"
message_expired = f"Ваш ключ {email} истек и был удален!\n\n Перейдите в профиль для создания нового ключа"
button_profile = types.InlineKeyboardButton(
text="👤 Мой профиль", callback_data="view_profile"
+44 -12
View File
@@ -4,6 +4,7 @@ from aiogram import F, Router, types
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.utils.keyboard import InlineKeyboardBuilder
from aiohttp import web
from loguru import logger
from yookassa import Configuration, Payment
@@ -60,14 +61,42 @@ async def process_callback_replenish_balance(
callback_query: types.CallbackQuery, state: FSMContext
):
tg_id = callback_query.from_user.id
inline_keyboard = []
for payment in PAYMENT_OPTIONS:
inline_keyboard.append(
InlineKeyboardButton(
text=payment.get("text"), callback_data=payment.get("callback_data")
)
builder = InlineKeyboardBuilder()
builder.row(
InlineKeyboardButton(
text=PAYMENT_OPTIONS[0]["text"],
callback_data=PAYMENT_OPTIONS[0]["callback_data"],
),
InlineKeyboardButton(
text=PAYMENT_OPTIONS[1]["text"],
callback_data=PAYMENT_OPTIONS[1]["callback_data"],
),
)
builder.row(
InlineKeyboardButton(
text=PAYMENT_OPTIONS[2]["text"],
callback_data=PAYMENT_OPTIONS[2]["callback_data"],
),
InlineKeyboardButton(
text=PAYMENT_OPTIONS[3]["text"],
callback_data=PAYMENT_OPTIONS[3]["callback_data"],
),
)
builder.row(
InlineKeyboardButton(
text=PAYMENT_OPTIONS[4]["text"],
callback_data=PAYMENT_OPTIONS[4]["callback_data"],
)
)
builder.row(
InlineKeyboardButton(
text=PAYMENT_OPTIONS[5]["text"],
callback_data=PAYMENT_OPTIONS[5]["callback_data"],
)
)
key_count = await get_key_count(tg_id)
@@ -76,14 +105,17 @@ async def process_callback_replenish_balance(
if not exists:
await add_connection(tg_id, balance=0.0, trial=0)
amount_keyboard = InlineKeyboardMarkup(inline_keyboard)
await bot.delete_message(
chat_id=tg_id, message_id=callback_query.message.message_id
)
try:
await bot.delete_message(
chat_id=tg_id, message_id=callback_query.message.message_id
)
except Exception as e:
logger.error(f"Не удалось удалить сообщение: {e}")
await bot.send_message(
chat_id=tg_id, text="Выберите сумму пополнения:", reply_markup=amount_keyboard
chat_id=tg_id,
text="Выберите сумму пополнения:",
reply_markup=builder.as_markup(),
)
await state.set_state(ReplenishBalanceState.choosing_amount)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 36 KiB

+1 -5
View File
@@ -58,14 +58,10 @@ async def process_callback_view_profile(
)
builder.row(InlineKeyboardButton(text="⬅️ Назад", callback_data="back_to_menu"))
# Попробуем удалить предыдущее сообщение
try:
await callback_query.message.delete()
except Exception as e:
logger.error(
f"Ошибка при удалении сообщения: {e}"
) # Логируем ошибку, если удаление не удалось
logger.error(f"Ошибка при удалении сообщения: {e}")
if os.path.isfile(image_path):
with open(image_path, "rb") as image_file:
await bot.send_photo(
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB