feat: remove !h and make the bot have an in-memory dict of greeted users instead of using the backoff service
This commit is contained in:
parent
48a3235323
commit
b2185f4174
52 changed files with 404 additions and 353 deletions
95
src/apps/httpapi/litestar/main.py
Normal file
95
src/apps/httpapi/litestar/main.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import httpx
|
||||
from litestar import Litestar, get
|
||||
from litestar.contrib.jinja import JinjaTemplateEngine
|
||||
from litestar.di import Provide
|
||||
from litestar.exceptions import HTTPException
|
||||
from litestar.static_files import StaticFilesConfig
|
||||
from litestar.template import TemplateConfig
|
||||
|
||||
from apps.httpapi.litestar.dependencies import (
|
||||
authenticate,
|
||||
get_authenticate_action,
|
||||
get_authenticator,
|
||||
get_chatbot_settings_svc,
|
||||
get_db,
|
||||
get_get_user_by_jwt_action,
|
||||
get_sentences_storer_svc,
|
||||
get_settings,
|
||||
get_user_repo,
|
||||
store_chatbot_settings_svc,
|
||||
)
|
||||
from apps.httpapi.litestar.errors import (
|
||||
after_exception_handler,
|
||||
http_exception_handler,
|
||||
httpx_status_error_handler,
|
||||
)
|
||||
from apps.httpapi.litestar.routes.api import (
|
||||
get_bot_settings,
|
||||
get_bot_status,
|
||||
get_index,
|
||||
get_tts_overlay,
|
||||
get_tts_permalink,
|
||||
manage_bot,
|
||||
save_bot_settings,
|
||||
)
|
||||
from apps.httpapi.litestar.routes.auth import get_code, login
|
||||
from huesoporro.bot import BotsManager
|
||||
from huesoporro.settings import Settings
|
||||
|
||||
|
||||
@get("/healthz")
|
||||
def get_health() -> dict:
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
def create_app():
|
||||
return Litestar(
|
||||
route_handlers=[
|
||||
get_health,
|
||||
login,
|
||||
get_index,
|
||||
get_tts_overlay,
|
||||
get_tts_permalink,
|
||||
get_code,
|
||||
manage_bot,
|
||||
get_bot_status,
|
||||
save_bot_settings,
|
||||
get_bot_settings,
|
||||
],
|
||||
static_files_config=(
|
||||
StaticFilesConfig(
|
||||
path="/tts_files",
|
||||
directories=[Settings.get().tts_cache_path],
|
||||
),
|
||||
StaticFilesConfig(
|
||||
path="static",
|
||||
directories=[Settings.get().static_files_path],
|
||||
),
|
||||
),
|
||||
template_config=TemplateConfig(
|
||||
directory=Settings.get().templates_files_path,
|
||||
engine=JinjaTemplateEngine,
|
||||
),
|
||||
exception_handlers={
|
||||
HTTPException: http_exception_handler,
|
||||
httpx.HTTPStatusError: httpx_status_error_handler,
|
||||
},
|
||||
after_exception=[after_exception_handler],
|
||||
dependencies={
|
||||
"s": Provide(get_settings, use_cache=True),
|
||||
"a": Provide(get_authenticator, use_cache=True),
|
||||
"user": Provide(authenticate),
|
||||
"db": Provide(get_db, use_cache=True),
|
||||
"bm": Provide(BotsManager, use_cache=True),
|
||||
"gbs": Provide(get_chatbot_settings_svc),
|
||||
"sbs": Provide(store_chatbot_settings_svc),
|
||||
"sss": Provide(get_sentences_storer_svc),
|
||||
"authenticator": Provide(get_authenticator),
|
||||
"authenticate_action": Provide(get_authenticate_action),
|
||||
"user_repo": Provide(get_user_repo),
|
||||
"get_user_by_jwt_action": Provide(get_get_user_by_jwt_action),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
app = create_app()
|
||||
Loading…
Add table
Add a link
Reference in a new issue