enable all modules per default. bot cannot be disabled.

This commit is contained in:
Frank Becker 2020-02-09 14:07:05 +01:00
parent 4e1ab44f6d
commit 81d07cebfd
3 changed files with 19 additions and 13 deletions

View File

@ -1,4 +1,5 @@
from datetime import datetime
from modules.common.module import BotModule
@ -6,7 +7,8 @@ class MatrixModule(BotModule):
def __init__(self, name):
super().__init__(name)
self.enable()
self.starttime = None
self.can_be_disabled = False
def matrix_start(self, bot):
super().matrix_start(bot)
@ -15,6 +17,7 @@ class MatrixModule(BotModule):
async def matrix_message(self, bot, room, event):
args = event.body.split()
if len(args) == 2:
if args[1] == 'quit':
await self.quit(bot, room, event)
elif args[1] == 'version':
@ -88,6 +91,7 @@ class MatrixModule(BotModule):
async def enable_module(self, bot, room, event, module_name):
bot.must_be_admin(room, event)
print(f"asked to enable {module_name}")
if bot.modules.get(module_name):
module = bot.modules.get(module_name)
module.enable()
@ -100,16 +104,19 @@ class MatrixModule(BotModule):
async def disable_module(self, bot, room, event, module_name):
bot.must_be_admin(room, event)
print(f"asked to disable {module_name}")
if bot.modules.get(module_name):
module = bot.modules.get(module_name)
module.disable()
module.matrix_stop(bot)
bot.save_settings()
await bot.send_text(room, f"module {module_name} disabled")
if module.can_be_disabled:
module.disable()
module.matrix_stop(bot)
bot.save_settings()
await bot.send_text(room, f"module {module_name} disabled")
else:
await bot.send_text(room, f"module {module_name} cannot be disabled")
else:
await bot.send_text(room, f"module with name {module_name} not found. execute !bot modules for a list of available modules")
async def show_modules(self, bot, room):
await bot.send_text(room, "Modules:\n")
for modulename, module in bot.modules.items():

View File

@ -27,7 +27,8 @@ class BotModule(ABC):
"""
def __init__(self, name):
self.enabled = False
self.enabled = True
self.can_be_disabled = True
self.name = name
def matrix_start(self, bot):
@ -80,7 +81,7 @@ class BotModule(ABC):
:return: a dict object that can be converted to JSON
:rtype: dict
"""
return {'enabled': self.enabled}
return {'enabled': self.enabled, 'can_be_disabled': self.can_be_disabled}
def set_settings(self, data):
"""Load these settings. It should be the same JSON you returned in previous get_settings
@ -88,8 +89,10 @@ class BotModule(ABC):
:param data: a dict object containing the settings read from the account
:type data: dict
"""
if data.get('enabled'):
if data.get('enabled') is not None:
self.enabled = data['enabled']
if data.get('can_be_disabled') is not None:
self.can_be_disabled = data['can_be_disabled']
def enable(self):
self.enabled = True

View File

@ -3,10 +3,6 @@ from modules.common.module import BotModule
class MatrixModule(BotModule):
def __init__(self, name):
super().__init__(name)
self.enable()
async def matrix_message(self, bot, room, event):
msg = f'This is Hemppa {bot.version}, a generic Matrix bot. Known commands:\n\n'