feat: database and config support for playback mode.

This commit is contained in:
Terry Geng
2020-02-26 22:56:07 +08:00
parent 6a1320f8f9
commit b85956ef2f
5 changed files with 43 additions and 15 deletions

View File

@ -614,7 +614,11 @@ def cmd_mode(bot, user, text, command, parameter):
if not parameter in ["one-shot", "loop", "random"]:
bot.send_msg(constants.strings('unknown_mode', mode=parameter), text)
else:
var.db.set('playlist', 'playback_mode', parameter)
var.playlist.set_mode(parameter)
logging.info("command: playback mode changed to %s." % parameter)
bot.send_msg(constants.strings("change_mode", mode=var.playlist.mode,
user=bot.mumble.users[text.actor]['name']), text)
if parameter == "random":
bot.stop()
var.playlist.randomize()

View File

@ -31,6 +31,8 @@ username = botamusique
comment = Hi, I'm here to play radio, local music or youtube/soundcloud music. Have fun!
# default volume from 0 to 1.
volume = 0.1
# playback mode should be one of "one-shot", "loop", "random"
playback_mode = one-shot
# Users allowed to kill the bot, or ban URLs.
admin = User1;User2;
@ -148,20 +150,20 @@ ducking_volume = duckv
drop_database = dropdatabase
[strings]
current_volume = Current volume: {volume}
current_ducking_volume = Volume on ducking: {volume}
change_volume = Volume set to {volume} by {user}
change_ducking_volume = Volume on ducking set to {volume} by {user}
bad_command = {command}: command not found
bad_parameter = {command}: invalid parameter
current_volume = Current volume: {volume}.
current_ducking_volume = Volume on ducking: {volume}.
change_volume = Volume set to {volume} by {user}.
change_ducking_volume = Volume on ducking set to {volume} by {user}.
bad_command = {command}: command not found.
bad_parameter = {command}: invalid parameter.
error_executing_command = {command}: Command failed with error: {error}.
not_admin = You are not an admin!
not_playing = Nothing is playing right now
no_file = File not found
wrong_pattern = Invalid regex: {error}
file_added = Added: {item}
not_playing = Nothing is playing right now.
no_file = File not found.
wrong_pattern = Invalid regex: {error}.
file_added = Added: {item}.
multiple_file_added = Multiple files added:
bad_url = Bad URL requested
bad_url = Bad URL requested.
preconfigurated_radio = Preconfigurated Radio available:
unable_download = Error while downloading music...
which_command = Do you mean <br /> {commands}
@ -172,8 +174,8 @@ now_playing = Now playing {item}<br />{thumb}
not_in_my_channel = You're not in my channel, command refused!
pm_not_allowed = Private message aren't allowed.
too_long = This music is too long, skip!
download_in_progress = Download of {item} in progress
removing_item = Removed entry {item} from playlist
download_in_progress = Download of {item} in progress...
removing_item = Removed entry {item} from playlist.
user_ban = You are banned, not allowed to do that!
url_ban = This url is banned!
rb_query_result = This is the result of your query, send !rbplay 'ID' to play a station:
@ -187,6 +189,7 @@ start_updating = Start updating...
file_missed = Music file '{file}' missed! This item has been removed from the playlist.
unknown_mode = Unknown playback mode '{mode}'. It should be one of <i>one-shot</i>, <i>loop</i>, <i>random</i>.
current_mode = Current playback mode is <i>{mode}</i>.
change_mode = Playback mode set to <i>{mode}</i> by {user}.
help = <h3>Commands</h3>
<b>Control</b>

View File

@ -8,6 +8,7 @@
# ========================================================
# [server] section tells the bot how to connect to your murmur server.
# This section will be overridden by command line arguments.
[server]
host = 127.0.0.1
port = 64738
@ -24,14 +25,26 @@ port = 64738
#comment = Hi, I'm here to play radio, local music or youtube/soundcloud music. Have fun!
# 'volume' is default volume from 0 to 1.
# This option will be overridden by value in the database.
#volume = 0.1
# 'playback_mode' defined the playback mode of the bot.
# it should be one of "one-shot" (play the playlist once), "loop" (looping through the playlist),
# or "random" (randomize the playlist).
# This option will be overridden by value in the database.
#playback_mode = one-shot
# 'admin': Users allowed to kill the bot, or ban URLs. Separated by ';'
#admin = User1;User2;
# 'music_folder': Folder that stores your local songs.
#music_folder = music_folder/
# 'database_path': The path of the database. The database will store things like your volume
# set by command !volume, your playback mode and your playlist, etc.
# This option will be overridden by command line arguments.
#database_path = database.db
# 'tmp_folder': Folder that stores the downloaded music.
# 'tmp_folder_max_size': in MB, 0 for no cache, -1 for unlimited size
# 'ignored_folders', 'ignored_files': files and folders that would be ignored during scanning.

View File

@ -16,7 +16,6 @@ class PlayList(list):
def set_mode(self, mode):
# modes are "one-shot", "loop", "random"
self.mode = mode
var.db.set('playlist', 'mode', mode)
if mode == "random":
self.randomize()

View File

@ -752,7 +752,16 @@ if __name__ == '__main__':
var.botamusique = MumbleBot(args)
command.register_all_commands(var.botamusique)
if var.config.getboolean('debug', 'save_playlist', fallback=True):
playback_mode = None
if var.db.has_option("playlist", "playback_mode"):
playback_mode = var.db.get('playlist', 'playback_mode')
else:
playback_mode = var.config.get('bot', 'playback_mode', fallback="one-shot")
if playback_mode in ["one-shot", "loop", "random"]:
var.playlist.set_mode(playback_mode)
if var.config.getboolean('bot', 'save_playlist', fallback=True):
logging.info("bot: load playlist from previous session")
var.playlist.load()