The mdplugin class is the foundation for creating custom plugins that extend McDis-RCON’s functionality for individual processes (servers and networks).
from mcdis_rcon.classes import Processimport discordimport asyncioclass mdplugin: def __init__(self, process: Process): """Called when plugin is loaded""" self.process = process # Initialize your variables here def listener_events(self, log: str): """Called for every console log line (synchronous)""" pass async def listener_on_message(self, message: discord.Message): """Called for every Discord message""" pass def unload(self): """Called when plugin is unloaded (optional)""" pass
Plugins can listen to any Discord.py event by prefixing with listener_:
async def listener_on_reaction_add(self, reaction, user): """Called when a reaction is added""" if user.bot: return if reaction.emoji == "✅": await self.process.send_to_console( f"{user.name} reacted with checkmark" )async def listener_on_member_join(self, member): """Called when a member joins the Discord""" await self.process.send_to_console( f"{member.name} joined the Discord server" )
Called when the plugin is unloaded (process stops or mdreload).
def unload(self): """Cleanup resources""" # Save data self.save_stats() # Cancel tasks if hasattr(self, 'background_task'): self.background_task.cancel() print(f"Plugin unloaded for {self.process.name}")
Always implement unload() if your plugin creates background tasks, opens files, or maintains state.
1. Process starts ↓2. Plugin __init__() called ↓3. listener_events() called for each console line listener_on_message() called for each Discord message ↓4. Process stops OR mdreload command ↓5. Plugin unload() called
class mdplugin: def __init__(self, process: Process): self.process = process self.client = process.client def listener_events(self, log: str): if "Server started" in log: # Notify all other processes for other in self.client.processes: if other.name != self.process.name and other.is_running(): other.execute( f"say {self.process.name} is now online!" )