feat: 'yplay' play the first result. add 'last' command. #87
This commit is contained in:
34
command.py
34
command.py
@ -32,7 +32,7 @@ def register_all_commands(bot):
|
||||
bot.register_command(constants.commands('play_radio'), cmd_play_radio)
|
||||
bot.register_command(constants.commands('rb_query'), cmd_rb_query)
|
||||
bot.register_command(constants.commands('rb_play'), cmd_rb_play)
|
||||
bot.register_command(constants.commands('yt_query'), cmd_yt_query)
|
||||
bot.register_command(constants.commands('yt_search'), cmd_yt_search)
|
||||
bot.register_command(constants.commands('yt_play'), cmd_yt_play)
|
||||
bot.register_command(constants.commands('help'), cmd_help)
|
||||
bot.register_command(constants.commands('stop'), cmd_stop)
|
||||
@ -46,6 +46,7 @@ def register_all_commands(bot):
|
||||
bot.register_command(constants.commands('ducking_volume'), cmd_ducking_volume)
|
||||
bot.register_command(constants.commands('current_music'), cmd_current_music)
|
||||
bot.register_command(constants.commands('skip'), cmd_skip)
|
||||
bot.register_command(constants.commands('last'), cmd_last)
|
||||
bot.register_command(constants.commands('remove'), cmd_remove)
|
||||
bot.register_command(constants.commands('list_file'), cmd_list_file)
|
||||
bot.register_command(constants.commands('queue'), cmd_queue)
|
||||
@ -451,7 +452,7 @@ def cmd_rb_play(bot, user, text, command, parameter):
|
||||
yt_last_result = []
|
||||
yt_last_page = 0 # TODO: if we keep adding global variables, we need to consider sealing all commands up into classes.
|
||||
|
||||
def cmd_yt_query(bot, user, text, command, parameter):
|
||||
def cmd_yt_search(bot, user, text, command, parameter):
|
||||
global log, yt_last_result, yt_last_page
|
||||
item_per_page = 5
|
||||
|
||||
@ -489,11 +490,21 @@ def _yt_format_result(results, start, count):
|
||||
|
||||
|
||||
def cmd_yt_play(bot, user, text, command, parameter):
|
||||
global log, yt_last_result
|
||||
global log, yt_last_result, yt_last_page
|
||||
|
||||
if parameter and parameter.isdigit() and 0 <= int(parameter) - 1 < len(yt_last_result):
|
||||
url = "https://www.youtube.com/watch?v=" + yt_last_result[int(parameter) - 1][0]
|
||||
cmd_play_url(bot, user, text, command, url)
|
||||
if parameter:
|
||||
if parameter.isdigit() and 0 <= int(parameter) - 1 < len(yt_last_result):
|
||||
url = "https://www.youtube.com/watch?v=" + yt_last_result[int(parameter) - 1][0]
|
||||
cmd_play_url(bot, user, text, command, url)
|
||||
else:
|
||||
results = util.youtube_search(parameter)
|
||||
if results:
|
||||
yt_last_result = results
|
||||
yt_last_page = 0
|
||||
url = "https://www.youtube.com/watch?v=" + yt_last_result[0][0]
|
||||
cmd_play_url(bot, user, text, command, url)
|
||||
else:
|
||||
bot.send_msg(constants.strings('yt_query_error'))
|
||||
else:
|
||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
||||
|
||||
@ -639,6 +650,17 @@ def cmd_skip(bot, user, text, command, parameter):
|
||||
bot.send_msg(constants.strings('queue_empty'), text)
|
||||
|
||||
|
||||
def cmd_last(bot, user, text, command, parameter):
|
||||
global log
|
||||
|
||||
if len(var.playlist) > 0:
|
||||
bot.interrupt_playing()
|
||||
bot.launch_music(len(var.playlist) - 1)
|
||||
bot.async_download_next()
|
||||
else:
|
||||
bot.send_msg(constants.strings('queue_empty'), text)
|
||||
|
||||
|
||||
def cmd_remove(bot, user, text, command, parameter):
|
||||
global log
|
||||
|
||||
|
Reference in New Issue
Block a user