mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-11-04 03:52:34 +00:00
32 commands overrode can_execute only to return False while their own <name>_enabled flag was off and otherwise defer to the base. BaseCommand now has an enabled_attr class attribute naming that flag, which can_execute checks first. Each command keeps reading its flag exactly as before (same section, default and legacy aliases), and code and tests that set help_enabled, webviewer_enabled and the like still work, since the flag is read at call time. Only overrides that were exactly 'if not self.<flag>: return False; return super().can_execute(...)' were converted, checked by AST. Commands with extra conditions (wx's delegate, joke's dark-joke DM rule, admin-only and DM-only checks, dadjoke's reversed order) keep their overrides. Several of the removed overrides called super().can_execute(message) without passing skip_channel_check; nothing calls them with it set, so honoring it now changes nothing.
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Ping command for the MeshCore Bot
|
|
Handles the 'ping' keyword response
|
|
"""
|
|
|
|
from typing import Optional
|
|
|
|
from ..models import MeshMessage
|
|
from .base_command import BaseCommand
|
|
|
|
|
|
class PingCommand(BaseCommand):
|
|
"""Handles the ping command.
|
|
|
|
A simple diagnostic command that responds with 'Pong!' or a custom configured response
|
|
to verify bot connectivity and responsiveness.
|
|
"""
|
|
|
|
# Plugin metadata
|
|
name = "ping"
|
|
enabled_attr = "ping_enabled"
|
|
keywords = ['ping']
|
|
description = "Responds to 'ping' with 'Pong!'"
|
|
category = "basic"
|
|
|
|
# Documentation
|
|
short_description = "Get a quick 'pong'response from the bot"
|
|
usage = "ping"
|
|
examples = ["ping"]
|
|
|
|
def __init__(self, bot):
|
|
"""Initialize the ping command.
|
|
|
|
Args:
|
|
bot: The bot instance.
|
|
"""
|
|
super().__init__(bot)
|
|
self.ping_enabled = self.get_config_value('Ping_Command', 'enabled', fallback=True, value_type='bool')
|
|
|
|
def get_help_text(self) -> str:
|
|
"""Get help text for the ping command.
|
|
|
|
Returns:
|
|
str: The help text for this command.
|
|
"""
|
|
return self.translate('commands.ping.description')
|
|
|
|
def get_response_format(self) -> Optional[str]:
|
|
"""Get the response format from config.
|
|
|
|
Returns:
|
|
Optional[str]: The format string for the response, or None if not configured.
|
|
"""
|
|
if self.bot.config.has_section('Keywords'):
|
|
format_str = self.bot.config.get('Keywords', 'ping', fallback=None)
|
|
return self._strip_quotes_from_config(format_str) if format_str else None
|
|
return None
|
|
|
|
async def execute(self, message: MeshMessage) -> bool:
|
|
"""Execute the ping command.
|
|
|
|
Args:
|
|
message: The message that triggered the command.
|
|
|
|
Returns:
|
|
bool: True if the response was sent successfully, False otherwise.
|
|
"""
|
|
return await self.handle_keyword_match(message)
|