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
This commit is contained in:
gammafn 2021-03-29 22:05:10 -05:00
parent 6f6acfd681
commit 1efce55ff8
1 changed files with 3 additions and 1 deletions

4
bot.py
View File

@ -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: