feat: Enhance command help functionality with channel restrictions

- Updated the CommandManager to include channel restrictions for help keyword processing, ensuring that help requests are only handled in monitored channels or DMs when enabled.
- Improved the HTML documentation for commands by adding a new "General Commands" section and refining existing command descriptions.
- Added new CSS styles for better presentation of command subcommands in the website documentation.
This commit is contained in:
agessaman
2026-01-15 17:56:27 -08:00
parent 76ba4f1c0e
commit 2b3f3489bd
4 changed files with 130 additions and 47 deletions
+1
View File
@@ -141,3 +141,4 @@ docs/local/
tests/
test_scripts/
dev/
website/
+35 -13
View File
@@ -294,19 +294,31 @@ class CommandManager:
# Check if message starts with any help keyword
for help_keyword in help_keywords:
if content_lower.startswith(help_keyword + ' '):
command_name = content_lower[len(help_keyword):].strip() # Remove help keyword prefix
help_text = self.get_help_for_command(command_name, message)
# Format the help response with message data (same as other keywords)
help_text = self.format_keyword_response(help_text, message)
matches.append(('help', help_text))
return matches
elif content_lower == help_keyword:
help_text = self.get_general_help()
# Format the help response with message data (same as other keywords)
help_text = self.format_keyword_response(help_text, message)
matches.append(('help', help_text))
return matches
if content_lower.startswith(help_keyword + ' ') or content_lower == help_keyword:
# Check channel restrictions for help keyword (same as other keywords/commands)
# DMs are allowed if respond_to_dms is enabled
if message.is_dm:
if not self.bot.config.getboolean('Channels', 'respond_to_dms', fallback=True):
break # DMs disabled, skip help keyword
else:
# For channel messages, check if channel is in monitor_channels
if message.channel not in self.monitor_channels:
break # Channel not monitored, skip help keyword
# Channel check passed, process help request
if content_lower.startswith(help_keyword + ' '):
command_name = content_lower[len(help_keyword):].strip() # Remove help keyword prefix
help_text = self.get_help_for_command(command_name, message)
# Format the help response with message data (same as other keywords)
help_text = self.format_keyword_response(help_text, message)
matches.append(('help', help_text))
return matches
elif content_lower == help_keyword:
help_text = self.get_general_help()
# Format the help response with message data (same as other keywords)
help_text = self.format_keyword_response(help_text, message)
matches.append(('help', help_text))
return matches
# Check all loaded plugins for matches
for command_name, command in self.commands.items():
@@ -339,6 +351,16 @@ class CommandManager:
if any(keyword.lower() in [k.lower() for k in cmd.keywords] for cmd in self.commands.values()):
continue
# Check channel restrictions for plain keywords (same as commands)
# DMs are allowed if respond_to_dms is enabled
if message.is_dm:
if not self.bot.config.getboolean('Channels', 'respond_to_dms', fallback=True):
continue # DMs disabled, skip this keyword
else:
# For channel messages, check if channel is in monitor_channels
if message.channel not in self.monitor_channels:
continue # Channel not monitored, skip this keyword
keyword_lower = keyword.lower()
# Check for exact match first
+5
View File
@@ -30,6 +30,11 @@ class BaseCommand(ABC):
cooldown_seconds: int = 0
category: str = "general"
# Documentation fields - to be overridden by subclasses for website generation
usage: str = "" # Usage syntax, e.g., "wx <zipcode|city> [tomorrow|7d|hourly|alerts]"
examples: List[str] = [] # Example commands, e.g., ["wx 98101", "wx seattle tomorrow"]
parameters: List[Dict[str, str]] = [] # Parameter definitions, e.g., [{"name": "location", "description": "US zip code or city name"}]
def __init__(self, bot):
self.bot = bot
self.logger = bot.logger
+89 -34
View File
@@ -519,6 +519,43 @@
font-size: 0.95rem;
}
.command-subcommands {
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid var(--border-subtle);
}
.subcommands-header {
font-size: 0.85rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.subcommand-item {
display: flex;
gap: 0.75rem;
margin-bottom: 0.5rem;
font-size: 0.9rem;
align-items: flex-start;
}
.subcommand-name {
font-family: 'JetBrains Mono', monospace;
color: var(--accent-cyan);
font-weight: 500;
min-width: 100px;
flex-shrink: 0;
}
.subcommand-desc {
color: var(--text-secondary);
flex: 1;
line-height: 1.5;
}
.command-channels {
color: var(--accent-cyan);
font-size: 0.85rem;
@@ -804,6 +841,7 @@
<li><a href="#commands-entertainment" class="nav-link nav-sublink">Entertainment</a></li>
<li><a href="#commands-fun" class="nav-link nav-sublink">Fun Commands</a></li>
<li><a href="#commands-games" class="nav-link nav-sublink">Games &amp; Entertainment</a></li>
<li><a href="#commands-general" class="nav-link nav-sublink">General Commands</a></li>
<li><a href="#commands-meshcore-info" class="nav-link nav-sublink">Mesh Network Info</a></li>
<li><a href="#commands-solar" class="nav-link nav-sublink">Solar &amp; Astronomical</a></li>
<li><a href="#commands-sports" class="nav-link nav-sublink">Sports</a></li>
@@ -939,6 +977,18 @@
<div class="category-section" id="commands-fun">
<h2 class="category-title"><a href="#commands-fun" class="anchor-link">Fun Commands</a></h2>
<div class="commands-grid">
<div class="command-card">
<div class="command-header">
<h3 class="command-name">dadjoke</h3>
<div class="command-keywords">
<span class="keyword-badge">dad joke</span>
<span class="keyword-badge">dadjokes</span>
<span class="keyword-badge">dad jokes</span>
</div>
</div>
<p class="command-description">Get a random dad joke from icanhazdadjoke.com</p>
<div class="command-channels">Channel: #jokes</div>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">hacker</h3>
@@ -953,18 +1003,6 @@
</div>
<p class="command-description">Simulates hacking a supervillain&#x27;s mainframe with hilarious error messages</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">dadjoke</h3>
<div class="command-keywords">
<span class="keyword-badge">dad joke</span>
<span class="keyword-badge">dadjokes</span>
<span class="keyword-badge">dad jokes</span>
</div>
</div>
<p class="command-description">Get a random dad joke from icanhazdadjoke.com</p>
<div class="command-channels">Channel: #jokes</div>
</div>
</div>
</div>
<div class="category-section" id="commands-games">
@@ -990,6 +1028,23 @@
</div>
</div>
</div>
<div class="category-section" id="commands-general">
<h2 class="category-title"><a href="#commands-general" class="anchor-link">General Commands</a></h2>
<div class="commands-grid">
<div class="command-card">
<div class="command-header">
<h3 class="command-name">airplanes</h3>
<div class="command-keywords">
<span class="keyword-badge">aircraft</span>
<span class="keyword-badge">planes</span>
<span class="keyword-badge">adsb</span>
<span class="keyword-badge">overhead</span>
</div>
</div>
<p class="command-description">Get aircraft overhead (usage: airplanes [location] [options] or overhead [lat,lon])</p>
</div>
</div>
</div>
<div class="category-section" id="commands-meshcore-info">
<h2 class="category-title"><a href="#commands-meshcore-info" class="anchor-link">Mesh Network Info</a></h2>
<div class="commands-grid">
@@ -1034,30 +1089,30 @@
</div>
<p class="command-description">Get HF band conditions for ham radio</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">satpass</h3>
</div>
<p class="command-description">Get satellite pass info: satpass &lt;NORAD_number_or_shortcut&gt; [visual]</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">moon</h3>
</div>
<p class="command-description">Get moon phase, rise/set times and position</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">sun</h3>
</div>
<p class="command-description">Get sunrise/sunset times</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">solar</h3>
</div>
<p class="command-description">Get current solar conditions and HF band info</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">satpass</h3>
</div>
<p class="command-description">Get satellite pass info: satpass &lt;NORAD_number_or_shortcut&gt; [visual]</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">sun</h3>
</div>
<p class="command-description">Get sunrise/sunset times</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">solarforecast</h3>
@@ -1099,6 +1154,16 @@
</div>
<p class="command-description">Get weather information for a zip code (usage: wx 12345)</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">gwx</h3>
<div class="command-keywords">
<span class="keyword-badge">globalweather</span>
<span class="keyword-badge">gwxa</span>
</div>
</div>
<p class="command-description">Get weather information for any global location (usage: gwx Tokyo)</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">aqi</h3>
@@ -1110,16 +1175,6 @@
</div>
<p class="command-description">Get Air Quality Index for a location (usage: aqi seattle, aqi greenwood, aqi vancouver canada, aqi 47.6,-122.3, or aqi help)</p>
</div>
<div class="command-card">
<div class="command-header">
<h3 class="command-name">gwx</h3>
<div class="command-keywords">
<span class="keyword-badge">globalweather</span>
<span class="keyword-badge">gwxa</span>
</div>
</div>
<p class="command-description">Get weather information for any global location (usage: gwx Tokyo)</p>
</div>
</div>
</div>