def listener_events(self, log: str): """Process every console line""" if "WARNING" in log: print(f"Warning detected: {log}") if "Done" in log and "For help" in log: print("Server finished starting")
Characteristics:
Synchronous (not async)
Called very frequently (every console line)
ANSI color codes are stripped
Blacklisted patterns are already filtered out
Avoid heavy processing in this method - it’s called for every console line.
async def listener_on_message(self, message: discord.Message): """Handle all Discord messages""" if message.author.bot: return if message.content.startswith("!hello"): await message.channel.send("Hello from the plugin!")
Called when someone joins/leaves/moves voice channels.
async def listener_on_voice_state_update(self, member, before, after): """Track voice channel activity""" if before.channel is None and after.channel is not None: # Joined voice await self.process.send_to_console( f"{member.name} joined voice: {after.channel.name}" )
From /home/daytona/workspace/source/mcdis_rcon/classes/McDisClient.py:819-828:
async def call_mdextras(self, function: str, args: tuple = tuple(), plugins: bool = True, addons: bool = True): if addons: await self.call_addons(function, args) if plugins: if function in self.discord_listeners: function = 'listener_' + function for process in self.processes: await process.call_plugins(function, args)
class mdplugin: def __init__(self, process): self.process = process self.monitored_channel_id = 1234567890 async def listener_on_message(self, message): # Filter by channel if message.channel.id != self.monitored_channel_id: return # Filter by author if message.author.bot: return # Filter by content if not message.content.startswith("!"): return # Process command await self.handle_command(message)
class mdplugin: def __init__(self, process): self.process = process self.state = "stopped" def listener_events(self, log: str): # State transitions based on logs if "Starting minecraft server" in log: self.state = "starting" elif "Done" in log and "For help" in log: self.state = "running" print("Server is now running") elif "Stopping server" in log: self.state = "stopping"