Merge pull request #36 from ancho/fix/persistent-pollservice-settings

fix: persistent settings for pollservices
This commit is contained in:
Ville Ranki 2020-02-08 13:35:16 +02:00 committed by GitHub
commit bfe190bee4
4 changed files with 13 additions and 14 deletions

11
bot.py
View File

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

View File

@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
from nio import RoomMessageText, MatrixRoom

View File

@ -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']

View File

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