From 1efce55ff8c4e7fc18e2e99676d84bb11cb2641b Mon Sep 17 00:00:00 2001 From: gammafn Date: Mon, 29 Mar 2021 22:05:10 -0500 Subject: [PATCH] Add module aliases A module can add an alias by simply defining def matrix_start(self, bot): super().matrix_start(bot) bot.module_aliases['my_alias'] = self.name No alias will override a module name --- bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 3843443..96bd8e9 100755 --- a/bot.py +++ b/bot.py @@ -40,6 +40,7 @@ class Bot: self.client = None self.join_on_invite = False self.modules = dict() + self.module_aliases = dict() self.leave_empty_rooms = True self.pollcount = 0 self.poll_task = None @@ -260,7 +261,8 @@ class Bot: # Strip away non-alphanumeric characters, including leading ! for security command = re.sub(r'\W+', '', command) - moduleobject = self.modules.get(command) + # Fallback to any declared aliases + moduleobject = self.modules.get(command) or self.modules.get(self.module_aliases.get(command)) if moduleobject is not None: if moduleobject.enabled: