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
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.9.tar.gz
(50.1 kB
view details)
Built Distribution
File details
Details for the file revolt_baidu.py-0.0.9.tar.gz
.
File metadata
- Download URL: revolt_baidu.py-0.0.9.tar.gz
- Upload date:
- Size: 50.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71d8885e0fe0d8b44c00276418ffb59e3c998a4af84f7d9b775d876a74764e0e |
|
MD5 | 2545ca99ee192f87dcb54deb2b72308a |
|
BLAKE2b-256 | 5d4a3320eb711d5afce6452ecc9973bd706751e20b3516535e255d303f268cb3 |
File details
Details for the file revolt_baidu.py-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: revolt_baidu.py-0.0.9-py3-none-any.whl
- Upload date:
- Size: 71.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a68cef829b7ba1458df7ddc61a9ca4757492c05e0d158c9f6e6041387d78244 |
|
MD5 | 4ce0542e9d60d075bf1299079771ab8a |
|
BLAKE2b-256 | 28c24b503d63fa9abd8f38361ad481dd735e2a8f255e057e6732e3f501ec9f39 |