Skip to content

Commit 4066e63

Browse files
committed
Add @bot.process_poll documentation
1 parent 57ee4e5 commit 4066e63

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

docs/api/bot.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,29 @@ components.
261261
262262
.. versionadded:: 0.4
263263

264+
.. py:decoratormethod:: poll_update
265+
266+
Functions decorated with this decorator will receive all the updates
267+
about new poll states. This allows you to act when a poll sent by the bot
268+
is changed (i.e. new votes) or when a poll seen by the bot is closed.
269+
270+
You can :ref:`request the following arguments <bot-structure-hooks-args>`
271+
in the decorated functions:
272+
273+
* **poll**: the poll that has just changed state
274+
(instance of :py:class:`~botogram.Poll`)
275+
276+
.. code-block:: python
277+
278+
@bot.poll_update
279+
def poll_update(poll):
280+
chat_id = mydb.retrieve_chat_by_poll_id(poll.id)
281+
if poll.is_closed:
282+
bot.chat(chat_id).send('Poll final results!\n%s' %
283+
'\n'.join(['%s: %s' % (o.text, str(o.voter_count)) for o in poll.options]))
284+
285+
.. versionadded:: 0.7
286+
264287
.. py:decoratormethod:: command(name, [hidden=False, order=0])
265288
266289
This decorator register a new command, and calls the decorated function

docs/api/components.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,33 @@ about how to create them in the ":ref:`custom-components`" chapter.
216216

217217
.. versionadded:: 0.4
218218

219+
.. py:method:: add_poll_update_hook(func)
220+
221+
All the functions provided to this method will receive all the updates
222+
about new poll states. This allows you to act when a poll sent by the bot
223+
is changed (i.e. new votes) or when a poll seen by the bot is closed.
224+
225+
You can :ref:`request the following arguments <bot-structure-hooks-args>`
226+
in the decorated functions:
227+
228+
* **poll**: the poll that has just changed state
229+
(instance of :py:class:`~botogram.Poll`)
230+
231+
.. code-block:: python
232+
233+
class PollUpdateComponent(botogram.Component):
234+
component_name = "poll-update"
235+
236+
def __init__(self):
237+
self.add_poll_update_hook(self.trigger)
238+
239+
def trigger(self, poll):
240+
bot.chat(some_id_here).send("New answers to the poll. Check it out!")
241+
242+
:param callable func: The function you want to use.
243+
244+
.. versionadded:: 0.7
245+
219246
.. py:method:: add_command(name, func, [hidden=False, order=0])
220247
221248
This function registers a new command, and calls the provided function

0 commit comments

Comments
 (0)