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
components[0]["label"] = "edited"
components[0]["enabled"] = False
# 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=[
Component(
type="button",
style="color:white; backgroundColor:green; fontSize:16px; fontWeight:400;",
label="continue",
enabled=True,
),
Component(
type="button", style="color:green", label="quit", enabled=True
),
Component(
type="button", style="color:red", label="restart", enabled=False
),
],
)
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
Release history Release notifications | RSS feed
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.4.tar.gz
(49.4 kB
view details)
Built Distribution
File details
Details for the file revolt_baidu.py-0.0.4.tar.gz
.
File metadata
- Download URL: revolt_baidu.py-0.0.4.tar.gz
- Upload date:
- Size: 49.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d71cb034da281325caef3c771a4777b8c071db866c3d4e4cdcee6bb2b74a709e |
|
MD5 | a5eff87d9b703ce16cdaa24c3478ed69 |
|
BLAKE2b-256 | c7f65bbb5689bbde11bcbcfe0ae6638b8f0f1c86c31caff6f941009c9e963ffa |
File details
Details for the file revolt_baidu.py-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: revolt_baidu.py-0.0.4-py3-none-any.whl
- Upload date:
- Size: 70.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dc436475449ca32952470ccec61659d36880cccfcba8b968234028b26cb1d72 |
|
MD5 | c23a8cfa3d78b7647e9da79ce211af47 |
|
BLAKE2b-256 | 832b39098c3ef65e20353967bafc3a4580dd77b49834fe1fc9973b48eb2d5d5f |