ptbstats.BaseStats¶
-
class
ptbstats.
BaseStats
(command, async_stats=False, async_command=False)¶ Bases:
Generic
[telegram.ext.handler.UT
],abc.ABC
Base class for storing and displaying statistics.
-
command
¶ The command that produces the statistics associated with this instance.
-
async_command
¶ Whether
reply_statistics()
should be run asynchronously usingtelegram.ext.Disptacher.run_async()
.
- Parameters
command (
str
) – The command that should produce the statistics associated with this instance.async_stats (
bool
) – Whether theprocess_update()
should be run asynchronously usingtelegram.ext.Disptacher.run_async()
. Defaults toFalse
.async_command (
bool
) – Whetherreply_statistics()
should be run asynchronously usingtelegram.ext.Disptacher.run_async()
. Defaults toFalse
.
Warning
command
must not appear twice between statistics instances!-
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): return update.effective_message and (Filters.text | Filters.sticker)(update)
-
persistent_data
()¶ In order to make statistics instances persistent, you will have to do two things:
Use persistence with your PTB setup
Override this method.
Warning
ptbstats uses stores data in
bot_data['PTBStats']
. Do not store any other data there.- Returns
Dictionary of attributes that are to be persisted. On reboot, this instances
__dict__
will be merged with this return value.- Return type
Dict[
str
, Any]
-
abstract
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
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 (
CallbackContext
) – Thetelegram.ext.CallbackContext
- Return type
-