Filter update, fixed bot stop, v0.4.0
- Fixed `asyncio.shield` not being awaited in `ClientManager.stop()` (that led to `next_batch` value not being saved and session not being closed properly) - `BaseEventFilter` does not have any abstract methods anymore and can be used to use callback for any event - `BaseEventFilter.__repr__` prints class name now - `BaseEventFilter.__call__` returns True now - Added `EventTypeFilter` which can be used to check if the event is an instance of some class - Removed most room events - Added `NewMessageFilter`, `EditedMessageFilter`, `RedactedMessageFilter`, `SenderIsFilter` and `SenderIsBotFilter` - Removed `FormattedTextFilter` - Text filters are derived from `NewMessageFilter` so they won't match edited messages anymore
This commit is contained in:
16
README.md
16
README.md
@@ -18,7 +18,7 @@ The package supports the following features:
|
||||
Use `pip` to install this package:
|
||||
|
||||
```bash
|
||||
python -m pip install git+https://git.tyukalov.su/nikita/mab@v0.3.0
|
||||
python -m pip install git+https://git.tyukalov.su/nikita/mab@v0.4.0
|
||||
```
|
||||
|
||||
You should specify package version you want to use, because `main` without tags
|
||||
@@ -27,18 +27,16 @@ contain unstable code.
|
||||
## Basic usage
|
||||
|
||||
This is the most simple bot you can create. It would respond to any message
|
||||
that starts with `!test`, `!hello` or `!hi`.
|
||||
that contains `hello` and `hi` words.
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from mab import MatrixBot, MatrixBotConfig
|
||||
from mab import TextCommandFilter
|
||||
from mab import TextContainsFilter, SenderIsBotFilter
|
||||
from mab.types import RoomEventData
|
||||
|
||||
async def on_valid_command(data: RoomEventData) -> None:
|
||||
# do not respond to ourselves
|
||||
if event.sender == data.bot.get_client().user_id:
|
||||
return
|
||||
async def on_message(data: RoomEventData) -> None:
|
||||
text = f"Your message contains {len(data.event.body)} symbols"
|
||||
await data.bot.send_text_to_room(data.room, text)
|
||||
|
||||
@@ -51,8 +49,8 @@ async def main() -> None:
|
||||
)
|
||||
bot = MatrixBot(matrix_bot_config)
|
||||
bot.add_callback(
|
||||
TextCommandFilter(["test", "hello", "hi"]),
|
||||
on_valid_command
|
||||
~SenderIsBotFilter() & TextContainsFilter(["test", "hello", "hi"]),
|
||||
on_message
|
||||
)
|
||||
await bot.start()
|
||||
# wait for Ctrl+C
|
||||
|
||||
Reference in New Issue
Block a user