fix: listfile problem

This commit is contained in:
Terry Geng 2020-04-10 10:08:42 +08:00
parent 9904795b1b
commit 622f86c8f2
3 changed files with 17 additions and 31 deletions

View File

@ -146,7 +146,7 @@ If you want information about auto-starting and auto-restarting of the bot, you
You can control the bot by both commands sent by text message and the web interface.
By default, all commands start with `!`. You can type `!help` in the text message to see the full list of commands supported, or see the [wiki page](https://github.com/azlux/botamusique/wiki/Command-Help).
By default, all commands start with `!`. You can type `!help` in the text message to see the full list of commands supported, or see the examples on the [wiki page](https://github.com/azlux/botamusique/wiki/Command-Help).
The web interface can be used if you'd like an intuitive way of interacting with the bot. Through it is fairly straightforward, a walk-through can be found on the [wiki page](https://github.com/azlux/botamusique/wiki/Web-interface-walk-through).

View File

@ -225,20 +225,6 @@ def cmd_pause(bot, user, text, command, parameter):
def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=False):
global log, song_shortlist
# if parameter is {index}
if parameter.isdigit():
music_wrappers = get_cached_wrappers_from_dicts(var.music_db.query_music(Condition()
.and_equal('type', 'file')
.order_by('path')
.limit(1)
.offset(int(parameter))), user)
if music_wrappers:
var.playlist.append(music_wrappers[0])
log.info("cmd: add to playlist: " + music_wrappers[0].format_debug_string())
bot.send_msg(constants.strings('file_added', item=music_wrappers[0].format_song_string()), text)
return
# assume parameter is a path
music_wrappers = get_cached_wrappers_from_dicts(var.music_db.query_music(Condition().and_equal('path', parameter)), user)
if music_wrappers:
@ -256,7 +242,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
for music_wrapper in music_wrappers:
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
msgs.append("{} ({})".format(music_wrapper.item().title, music_wrapper.item().path))
msgs.append("<b>{:s}</b> ({:s})".format(music_wrapper.item().title, music_wrapper.item().path))
var.playlist.extend(music_wrappers)
@ -753,36 +739,36 @@ def cmd_remove(bot, user, text, command, parameter):
def cmd_list_file(bot, user, text, command, parameter):
global log
global song_shortlist
page = 0
files = var.music_db.query_music(Condition()
.and_equal('type', 'file')
.order_by('path'))
files = [ file['path'] for file in var.music_db.query_music(Condition()
.and_equal('type', 'file')
.order_by('path')
.limit(ITEMS_PER_PAGE)
.offset(page * ITEMS_PER_PAGE)) ]
song_shortlist = files
msgs = [constants.strings("multiple_file_found")]
msgs = [constants.strings("multiple_file_found") + "<ul>"]
try:
count = 0
for index, file in enumerate(files):
if parameter:
match = re.search(parameter, file)
match = re.search(parameter, file['path'])
if not match:
continue
count += 1
if count > ITEMS_PER_PAGE:
break
msgs.append("<b>{:0>3d}</b> - {:s}".format(index, file))
msgs.append("<li><b>{:d}</b> - <b>{:s}</b> ({:s})</li>".format(index + 1, file['title'], file['path']))
if count != 0:
msgs.append("</ul>")
if count > ITEMS_PER_PAGE:
msgs.append(constants.strings("records_omitted"))
send_multi_lines(bot, msgs, text)
msgs.append(constants.strings("shortlist_instruction"))
send_multi_lines(bot, msgs, text, "")
else:
bot.send_msg(constants.strings('no_file'), text)
bot.send_msg(constants.strings("no_file"), text)
except re.error as e:
msg = constants.strings('wrong_pattern', error=str(e))

View File

@ -31,7 +31,7 @@ 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", "autoplay"
# playback mode should be one of "one-shot", "repeat", "random", "autoplay"
playback_mode = one-shot
autoplay_length = 5
clear_when_stop_in_oneshot = False
@ -236,7 +236,7 @@ database_dropped = Database dropped. All records have gone.
new_version_found = <h3>Update Available!</h3> New version of botamusique is available, send <i>!update</i> to update!
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>.
unknown_mode = Unknown playback mode '{mode}'. It should be one of <i>one-shot</i>, <i>repeat</i>, <i>random</i>.
current_mode = Current playback mode is <i>{mode}</i>.
change_mode = Playback mode set to <i>{mode}</i> by {user}.
repeat = Repeat {song} for {n} times.
@ -277,7 +277,7 @@ help = <h3>Commands</h3>
<li> <b>!<u>n</u>ow </b> (or <b>!np</b>) - display the current song </li>
<li> <b>!<u>q</u>ueue </b> - display items in the playlist </li>
<li> <b>!<u>t</u>ag </b> {tags} - add all items with tags {tags}, tags separated by ",". </li>
<li> <b>!file </b>(or <b>!f</b>) {path/folder/index/keyword} - add a single file to the playlist by its path or index returned by !listfile </li>
<li> <b>!file </b>(or <b>!f</b>) {path/folder/keyword} - add a single file to the playlist by its path or keyword in its path. </li>
<li> <b>!<u>filem</u>atch </b>(or <b>!fm</b>) {pattern} - add all files that match regex {pattern} </li>
<li> <b>!<u>ur</u>l </b> {url} - add Youtube or SoundCloud music </li>
<li> <b>!<u>playl</u>ist </b> {url} [{offset}] - add all items in a Youtube or SoundCloud playlist, and start with the {offset}-th item </li>