diff --git a/configuration.default.ini b/configuration.default.ini index 79e0a21..53f3dc7 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -85,6 +85,9 @@ ducking = False ducking_volume = 0.05 ducking_threshold = 3000 +# if auto_stop is enabled and a user leaves and the bot is left alone, stop and clear the playlist +auto_stop = False + [webinterface] # Set enabled to True if you'd like to use the web interface to manage your playlist, upload files, etc. enabled = False diff --git a/configuration.example.ini b/configuration.example.ini index 27b3343..3ad7490 100644 --- a/configuration.example.ini +++ b/configuration.example.ini @@ -98,6 +98,9 @@ port = 64738 #ducking_volume = 0.05 #ducking_threshold = 3000 +# 'auto_stop': If a user leaves and the bot is left alone, stop and clear the playlist +#auto_stop = False + # [webinterface] stores settings related to the web interface. [webinterface] # 'enable': Set 'enabled' to True if you'd like to use the web interface to manage diff --git a/mumbleBot.py b/mumbleBot.py index 2bec6fc..39cb012 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -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 # =======================