How anka-afk/astrbot_plugin_daily_news works
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 Plugin orchestrator · config.py Configuration access · news_image_generator.py Local image renderer · metadata.yaml Extension metadata
Components 17
AstrBot Host
Extension runtime, events, scheduling, and transport.
- Activation lifecycle · Starts and cancels scheduled work.
- AstrBot transport · Routes messages through installed platform adapters.
- Invoking session · Requester-scoped destination for /get_news.
Daily News Plugin
- Extension metadata · Identifies the plugin to AstrBot.
metadata.yaml - Config schema
_conf_schema.json - Configuration access · Loaded at initialization; changes require restart.
config.py - Plugin orchestrator · Registers commands, lifecycle behavior, scheduling, acquisition, and delivery.
main.py - Daily timer · Fires at configured server-time push_time.
main.py - /news_status · Reports effective settings and next run.
main.py - /push_news [mode] · Globally fans out to configured targets.
main.py - /get_news [mode] · Replies only to the invoking session.
main.py - Content selection · Selects image, text, or both for outbound messages.
main.py - News acquisition · Retrieves current Daily 60 Seconds data.
main.py - Local image renderer · Produces a sendable visual-news image when enabled.
news_image_generator.py - Visual assets
assets - Configured targets · Platform, message type, and recipient/group routing identifiers.
config.py
News Source
- Daily 60 Seconds API · Primary source for text and API-supplied image content.
Connections 22
- 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