Merge pull request #112 from tainmart/master

Add feature autostop
This commit is contained in:
azlux 2020-03-25 10:39:23 +01:00 committed by GitHub
commit 2554000371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -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

View File

@ -98,6 +98,12 @@ port = 64738
#ducking_volume = 0.05
#ducking_threshold = 3000
# 'when_nobody_in_channel': should the music stop playing when everybody left the channel
# it should be one of "pause" (pause current song), "pause_resume" (pause current song and resume once somebody reenters the channel)
# "stop" (also clears playlist) or "nothing" (keep playing music)
# If a user leaves and the bot is left alone, stop and clear the playlist
#when_nobody_in_channel = nothing
# [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

View File

@ -149,6 +149,13 @@ class MumbleBot:
self.ducking_sound_received)
self.mumble.set_receive_sound(True)
if var.config.get("bot", "when_nobody_in_channel") not in ['pause', 'pause_resume', 'stop', 'nothing']:
self.log.warn('Config "when_nobody_in_channel" is not on of "pause", "pause_resume", "stop" or "nothing", falling back to "nothing".')
if var.config.get("bot", "when_nobody_in_channel", fallback='nothing') in ['pause', 'pause_resume', '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 +321,29 @@ class MumbleBot:
else:
return False
# =======================
# Users changed
# =======================
def users_changed(self, user, message):
own_channel = self.mumble.channels[self.mumble.users.myself['channel_id']]
# only check if there is one more user currently in the channel
# else when the music is paused and somebody joins, music would start playing again
if len(own_channel.get_users()) == 2:
if var.config.get("bot", "when_nobody_in_channel") == "pause_resume":
self.resume()
elif var.config.get("bot", "when_nobody_in_channel") == "pause":
self.send_msg('Music was paused after everyone left. !play to resume');
elif len(own_channel.get_users()) == 1:
# if the bot is the only user left in the channel
self.log.info('bot: Other users in the channel left. Stopping music now.')
if var.config.get("bot", "when_nobody_in_channel") == "stop":
self.clear()
else:
self.pause()
# =======================
# Launch and Download
# =======================