From aea459c2935ef482d6fec81b5167736ee0db2f28 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 29 Nov 2023 18:48:24 +0100 Subject: [PATCH] Use consistent variable name in updates doc --- client/doc/concepts/updates.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/client/doc/concepts/updates.rst b/client/doc/concepts/updates.rst index a4668c98..9aae9712 100644 --- a/client/doc/concepts/updates.rst +++ b/client/doc/concepts/updates.rst @@ -105,8 +105,8 @@ If you need state, you can use a class with a ``__call__`` method defined: .. code-block:: python # Anonymous filter which only handles messages with ID = 1000 - client.add_event_handler(handler, events.NewMessage, lambda e: e.id == 1000) - # this parameter is the filter ^--------------------^ + bot.add_event_handler(handler, events.NewMessage, lambda e: e.id == 1000) + # this parameter is the filter ^--------------------^ # ... @@ -114,7 +114,7 @@ If you need state, you can use a class with a ``__call__`` method defined: "A filter that only handles messages when their ID is divisible by 2" return event.id % 2 == 0 - client.add_event_handler(handler, events.NewMessage, only_odd_messages) + bot.add_event_handler(handler, events.NewMessage, only_odd_messages) # ... @@ -126,7 +126,7 @@ If you need state, you can use a class with a ``__call__`` method defined: def __call__(self, event): return event.id % self.divisible_by == 0 - client.add_event_handler(handler, events.NewMessage, OnlyDivisibleMessages(7)) + bot.add_event_handler(handler, events.NewMessage, OnlyDivisibleMessages(7)) Custom filters should accept any :class:`~events.Event`. You can use :func:`isinstance` if your filter can only deal with certain types of events. @@ -139,7 +139,7 @@ This makes it very convenient to write custom filters using the :keyword:`lambda .. code-block:: python - @client.on(events.NewMessage, lambda e: e.id == 1000) + @bot.on(events.NewMessage, lambda e: e.id == 1000) async def handler(event): ... @@ -156,11 +156,11 @@ By default, the library will stop calling the rest of handlers after one is call .. code-block:: python - @client.on(events.NewMessage) + @bot.on(events.NewMessage) async def first(event): print('This is always called on new messages!') - @client.on(events.NewMessage) + @bot.on(events.NewMessage) async def second(event): print('This will never be called, because "first" already ran.') @@ -172,12 +172,12 @@ If that's the case, you can :keyword:`return` :class:`events.Continue`: .. code-block:: python - @client.on(events.NewMessage) + @bot.on(events.NewMessage) async def first(event): print('This is always called on new messages!') return events.Continue - @client.on(events.NewMessage) + @bot.on(events.NewMessage) async def second(event): print('Now this one runs as well!') @@ -185,8 +185,8 @@ Alternatively, if this is *always* the behaviour you want, you can configure it .. code-block:: python - client = Client(..., check_all_handlers=True) - # ^^^^^^^^^^^^^^^^^^^^^^^ + bot = Client(..., check_all_handlers=True) + # ^^^^^^^^^^^^^^^^^^^^^^^ # Now the code above will call both handlers, even without returning events.Continue If you need a more complicated setup, consider sorting all your handlers beforehand.