feat: Prompt the position of the song added by cli. Implement #186.

This commit is contained in:
Terry Geng 2020-07-14 19:20:12 +08:00
parent 7daef187a4
commit 56399c499f
No known key found for this signature in database
GPG Key ID: F982F8EA1DF720E7
3 changed files with 23 additions and 8 deletions

View File

@ -113,6 +113,18 @@ def send_multi_lines_in_channel(bot, lines, linebreak="<br />"):
bot.send_channel_msg(msg)
def send_item_added_message(bot, wrapper, index, text):
if index == var.playlist.current_index + 1:
bot.send_msg(tr('file_added', item=wrapper.format_song_string()) +
tr('position_in_the_queue', position=tr('next_to_play')), text)
elif index == len(var.playlist) - 1:
bot.send_msg(tr('file_added', item=wrapper.format_song_string()) +
tr('position_in_the_queue', position=tr('last_song_on_the_queue')), text)
else:
bot.send_msg(tr('file_added', item=wrapper.format_song_string()) +
tr('position_in_the_queue', position=f"{index + 1}/{len(var.playlist)}."), text)
# ---------------- Variables -----------------
ITEMS_PER_PAGE = 50
@ -223,7 +235,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
if music_wrappers:
var.playlist.append(music_wrappers[0])
log.info("cmd: add to playlist: " + music_wrappers[0].format_debug_string())
bot.send_msg(tr('file_added', item=music_wrappers[0].format_song_string()), text)
send_item_added_message(bot, music_wrappers[0], len(var.playlist) - 1, text)
return
# assume parameter is a folder
@ -250,7 +262,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
music_wrapper = get_cached_wrapper_from_dict(matches[0], user)
var.playlist.append(music_wrapper)
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
bot.send_msg(tr('file_added', item=music_wrapper.format_song_string()), text)
send_item_added_message(bot, music_wrapper, len(var.playlist) - 1, text)
return
elif len(matches) > 1:
song_shortlist = matches
@ -321,7 +333,7 @@ def cmd_play_url(bot, user, text, command, parameter):
var.playlist.append(music_wrapper)
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
bot.send_msg(tr('file_added', item=music_wrapper.format_song_string()), text)
send_item_added_message(bot, music_wrapper, len(var.playlist) - 1, text)
if len(var.playlist) == 2:
# If I am the second item on the playlist. (I am the next one!)
bot.async_download_next()
@ -371,7 +383,7 @@ def cmd_play_radio(bot, user, text, command, parameter):
var.playlist.append(music_wrapper)
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
bot.send_msg(tr('file_added', item=music_wrapper.format_song_string()), text)
send_item_added_message(bot, music_wrapper, len(var.playlist) - 1, text)
else:
bot.send_msg(tr('bad_url'), text)
@ -989,7 +1001,7 @@ def cmd_search_library(bot, user, text, command, parameter):
music_wrapper = get_cached_wrapper(items[0], user)
var.playlist.append(music_wrapper)
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
bot.send_channel_msg(tr('file_added', item=music_wrapper.format_song_string()))
send_item_added_message(bot, music_wrapper, len(var.playlist) - 1, text)
else:
for item in items:
count += 1
@ -1065,7 +1077,7 @@ def cmd_shortlist(bot, user, text, command, parameter):
music_wrapper = get_cached_wrapper_from_scrap(**kwargs)
var.playlist.append(music_wrapper)
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
bot.send_channel_msg(tr('file_added', item=music_wrapper.format_song_string()))
send_item_added_message(bot, music_wrapper, len(var.playlist) - 1, text)
return
bot.send_msg(tr('bad_parameter', command=command), text)

View File

@ -22,7 +22,7 @@
"download_in_progress": "Download of <b>{item}</b> in progress...",
"error_executing_command": "{command}: Command failed with error: {error}.",
"file": "File",
"file_added": "Added {item}.",
"file_added": "Added {item}. ",
"file_deleted": "Deleted {item} from the library.",
"file_item": "<b>{artist} - {title}</b> <i>added by</i> {user}",
"file_missed": "Music file '{file}' missed! This item has been removed from the playlist.",
@ -32,7 +32,9 @@
"multiple_file_deleted": "Multiple items deleted from the library:",
"multiple_file_found": "Found:",
"multiple_matches": "File not found! Possible candidates:",
"last_song_on_the_queue": "Last one on the queue.",
"new_version_found": "<h2>Update Available!</h2> Version {new_version} of botamusique is available! <hr />\n<h3>Changelog</h3> {changelog} <hr /> Send <i>!update</i> to update!",
"next_to_play": "Next song.",
"no_file": "File not found.",
"not_admin": "You are not an admin!",
"not_in_my_channel": "You're not in my channel!",
@ -42,6 +44,7 @@
"paused": "Music paused.",
"playlist_fetching_failed": "Unable to fetch the playlist!",
"pm_not_allowed": "Private message aren't allowed.",
"position_in_the_queue" : "Position: {position}",
"preconfigurated_radio": "Preconfigurated Radio available:",
"queue_contents": "Items on the playlist:",
"queue_empty": "Playlist is empty!",

View File

@ -7,7 +7,7 @@ if TYPE_CHECKING:
import database
bot: 'mumbleBot.MumbleBot' = None
playlist: Type['media.playlist.BasePlaylist'] = None
playlist: 'media.playlist.BasePlaylist' = None
cache: 'media.cache.MusicCache' = None
user = ""