コード例 #1
0
ファイル: chats.py プロジェクト: ExpressApp/pybotx
async def get_bot_chats(request: requests.Request) -> responses.Response:
    """Return list of bot chats.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
         List of bot chats.
    """
    payload = chat_list.ChatList.parse_obj(request.query_params)
    add_request_to_collection(request, 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,
            ),
        ], ), ), )
コード例 #2
0
ファイル: chats.py プロジェクト: ExpressApp/pybotx
async def get_info(request: requests.Request) -> responses.Response:
    """Handle retrieving information of chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with information of chat.
    """
    payload = info.Info.parse_obj(request.query_params)
    add_request_to_collection(request, 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,
        ), ), )
コード例 #3
0
ファイル: chats.py プロジェクト: ExpressApp/pybotx
async def post_add_user(request: requests.Request) -> responses.Response:
    """Handle adding of user to chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of adding.
    """
    payload = add_user.AddUser.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[bool](result=True))
コード例 #4
0
ファイル: chats.py プロジェクト: ExpressApp/pybotx
async def post_add_admin_role(request: requests.Request) -> responses.Response:
    """Handle promoting users to admins request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of adding.
    """
    payload = add_admin_role.AddAdminRole.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[bool](result=True))
コード例 #5
0
ファイル: chats.py プロジェクト: ExpressApp/pybotx
async def post_stealth_set(request: requests.Request) -> responses.Response:
    """Handle stealth enabling in chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of enabling stealth.
    """
    payload = stealth_set.StealthSet.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[bool](result=True))
コード例 #6
0
ファイル: bots.py プロジェクト: ExpressApp/pybotx
async def get_token(request: Request) -> Response:
    """Handle retrieving token from BotX API request.

    Arguments:
        request: starlette request for route.

    Returns:
        Return response with new token.
    """
    request_data = {**request.path_params, **request.query_params}
    payload = Token(**request_data)
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[str](result="real token"))
コード例 #7
0
ファイル: users.py プロジェクト: ExpressApp/pybotx
async def get_by_email(request: Request) -> Response:
    """Handle retrieving information about user request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with information about user.
    """
    payload = ByEmail.parse_obj(request.query_params)
    add_request_to_collection(request, payload)
    return PydanticResponse(
        APIResponse[UserFromSearch](result=create_test_user(
            email=payload.email)), )
コード例 #8
0
ファイル: chats.py プロジェクト: ExpressApp/pybotx
async def post_create(request: requests.Request) -> responses.Response:
    """Handle creation of new chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of creation.
    """
    payload = create.Create.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(
        APIResponse[ChatCreatedResult](result=ChatCreatedResult(
            chat_id=uuid.uuid4())), )