diff options
| author | Ritabrata Das <[email protected]> | 2025-03-02 11:14:16 +0530 |
|---|---|---|
| committer | Ritabrata Das <[email protected]> | 2025-03-02 11:14:16 +0530 |
| commit | 520853a8a659f0dc296f0d5fb301913cbee37688 (patch) | |
| tree | 8a0200d1d22ca9d6828ceaec7129cb3efbf347c6 /lib | |
| parent | 30c7e24aa8de762a1b8c21476e9e8436db1b9826 (diff) | |
handle client exits gracefully and improve plugin manager
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Player.py | 1 | ||||
| -rw-r--r-- | lib/discordSync.py | 2 | ||||
| -rw-r--r-- | lib/plugin_manager.py | 17 |
3 files changed, 15 insertions, 5 deletions
diff --git a/lib/Player.py b/lib/Player.py index 8e2250a..cfd50a8 100644 --- a/lib/Player.py +++ b/lib/Player.py @@ -13,6 +13,7 @@ class Player: self.streamWriterObject = streamWriterObject self.is_a_bot = True # We check if they are still present after LOGIN packet, then they're not a bot self.iff = 1 + self.connection_closed = False def set_aircraft(self, aircraft:Aircraft): self.aircraft = aircraft diff --git a/lib/discordSync.py b/lib/discordSync.py index 0a8e8be..770543e 100644 --- a/lib/discordSync.py +++ b/lib/discordSync.py @@ -84,8 +84,6 @@ async def monitor_channel(channel_id, playerList:list): encoded_msg = txtMsgr.encode(f"[Discord] {message['author']['username']}: {message['content']}", True) for player in playerList: if player.streamWriterObject.is_closing(): - if not player.is_a_bot: - asyncio.create_task(discord_send_message(channel_id, f"{player.username} has left the server!")) playerList.remove(player) # Remove disconnected players continue player.streamWriterObject.write(encoded_msg) diff --git a/lib/plugin_manager.py b/lib/plugin_manager.py index 52fb1f7..5cc93d2 100644 --- a/lib/plugin_manager.py +++ b/lib/plugin_manager.py @@ -45,13 +45,24 @@ class PluginManager: self.hooks[hook_name] = [] self.hooks[hook_name].append(callback) - def register_command(self, command_name, callback): - """Registers the command with the plugin manager""" + def register_command(self, command_name, callback, help_text="No Description", alias:str=None): + """Registers the command with the plugin manager + Set help text to help users understand what your command does. + """ if command_name in self.commands: warning(f"Command {command_name} already registered, Ignoring this registration") else: self.commands[command_name] = callback - self.help_message = self.help_message + f"/{command_name}\n" + if alias == None: + self.help_message = self.help_message + f"/{command_name} : {help_text}\n" + if alias != None: + if alias in self.commands: + warning(f"Command {alias} already registered, Ignoring this registration") + else: + self.commands[alias] = callback + self.help_message = self.help_message + f"/{command_name} [{alias}] : {help_text}\n" + + def triggar_hook(self, hook_name, data, *args, **kwargs): """Triggars the callbacks for the hook. |
