1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- from dataclasses import dataclass, field
- from datetime import datetime
- from collections.abc import Callable, Coroutine, Container
- from typing import Union, Any, Optional
- from aiosqlite.core import Connection
- @dataclass
- class Attachment:
- name: str
- body: Union[str, bytes]
- @dataclass
- class Message:
- origin_id: str
- channel_id: str
- sender_id: str
- timestamp: datetime
- origin_admin: bool
- channel_admin: bool
- text: Optional[str]
- attachments: list[Attachment]
- @dataclass
- class Response:
- origin_id: str
- channel_id: str
- text: Optional[str]
- attachments: list[Attachment]
- @staticmethod
- def from_message(msg: Message, text: Optional[str] = None, attachments: list[Attachment] = None) -> "Response":
- return Response(
- origin_id=msg.origin_id,
- channel_id=msg.channel_id,
- text=text,
- attachments=attachments or [],
- )
- @dataclass
- class Context:
- config: Callable[[str], Any]
- respond: Callable[[], Coroutine[None, None, None]]
- database: Callable[[], Coroutine[None, None, Connection]]
- CommandType = Callable[[Message, Context], Coroutine[None, None, None]]
- StartupShutdownType = Callable[[Context], Coroutine[None, None, None]]
- @dataclass
- class CommandConfiguration:
- commands: dict[str, CommandType]
- call_and_response: dict[str, str]
- aliases: dict[str, str]
- bangs: Container[str] = ("!",)
- startup: list[StartupShutdownType] = field(default_factory=list)
- shutdown: list[StartupShutdownType] = field(default_factory=list)
|