# distillery_maskmaker ## Overview The `distillery_maskmaker.py` script is a specialized component of the [[Distillery]] system, responsible for creating and manipulating image masks. It provides functionality to generate grid overlays, render masks on images, and prepare masked images for sending to users via Discord. The main components of this script include: 1. **MaskMaker class:** The primary class containing methods for mask creation and manipulation. 2. **Cooldown class:** A utility class for managing rate limiting in Discord message sending. 3. **create_and_send_mask_files function**: A standalone function that orchestrates the mask creation and sending process. ## Key Functions and Methods ### MaskMaker Class - [[MaskMaker grid_to_pixel]]: Converts grid coordinates to pixel coordinates. - [[MaskMaker render_mask_on_image]]: Applies a mask to an image based on grid coordinates. - [[MaskMaker create_image_with_grid]]: Creates an image with a grid overlay and cell coordinates. ### Cooldown Class - [[Maskmaker Cooldown]]: Implements a delay mechanism to prevent rate limiting. ### Standalone Functions - [[MaskMaker create_and_send_mask_files]]: Orchestrates the process of creating mask files and sending them via Discord. ## Integration with Other Components The `distillery_maskmaker.py` script integrates with other components of the [[Distillery]] system: - It uses the [[AWSManager]] class from [[distillery_aws]] for interacting with AWS services, particularly for downloading files from S3. - The script interacts with Discord's API through the `discord` library to send messages and files. - It may be called by [[Distillery Commands]] or [[Distillery Bot]] when users request mask-related operations. ## Configuration The script loads configuration settings from the `config.json` file: ```python CONFIG = json.load(open('config/config.json')) MAX_RESEND_ATTEMPTS = CONFIG['MAX_RESEND_ATTEMPTS'] ``` It also uses a custom font file for adding text to images: ```python font = ImageFont.truetype("assets/SpaceMono-Bold.ttf", font_size) ``` ## Error Handling The script uses a consistent error handling approach: - Each method is wrapped in a try-except block to catch and raise exceptions. - Errors during file sending are logged using the `AWSManager.print_log` method. - The script implements a retry mechanism for sending files to Discord. ## Usage The main entry point for using this script is the `create_and_send_mask_files()` function. It is typically called by other parts of the Distillery system when mask operations are requested. Example usage: ```python await create_and_send_mask_files(ctx, aws_manager, request_id, instance_identifier, command_args, parsed_output_after_s3_upload, params_text, username, start_time) ```