Skip to content

Commit

Permalink
Merge pull request #30 from ikhit/master
Browse files Browse the repository at this point in the history
add redis set timer command
  • Loading branch information
GreenVibesOnly authored Oct 18, 2024
2 parents 4922ae1 + 0106f22 commit b3a6b76
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 91 deletions.
6 changes: 5 additions & 1 deletion app/admin/handlers/admin_handlers/superuser_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
SUPERUSER_SPECIAL_BUTTONS,
SUPERUSER_SPECIAL_OPTIONS,
)
from redis_db.connect import get_redis_connection
from bot.exceptions import message_exception_handler
from models.models import User, RoleEnum
from crud.request_to_manager import get_manager_stats
Expand Down Expand Up @@ -336,7 +337,10 @@ async def check_and_set_new_timer(
):
"""Проверить и выставить новый таймер."""
try:
# await change_timer(message.text, session)
redis_client = await get_redis_connection()

await redis_client.set("timeout", int(message.text))
await redis_client.close()
await message.answer(
f"Новый таймер на {message.text} секунд установлен!",
reply_markup=await get_inline_keyboard(
Expand Down
74 changes: 0 additions & 74 deletions app/alembic/versions/4f7c029c89f4_add_timer.py

This file was deleted.

11 changes: 9 additions & 2 deletions app/bot/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

from aiogram import Router, F
from aiogram.filters import CommandStart, Command
from aiogram.fsm.context import FSMContext
from aiogram.types import Message
from sqlalchemy.ext.asyncio import AsyncSession

from admin.keyboards.keyboards import get_inline_keyboard
from admin.admin_settings import MAIN_MENU_BUTTONS
from bot.bot_const import (
ADMIN_NEGATIVE_ANSWER, ADMIN_POSITIVE_ANSWER, START_MESSAGE
ADMIN_NEGATIVE_ANSWER,
ADMIN_POSITIVE_ANSWER,
START_MESSAGE,
)
from models.models import RoleEnum
from crud.users import create_user_id, get_role_by_tg_id, is_user_in_db
Expand Down Expand Up @@ -53,9 +56,13 @@ async def cmd_admin(message: Message, session: AsyncSession) -> None:
log_error_text="Ошибка при обработке команды /start."
)
@router.message(CommandStart())
async def cmd_start(message: Message, session: AsyncSession) -> None:
async def cmd_start(
message: Message, state: FSMContext, session: AsyncSession
) -> None:
"""Выводит приветствие пользователя."""

await state.clear()

user_id = get_user_id(message)

redis_client = await get_redis_connection()
Expand Down
12 changes: 1 addition & 11 deletions app/core/init_db.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from admin.admin_settings import PORTFOLIO_DEFAULT_DATA
from admin.admin_settings import admin_list
from crud.timer import get_timer
from crud.users import create_user_id
from crud.user_crud import user_crud
from core.db import AsyncSessionLocal
from crud.portfolio_projects_crud import portfolio_crud
from models.models import Timer, RoleEnum
from models.models import RoleEnum


async def add_portfolio():
Expand All @@ -27,12 +26,3 @@ async def set_admin():
await user_crud.update(user, RoleEnum.ADMIN , session)


async def set_timer():
"""Установить таймер активности."""
async with AsyncSessionLocal() as session:
if not await get_timer(session):
timer = Timer()
session.add(timer)
await session.commit()
await session.refresh(timer)
return timer
3 changes: 1 addition & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bot.callbacks import router as callback_router
from bot.fsm_contexts.manager_context import router as fsm_context_router
from bot.fsm_contexts.feedback_context import router as feedback_context
from core.init_db import add_portfolio, set_admin, set_timer
from core.init_db import add_portfolio, set_admin
from admin.handlers.admin_handlers import admin_router
from loggers.log import setup_logging

Expand Down Expand Up @@ -38,7 +38,6 @@ async def main() -> None:
dispatcher.update.middleware(
DataBaseSession(session_pool=AsyncSessionLocal)
)
await set_timer()
await add_portfolio()
await set_admin()
await dispatcher.start_polling(bot)
Expand Down
2 changes: 1 addition & 1 deletion app/redis_db/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ async def get_redis_connection():
"""Подключение к Redis."""

return await aioredis.from_url(
"redis://158.160.77.163:6379", decode_responses=True # localhost:
"redis://localhost", decode_responses=True # localhost:158.160.77.163:6379
)

0 comments on commit b3a6b76

Please sign in to comment.