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
68
src/apps/httpapi/litestar/dependencies.py
Normal file
68
src/apps/httpapi/litestar/dependencies.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue