revolt-baidu.py


Namerevolt-baidu.py JSON
Version 0.0.11 PyPI version JSON
download
home_pageNone
SummaryPython wrapper for the revolt.chat API
upload_time2023-09-27 12:44:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords api async http websockets wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Revolt.py

An async library to interact with the <https://revolt.chat> API.

You can join the support server [here](https://rvlt.gg/FDXER6hr) and find the library's documentation [here](https://revoltpy.readthedocs.io/en/latest/).

## Installing

You can use `pip` to install revolt.py. It differs slightly depending on what OS/Distro you use.

On Windows

```
py -m pip install -U revolt-baidu.py # -U to update
```

On macOS and Linux

```
python3 -m pip install -U revolt-baidu.py
```

## Example

More examples can be found in the [examples folder](https://github.com/revolt-customize/revolt.py/tree/master/examples).

```py
import revolt
import asyncio

class Client(revolt.Client):
    async def on_message(self, message: revolt.Message):
        if message.content == "hello":
            await message.channel.send("hi how are you")

async def main():
    async with revolt.utils.client_session() as session:
        client = Client(session, "BOT TOKEN HERE")
        await client.start()

asyncio.run(main())
```

## Bot interaction example

```py
class Client(revolt.Client):
    async def on_interaction(
        self, interaction: InteractionEventPayload, message: revolt.Message
    ) -> None:
        logger.info("interaction %s", interaction)
        user = self.get_user(interaction["author_id"])
        await message.channel.send(
            f"Username: {user.name} Your choice is: {interaction['content']} "
        )
        components = message.components
        for com in components:
            if isinstance(com, ButtonComponent):
                com.label = "edited"
                com.enabled = False
            elif isinstance(com, StatusComponent):
                com.label = "new status"

        # update the button component's label
        await message.edit(content="edited", components=components)

    async def on_message(self, message: revolt.Message):
        if message.content == "/button":
            await message.channel.send(
                "you have these options",
                components=[
                    ButtonComponent(
                        style="color:white; backgroundColor:green; fontSize:16px; fontWeight:400;",
                        label="continue",
                        enabled=True,
                    ),
                    LineBreakComponent(),
                    StatusComponent(label="this is status window"),
                ],
            )
```

## Stream Message Example

```py
from revolt.stream_handler import StreamGenerator

class Client(revolt.Client):
    def need_reply(self, message: revolt.Message) -> bool:
        message_user = self.get_user(message.author.id)
        is_response = False
        for user in message.mentions:
            if user.id == self.user.id:
                is_response = True

        if message.channel.channel_type == ChannelType.direct_message:
            is_response = True

        return message_user.id != self.user.id and is_response

    async def on_message(self, message: revolt.Message):
        if not self.need_reply(message):
            return

        g = StreamGenerator()

        async def stream_message():
            for i in range(10):
                await g.push_message(f"hello {i}  ")

            # needs to call g.close when generating has been finished
            await g.close()

        asyncio.create_task(stream_message())
        await message.channel.send(stream_generator=g.generator())
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "revolt-baidu.py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "api,async,http,websockets,wrapper",
    "author": null,
    "author_email": "Zomatree <me@zomatree.live>",
    "download_url": "https://files.pythonhosted.org/packages/53/8f/d4448e825a9b762415b524df8a1bd8e40bc851668259763b7ce8c452ae55/revolt_baidu.py-0.0.11.tar.gz",
    "platform": null,
    "description": "# Revolt.py\n\nAn async library to interact with the <https://revolt.chat> API.\n\nYou can join the support server [here](https://rvlt.gg/FDXER6hr) and find the library's documentation [here](https://revoltpy.readthedocs.io/en/latest/).\n\n## Installing\n\nYou can use `pip` to install revolt.py. It differs slightly depending on what OS/Distro you use.\n\nOn Windows\n\n```\npy -m pip install -U revolt-baidu.py # -U to update\n```\n\nOn macOS and Linux\n\n```\npython3 -m pip install -U revolt-baidu.py\n```\n\n## Example\n\nMore examples can be found in the [examples folder](https://github.com/revolt-customize/revolt.py/tree/master/examples).\n\n```py\nimport revolt\nimport asyncio\n\nclass Client(revolt.Client):\n    async def on_message(self, message: revolt.Message):\n        if message.content == \"hello\":\n            await message.channel.send(\"hi how are you\")\n\nasync def main():\n    async with revolt.utils.client_session() as session:\n        client = Client(session, \"BOT TOKEN HERE\")\n        await client.start()\n\nasyncio.run(main())\n```\n\n## Bot interaction example\n\n```py\nclass Client(revolt.Client):\n    async def on_interaction(\n        self, interaction: InteractionEventPayload, message: revolt.Message\n    ) -> None:\n        logger.info(\"interaction %s\", interaction)\n        user = self.get_user(interaction[\"author_id\"])\n        await message.channel.send(\n            f\"Username: {user.name} Your choice is: {interaction['content']} \"\n        )\n        components = message.components\n        for com in components:\n            if isinstance(com, ButtonComponent):\n                com.label = \"edited\"\n                com.enabled = False\n            elif isinstance(com, StatusComponent):\n                com.label = \"new status\"\n\n        # update the button component's label\n        await message.edit(content=\"edited\", components=components)\n\n    async def on_message(self, message: revolt.Message):\n        if message.content == \"/button\":\n            await message.channel.send(\n                \"you have these options\",\n                components=[\n                    ButtonComponent(\n                        style=\"color:white; backgroundColor:green; fontSize:16px; fontWeight:400;\",\n                        label=\"continue\",\n                        enabled=True,\n                    ),\n                    LineBreakComponent(),\n                    StatusComponent(label=\"this is status window\"),\n                ],\n            )\n```\n\n## Stream Message Example\n\n```py\nfrom revolt.stream_handler import StreamGenerator\n\nclass Client(revolt.Client):\n    def need_reply(self, message: revolt.Message) -> bool:\n        message_user = self.get_user(message.author.id)\n        is_response = False\n        for user in message.mentions:\n            if user.id == self.user.id:\n                is_response = True\n\n        if message.channel.channel_type == ChannelType.direct_message:\n            is_response = True\n\n        return message_user.id != self.user.id and is_response\n\n    async def on_message(self, message: revolt.Message):\n        if not self.need_reply(message):\n            return\n\n        g = StreamGenerator()\n\n        async def stream_message():\n            for i in range(10):\n                await g.push_message(f\"hello {i}  \")\n\n            # needs to call g.close when generating has been finished\n            await g.close()\n\n        asyncio.create_task(stream_message())\n        await message.channel.send(stream_generator=g.generator())\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python wrapper for the revolt.chat API",
    "version": "0.0.11",
    "project_urls": {
        "Bug Tracker": "https://github.com/psychopurp/revolt.py/issues",
        "Documentation": "https://revoltpy.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/psychopurp/revolt.py",
        "Source Code": "https://github.com/psychopurp/revolt.py"
    },
    "split_keywords": [
        "api",
        "async",
        "http",
        "websockets",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3b038515c07bce8e3e90fb4d732485a572c75cdefc7e02b4bf255fe580ed7111",
                "md5": "f3361137f885be4869cade79f3000215",
                "sha256": "aece006cbcc2b21ec95b98e990d9fec9a988c0c04118dd8bea5e44f98d1c9661"
            },
            "downloads": -1,
            "filename": "revolt_baidu.py-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f3361137f885be4869cade79f3000215",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 71437,
            "upload_time": "2023-09-27T12:44:20",
            "upload_time_iso_8601": "2023-09-27T12:44:20.858423Z",
            "url": "https://files.pythonhosted.org/packages/3b/03/8515c07bce8e3e90fb4d732485a572c75cdefc7e02b4bf255fe580ed7111/revolt_baidu.py-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "538fd4448e825a9b762415b524df8a1bd8e40bc851668259763b7ce8c452ae55",
                "md5": "ff26d821df454461104deaf081b50822",
                "sha256": "7a2e9a2353485f078afec8fca80fb310cf4f34d2d088f9e4315b9bed02170194"
            },
            "downloads": -1,
            "filename": "revolt_baidu.py-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "ff26d821df454461104deaf081b50822",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 50241,
            "upload_time": "2023-09-27T12:44:18",
            "upload_time_iso_8601": "2023-09-27T12:44:18.092284Z",
            "url": "https://files.pythonhosted.org/packages/53/8f/d4448e825a9b762415b524df8a1bd8e40bc851668259763b7ce8c452ae55/revolt_baidu.py-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-27 12:44:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "psychopurp",
    "github_project": "revolt.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "revolt-baidu.py"
}
        
Elapsed time: 0.12639s