How mrsakine/clean_tg_channel works
Main Components
• Configuration Loader: This component is responsible for reading the user's configuration from the config.json file (created from config.example.json), including the API_ID, API_HASH, and CHANNEL_ID.
• Authentication & Session Manager: Represented in the main.py script, this component handles:
• Prompting the user for their phone number.
• Receiving the confirmation code (and 2FA password if needed).
• Maintaining and reusing the Pyrogram session.
• Pyrogram Client Library: This library wraps interactions with the Telegram API. It establishes a secure connection and abstracts complexities related to network calls and session management.
• Command Processor (Cleaning Logic): When the user sends the "/delete" command in the channel, this triggers the cleaning process. This module is orchestrated through the script logic in main.py, directing calls to the appropriate API functionality via Pyrogram.
• User Interface / Input Mechanism: This reflects the command-line interaction where the user enters their phone number, confirmation code, and commands (like /delete).
Relationships and Interactions
• The Authentication & Session Manager then interacts with the user (via CLI) to authenticate and establish a session, storing session data for reuse.
• Once authenticated, the Pyrogram Client communicates with the Telegram API Server using the provided credentials and session data.
• Finally, when the user issues the "/delete" command, the Command Processor triggers cleaning actions that involve sending commands via the Pyrogram Client to the Telegram API (affecting the given channel).
Architectural Patterns / Design Principles
• Separation of Concerns: The configuration, authentication, API interaction, and command processing are distinct, even if they’re implemented in a single main.py file.
• Persistence: The saved session helps streamline subsequent interactions, reducing redundant authentication steps.
• Reliance on a well-maintained external library (Pyrogram) for the heavy lifting of networking and session management.
Relevant Technologies
• Python: The core programming language.
• Pyrogram: The Telegram client library.
• Telegram API: The external service the utility interacts with for channel management.
• Start from the user’s perspective (CLI inputs).
• Branch out to the configuration and authentication components.
• Internal management by the Pyrogram library, and then the outbound communication to the Telegram API.