# raulalr/hll_name_banned architecture

> Architecture diagram of the GitHub repository raulalr/hll_name_banned, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raulalr/hll_name_banned
- Repository: https://github.com/raulalr/hll_name_banned

## Overview

##### Main Components
- Bot Core (name_banned.py): The central script that contains the business logic for name monitoring, sending warnings, logging, and executing bans.
- Configuration Module: Represents the .env file that holds all environmental variables such as RCON URLs, credentials, API endpoints, messages, and settings like NUM_WARNINGS and ENABLE_BAN.
- RCON Client Integration: A component (or dependency wrapper) based on hll_rcon_tool. This is responsible for connecting with the RCON servers and making the necessary API calls (login, get players, send messages, etc.).
- External Services:
- RCON Servers: These are the external endpoints (one or more, as indicated by comma-separated URLs) that the bot interacts with.
- Discord Webhook: An integration point for outbound notifications when a ban is executed.
- API Communication Endpoints: Logical grouping of endpoints (e.g., URL_LOGIN, URL_GET_PLAYERS, URL_MESSAGE, etc.) used to perform actions with the game server.

##### Relationships and Data Flow
- The Bot Core starts by reading its configuration from the .env file.
- It uses the configuration values (e.g., URLS_RCON, USER_RCON, PASSWORD_RCON) to authenticate via the RCON integration.
- Once connected, it periodically (or on event) retrieves the list of players (using URL_GET_PLAYERS) and checks each user’s name.
- For names that do not meet criteria, the bot sends a warning message through the appropriate API endpoint (using URL_MESSAGE) and logs the action.
- If the number of warnings exceeds the set threshold (NUM_WARNINGS) and if ENABLE_BAN is true, the bot proceeds to trigger the ban workflow, which may include:
- Executing the ban action through the RCON connection (and logging via SUCCESSFUL_BAN_MSG).
- Notifying a Discord channel using the webhook (DISCORD_WEBHOOK_URL and DISCORD_MSG).
- Error handling (using messages such as ERROR_LOGIN_MSG, ERROR_IN_MSG, and UNEXPECTED_ERROR_MSG) is also an integral part of the workflow.

##### Important Architectural Patterns and Design Principles
- Configuration-Driven Design: The behavior of the bot (warnings vs. bans) is driven by parameters in the .env file.
- External Service Integration: The bot acts as an intermediary between the game server (RCON endpoints) and user notification systems (Discord), illustrating a microservice-like approach.
- Modular Structure: Although it’s a single-file project, the separation of concerns is visible in how the configuration, monitoring logic, and external communications are conceptually separated.
- Error Logging and Monitoring: The use of clear error messages and logging indicates an attention to fault-tolerance and traceability.

##### Technology, Frameworks, or Libraries
- Python is the primary language (as indicated by the .py file and the nature of the project).
- hll_rcon_tool (a dependency required by the bot) handles the interactions with the RCON servers.
- Use of .env and requirements.txt suggests that a configuration loader (like python-dotenv) and dependency management (pip) are part of the implementation.
- There is an integration with Discord via webhooks to notify server moderators of bans.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration Layer"
        ENV[".env (Configuration)"]:::internal
    end

    subgraph "Core Bot"
        BOT["name_banned.py (Bot Core)"]:::internal
        RCON_CLIENT["RCON Client\n(hll_rcon_tool)"]:::internal
        DEP["Dependency Management\n(requirements.txt)"]:::internal
    end

    subgraph "External Services"
        RCON_SERVERS["RCON Servers"]:::external
        DISCORD["Discord Webhook\n(Notification)"]:::external
    end

    ENV -->|"ReadConfig"| BOT
    BOT -->|"Login/GetPlayers/Warning/Ban"| RCON_CLIENT
    RCON_CLIENT -->|"RCONAPICalls"| RCON_SERVERS
    BOT -->|"SendNotification"| DISCORD
    BOT ---|"UsesDependency"| DEP

    click BOT "https://github.com/raulalr/hll_name_banned/blob/master/name_banned.py"
    click ENV "https://github.com/raulalr/hll_name_banned/blob/master/.env"
    click DEP "https://github.com/raulalr/hll_name_banned/blob/master/requirements.txt"

    classDef internal fill:#b3cde0,stroke:#1f78b4,stroke-width:2px;
    classDef external fill:#fbb4ae,stroke:#e31a1c,stroke-width:2px;
```
