Updated to v0.3.0
This commit is contained in:
35
README.md
35
README.md
@@ -6,14 +6,24 @@ because I wasn't satisfied by simplicity and usage of other libraries. So
|
|||||||
this library does not aim to be "the best matrix bot library", it only aims to
|
this library does not aim to be "the best matrix bot library", it only aims to
|
||||||
be good enough for me.
|
be good enough for me.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
The package supports the following features:
|
||||||
|
- **Filter-based callback system**
|
||||||
|
- **Images sending**
|
||||||
|
- **Videos sending with automatic thumbnail generation (requires `ffmpeg`)**
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Use `pip` to install this package:
|
Use `pip` to install this package:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m pip install git+https://git.tyukalov.su/nikita/mab
|
python -m pip install git+https://git.tyukalov.su/nikita/mab@v0.3.0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You should specify package version you want to use, because `main` without tags
|
||||||
|
contain unstable code.
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
This is the most simple bot you can create. It would respond to any message
|
This is the most simple bot you can create. It would respond to any message
|
||||||
@@ -23,21 +33,16 @@ that starts with `!test`, `!hello` or `!hi`.
|
|||||||
import asyncio
|
import asyncio
|
||||||
from mab import MatrixBot, MatrixBotConfig
|
from mab import MatrixBot, MatrixBotConfig
|
||||||
from mab import TextCommandFilter
|
from mab import TextCommandFilter
|
||||||
|
from mab.types import RoomEventData
|
||||||
|
|
||||||
from nio import MatrixRoom, MatrixMessageText
|
async def on_valid_command(data: RoomEventData) -> None:
|
||||||
|
|
||||||
bot: MatrixBot
|
|
||||||
|
|
||||||
async def on_valid_command(room: MatrixRoom, event: RoomMessageText) -> None:
|
|
||||||
global bot
|
|
||||||
# do not respond to ourselves
|
# do not respond to ourselves
|
||||||
if event.sender == bot.get_client().user_id:
|
if event.sender == data.bot.get_client().user_id:
|
||||||
return
|
return
|
||||||
text = f"Your message contains {len(event.body)} symbols"
|
text = f"Your message contains {len(data.event.body)} symbols"
|
||||||
await bot.send_text_to_room(room.room_id, text)
|
await data.bot.send_text_to_room(data.room, text)
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
global bot
|
|
||||||
# create and start the bot
|
# create and start the bot
|
||||||
cfg = MatrixBotConfig(
|
cfg = MatrixBotConfig(
|
||||||
matrix_homeserver_url="matrix.domain.su",
|
matrix_homeserver_url="matrix.domain.su",
|
||||||
@@ -45,11 +50,11 @@ async def main() -> None:
|
|||||||
storage_directory=Path("storage_nagibator666")
|
storage_directory=Path("storage_nagibator666")
|
||||||
)
|
)
|
||||||
bot = MatrixBot(matrix_bot_config)
|
bot = MatrixBot(matrix_bot_config)
|
||||||
bot.add_event_callback(
|
bot.add_callback(
|
||||||
on_valid_command,
|
TextCommandFilter(["test", "hello", "hi"]),
|
||||||
TextCommandFilter(["test", "hello", "hi"])
|
on_valid_command
|
||||||
)
|
)
|
||||||
bot.start()
|
await bot.start()
|
||||||
# wait for Ctrl+C
|
# wait for Ctrl+C
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "mab"
|
name = "mab"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Tyukalov Nikita", email = "nikita@tyukalov.su" }
|
{ name = "Tyukalov Nikita", email = "nikita@tyukalov.su" }
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user