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:
cătălin 2025-02-26 11:53:18 +01:00
commit b2185f4174
No known key found for this signature in database
52 changed files with 404 additions and 353 deletions

View file

@ -0,0 +1,68 @@
from litestar import Request
from litestar.exceptions import HTTPException
from huesoporro.actions.authenticate import AuthenticateAction
from huesoporro.actions.get_user_by_jwt import GetUserByJWTAction
from huesoporro.infra.authenticator import TwitchAuthenticator
from huesoporro.infra.db import Database
from huesoporro.infra.repos import UserRepo
from huesoporro.libs.db import MarkovDatabase
from huesoporro.models import User
from huesoporro.settings import Settings
from huesoporro.svc.get_chatbot_settings import ChatbotSettingsGetterSvc
from huesoporro.svc.store import SentenceStorerSvc
from huesoporro.svc.store_settings import ChatbotSettingsStorerSvc
def get_settings() -> Settings:
return Settings.get()
def get_authenticator(s: Settings) -> TwitchAuthenticator:
return TwitchAuthenticator(s=s)
def get_db(s: Settings):
return Database(s=s)
async def get_get_user_by_jwt_action(
user_repo: UserRepo, authenticator: TwitchAuthenticator, s: Settings
):
return GetUserByJWTAction(user_repo=user_repo, authenticator=authenticator, s=s)
async def authenticate(
request: Request, get_user_by_jwt_action: GetUserByJWTAction
) -> User:
token = request.query_params.get("huesoporro_token")
if token:
return await get_user_by_jwt_action.run(token)
cookies = request.cookies.get("huesoporroAuth")
if cookies:
return await get_user_by_jwt_action.run(cookies)
raise HTTPException(status_code=401, detail="Unauthorized")
async def get_chatbot_settings_svc(db: Database):
return ChatbotSettingsGetterSvc(db=db)
async def store_chatbot_settings_svc(db: Database):
return ChatbotSettingsStorerSvc(db=db)
async def get_sentences_storer_svc(db: MarkovDatabase):
return SentenceStorerSvc(db=db)
async def get_user_repo(s: Settings):
return UserRepo(s=s)
async def get_authenticate_action(
user_repo: UserRepo, authenticator: TwitchAuthenticator, s: Settings
):
return AuthenticateAction(user_repo=user_repo, authenticator=authenticator, s=s)