mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-05-14 11:25:12 +00:00
Implement feed manager configuration and refactor command settings
- Added a new [Feed_Manager] section in the configuration to enable or disable RSS/API feed subscriptions, defaulting to false. - Updated the FeedManager class to handle missing configuration sections gracefully, ensuring compatibility with upgrades. - Refactored joke command configuration to standardize the use of an `enabled` key, replacing legacy `*_enabled` keys for clarity. - Adjusted the PathCommand class to enable the "p" shortcut by default, improving user experience.
This commit is contained in:
@@ -213,6 +213,10 @@ respond_to_dms = true
|
||||
# "Awful Username" also matches "Awful Username 🍆". No bot responses in channels or DMs.
|
||||
banned_users =
|
||||
|
||||
[Feed_Manager]
|
||||
# Enable or disable RSS/API feed subscriptions (disabled by default)
|
||||
feed_manager_enabled = false
|
||||
|
||||
[Logging]
|
||||
# Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
# DEBUG: Most verbose, shows all details
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Upgrade Guide
|
||||
|
||||
This document describes changes that may affect users upgrading from previous versions.
|
||||
|
||||
## Upgrading from v0.7
|
||||
|
||||
### Config Compatibility
|
||||
|
||||
Previous config files continue to work. The following legacy config formats are supported:
|
||||
|
||||
- **`[Jokes]`** with `joke_enabled` / `dadjoke_enabled` — Migrated to `[Joke_Command]` and `[DadJoke_Command]` with `enabled`. Both formats work; consider updating to the new format.
|
||||
- **`[Stats]` / `stats_enabled`**, **`[Sports]` / `sports_enabled`**, **`[Hacker]` / `hacker_enabled`**, **`[Alert_Command]` / `alert_enabled`** — All support the legacy `*_enabled` key; the new `enabled` key is preferred.
|
||||
|
||||
### Banned Users: Prefix Matching
|
||||
|
||||
`[Banned_Users]` uses **prefix (starts-with) matching** for `banned_users` entries. A banned entry `"Awful Username"` matches both `"Awful Username"` and `"Awful Username 🍆"`. If you rely on exact matching, ensure your banned entries are specific enough.
|
||||
|
||||
### New Optional Sections
|
||||
|
||||
- **`[Feed_Manager]`** — If you use RSS/API feeds, add this section. If absent, the feed manager is disabled. New installs and minimal configs include `[Feed_Manager]` with `feed_manager_enabled = false`.
|
||||
- **`[Path_Command]`** — New options like `path_selection_preset`, `enable_p_shortcut` (default: true), and graph-related settings. Omitted options use sensible defaults.
|
||||
@@ -125,8 +125,8 @@ class PathCommand(BaseCommand):
|
||||
self.medium_confidence_symbol = bot.config.get('Path_Command', 'medium_confidence_symbol', fallback='📍')
|
||||
self.low_confidence_symbol = bot.config.get('Path_Command', 'low_confidence_symbol', fallback='❓')
|
||||
|
||||
# Check if "p" shortcut is enabled (off by default)
|
||||
self.enable_p_shortcut = bot.config.getboolean('Path_Command', 'enable_p_shortcut', fallback=False)
|
||||
# Check if "p" shortcut is enabled (on by default)
|
||||
self.enable_p_shortcut = bot.config.getboolean('Path_Command', 'enable_p_shortcut', fallback=True)
|
||||
if self.enable_p_shortcut:
|
||||
# Add "p" to keywords if enabled
|
||||
if "p" not in self.keywords:
|
||||
|
||||
+21
-14
@@ -178,7 +178,7 @@ class MeshCoreBot:
|
||||
try:
|
||||
self.feed_manager = FeedManager(self)
|
||||
self.logger.info("Feed manager initialized successfully")
|
||||
except (OSError, ValueError, AttributeError, ImportError) as e:
|
||||
except (OSError, ValueError, AttributeError, ImportError, configparser.NoSectionError) as e:
|
||||
self.logger.warning(f"Failed to initialize feed manager: {e}")
|
||||
self.feed_manager = None
|
||||
|
||||
@@ -517,25 +517,26 @@ startup_advert = false
|
||||
# false: Manual mode - no automatic actions, use !repeater commands to manage contacts (default)
|
||||
auto_manage_contacts = false
|
||||
|
||||
[Jokes]
|
||||
# Enable or disable the joke command
|
||||
# true: Joke command is available
|
||||
# false: Joke command is disabled
|
||||
joke_enabled = true
|
||||
[Joke_Command]
|
||||
# Enable or disable the joke command (true/false)
|
||||
enabled = true
|
||||
|
||||
# Enable seasonal joke defaults
|
||||
# When enabled, October defaults to spooky jokes, December defaults to Christmas jokes
|
||||
# true: Seasonal defaults are applied
|
||||
# Enable seasonal joke defaults (October: spooky, December: Christmas)
|
||||
# true: Seasonal defaults are applied (default)
|
||||
# false: No seasonal defaults (always random)
|
||||
seasonal_jokes = true
|
||||
|
||||
# Enable or disable the dad joke command
|
||||
# true: Dad joke command is available
|
||||
# false: Dad joke command is disabled
|
||||
dadjoke_enabled = true
|
||||
# Handle long jokes (over 130 characters)
|
||||
# false: Fetch new jokes until we get a short one (default)
|
||||
# true: Split long jokes into multiple messages
|
||||
long_jokes = false
|
||||
|
||||
[DadJoke_Command]
|
||||
# Enable or disable the dad joke command (true/false)
|
||||
enabled = true
|
||||
|
||||
# Handle long jokes (over 130 characters)
|
||||
# false: Fetch new jokes until we get a short one
|
||||
# false: Fetch new jokes until we get a short one (default)
|
||||
# true: Split long jokes into multiple messages
|
||||
long_jokes = false
|
||||
|
||||
@@ -583,6 +584,12 @@ respond_to_dms = true
|
||||
# "Awful Username" also matches "Awful Username 🍆". No bot responses in channels or DMs.
|
||||
banned_users =
|
||||
|
||||
[Feed_Manager]
|
||||
# Enable or disable RSS/API feed subscriptions
|
||||
# true: Feed manager polls configured feeds and sends updates to channels
|
||||
# false: Feed manager disabled (default)
|
||||
feed_manager_enabled = false
|
||||
|
||||
[Scheduled_Messages]
|
||||
# Scheduled message format: HHMM = channel:message
|
||||
# Time format: HHMM (24-hour, no colon)
|
||||
|
||||
+21
-10
@@ -28,16 +28,27 @@ class FeedManager:
|
||||
self.logger = bot.logger
|
||||
self.db_path = bot.db_manager.db_path
|
||||
|
||||
# Configuration
|
||||
self.enabled = bot.config.getboolean('Feed_Manager', 'feed_manager_enabled', fallback=False)
|
||||
self.default_check_interval = bot.config.getint('Feed_Manager', 'default_check_interval_seconds', fallback=300)
|
||||
self.max_items_per_check = bot.config.getint('Feed_Manager', 'max_items_per_check', fallback=10)
|
||||
self.request_timeout = bot.config.getint('Feed_Manager', 'feed_request_timeout', fallback=30)
|
||||
self.user_agent = bot.config.get('Feed_Manager', 'feed_user_agent', fallback='MeshCoreBot/1.0 FeedManager')
|
||||
self.rate_limit_seconds = bot.config.getfloat('Feed_Manager', 'feed_rate_limit_seconds', fallback=5.0)
|
||||
self.max_message_length = bot.config.getint('Feed_Manager', 'max_message_length', fallback=130)
|
||||
self.default_output_format = bot.config.get('Feed_Manager', 'default_output_format', fallback='{emoji} {body|truncate:100} - {date}\n{link|truncate:50}')
|
||||
self.default_send_interval = bot.config.getfloat('Feed_Manager', 'default_message_send_interval_seconds', fallback=2.0)
|
||||
# Configuration (guard against missing [Feed_Manager] section for upgrade compatibility)
|
||||
if not bot.config.has_section('Feed_Manager'):
|
||||
self.enabled = False
|
||||
self.default_check_interval = 300
|
||||
self.max_items_per_check = 10
|
||||
self.request_timeout = 30
|
||||
self.user_agent = 'MeshCoreBot/1.0 FeedManager'
|
||||
self.rate_limit_seconds = 5.0
|
||||
self.max_message_length = 130
|
||||
self.default_output_format = '{emoji} {body|truncate:100} - {date}\n{link|truncate:50}'
|
||||
self.default_send_interval = 2.0
|
||||
else:
|
||||
self.enabled = bot.config.getboolean('Feed_Manager', 'feed_manager_enabled', fallback=False)
|
||||
self.default_check_interval = bot.config.getint('Feed_Manager', 'default_check_interval_seconds', fallback=300)
|
||||
self.max_items_per_check = bot.config.getint('Feed_Manager', 'max_items_per_check', fallback=10)
|
||||
self.request_timeout = bot.config.getint('Feed_Manager', 'feed_request_timeout', fallback=30)
|
||||
self.user_agent = bot.config.get('Feed_Manager', 'feed_user_agent', fallback='MeshCoreBot/1.0 FeedManager')
|
||||
self.rate_limit_seconds = bot.config.getfloat('Feed_Manager', 'feed_rate_limit_seconds', fallback=5.0)
|
||||
self.max_message_length = bot.config.getint('Feed_Manager', 'max_message_length', fallback=130)
|
||||
self.default_output_format = bot.config.get('Feed_Manager', 'default_output_format', fallback='{emoji} {body|truncate:100} - {date}\n{link|truncate:50}')
|
||||
self.default_send_interval = bot.config.getfloat('Feed_Manager', 'default_message_send_interval_seconds', fallback=2.0)
|
||||
|
||||
# Rate limiting per domain
|
||||
self._domain_last_request: Dict[str, float] = {}
|
||||
|
||||
Reference in New Issue
Block a user