ptbstats.BaseStats#

class ptbstats.BaseStats(command, block_stats=True, block_command=True)#

Base class for storing and displaying statistics.

Warning

command must not appear twice between statistics instances!

Parameters:
  • command (str) – The command that should produce the statistics associated with this instance.

  • block_stats (bool) – Whether the process_update() should be run blocking. Defaults to True.

  • block_command (bool) – Whether reply_statistics() should be run blocking. Defaults to True.

command#

The command that produces the statistics associated with this instance.

block_stats#

Whether the process_update() should be run blocking.

block_command#

Whether reply_statistics() should be run blocking.

abstract check_update(update)#

This method is called to determine if an update should be processed by this statistics instance. It must always be overridden.

Note

You can imitate Filters by this method by something like:

def check_update(self, update: Update):
    filters_check = (filters.TEXT | filters.STICKER).check_update(update)
    return update.effective_message and filters_check
Parameters:

update (telegram.Update) – The update to be tested.

Return type:

Optional[bool]

Returns:

Either None or False if the update should not be handled, True otherwise.

abstract load_data(application)#

Will be called on startup to load the data stored by store_data() from the persistence. If you don’t use persistence, just pass.

Parameters:

application (telegram.ext.Application) – The application that was set via ptbstats.set_application().

Return type:

None

abstract async process_update(update)#

This method is called on every update, that passes check_update(). The telegram.ext.CallbackContext argument is deliberately not passed, as this method should be independent from it.

This method must be overridden to update the statistics in an appropriate manner.

Parameters:

update (Update) – The telegram.Update.

Return type:

None

abstract async reply_statistics(update, context)#

This method will be used as the callback of the telegram.ext.CommandHandler associated with this statistics instance. It must be overridden to reply with the current status of the statistics in an appropriate manner.

Parameters:
Return type:

None

abstract store_data(context)#

Will be called after handling an update. Any data that should be persisted must be stored in context.bot_data. If you don’t use persistence, just pass.

Parameters:

context (telegram.ext.CallbackContext) – The callback context

Return type:

None