Initial commit

This commit is contained in:
2025-04-20 23:22:04 +02:00
commit 054f182215
17 changed files with 1312 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import xmpp_api.api.bot as bot_api
import xmpp_api.db.bot as bot_db
def bot_constraint_to_db(constraint: bot_api.BotConstraint) -> bot_db.BotConstraint:
match constraint:
case bot_api.BotDomainConstraint:
return bot_db.BotDomainConstraint(
domains=constraint.domains,
)
case _:
# TODO: Proper exception type
raise Exception()
def bot_constraint_from_db(constraint: bot_db.BotConstraint) -> bot_api.BotConstraint:
match constraint:
case bot_db.BotDomainConstraint:
return bot_api.BotDomainConstraint(
domains=constraint.domains,
)
case _:
# TODO: Proper exception type
raise Exception()

5
src/xmpp_api/util/db.py Normal file
View File

@@ -0,0 +1,5 @@
import uuid as py_uuid
def uuid() -> str:
return py_uuid.uuid4().hex

View File

@@ -0,0 +1,6 @@
from secrets import token_bytes
def generate_token(length: int = 32) -> str:
# TODO: PBKDF2?
return token_bytes(length).hex()