# anka-afk/astrbot_plugin_daily_news architecture

> Architecture diagram of the GitHub repository anka-afk/astrbot_plugin_daily_news, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anka-afk/astrbot_plugin_daily_news
- Repository: https://github.com/anka-afk/astrbot_plugin_daily_news

## Overview

#### Purpose and Runtime

AstrBot Daily News is a Python 3.10+ AstrBot plugin that retrieves “60 seconds” daily news and distributes it to configured chat targets. It supports scheduled delivery, administrator-triggered global delivery, and requester-scoped delivery. The plugin runs inside the AstrBot extension runtime rather than as a standalone web application.

Key entry/module paths: `main.py`, `metadata.yaml`, `config.py`.

#### Plugin Entry and Host Integration

`main.py` is the primary plugin entry point. It is expected to register AstrBot commands, lifecycle behavior, and scheduled work, then use AstrBot’s message/session abstractions to send content across supported platforms.

`metadata.yaml` identifies the extension to AstrBot and is the deployment/discovery boundary. `main.py` should be treated as the orchestration layer between host events, configuration, news acquisition, and outgoing messages.

Paths: `main.py`, `metadata.yaml`.

#### Configuration Contract

Plugin configuration controls:
- destination session identifiers (`target_groups`);
- server-time-based delivery time (`push_time`);
- whether text accompanies image content;
- whether images are locally rendered or fetched from an API.

`config.py` centralizes configuration defaults or access, while `_conf_schema.json` defines the host-facing configuration schema. Configuration is read at plugin initialization and changes require plugin restart, making startup/reload a material boundary.

Paths: `config.py`, `_conf_schema.json`.

#### News Acquisition and Content Modes

The external news source is the Daily 60 Seconds API, principally `https://60s-api.viki.moe/v2/60s`; the README notes a fallback API domain exists. News retrieval produces textual headlines/content and, depending on mode, an image representation.

The core content selection flow is shared by scheduled and manual operations: acquire current news, resolve requested mode (`image`, `text`, or `all`), then create corresponding outbound message payloads.

Paths: `main.py`, `news_image_generator.py`.

#### Image Rendering Boundary

`news_image_generator.py` encapsulates local visual-news generation. When `use_local_image_draw` is enabled, fetched news data crosses into this renderer to produce a sendable image; when disabled, the plugin instead relies on API-supplied image content. This isolates rendering dependencies/assets from command and delivery logic.

Static visual resources, if used by the renderer, belong under `assets/`.

Paths: `news_image_generator.py`, `assets`, `main.py`.

#### Scheduling and Delivery Flow

On activation, the plugin establishes a daily timer based on `push_time`. At each firing, it fetches news once, formats it according to configured display choices, and fan-outs messages to every configured target identifier. Lifecycle handling must cancel the timer when the plugin is disabled or unloaded, preventing orphan deliveries.

Target identifiers encode platform, message type, and recipient/group ID, allowing AstrBot’s host transport layer to route delivery across QQ-derived adapters, Telegram, DingTalk, Lark, and other installed platforms.

Paths: `main.py`, `config.py`.

#### Command Entry Points and Scope Boundary

Three AstrBot commands form the interactive control plane:
- `/news_status`: reports effective targets, presentation settings, and next scheduled run.
- `/push_news [mode]`: performs global fan-out to configured targets.
- `/get_news [mode]`: sends only to the invoking session/user.

The first two operate on plugin-wide configuration; `/get_news` deliberately bypasses configured-target fan-out and uses the inbound event/session as its delivery scope.

Paths: `main.py`, `_conf_schema.json`.

Main entry points: [`main.py`](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py) (Plugin orchestrator), [`config.py`](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/config.py) (Configuration access), [`news_image_generator.py`](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/news_image_generator.py) (Local image renderer), [`metadata.yaml`](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/metadata.yaml) (Extension metadata)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["AstrBot Host"]
  node_lifecycle["Activation lifecycle<br/>host lifecycle"]
  node_transport["AstrBot transport<br/>host messaging"]
  node_request_session["Invoking session<br/>inbound session"]
end

subgraph group_plugin["Daily News Plugin"]
  node_metadata["Extension metadata<br/>discovery manifest<br/>[metadata.yaml]"]
  node_schema["Config schema<br/>host config contract<br/>[_conf_schema.json]"]
  node_config["Configuration access<br/>config module<br/>[config.py]"]
  node_entry["Plugin orchestrator<br/>extension entry<br/>[main.py]"]
  node_timer["Daily timer<br/>scheduled task<br/>[main.py]"]
  node_status["/news_status<br/>AstrBot command<br/>[main.py]"]
  node_push["/push_news &#91;mode&#93;<br/>AstrBot command<br/>[main.py]"]
  node_get["/get_news &#91;mode&#93;<br/>AstrBot command<br/>[main.py]"]
  node_content["Content selection<br/>payload builder<br/>[main.py]"]
  node_acquisition["News acquisition<br/>API client<br/>[main.py]"]
  node_renderer["Local image renderer<br/>image generation"]
  node_assets["Visual assets<br/>renderer resources"]
  node_targets["Configured targets<br/>session identifiers<br/>[config.py]"]
end

subgraph group_external["News Source"]
  node_api{{"Daily 60 Seconds API<br/>external news API"}}
end

node_metadata -->|"discovers"| node_entry
node_schema -->|"defines"| node_config
node_config -->|"initializes"| node_entry
node_lifecycle -->|"activates / unloads"| node_entry
node_entry -->|"creates / cancels"| node_timer
node_config -->|"push_time"| node_timer
node_entry -->|"registers"| node_status
node_entry -->|"registers"| node_push
node_entry -->|"registers"| node_get
node_timer -->|"daily fetch"| node_acquisition
node_push -->|"manual fetch"| node_acquisition
node_get -->|"request fetch"| node_acquisition
node_acquisition -->|"retrieves news"| node_api
node_acquisition -->|"news data"| node_content
node_config -->|"display mode"| node_content
node_content -->|"local image mode"| node_renderer
node_renderer -->|"uses"| node_assets
node_content -->|"API image or text payload"| node_transport
node_config -->|"target_groups"| node_targets
node_targets -->|"fan-out destinations"| node_transport
node_get -->|"uses scope"| node_request_session
node_request_session -->|"requester-only delivery"| node_transport

click node_metadata "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/metadata.yaml"
click node_schema "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/_conf_schema.json"
click node_config "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/config.py"
click node_entry "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_timer "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_status "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_push "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_get "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_content "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_acquisition "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py"
click node_renderer "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/news_image_generator.py"
click node_assets "https://github.com/anka-afk/astrbot_plugin_daily_news/tree/main/assets"
click node_targets "https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_lifecycle,node_transport,node_request_session toneBlue
class node_metadata,node_schema,node_config,node_entry,node_timer,node_status,node_push,node_get,node_content,node_acquisition,node_renderer,node_assets,node_targets toneAmber
class node_api toneMint
```

## Components

### AstrBot Host

Extension runtime, events, scheduling, and transport.

- **Activation lifecycle**: host lifecycle · Starts and cancels scheduled work.
- **AstrBot transport**: host messaging · Routes messages through installed platform adapters.
- **Invoking session**: inbound session · Requester-scoped destination for /get_news.

### Daily News Plugin

- [Extension metadata](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/metadata.yaml): discovery manifest · Identifies the plugin to AstrBot. · `metadata.yaml`
- [Config schema](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/_conf_schema.json): host config contract · `_conf_schema.json`
- [Configuration access](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/config.py): config module · Loaded at initialization; changes require restart. · `config.py`
- [Plugin orchestrator](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): extension entry · Registers commands, lifecycle behavior, scheduling, acquisition, and delivery. · `main.py`
- [Daily timer](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): scheduled task · Fires at configured server-time push_time. · `main.py`
- [/news_status](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): AstrBot command · Reports effective settings and next run. · `main.py`
- [/push_news [mode]](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): AstrBot command · Globally fans out to configured targets. · `main.py`
- [/get_news [mode]](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): AstrBot command · Replies only to the invoking session. · `main.py`
- [Content selection](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): payload builder · Selects image, text, or both for outbound messages. · `main.py`
- [News acquisition](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/main.py): API client · Retrieves current Daily 60 Seconds data. · `main.py`
- [Local image renderer](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/news_image_generator.py): image generation · Produces a sendable visual-news image when enabled. · `news_image_generator.py`
- [Visual assets](https://github.com/anka-afk/astrbot_plugin_daily_news/tree/main/assets): renderer resources · `assets`
- [Configured targets](https://github.com/anka-afk/astrbot_plugin_daily_news/blob/main/config.py): session identifiers · Platform, message type, and recipient/group routing identifiers. · `config.py`

### News Source

- **Daily 60 Seconds API**: external news API · Primary source for text and API-supplied image content.

## Connections

- Extension metadata → Plugin orchestrator: discovers
- Config schema → Configuration access: defines
- Configuration access → Plugin orchestrator: initializes
- Activation lifecycle → Plugin orchestrator: activates / unloads
- Plugin orchestrator → Daily timer: creates / cancels
- Configuration access → Daily timer: push_time
- Plugin orchestrator → /news_status: registers
- Plugin orchestrator → /push_news [mode]: registers
- Plugin orchestrator → /get_news [mode]: registers
- Daily timer → News acquisition: daily fetch
- /push_news [mode] → News acquisition: manual fetch
- /get_news [mode] → News acquisition: request fetch
- News acquisition → Daily 60 Seconds API: retrieves news
- News acquisition → Content selection: news data
- Configuration access → Content selection: display mode
- Content selection → Local image renderer: local image mode
- Local image renderer → Visual assets: uses
- Content selection → AstrBot transport: API image or text payload
- Configuration access → Configured targets: target_groups
- Configured targets → AstrBot transport: fan-out destinations
- /get_news [mode] → Invoking session: uses scope
- Invoking session → AstrBot transport: requester-only delivery
