ptbstats.register module

Module providing the register_stats() method.

ptbstats.register.register_stats(stats, admin_id=None, stats_group=None, command_group=None)

Register a statistics instance. This will register two handlers on the dispatcher set with set_dispatcher():

  1. The stats handler. By default, each of those handlers will get it’s own group,

    starting with -10e10. That should be enough to not interfere with your other handlers.

  2. A telegram.ext.CommandHandler that will listen for command and call stats.reply_statistics() to report the current statistics. By default, all those command handlers will be added to group 0. If you register the statsistics before your other handlers, that should usually be enough to make sure that the command will not be catched by other handlers.

Moreover, makes sure hat persisted data is loaded into the statistics instances. To store that data, dispatcher.bot_data['PTBStats'] is used and will be assumed not to be occupied by other data.

Parameters
  • stats (BaseStats) – The statistics instance to be added.

  • admin_id (Union[int, List[int], None]) – Optional. If passed, only the admin/s with the corresponding user ids will be allowed to query the statistics.

  • stats_group (Optional[int]) – Optional. The group to register the statistics handler to instead of the default.

  • command_group (Optional[int]) – Optional. The group te register the command handler to instead of the default.

Returns:

Return type

None

ptbstats.register.set_dispatcher(dispatcher)

Set the dispatcher to be used with ptbstats.

Parameters

dispatcher (Dispatcher) – The telegram.ext.Dispatcher`

Return type

None