4 import pymumble.pymumble_py3 as pymumble
10 import variables as var
11 from librb import radiobrowser
12 from database import SettingsDatabase, MusicDatabase
13 from media.playlist import get_item_wrapper, get_item_wrapper_by_id, get_item_wrappers_by_tags
14 from media.file import FileItem
15 from media.url_from_playlist import PlaylistURLItem, get_playlist_info
16 from media.url import URLItem
17 from media.radio import RadioItem
19 log = logging.getLogger("bot")
21 def register_all_commands(bot):
22 bot.register_command(constants.commands('joinme'), cmd_joinme)
23 bot.register_command(constants.commands('user_ban'), cmd_user_ban)
24 bot.register_command(constants.commands('user_unban'), cmd_user_unban)
25 bot.register_command(constants.commands('url_ban'), cmd_url_ban)
26 bot.register_command(constants.commands('url_unban'), cmd_url_unban)
27 bot.register_command(constants.commands('play'), cmd_play)
28 bot.register_command(constants.commands('pause'), cmd_pause)
29 bot.register_command(constants.commands('play_file'), cmd_play_file)
30 bot.register_command(constants.commands('play_file_match'), cmd_play_file_match)
31 bot.register_command(constants.commands('play_url'), cmd_play_url)
32 bot.register_command(constants.commands('play_playlist'), cmd_play_playlist)
33 bot.register_command(constants.commands('play_radio'), cmd_play_radio)
34 bot.register_command(constants.commands('rb_query'), cmd_rb_query)
35 bot.register_command(constants.commands('rb_play'), cmd_rb_play)
36 bot.register_command(constants.commands('yt_search'), cmd_yt_search)
37 bot.register_command(constants.commands('yt_play'), cmd_yt_play)
38 bot.register_command(constants.commands('help'), cmd_help)
39 bot.register_command(constants.commands('stop'), cmd_stop)
40 bot.register_command(constants.commands('clear'), cmd_clear)
41 bot.register_command(constants.commands('kill'), cmd_kill)
42 bot.register_command(constants.commands('update'), cmd_update)
43 bot.register_command(constants.commands('stop_and_getout'), cmd_stop_and_getout)
44 bot.register_command(constants.commands('volume'), cmd_volume)
45 bot.register_command(constants.commands('ducking'), cmd_ducking)
46 bot.register_command(constants.commands('ducking_threshold'), cmd_ducking_threshold)
47 bot.register_command(constants.commands('ducking_volume'), cmd_ducking_volume)
48 bot.register_command(constants.commands('current_music'), cmd_current_music)
49 bot.register_command(constants.commands('skip'), cmd_skip)
50 bot.register_command(constants.commands('last'), cmd_last)
51 bot.register_command(constants.commands('remove'), cmd_remove)
52 bot.register_command(constants.commands('list_file'), cmd_list_file)
53 bot.register_command(constants.commands('queue'), cmd_queue)
54 bot.register_command(constants.commands('random'), cmd_random)
55 bot.register_command(constants.commands('repeat'), cmd_repeat)
56 bot.register_command(constants.commands('mode'), cmd_mode)
57 bot.register_command(constants.commands('drop_database'), cmd_drop_database, True)
58 bot.register_command(constants.commands('recache'), cmd_refresh_cache, True)
61 bot.register_command('rtrms', cmd_real_time_rms, True)
62 bot.register_command('loop', cmd_loop_state, True)
63 bot.register_command('item', cmd_item, True)
65 def send_multi_lines(bot, lines, text, linebreak="<br />"):
73 if (len(msg) + len(newline)) > (bot.mumble.get_max_message_length() - 4) != 0: # 4 == len("<br>")
74 bot.send_msg(msg, text)
78 bot.send_msg(msg, text)
80 # ---------------- Commands ------------------
83 def cmd_joinme(bot, user, text, command, parameter):
86 bot.mumble.users.myself.move_in(
87 bot.mumble.users[text.actor]['channel_id'], token=parameter)
90 def cmd_user_ban(bot, user, text, command, parameter):
93 if bot.is_admin(user):
95 bot.mumble.users[text.actor].send_text_message(util.user_ban(parameter))
97 bot.mumble.users[text.actor].send_text_message(util.get_user_ban())
99 bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
103 def cmd_user_unban(bot, user, text, command, parameter):
106 if bot.is_admin(user):
108 bot.mumble.users[text.actor].send_text_message(util.user_unban(parameter))
110 bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
114 def cmd_url_ban(bot, user, text, command, parameter):
117 if bot.is_admin(user):
119 bot.mumble.users[text.actor].send_text_message(util.url_ban(util.get_url_from_input(parameter)))
121 bot.mumble.users[text.actor].send_text_message(util.get_url_ban())
123 bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
127 def cmd_url_unban(bot, user, text, command, parameter):
130 if bot.is_admin(user):
132 bot.mumble.users[text.actor].send_text_message(util.url_unban(util.get_url_from_input(parameter)))
134 bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
138 def cmd_play(bot, user, text, command, parameter):
141 if len(var.playlist) > 0:
143 if parameter.isdigit() and 1 <= int(parameter) <= len(var.playlist):
144 var.playlist.point_to(int(parameter) - 1 - 1) # First "-1" transfer 12345 to 01234, second "-1"
145 # point to the previous item. the loop will next to
149 bot.send_msg(constants.strings('invalid_index', index=parameter), text)
154 bot.send_msg(var.playlist.current_item().format_current_playing(), text)
157 bot.send_msg(constants.strings('queue_empty'), text)
160 def cmd_pause(bot, user, text, command, parameter):
164 bot.send_msg(constants.strings('paused'))
167 def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=False):
170 # if parameter is {index}
171 if parameter.isdigit():
172 files = var.library.files
173 if int(parameter) < len(files):
174 music_wrapper = get_item_wrapper_by_id(bot, var.library.file_id_lookup[files[int(parameter)]], user)
175 var.playlist.append(music_wrapper)
176 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
177 bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
180 # if parameter is {path}
182 # sanitize "../" and so on
183 # path = os.path.abspath(os.path.join(var.music_folder, parameter))
184 # if not path.startswith(os.path.abspath(var.music_folder)):
185 # bot.send_msg(constants.strings('no_file'), text)
188 if parameter in var.library.files:
189 music_wrapper = get_item_wrapper(bot, type='file', path=parameter, user=user)
190 var.playlist.append(music_wrapper)
191 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
192 bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
195 # if parameter is {folder}
196 files = var.library.dir.get_files(parameter)
198 msgs = [constants.strings('multiple_file_added')]
203 music_wrapper = get_item_wrapper_by_id(bot, var.library.file_id_lookup[file],user)
204 var.playlist.append(music_wrapper)
205 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
206 msgs.append("{} ({})".format(music_wrapper.item().title, music_wrapper.item().path))
209 send_multi_lines(bot, msgs, text)
213 # try to do a partial match
214 files = var.library.files
215 matches = [(index, file) for index, file in enumerate(files) if parameter.lower() in file.lower()]
216 if len(matches) == 1:
218 music_wrapper = get_item_wrapper_by_id(bot, var.library.file_id_lookup[file],user)
219 var.playlist.append(music_wrapper)
220 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
221 bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
223 elif len(matches) > 1:
224 msgs = [ constants.strings('multiple_matches') ]
225 for match in matches:
226 music_wrapper = get_item_wrapper_by_id(bot, var.library.file_id_lookup[match[1]], user)
227 msgs.append("<b>{:0>3d}</b> - <b>{:s}</b> ({:s})".format(
228 match[0], music_wrapper.item().title, match[1]))
229 send_multi_lines(bot, msgs, text)
232 if do_not_refresh_cache:
233 bot.send_msg(constants.strings("no_file"), text)
235 var.library.build_dir_cache(bot)
236 cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=True)
239 def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=False):
242 music_folder = var.music_folder
244 files = var.library.files
245 msgs = [ constants.strings('multiple_file_added') + "<ul>"]
250 match = re.search(parameter, file)
251 if match and match[0]:
253 music_wrapper = get_item_wrapper_by_id(bot, var.library.file_id_lookup[file], user)
254 music_wrappers.append(music_wrapper)
255 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
256 msgs.append("<li><b>{}</b> ({})</li>".format(music_wrapper.item().title,
257 file[:match.span()[0]]
258 + "<b style='color:pink'>"
259 + file[match.span()[0]: match.span()[1]]
261 + file[match.span()[1]:]
266 var.playlist.extend(music_wrappers)
267 send_multi_lines(bot, msgs, text, "")
269 if do_not_refresh_cache:
270 bot.send_msg(constants.strings("no_file"), text)
272 var.library.build_dir_cache(bot)
273 cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=True)
275 except re.error as e:
276 msg = constants.strings('wrong_pattern', error=str(e))
277 bot.send_msg(msg, text)
279 bot.send_msg(constants.strings('bad_parameter', command=command))
282 def cmd_play_url(bot, user, text, command, parameter):
285 url = util.get_url_from_input(parameter)
286 music_wrapper = get_item_wrapper(bot, type='url', url=url, user=user)
287 var.playlist.append(music_wrapper)
289 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
290 bot.send_msg(constants.strings('file_added', item=music_wrapper.format_short_string()), text)
291 if len(var.playlist) == 2:
292 # If I am the second item on the playlist. (I am the next one!)
293 bot.async_download_next()
296 def cmd_play_playlist(bot, user, text, command, parameter):
299 offset = 0 # if you want to start the playlist at a specific index
301 offset = int(parameter.split(" ")[-1])
305 url = util.get_url_from_input(parameter)
306 log.debug("cmd: fetching media info from playlist url %s" % url)
307 items = get_playlist_info(url=url, start_index=offset, user=user)
309 items = var.playlist.extend(list(map(
310 lambda item: get_item_wrapper(bot, **item), items)))
312 log.info("cmd: add to playlist: " + music.format_debug_string())
314 bot.send_msg(constants.strings("playlist_fetching_failed"), text)
317 def cmd_play_radio(bot, user, text, command, parameter):
321 all_radio = var.config.items('radio')
322 msg = constants.strings('preconfigurated_radio')
325 if len(i[1].split(maxsplit=1)) == 2:
326 comment = " - " + i[1].split(maxsplit=1)[1]
327 msg += "<br />" + i[0] + comment
328 bot.send_msg(msg, text)
330 if var.config.has_option('radio', parameter):
331 parameter = var.config.get('radio', parameter)
332 parameter = parameter.split()[0]
333 url = util.get_url_from_input(parameter)
335 music_wrapper = get_item_wrapper(bot, type='radio', url=url)
337 var.playlist.append(music_wrapper)
338 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
340 bot.send_msg(constants.strings('bad_url'))
343 def cmd_rb_query(bot, user, text, command, parameter):
346 log.info('cmd: Querying radio stations')
348 log.debug('rbquery without parameter')
349 msg = constants.strings('rb_query_empty')
350 bot.send_msg(msg, text)
352 log.debug('cmd: Found query parameter: ' + parameter)
353 # bot.send_msg('Searching for stations - this may take some seconds...', text)
354 rb_stations = radiobrowser.getstations_byname(parameter)
355 msg = constants.strings('rb_query_result')
356 msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th></tr>'
358 log.debug('cmd: No matches found for rbquery ' + parameter)
359 bot.send_msg('Radio-Browser found no matches for ' + parameter, text)
361 for s in rb_stations:
363 stationname = s['stationname']
364 country = s['country']
366 bitrate = s['bitrate']
368 # msg += f'<tr><td>{stationid}</td><td>{stationname}</td><td>{genre}</td><td>{codec}/{bitrate}</td><td>{country}</td></tr>'
369 msg += '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s/%s</td><td>%s</td></tr>' % (
370 stationid, stationname, genre, codec, bitrate, country)
372 # Full message as html table
374 bot.send_msg(msg, text)
375 # Shorten message if message too long (stage I)
377 log.debug('Result too long stage I')
378 msg = constants.strings('rb_query_result') + ' (shortened L1)'
379 msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th></tr>'
380 for s in rb_stations:
382 stationname = s['stationname']
383 # msg += f'<tr><td>{stationid}</td><td>{stationname}</td>'
384 msg += '<tr><td>%s</td><td>%s</td>' % (stationid, stationname)
387 bot.send_msg(msg, text)
388 # Shorten message if message too long (stage II)
390 log.debug('Result too long stage II')
391 msg = constants.strings('rb_query_result') + ' (shortened L2)'
392 msg += '!rbplay ID - Station Name'
393 for s in rb_stations:
395 stationname = s['stationname'][:12]
396 # msg += f'{stationid} - {stationname}'
397 msg += '%s - %s' % (stationid, stationname)
399 bot.send_msg(msg, text)
400 # Message still too long
402 bot.send_msg('Query result too long to post (> 5000 characters), please try another query.',
406 def cmd_rb_play(bot, user, text, command, parameter):
409 log.debug('cmd: Play a station by ID')
411 log.debug('rbplay without parameter')
412 msg = constants.strings('rb_play_empty')
413 bot.send_msg(msg, text)
415 log.debug('cmd: Retreiving url for station ID ' + parameter)
416 rstation = radiobrowser.getstationname_byid(parameter)
417 stationname = rstation[0]['name']
418 country = rstation[0]['country']
419 codec = rstation[0]['codec']
420 bitrate = rstation[0]['bitrate']
421 genre = rstation[0]['tags']
422 homepage = rstation[0]['homepage']
423 msg = 'Radio station added to playlist:'
424 # msg += '<table><tr><th>ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th><th>Homepage</th></tr>' + \
425 # f'<tr><td>{parameter}</td><td>{stationname}</td><td>{genre}</td><td>{codec}/{bitrate}</td><td>{country}</td><td>{homepage}</td></tr></table>'
426 msg += '<table><tr><th>ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th><th>Homepage</th></tr>' + \
427 '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s/%s</td><td>%s</td><td>%s</td></tr></table>' \
428 % (parameter, stationname, genre, codec, bitrate, country, homepage)
429 log.debug('cmd: Added station to playlist %s' % stationname)
430 bot.send_msg(msg, text)
431 url = radiobrowser.geturl_byid(parameter)
433 log.info('cmd: Found url: ' + url)
434 music_wrapper = get_item_wrapper(bot, type='radio', url=url, name=stationname)
435 var.playlist.append(music_wrapper)
436 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
437 bot.async_download_next()
439 log.info('cmd: No playable url found.')
440 msg += "No playable url found for this station, please try another station."
441 bot.send_msg(msg, text)
444 yt_last_page = 0 # TODO: if we keep adding global variables, we need to consider sealing all commands up into classes.
446 def cmd_yt_search(bot, user, text, command, parameter):
447 global log, yt_last_result, yt_last_page
452 if parameter.startswith("-n"):
454 if len(yt_last_result) > yt_last_page * item_per_page:
455 msg = _yt_format_result(yt_last_result, yt_last_page * item_per_page, item_per_page)
456 bot.send_msg(constants.strings('yt_result', result_table=msg), text)
458 bot.send_msg(constants.strings('yt_no_more'))
462 results = util.youtube_search(parameter)
464 yt_last_result = results
466 msg = _yt_format_result(results, 0, item_per_page)
467 bot.send_msg(constants.strings('yt_result', result_table=msg), text)
469 bot.send_msg(constants.strings('yt_query_error'))
471 bot.send_msg(constants.strings('bad_parameter', command=command), text)
473 def _yt_format_result(results, start, count):
474 msg = '<table><tr><th width="10%">Index</th><th>Title</th><th width="20%">Uploader</th></tr>'
475 for index, item in enumerate(results[start:start+count]):
476 msg += '<tr><td>{index:d}</td><td>{title}</td><td>{uploader}</td></tr>'.format(
477 index=index + 1 + start, title=item[1], uploader=item[2])
483 def cmd_yt_play(bot, user, text, command, parameter):
484 global log, yt_last_result, yt_last_page
487 if parameter.isdigit() and 0 <= int(parameter) - 1 < len(yt_last_result):
488 url = "https://www.youtube.com/watch?v=" + yt_last_result[int(parameter) - 1][0]
489 cmd_play_url(bot, user, text, command, url)
491 results = util.youtube_search(parameter)
493 yt_last_result = results
495 url = "https://www.youtube.com/watch?v=" + yt_last_result[0][0]
496 cmd_play_url(bot, user, text, command, url)
498 bot.send_msg(constants.strings('yt_query_error'))
500 bot.send_msg(constants.strings('bad_parameter', command=command), text)
503 def cmd_help(bot, user, text, command, parameter):
506 bot.send_msg(constants.strings('help'), text)
507 if bot.is_admin(user):
508 bot.send_msg(constants.strings('admin_help'), text)
511 def cmd_stop(bot, user, text, command, parameter):
515 bot.send_msg(constants.strings('stopped'), text)
518 def cmd_clear(bot, user, text, command, parameter):
522 bot.send_msg(constants.strings('cleared'), text)
525 def cmd_kill(bot, user, text, command, parameter):
528 if bot.is_admin(user):
532 bot.mumble.users[text.actor].send_text_message(
533 constants.strings('not_admin'))
536 def cmd_update(bot, user, text, command, parameter):
539 if bot.is_admin(user):
540 bot.mumble.users[text.actor].send_text_message(
541 constants.strings('start_updating'))
542 msg = util.update(bot.version)
543 bot.mumble.users[text.actor].send_text_message(msg)
545 bot.mumble.users[text.actor].send_text_message(
546 constants.strings('not_admin'))
549 def cmd_stop_and_getout(bot, user, text, command, parameter):
554 bot.mumble.channels.find_by_name(bot.channel).move_in()
557 def cmd_volume(bot, user, text, command, parameter):
560 # The volume is a percentage
561 if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
562 bot.volume_set = float(float(parameter) / 100)
563 bot.send_msg(constants.strings('change_volume',
564 volume=int(bot.volume_set * 100), user=bot.mumble.users[text.actor]['name']), text)
565 var.db.set('bot', 'volume', str(bot.volume_set))
566 log.info('cmd: volume set to %d' % (bot.volume_set * 100))
568 bot.send_msg(constants.strings('current_volume', volume=int(bot.volume_set * 100)), text)
571 def cmd_ducking(bot, user, text, command, parameter):
574 if parameter == "" or parameter == "on":
575 bot.is_ducking = True
576 var.db.set('bot', 'ducking', True)
577 bot.ducking_volume = var.config.getfloat("bot", "ducking_volume", fallback=0.05)
578 bot.ducking_threshold = var.config.getint("bot", "ducking_threshold", fallback=5000)
579 bot.mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED,
580 bot.ducking_sound_received)
581 bot.mumble.set_receive_sound(True)
582 log.info('cmd: ducking is on')
584 bot.send_msg(msg, text)
585 elif parameter == "off":
586 bot.is_ducking = False
587 bot.mumble.set_receive_sound(False)
588 var.db.set('bot', 'ducking', False)
590 log.info('cmd: ducking is off')
591 bot.send_msg(msg, text)
594 def cmd_ducking_threshold(bot, user, text, command, parameter):
597 if parameter and parameter.isdigit():
598 bot.ducking_threshold = int(parameter)
599 var.db.set('bot', 'ducking_threshold', str(bot.ducking_threshold))
600 msg = "Ducking threshold set to %d." % bot.ducking_threshold
601 bot.send_msg(msg, text)
603 msg = "Current ducking threshold is %d." % bot.ducking_threshold
604 bot.send_msg(msg, text)
607 def cmd_ducking_volume(bot, user, text, command, parameter):
610 # The volume is a percentage
611 if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
612 bot.ducking_volume = float(float(parameter) / 100)
613 bot.send_msg(constants.strings('change_ducking_volume',
614 volume=int(bot.ducking_volume * 100), user=bot.mumble.users[text.actor]['name']), text)
615 # var.db.set('bot', 'volume', str(bot.volume_set))
616 var.db.set('bot', 'ducking_volume', str(bot.ducking_volume))
617 log.info('cmd: volume on ducking set to %d' % (bot.ducking_volume * 100))
619 bot.send_msg(constants.strings('current_ducking_volume', volume=int(bot.ducking_volume * 100)), text)
622 def cmd_current_music(bot, user, text, command, parameter):
626 if len(var.playlist) > 0:
627 bot.send_msg(var.playlist.current_item().format_current_playing())
629 reply = constants.strings('not_playing')
630 bot.send_msg(reply, text)
633 def cmd_skip(bot, user, text, command, parameter):
638 if len(var.playlist) == 0:
639 bot.send_msg(constants.strings('queue_empty'), text)
642 def cmd_last(bot, user, text, command, parameter):
645 if len(var.playlist) > 0:
647 var.playlist.point_to(len(var.playlist) - 1)
649 bot.send_msg(constants.strings('queue_empty'), text)
652 def cmd_remove(bot, user, text, command, parameter):
655 # Allow to remove specific music into the queue with a number
656 if parameter and parameter.isdigit() and int(parameter) > 0 \
657 and int(parameter) <= len(var.playlist):
659 index = int(parameter) - 1
662 if index == var.playlist.current_index:
663 removed = var.playlist.remove(index)
665 if index < len(var.playlist):
668 var.playlist.current_index -= 1
669 # then the bot will move to next item
671 else: # if item deleted is the last item of the queue
672 var.playlist.current_index -= 1
676 removed = var.playlist.remove(index)
678 bot.send_msg(constants.strings('removing_item',
679 item=removed.format_short_string()), text)
681 log.info("cmd: delete from playlist: " + removed.format_debug_string())
683 bot.send_msg(constants.strings('bad_parameter', command=command))
686 def cmd_list_file(bot, user, text, command, parameter):
689 files = var.library.files
690 msgs = [ "<br> <b>Files available:</b>" if not parameter else "<br> <b>Matched files:</b>" ]
693 for index, file in enumerate(files):
695 match = re.search(parameter, file)
700 msgs.append("<b>{:0>3d}</b> - {:s}".format(index, file))
703 send_multi_lines(bot, msgs, text)
705 bot.send_msg(constants.strings('no_file'), text)
707 except re.error as e:
708 msg = constants.strings('wrong_pattern', error=str(e))
709 bot.send_msg(msg, text)
712 def cmd_queue(bot, user, text, command, parameter):
715 if len(var.playlist) == 0:
716 msg = constants.strings('queue_empty')
717 bot.send_msg(msg, text)
719 msgs = [ constants.strings('queue_contents')]
720 for i, music in enumerate(var.playlist):
722 if i == var.playlist.current_index:
723 newline = "<b style='color:orange'>{} ({}) {} </b>".format(i + 1, music.display_type(),
724 music.format_short_string())
726 newline = '<b>{}</b> ({}) {}'.format(i + 1, music.display_type(),
727 music.format_short_string())
731 send_multi_lines(bot, msgs, text)
733 def cmd_random(bot, user, text, command, parameter):
737 var.playlist.randomize()
739 def cmd_repeat(bot, user, text, command, parameter):
743 if parameter and parameter.isdigit():
744 repeat = int(parameter)
746 music = var.playlist.current_item()
747 for _ in range(repeat):
749 var.playlist.current_index + 1,
752 log.info("bot: add to playlist: " + music.format_debug_string)
754 bot.send_msg(constants.strings("repeat", song=music.format_song_string(), n=str(repeat)), text)
756 def cmd_mode(bot, user, text, command, parameter):
760 bot.send_msg(constants.strings("current_mode", mode=var.playlist.mode), text)
762 if not parameter in ["one-shot", "repeat", "random", "autoplay"]:
763 bot.send_msg(constants.strings('unknown_mode', mode=parameter), text)
765 var.db.set('playlist', 'playback_mode', parameter)
766 var.playlist = media.playlist.get_playlist(parameter, var.playlist)
767 log.info("command: playback mode changed to %s." % parameter)
768 bot.send_msg(constants.strings("change_mode", mode=var.playlist.mode,
769 user=bot.mumble.users[text.actor]['name']), text)
770 if parameter == "random":
774 def cmd_play_tags(bot, user, text, command, parameter):
776 bot.send_msg(constants.strings('bad_parameter', command=command))
779 msgs = [constants.strings('multiple_file_added') + "<ul>"]
782 tags = parameter.split(",")
783 tags = list(map(lambda t: t.strip(), tags))
784 music_wrappers = get_item_wrappers_by_tags(bot, tags)
785 for music_wrapper in music_wrappers:
787 log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
788 msgs.append("<li><b>{}</b> (<i>{}</i>)</li>".format(music_wrapper.item().title, ", ".join(music_wrapper.item().tags)))
793 var.playlist.extend(music_wrappers)
794 send_multi_lines(bot, msgs, text, "")
796 bot.send_msg(constants.strings("no_file"), text)
799 def cmd_tag(bot, user, text, command, parameter):
802 def cmd_untag(bot, user, text, command, parameter):
805 def cmd_list_tagged(bot, user, text, command, parameter):
808 def cmd_drop_database(bot, user, text, command, parameter):
812 var.db = SettingsDatabase(var.dbfile)
813 var.music_db.drop_table()
814 var.music_db = MusicDatabase(var.dbfile)
815 log.info("command: database dropped.")
816 bot.send_msg(constants.strings('database_dropped'), text)
818 def cmd_refresh_cache(bot, user, text, command, parameter):
820 var.library.build_dir_cache(bot)
821 log.info("command: cache refreshed.")
822 bot.send_msg(constants.strings('cache_refreshed'), text)
825 def cmd_real_time_rms(bot, user, text, command, parameter):
826 bot._display_rms = not bot._display_rms
828 def cmd_loop_state(bot, user, text, command, parameter):
829 print(bot._loop_status)
831 def cmd_item(bot, user, text, command, parameter):
832 print(bot.wait_for_downloading)
833 print(var.playlist.current_item().to_dict())