Improved filters system
- `RoomEventData` is renamed to `EventContext` and moved to context.py - `EventContext.filter` is removed - Added context variables system which improves type hints and simplifies callbacks code - `BodyCommandFilter` sets context variables from now on - Added `super().__call__` invocation to filters implements in base.py - Examples are updated to include required changes
This commit is contained in:
@@ -9,21 +9,13 @@ import asyncio
|
||||
import os
|
||||
import logging
|
||||
|
||||
from mab import (
|
||||
MatrixBot,
|
||||
MatrixBotConfig,
|
||||
RoomEventData,
|
||||
BodyExistsFilter,
|
||||
MessageTypeFilter,
|
||||
SenderIsBotFilter,
|
||||
MessageType
|
||||
)
|
||||
from mab import *
|
||||
|
||||
from _environment import check_environment
|
||||
|
||||
async def on_text_message(data: RoomEventData) -> None:
|
||||
async def on_text_message(ctx: EventContext) -> None:
|
||||
"""This callback is called when a text message arrives."""
|
||||
await data.bot.send_text(data.room, data.event.body) # type: ignore
|
||||
await ctx.bot.send_text(ctx.room, ctx[CTX_BODY])
|
||||
|
||||
async def main() -> None:
|
||||
"""Application entry point"""
|
||||
|
||||
Reference in New Issue
Block a user