fix: persistent settings for pollservices
pollservices didn't return the settings dictionary and the call to super was missing.
This commit is contained in:
parent
f8825a0582
commit
267b4241f8
9
bot.py
9
bot.py
|
@ -137,8 +137,8 @@ class Bot:
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
print(f"Unknown command: {command}")
|
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):
|
async def invite_cb(self, room, event):
|
||||||
room: MatrixRoom
|
room: MatrixRoom
|
||||||
|
@ -155,7 +155,8 @@ class Bot:
|
||||||
print(f"joining room '{room.display_name}'({room.room_id}) invited by '{event.sender}'")
|
print(f"joining room '{room.display_name}'({room.room_id}) invited by '{event.sender}'")
|
||||||
break
|
break
|
||||||
else:
|
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):
|
def load_module(self, modulename):
|
||||||
try:
|
try:
|
||||||
|
@ -256,7 +257,6 @@ class Bot:
|
||||||
print("The environment variables MATRIX_SERVER, MATRIX_USER and BOT_OWNERS are mandatory")
|
print("The environment variables MATRIX_SERVER, MATRIX_USER and BOT_OWNERS are mandatory")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.load_settings(self.get_account_data())
|
self.load_settings(self.get_account_data())
|
||||||
enabled_modules = [module for module_name, module in self.modules.items() if module.enabled]
|
enabled_modules = [module for module_name, module in self.modules.items() if module.enabled]
|
||||||
|
@ -330,6 +330,7 @@ class Bot:
|
||||||
else:
|
else:
|
||||||
await self.client.client_session.close()
|
await self.client.client_session.close()
|
||||||
|
|
||||||
|
|
||||||
bot = Bot()
|
bot = Bot()
|
||||||
bot.init()
|
bot.init()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from nio import RoomMessageText, MatrixRoom
|
from nio import RoomMessageText, MatrixRoom
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -94,22 +94,23 @@ class PollingService(BotModule):
|
||||||
bot.must_be_admin(room, event)
|
bot.must_be_admin(room, event)
|
||||||
|
|
||||||
account = args[2]
|
account = args[2]
|
||||||
print(
|
print(f'Removing {self.service_name} account {account} from room id {room.room_id}')
|
||||||
f'Removing {self.service_name} account {account} from room id {room.room_id}')
|
|
||||||
|
|
||||||
if self.account_rooms.get(room.room_id):
|
if self.account_rooms.get(room.room_id):
|
||||||
self.account_rooms[room.room_id].remove(account)
|
self.account_rooms[room.room_id].remove(account)
|
||||||
|
|
||||||
print(
|
print(f'{self.service_name} accounts now for this room {self.account_rooms.get(room.room_id)}')
|
||||||
f'{self.service_name} accounts now for this room {self.account_rooms.get(room.room_id)}')
|
|
||||||
|
|
||||||
bot.save_settings()
|
bot.save_settings()
|
||||||
await bot.send_text(room, f'Removed {self.service_name} account from this room')
|
await bot.send_text(room, f'Removed {self.service_name} account from this room')
|
||||||
|
|
||||||
def get_settings(self):
|
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):
|
def set_settings(self, data):
|
||||||
|
super().set_settings(data)
|
||||||
if data.get('account_rooms'):
|
if data.get('account_rooms'):
|
||||||
self.account_rooms = data['account_rooms']
|
self.account_rooms = data['account_rooms']
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,3 @@ class MatrixModule(BotModule):
|
||||||
|
|
||||||
def help(self):
|
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"
|
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)))
|
|
Loading…
Reference in New Issue