Exemplo n.º 1
0
def get_info(request: Request, settings: Settings) -> Response:
    """Handle retrieving information of chat request.

    Arguments:
        request: HTTP request from Molten.
        settings: application settings with storage.

    Returns:
        Response with information of chat.
    """
    payload = info.Info.parse_obj(request.params)
    add_request_to_collection(settings, payload)

    inserted_ad = dt.fromisoformat("2019-08-29T11:22:48.358586+00:00")
    return PydanticResponse(
        APIResponse[chats.ChatFromSearch](
            result=chats.ChatFromSearch(
                name="chat name",
                chat_type=enums.ChatTypes.group_chat,
                creator=uuid.uuid4(),
                group_chat_id=payload.group_chat_id,
                members=[
                    users.UserFromChatSearch(
                        user_huid=uuid.uuid4(),
                        user_kind=enums.UserKinds.user,
                        admin=True,
                    ),
                ],
                inserted_at=inserted_ad,
            ),
        ),
    )
Exemplo n.º 2
0
def get_bot_chats(request: Request, settings: Settings) -> Response:
    """Return list of bot chats.

    Arguments:
        request: HTTP request from Molten.
        settings: application settings with storage.

    Returns:
         List of bot chats.
    """
    payload = chat_list.ChatList.parse_obj(request.params)
    add_request_to_collection(settings, payload)

    inserted_at = dt.fromisoformat("2019-08-29T11:22:48.358586+00:00")
    updated_at = dt.fromisoformat("2019-09-29T10:30:48.358586+00:00")
    return PydanticResponse(
        APIResponse[chats.BotChatList](
            result=chats.BotChatList(
                __root__=[
                    chats.BotChatFromList(
                        name="chat name",
                        description="test",
                        chat_type=enums.ChatTypes.group_chat,
                        group_chat_id=uuid.uuid4(),
                        members=[uuid.uuid4()],
                        inserted_at=inserted_at,
                        updated_at=updated_at,
                    ),
                ],
            ),
        ),
    )
Exemplo n.º 3
0
def post_add_user(request_data: RequestData, settings: Settings) -> Response:
    """Handle adding of user to chat request.

    Arguments:
        request_data: parsed json data from request.
        settings: application settings with storage.

    Returns:
        Response with result of adding.
    """
    payload = add_user.AddUser.parse_obj(request_data)
    add_request_to_collection(settings, payload)
    return PydanticResponse(APIResponse[bool](result=True))
Exemplo n.º 4
0
def post_add_admin_role(request_data: RequestData, settings: Settings) -> Response:
    """Handle promoting users to admins request.

    Arguments:
        request_data: parsed json data from request.
        settings: application settings with storage.

    Returns:
        Response with result of adding.
    """
    payload = add_admin_role.AddAdminRole.parse_obj(request_data)
    add_request_to_collection(settings, payload)
    return PydanticResponse(APIResponse[bool](result=True))
Exemplo n.º 5
0
def post_stealth_disable(request_data: RequestData, settings: Settings) -> Response:
    """Handle stealth disabling in chat request.

    Arguments:
        request_data: parsed json data from request.
        settings: application settings with storage.

    Returns:
        Response with result of disabling stealth.
    """
    payload = stealth_disable.StealthDisable.parse_obj(request_data)
    add_request_to_collection(settings, payload)
    return PydanticResponse(APIResponse[bool](result=True))
Exemplo n.º 6
0
def post_create(request_data: RequestData, settings: Settings) -> Response:
    """Handle creation of new chat request.

    Arguments:
        request_data: parsed json data from request.
        settings: application settings with storage.

    Returns:
        Response with result of creation.
    """
    payload = create.Create.parse_obj(request_data)
    add_request_to_collection(settings, payload)
    return PydanticResponse(
        APIResponse[ChatCreatedResult](result=ChatCreatedResult(chat_id=uuid.uuid4())),
    )
Exemplo n.º 7
0
def get_by_email(request: Request, settings: Settings) -> Response:
    """Handle retrieving information about user request.

    Arguments:
        request: HTTP request from Molten.
        settings: application settings with storage.

    Returns:
        Response with information about user.
    """
    payload = ByEmail.parse_obj(dict(request.params))
    add_request_to_collection(settings, payload)
    return PydanticResponse(
        APIResponse[UserFromSearch](result=create_test_user(email=payload.email)),
    )
Exemplo n.º 8
0
def get_token(bot_id: str, request: Request, settings: Settings) -> Response:
    """Handle retrieving token from BotX API request.

    Arguments:
        bot_id: ID of bot from query params.
        request: modten request for route.
        settings: application settings with storage.

    Returns:
        Return response with new token.
    """
    signature = request.params["signature"]
    payload = Token(bot_id=UUID(bot_id), signature=signature)
    add_request_to_collection(settings, payload)
    return PydanticResponse(APIResponse[str](result="real token"))