commands.stats_commands module

User Statistics Collection Commands

This module provides Discord slash commands for collecting and managing user message statistics from Discord channels.

class commands.stats_commands.StatsCollector(bot)[source]

Bases: object

Service class for collecting user message statistics.

__init__(bot)[source]
async collect_user_stats(guild, target_user=None, channels=None, days_back=None, job_id=None)[source]

Collect message statistics for user(s) in specified channels.

Parameters:
  • guild (Guild) – Discord guild to scan

  • target_user (Member) – Specific user to collect stats for (None = all users)

  • channels (list[TextChannel]) – List of channels to scan (None = all text channels)

  • days_back (int) – Number of days to look back (None = all time)

  • job_id (str) – Unique job identifier for progress tracking

Returns:

Collection results with statistics

Return type:

dict

get_job_status(job_id)[source]

Get status of a collection job.

Return type:

dict

cancel_job(job_id)[source]

Cancel a running collection job.

Return type:

bool

get_active_guild_job(guild_id)[source]

Check if there’s an active collection job for a specific guild.

Return type:

dict

async collect_user_stats_streaming(guild, target_user=None, channels=None, days_back=None, job_id=None)[source]

Collect message statistics using streaming approach to minimize memory usage.

This method processes messages one by one and writes statistics to the database immediately, avoiding accumulation of large amounts of data in memory.

Parameters:
  • guild (Guild) – Discord guild to scan

  • target_user (Member) – Specific user to collect stats for (None = all users)

  • channels (list[TextChannel]) – List of channels to scan (None = all text channels)

  • days_back (int) – Number of days to look back (None = all time)

  • job_id (str) – Unique job identifier for progress tracking

Returns:

Collection summary (minimal data kept in memory)

Return type:

dict

commands.stats_commands.setup_stats_commands(bot)[source]

Setup all user statistics slash commands.