You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
992 B
Python

from __future__ import annotations
"""
Utilities for the bot.
"""
from typing import TYPE_CHECKING
from dataclasses import (
dataclass,
field
)
if TYPE_CHECKING:
from .client import Client
RoomAlias = str
RoomId = str
@dataclass
class Room:
""" Class representing a room.
"""
id: RoomId
aliases: set[RoomAlias] = field(default_factory=set)
def ignore_client_message(
callback: Callable[[Client, nio.rooms.Room, nio.events.room_events.RoomMessageText], Awaitable[None]]
)->Callable[[Client, nio.rooms.Room, nio.events.room_events.RoomMessageText], Awaitable[None]]:
"""
Decorator for message callback.
The decorated callback will ignore message sent by the client.
"""
async def new_callback(
client: Client,
room: nio.rooms.Room,
message: nio.events.room_events.RoomMessageText
):
if client.user_id != message.sender:
await callback(client, room, message)
return new_callback