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 theprocess_update()
should be run blocking. Defaults toTrue
.block_command (
bool
) – Whetherreply_statistics()
should be run blocking. Defaults toTrue
.
- 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
- 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, justpass
.- Parameters:
application (
telegram.ext.Application
) – The application that was set viaptbstats.set_application()
.- Return type:
- abstract async process_update(update)#
This method is called on every update, that passes
check_update()
. Thetelegram.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
) – Thetelegram.Update
.- Return type:
- 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:
update (
Update
) – Thetelegram.Update
.context (
TypeVar
(_CCT
, bound=CallbackContext
)) – Thetelegram.ext.CallbackContext
- Return type:
- 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, justpass
.- Parameters:
context (
telegram.ext.CallbackContext
) – The callback context- Return type: