Skip to content

Filters

See Filters for the list of ready-made ones and how they compose.

sunnygram.filters.Filter

A question about what arrived, which combines with other questions.

sunnygram.filters.make

make(test: Predicate, name: str | None = None) -> Filter

Build a filter out of a function, sync or async.

A filter written here is the program's own, so it is not wrapped in the guard the built-in ones have: one that raises is a fault in the program and is reported as one instead of quietly counting as a no.

sunnygram.filters.command

command(name: str | list[str], *, prefixes: str = '/', to_me: bool = False) -> Filter

Messages that start with a command, with the arguments split out.

A match leaves the pieces on the message as command and arguments, so a handler reads them instead of parsing the text again. to_me limits it to the form addressed to a particular bot, which is what a command in a group looks like when more than one bot is in it.

sunnygram.filters.regex

regex(pattern: str | Pattern[str], *, flags: int = 0) -> Filter

Text that matches, with the match left on what was asked about.

Works on anything that has text: a message, a button press whose text is the payload it was built with, an inline query whose text is what is being typed. The match object is left on it, so a handler reads the groups rather than running the pattern a second time.

sunnygram.filters.user

user(*who: int | str) -> Filter

Messages from any of these people, by id or by username.

sunnygram.filters.chat

chat(*where: int | str) -> Filter

Messages in any of these chats, by id or by username.