From 267b4241f8b5947318c4792ce0579c4c586fb82e Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Sat, 8 Feb 2020 11:02:58 +0100 Subject: [PATCH] fix: persistent settings for pollservices pollservices didn't return the settings dictionary and the call to super was missing. --- bot.py | 11 ++++++----- modules/common/module.py | 1 + modules/common/pollingservice.py | 11 ++++++----- modules/url.py | 4 ---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bot.py b/bot.py index c396bf6..6f08848 100755 --- a/bot.py +++ b/bot.py @@ -137,8 +137,8 @@ class Bot: traceback.print_exc(file=sys.stderr) else: print(f"Unknown command: {command}") - await self.send_text(room, f"Sorry. I don't know what to do. Execute !help to get a list of available commands.") - + await self.send_text(room, + f"Sorry. I don't know what to do. Execute !help to get a list of available commands.") async def invite_cb(self, room, event): room: MatrixRoom @@ -155,7 +155,8 @@ class Bot: print(f"joining room '{room.display_name}'({room.room_id}) invited by '{event.sender}'") break else: - print(f'Received invite event, but not joining as sender is not owner or bot not configured to join on invite. {event}') + print( + f'Received invite event, but not joining as sender is not owner or bot not configured to join on invite. {event}') def load_module(self, modulename): try: @@ -241,7 +242,7 @@ class Bot: if matrix_server and self.matrix_user and bot_owners: self.client = AsyncClient(matrix_server, self.matrix_user) - self.client.access_token = access_token + self.client.access_token = access_token if self.client.access_token is None: if self.matrix_pass is None: @@ -256,7 +257,6 @@ class Bot: print("The environment variables MATRIX_SERVER, MATRIX_USER and BOT_OWNERS are mandatory") sys.exit(1) - def start(self): self.load_settings(self.get_account_data()) enabled_modules = [module for module_name, module in self.modules.items() if module.enabled] @@ -330,6 +330,7 @@ class Bot: else: await self.client.client_session.close() + bot = Bot() bot.init() try: diff --git a/modules/common/module.py b/modules/common/module.py index db39f2e..29ab00f 100644 --- a/modules/common/module.py +++ b/modules/common/module.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod + from nio import RoomMessageText, MatrixRoom diff --git a/modules/common/pollingservice.py b/modules/common/pollingservice.py index bedac51..d51b5e3 100644 --- a/modules/common/pollingservice.py +++ b/modules/common/pollingservice.py @@ -94,22 +94,23 @@ class PollingService(BotModule): bot.must_be_admin(room, event) account = args[2] - print( - f'Removing {self.service_name} account {account} from room id {room.room_id}') + print(f'Removing {self.service_name} account {account} from room id {room.room_id}') if self.account_rooms.get(room.room_id): self.account_rooms[room.room_id].remove(account) - print( - f'{self.service_name} accounts now for this room {self.account_rooms.get(room.room_id)}') + print(f'{self.service_name} accounts now for this room {self.account_rooms.get(room.room_id)}') bot.save_settings() await bot.send_text(room, f'Removed {self.service_name} account from this room') def get_settings(self): - return {'account_rooms': self.account_rooms} + data = super().get_settings() + data['account_rooms'] = self.account_rooms + return data def set_settings(self, data): + super().set_settings(data) if data.get('account_rooms'): self.account_rooms = data['account_rooms'] diff --git a/modules/url.py b/modules/url.py index 3536d99..c68a4b4 100644 --- a/modules/url.py +++ b/modules/url.py @@ -165,7 +165,3 @@ class MatrixModule(BotModule): def help(self): return "If I see a url in a message I will try to get the title from the page and spit it out" - - def dump(self, obj): - for attr in dir(obj): - print("obj.%s = %r" % (attr, getattr(obj, attr))) \ No newline at end of file