services.stats_service module

Statistics Service for Django Integration

This service handles saving Discord message statistics to the Django database. It provides an interface between the Discord bot and the Django web application.

class services.stats_service.StatsService[source]

Bases: object

Service for managing user statistics data with Django integration.

__init__()[source]
save_statistics_to_django(stats_data, job_id=None)[source]

Save collected statistics to Django database.

Parameters:
  • stats_data (dict) – Statistics data from bot collection

  • job_id (str) – Optional job ID for tracking

Returns:

True if saved successfully, False otherwise

Return type:

bool

async save_statistics_to_django_async(stats_data, job_id=None)[source]

Async version of save_statistics_to_django for use in Discord bot context.

Return type:

bool

create_collection_job(guild_id, guild_name, target_user_id=None, target_username=None, time_range_days=None)[source]

Create a statistics collection job in Django.

Returns:

Job ID if successful, None otherwise

Return type:

str

get_user_statistics(guild_id, user_id=None)[source]

Get user statistics from Django database.

Parameters:
  • guild_id (int) – Discord guild ID

  • user_id (int) – Optional specific user ID

Returns:

Statistics data

Return type:

dict

save_message_statistics_streaming(guild_id, guild_name, channel_id, channel_name, user_id, username, avatar_url='', message_timestamp=None)[source]

Save a single message’s statistics incrementally to reduce memory usage.

Parameters:
  • guild_id (int) – Discord guild ID

  • guild_name (str) – Guild name

  • channel_id (int) – Discord channel ID

  • channel_name (str) – Channel name

  • user_id (int) – Discord user ID

  • username (str) – User’s display name

  • avatar_url (str) – User’s avatar URL

  • message_timestamp (datetime) – When the message was created

Returns:

True if saved successfully

Return type:

bool

async save_message_statistics_streaming_async(guild_id, guild_name, channel_id, channel_name, user_id, username, avatar_url='', message_timestamp=None)[source]

Async version of save_message_statistics_streaming.

Return type:

bool

get_available_guilds()[source]

Get list of available guilds with statistics data.

Return type:

list