Skip to main content

Python wrapper for the revolt.chat API

Project description

Revolt.py

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

You can join the support server here and find the library's documentation here.

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.

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

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

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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

revolt_baidu.py-0.0.8.tar.gz (50.1 kB view details)

Uploaded Source

Built Distribution

revolt_baidu.py-0.0.8-py3-none-any.whl (71.3 kB view details)

Uploaded Python 3

File details

Details for the file revolt_baidu.py-0.0.8.tar.gz.

File metadata

  • Download URL: revolt_baidu.py-0.0.8.tar.gz
  • Upload date:
  • Size: 50.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for revolt_baidu.py-0.0.8.tar.gz
Algorithm Hash digest
SHA256 c5240ef4d06876ea3cc797bd68be5da832a9bf34ce472e818609372df6fcfa15
MD5 a61c0a678a578ba1d8f42783d6acfa9c
BLAKE2b-256 4751c1dc4a6717d58f0d0f6955411e9ba3bc75f60f0dac352de2ab3d1be78f7e

See more details on using hashes here.

File details

Details for the file revolt_baidu.py-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for revolt_baidu.py-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 606b69b657411cdabb0d59a6ce9e3e84a4988fbe34a4d6b767d87a08e8f3ca9f
MD5 7cf34847e32ab210744a25878d4b5c90
BLAKE2b-256 25db63377d4df76886b1c1f64625f815e9c57f55d7b6b76872d50c6fc6fe9690

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page