# vxunderground/threatintelligencediscordbot architecture

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

- Interactive diagram: https://gitdiagram.com/vxunderground/threatintelligencediscordbot
- Repository: https://github.com/vxunderground/threatintelligencediscordbot

## Overview

##### Project type and purpose
- This is a backend “Threat Intelligence Bot” written in Python. It’s not a GUI or full-stack web app—it’s a CLI-driven monitoring service that:
- Polls RSS feeds on a schedule (every 1800s)
- Listens to Telegram channels in real time
- Formats and pushes updates into Discord via Webhooks
- Its primary use case is ingesting threat-intel data (ransomware feeds, clearnet sites, Telegram) and outputting alerts to one or more Discord channels.

##### File structure
- Top-level:
- config.ini – central configuration (webhook URLs, Telegram API credentials, image folder)
- requirements.txt – Python dependencies (discord.py, python-telegram-client, requests, etc.)
- TelegramImages/ – storage for downloaded channel images
- Source/ directory:
- __main__.py – CLI entrypoint; parses “rss” vs. “telegram” argument and dispatches
- Bots/RSS.py – scheduled RSS polling, de-duping, logging to RSSLog.txt
- Bots/Telegram.py – real-time Telegram client, image download logic
- Formatting.py – message‐templating helpers for Discord payloads
- Utils.py – shared utilities (e.g., load config, file I/O, webhook sender)
- RSSLog.txt – local state to avoid re-posting same items

##### README for additional insights
- Confirms Python 3.10, cross-platform (Windows/Linux)
- Requires 5 Discord webhooks by default (private sector, government, ransomware, log, etc.)
- On first Telegram run: handles 2FA, persists session file
- Users can add/remove RSS feeds by editing a list in RSS.py

a. Main components
- Input Sources:
– External RSS Feed Providers
– Telegram Channels
- Core Application:
– CLI Dispatcher (__main__.py)
– RSS Bot Module (RSS.py)
– Telegram Bot Module (Telegram.py)
– Shared Utilities (Utils.py)
– Formatting Layer (Formatting.py)
- Configuration Store: config.ini
- Persistence:
– RSSLog.txt (state tracking)
– TelegramImages/ (image store)
– Telegram session file (auto-created)
- Output Sink: Discord Webhooks

b. Relationships & interactions
1. At startup, __main__.py reads config.ini (→ Utils.load_config)
2. Based on argument “rss” or “telegram”, dispatcher invokes the corresponding bot
3. RSS Bot:
– Iterates through rss_feed_list → fetches feed URLs → parses new items
– Logs processed items to RSSLog.txt → formats message → posts to Discord via Webhook API
4. Telegram Bot:
– Connects to Telegram API → listens for new messages/images
– Downloads images to TelegramImages/ → formats text+media → posts via Webhook
– On 2FA prompt, reads user input → resumes session → persists session file
5. Formatting.py supplies consistent embed/message templates
6. Utils.py handles HTTP calls, file I/O, logging

c. Architectural patterns & design principles
- Modular separation by concern:
– Dispatcher vs. Bot logic vs. Formatting vs. Utils
- Single-responsibility principle: each file does one job
- Config-driven: behavior controlled via config.ini
- State persistence to avoid duplication

d. Key technologies/frameworks
– Python 3.10
– discord.py for Webhooks
– python-telegram-client (or Telethon)
– feedparser or requests+ElementTree in RSS.py
– configparser for config.ini
– Standard library modules (logging, os, time, argparse)

##### Essential elements
- Labels on every component (e.g., “RSS.py”)
- 1800s scheduler on the RSS flow and “real-time” on Telegram

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Sources
    RSSProviders["RSS Feed Providers"]:::external
    TelegramChannels["Telegram Channels"]:::external
    Discord["Discord Webhooks"]:::external

    %% Configuration and Dependencies
    Config["config.ini"]:::config
    Requirements["requirements.txt"]:::config

    %% Persistence Stores
    RSSLog["RSSLog.txt"]:::persistence
    subgraph "TelegramImages/" 
        direction TB
        TelegramImagesDir["TelegramImages/"]:::persistence
        Gitignore[".gitignore"]:::persistence
    end
    Session["Telegram Session File"]:::persistence

    %% Core Application
    subgraph "Core Application"
        direction TB
        Dispatcher["__main__.py"]:::core
        RSSBot["RSS.py"]:::core
        TelegramBot["Telegram.py"]:::core
        Formatting["Formatting.py"]:::core
        Utils["Utils.py"]:::core
    end

    %% Data Flows
    RSSProviders -->|fetch every 1800s| RSSBot
    TelegramChannels -->|real-time events| TelegramBot

    Dispatcher -->|args rss| RSSBot
    Dispatcher -->|args telegram| TelegramBot
    Dispatcher -->|load_config| Utils
    Dispatcher -->|reads| Config

    RSSBot -->|read/write| RSSLog
    RSSBot -->|format message| Formatting
    RSSBot -->|POST /webhook| Utils
    Utils -->|"POST payload"| Discord

    TelegramBot -->|download images| TelegramImagesDir
    TelegramBot -->|format message| Formatting
    TelegramBot -->|POST /webhook| Utils
    TelegramBot -->|persist session| Session

    Formatting -->|uses| Utils
    Utils -->|reads| Config

    %% Containment
    TelegramImagesDir --> Gitignore

    %% Click Events
    click Dispatcher "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/Source/__main__.py"
    click RSSBot "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/Source/Bots/RSS.py"
    click TelegramBot "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/Source/Bots/Telegram.py"
    click Formatting "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/Source/Formatting.py"
    click Utils "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/Source/Utils.py"
    click Config "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/config.ini"
    click Requirements "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/requirements.txt"
    click RSSLog "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/Source/RSSLog.txt"
    click TelegramImagesDir "https://github.com/vxunderground/threatintelligencediscordbot/tree/main/TelegramImages/"
    click Gitignore "https://github.com/vxunderground/threatintelligencediscordbot/blob/main/TelegramImages/.gitignore"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#1E70BF,color:#1E70BF;
    classDef external fill:#DFFFE0,stroke:#2E8B57,color:#2E8B57;
    classDef config fill:#E8E8E8,stroke:#888888,color:#333333;
    classDef persistence fill:#F0F0F0,stroke:#666666,color:#555555;
```
