Files
synapse-module-auto-invite/module_auto_invite.py

34 lines
1.2 KiB
Python

class AutoInvite:
def __init__(self, config, api: ModuleApi):
self.config = config
self.api = api
self.api.register_room_creation_handler(self.on_room_creation)
@staticmethod
def parse_config(config):
return config
async def on_room_creation(self, room_id: str, creator: str):
# Invite the bot to the room
await self.api.update_room_membership(
sender=creator,
target=self.config['auto_invite_user_id'],
room_id=room_id,
membership="invite"
)
# Adjust power levels, as before
await self.adjust_power_levels(room_id, creator)
async def adjust_power_levels(self, room_id: str, creator: str):
current_levels = await self.api.get_power_levels(room_id)
current_levels['users'][self.config['auto_invite_user_id']] = 100
current_levels['users'][creator] = 90
if 'invite' in current_levels and current_levels['invite'] > 90:
current_levels['invite'] = 50
await self.api.set_power_levels(room_id, creator, current_levels)
def setup(config: dict, api: ModuleApi) -> AutoInvite:
return AutoInvite(config, api)