24 lines
839 B
Python
24 lines
839 B
Python
import xmpp_api.api.types.v1.bot as bot_api
|
|
import xmpp_api.db.bot as bot_db
|
|
from xmpp_api.exceptions.base import UnknownConstraintException
|
|
|
|
|
|
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 _:
|
|
raise UnknownConstraintException(constraint.__class__.__name__)
|
|
|
|
|
|
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 _:
|
|
raise UnknownConstraintException(constraint.__class__.__name__)
|