-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add help command to list active plugin commands (#43)
* Add help command to list active plugin commands * Format plugin responses
- Loading branch information
1 parent
d2421e5
commit 1efa58d
Showing
12 changed files
with
158 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import re | ||
|
||
from plugins.base_plugin import BasePlugin | ||
from plugin_loader import load_plugins | ||
|
||
|
||
class Plugin(BasePlugin): | ||
plugin_name = "help" | ||
|
||
@property | ||
def description(self): | ||
return f"List supported relay commands" | ||
|
||
async def handle_meshtastic_message( | ||
self, packet, formatted_message, longname, meshnet_name | ||
): | ||
return False | ||
|
||
def get_matrix_commands(self): | ||
return [self.plugin_name] | ||
|
||
def get_mesh_commands(self): | ||
return [] | ||
|
||
async def handle_room_message(self, room, event, full_message): | ||
full_message = full_message.strip() | ||
if not self.matches(full_message): | ||
return False | ||
|
||
command = None | ||
|
||
match = re.match(r"^.*: !help\s+(.+)$", full_message) | ||
if match: | ||
command = match.group(1) | ||
|
||
plugins = load_plugins() | ||
|
||
if command: | ||
reply = f"No such command: {command}" | ||
|
||
for plugin in plugins: | ||
if command in plugin.get_matrix_commands(): | ||
reply = f"`!{command}`: {plugin.description}" | ||
else: | ||
commands = [] | ||
for plugin in plugins: | ||
commands.extend(plugin.get_matrix_commands()) | ||
reply = "Available commands: " + ", ".join(commands) | ||
|
||
response = await self.send_matrix_message(room.room_id, reply) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters