diff --git a/command.py b/command.py index e8e32b4..725f0c8 100644 --- a/command.py +++ b/command.py @@ -1,6 +1,5 @@ # coding=utf-8 import logging -import os.path import pymumble.pymumble_py3 as pymumble import re @@ -10,15 +9,13 @@ import util import variables as var from librb import radiobrowser from database import SettingsDatabase, MusicDatabase -from media.item import item_builders, item_loaders, item_id_generators, dict_to_item, dicts_to_items +from media.item import item_id_generators, dict_to_item, dicts_to_items from media.cache import get_cached_wrapper_from_scrap, get_cached_wrapper_by_id, get_cached_wrappers_by_tags -from media.file import FileItem -from media.url_from_playlist import PlaylistURLItem, get_playlist_info -from media.url import URLItem -from media.radio import RadioItem +from media.url_from_playlist import get_playlist_info log = logging.getLogger("bot") + def register_all_commands(bot): bot.register_command(constants.commands('joinme'), cmd_joinme, no_partial_match=False, access_outside_channel=True) bot.register_command(constants.commands('user_ban'), cmd_user_ban, no_partial_match=True) @@ -71,6 +68,7 @@ def register_all_commands(bot): bot.register_command('loop', cmd_loop_state, True) bot.register_command('item', cmd_item, True) + def send_multi_lines(bot, lines, text, linebreak="
"): global log @@ -79,19 +77,20 @@ def send_multi_lines(bot, lines, text, linebreak="
"): for newline in lines: msg += br br = linebreak - if (len(msg) + len(newline)) > (bot.mumble.get_max_message_length() - 4) != 0: # 4 == len("
") + if (len(msg) + len(newline)) > (bot.mumble.get_max_message_length() - 4) != 0: # 4 == len("
") bot.send_msg(msg, text) msg = "" msg += newline bot.send_msg(msg, text) + # ---------------- Variables ----------------- song_shortlist = [] -# ---------------- Commands ------------------ +# ---------------- Commands ------------------ def cmd_joinme(bot, user, text, command, parameter): global log @@ -146,6 +145,7 @@ def cmd_url_ban(bot, user, text, command, parameter): bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin')) return + def cmd_url_ban_list(bot, user, text, command, parameter): if bot.is_admin(user): bot.mumble.users[text.actor].send_text_message(util.get_url_ban()) @@ -153,6 +153,7 @@ def cmd_url_ban_list(bot, user, text, command, parameter): bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin')) return + def cmd_url_unban(bot, user, text, command, parameter): global log @@ -170,9 +171,11 @@ def cmd_play(bot, user, text, command, parameter): if len(var.playlist) > 0: if parameter: if parameter.isdigit() and 1 <= int(parameter) <= len(var.playlist): - var.playlist.point_to(int(parameter) - 1 - 1) # First "-1" transfer 12345 to 01234, second "-1" - # point to the previous item. the loop will next to - # the one you want + # First "-1" transfer 12345 to 01234, second "-1" + # point to the previous item. the loop will next to + # the one you want + var.playlist.point_to(int(parameter) - 1 - 1) + bot.interrupt() else: bot.send_msg(constants.strings('invalid_index', index=parameter), text) @@ -241,7 +244,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals else: # try to do a partial match files = var.cache.files - matches = [ file for file in files if parameter.lower() in file.lower()] + matches = [file for file in files if parameter.lower() in file.lower()] if len(matches) == 1: file = matches[0] music_wrapper = get_cached_wrapper_by_id(bot, var.cache.file_id_lookup[file], user) @@ -250,7 +253,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string())) return elif len(matches) > 1: - msgs = [ constants.strings('multiple_matches') ] + msgs = [constants.strings('multiple_matches')] song_shortlist = [] for index, match in enumerate(matches): id = var.cache.file_id_lookup[match] @@ -274,10 +277,9 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=False): global log - music_folder = var.music_folder if parameter: files = var.cache.files - msgs = [ constants.strings('multiple_file_added') + "