mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-06-30 03:11:39 +00:00
b1a8b2e5d5
- Added `normalize_command_content` method to `CommandManager` to streamline command prefix handling, ensuring consistent processing of incoming messages. - Updated `format_keyword_response`, `check_keywords`, and `execute` methods to utilize the new normalization logic, reducing redundancy and improving clarity. - Refactored related command classes to remove legacy prefix stripping logic, enhancing maintainability and ensuring all commands adhere to the new normalization approach. - Enhanced tests to cover various scenarios for command prefix handling, ensuring robust functionality across different configurations.
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Channel pause command
|
|
DM-only admin: pause or resume bot responses on public channels (in-memory only).
|
|
"""
|
|
|
|
from ..models import MeshMessage
|
|
from .base_command import BaseCommand
|
|
|
|
|
|
class ChannelPauseCommand(BaseCommand):
|
|
"""Pause or resume channel-triggered bot responses (greeter, keywords, commands)."""
|
|
|
|
name = "channelpause"
|
|
keywords = ["channelpause", "channelresume"]
|
|
description = "Pause or resume bot responses on channels (DM only, admin only)"
|
|
requires_dm = True
|
|
cooldown_seconds = 2
|
|
category = "admin"
|
|
|
|
def __init__(self, bot):
|
|
super().__init__(bot)
|
|
|
|
def can_execute(self, message: MeshMessage, skip_channel_check: bool = False) -> bool:
|
|
if not self.requires_admin_access():
|
|
return False
|
|
return super().can_execute(message, skip_channel_check=skip_channel_check)
|
|
|
|
def requires_admin_access(self) -> bool:
|
|
return True
|
|
|
|
def get_help_text(self) -> str:
|
|
return (
|
|
"Controls whether the bot responds to public channel messages.\n"
|
|
"DMs always work (including this command).\n"
|
|
"Not saved across restarts.\n"
|
|
"Usage: channelpause — stop channel responses\n"
|
|
" channelresume — resume channel responses"
|
|
)
|
|
|
|
def _stripped_content_lower(self, message: MeshMessage) -> str:
|
|
content = self._strip_mentions(message.content.strip())
|
|
return content.lower()
|
|
|
|
async def execute(self, message: MeshMessage) -> bool:
|
|
text = self._stripped_content_lower(message)
|
|
resume_kw = self.keywords[1].lower()
|
|
pause_kw = self.keywords[0].lower()
|
|
|
|
if text == resume_kw or text.startswith(resume_kw + " "):
|
|
self.bot.channel_responses_enabled = True
|
|
reply = "Channel responses: ON. The bot will respond on public channels again."
|
|
elif text == pause_kw or text.startswith(pause_kw + " "):
|
|
self.bot.channel_responses_enabled = False
|
|
reply = (
|
|
"Channel responses: OFF. No greeter, keywords, or commands on channels; "
|
|
"DMs still work. Not persisted after restart."
|
|
)
|
|
else:
|
|
reply = "Use channelpause or channelresume."
|
|
|
|
await self.send_response(message, reply)
|
|
return True
|