add feature autostop

This commit is contained in:
Martin Römer
2020-03-23 16:08:26 +01:00
parent 6caca5f307
commit 8f48b7deda
3 changed files with 21 additions and 0 deletions

View File

@ -149,6 +149,10 @@ class MumbleBot:
self.ducking_sound_received)
self.mumble.set_receive_sound(True)
if not var.db.has_option("bot", "auto_stop") and var.config.getboolean("bot", "auto_stop", fallback=False)\
or var.config.getboolean("bot", "auto_stop"):
self.mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_USERREMOVED, self.users_changed)
self.mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_USERUPDATED, self.users_changed)
# Debug use
self._loop_status = 'Idle'
self._display_rms = False
@ -314,6 +318,17 @@ class MumbleBot:
else:
return False
# =======================
# Users changed
# =======================
def users_changed(self, user, message):
own_channel = self.mumble.channels[self.mumble.users.myself['channel_id']]
# if the bot is the only user left in the channel
if len(own_channel.get_users()) == 1:
self.log.info('Other users in the channel left. Stopping music now.')
self.clear()
# =======================
# Launch and Download
# =======================