mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-11 22:30:41 +03:00
switch to desktop
This commit is contained in:
parent
7e995866ff
commit
29355722fa
@ -6,15 +6,15 @@ from telegram.ext import CommandHandler, MessageHandler, filters
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CommandHandlers:
|
class BotEventHandlers:
|
||||||
handlers: list[Any] = field(default_factory=list[Any])
|
handlers: list[Any] = field(default_factory=list[Any])
|
||||||
|
|
||||||
def add_handler(self, handler: Any) -> None:
|
def add_handler(self, handler: Any) -> None:
|
||||||
self.handlers.append(handler)
|
self.handlers.append(handler)
|
||||||
|
|
||||||
|
|
||||||
command_handlers = CommandHandlers()
|
bot_event_handlers = BotEventHandlers()
|
||||||
|
|
||||||
command_handlers.add_handler(CommandHandler("help", help_command))
|
bot_event_handlers.add_handler(CommandHandler("help", help_command))
|
||||||
command_handlers.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, ask_question))
|
bot_event_handlers.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, ask_question))
|
||||||
command_handlers.add_handler(MessageHandler(filters.VOICE | filters.AUDIO, voice_recognize))
|
bot_event_handlers.add_handler(MessageHandler(filters.VOICE | filters.AUDIO, voice_recognize))
|
||||||
|
@ -3,7 +3,7 @@ from functools import cached_property
|
|||||||
|
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from core.bot import BotApplication, BotQueue
|
from core.bot import BotApplication, BotQueue
|
||||||
from core.handlers import command_handlers
|
from core.handlers import bot_event_handlers
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.responses import UJSONResponse
|
from fastapi.responses import UJSONResponse
|
||||||
from routers import api_router
|
from routers import api_router
|
||||||
@ -59,7 +59,7 @@ class Application:
|
|||||||
|
|
||||||
def create_app(settings: AppSettings | None = None) -> FastAPI:
|
def create_app(settings: AppSettings | None = None) -> FastAPI:
|
||||||
settings = settings or get_settings()
|
settings = settings or get_settings()
|
||||||
bot_app = BotApplication(settings=settings, handlers=command_handlers.handlers)
|
bot_app = BotApplication(settings=settings, handlers=bot_event_handlers.handlers)
|
||||||
|
|
||||||
return Application(settings=settings, bot_app=bot_app).fastapi_app
|
return Application(settings=settings, bot_app=bot_app).fastapi_app
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ from typing import Any, AsyncGenerator
|
|||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
from core.bot import BotApplication
|
from core.bot import BotApplication
|
||||||
from core.handlers import command_handlers
|
from core.handlers import bot_event_handlers
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
from main import Application as AppApplication
|
from main import Application as AppApplication
|
||||||
@ -229,7 +229,7 @@ async def main_application(
|
|||||||
bot_app = BotApplication(
|
bot_app = BotApplication(
|
||||||
application=bot_application,
|
application=bot_application,
|
||||||
settings=test_settings,
|
settings=test_settings,
|
||||||
handlers=command_handlers.handlers,
|
handlers=bot_event_handlers.handlers,
|
||||||
)
|
)
|
||||||
fast_api_app = AppApplication(settings=test_settings, bot_app=bot_app).fastapi_app
|
fast_api_app = AppApplication(settings=test_settings, bot_app=bot_app).fastapi_app
|
||||||
yield fast_api_app
|
yield fast_api_app
|
||||||
|
Loading…
x
Reference in New Issue
Block a user