Use consistent variable name in updates doc

This commit is contained in:
Lonami Exo 2023-11-29 18:48:24 +01:00
parent 70fb266eea
commit aea459c293

View File

@ -105,7 +105,7 @@ If you need state, you can use a class with a ``__call__`` method defined:
.. code-block:: python .. code-block:: python
# Anonymous filter which only handles messages with ID = 1000 # Anonymous filter which only handles messages with ID = 1000
client.add_event_handler(handler, events.NewMessage, lambda e: e.id == 1000) bot.add_event_handler(handler, events.NewMessage, lambda e: e.id == 1000)
# this parameter is the filter ^--------------------^ # 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" "A filter that only handles messages when their ID is divisible by 2"
return event.id % 2 == 0 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): def __call__(self, event):
return event.id % self.divisible_by == 0 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`. Custom filters should accept any :class:`~events.Event`.
You can use :func:`isinstance` if your filter can only deal with certain types of events. 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 .. 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): 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 .. code-block:: python
@client.on(events.NewMessage) @bot.on(events.NewMessage)
async def first(event): async def first(event):
print('This is always called on new messages!') print('This is always called on new messages!')
@client.on(events.NewMessage) @bot.on(events.NewMessage)
async def second(event): async def second(event):
print('This will never be called, because "first" already ran.') 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 .. code-block:: python
@client.on(events.NewMessage) @bot.on(events.NewMessage)
async def first(event): async def first(event):
print('This is always called on new messages!') print('This is always called on new messages!')
return events.Continue return events.Continue
@client.on(events.NewMessage) @bot.on(events.NewMessage)
async def second(event): async def second(event):
print('Now this one runs as well!') print('Now this one runs as well!')
@ -185,7 +185,7 @@ Alternatively, if this is *always* the behaviour you want, you can configure it
.. code-block:: python .. 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 # Now the code above will call both handlers, even without returning events.Continue