Merge branch 'master' into master

This commit is contained in:
Ville Ranki 2021-01-23 22:10:49 +02:00 committed by GitHub
commit 06a35f5a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -528,6 +528,8 @@ Typically set your own id into it.
`OWNERS_ONLY` is an optional variable once defined only the owners can operate the bot (this is a form of whitelisting) `OWNERS_ONLY` is an optional variable once defined only the owners can operate the bot (this is a form of whitelisting)
`LEAVE_EMPTY_ROOMS` (default true) if this is set to false, the bot will stay in empty rooms
__*ATTENTION:*__ Don't include bot itself in `BOT_OWNERS` if cron or any other module that can cause bot to send custom commands is used, as it could potentially be used to run owner commands as the bot itself. __*ATTENTION:*__ Don't include bot itself in `BOT_OWNERS` if cron or any other module that can cause bot to send custom commands is used, as it could potentially be used to run owner commands as the bot itself.
To enable debugging for the root logger set `DEBUG=True`. To enable debugging for the root logger set `DEBUG=True`.

5
bot.py
View File

@ -40,6 +40,7 @@ class Bot:
self.client = None self.client = None
self.join_on_invite = False self.join_on_invite = False
self.modules = dict() self.modules = dict()
self.leave_empty_rooms = True
self.pollcount = 0 self.pollcount = 0
self.poll_task = None self.poll_task = None
self.owners = [] self.owners = []
@ -385,11 +386,13 @@ class Bot:
access_token = os.getenv('MATRIX_ACCESS_TOKEN') access_token = os.getenv('MATRIX_ACCESS_TOKEN')
join_on_invite = os.getenv('JOIN_ON_INVITE') join_on_invite = os.getenv('JOIN_ON_INVITE')
owners_only = os.getenv('OWNERS_ONLY') is not None owners_only = os.getenv('OWNERS_ONLY') is not None
leave_empty_rooms = os.getenv('LEAVE_EMPTY_ROOMS')
if matrix_server and self.matrix_user and bot_owners and access_token: if matrix_server and self.matrix_user and bot_owners and access_token:
self.client = AsyncClient(matrix_server, self.matrix_user, ssl = matrix_server.startswith("https://")) self.client = AsyncClient(matrix_server, self.matrix_user, ssl = matrix_server.startswith("https://"))
self.client.access_token = access_token self.client.access_token = access_token
self.join_on_invite = (join_on_invite or '').lower() == 'true' self.join_on_invite = (join_on_invite or '').lower() == 'true'
self.leave_empty_rooms = (leave_empty_rooms or 'true').lower() == 'true'
self.owners = bot_owners.split(',') self.owners = bot_owners.split(',')
self.owners_only = owners_only self.owners_only = owners_only
self.get_modules() self.get_modules()
@ -423,7 +426,7 @@ class Bot:
await self.client.sync() await self.client.sync()
for roomid, room in self.client.rooms.items(): for roomid, room in self.client.rooms.items():
self.logger.info(f"Bot is on '{room.display_name}'({roomid}) with {len(room.users)} users") self.logger.info(f"Bot is on '{room.display_name}'({roomid}) with {len(room.users)} users")
if len(room.users) == 1: if len(room.users) == 1 and self.leave_empty_rooms:
self.logger.info(f'Room {roomid} has no other users - leaving it.') self.logger.info(f'Room {roomid} has no other users - leaving it.')
self.logger.info(await self.client.room_leave(roomid)) self.logger.info(await self.client.room_leave(roomid))