def message_received(self, text): message = text.message.strip() if message[0] == '!': message = message[1:].split(' ', 1) if len(message) > 0: command = message[0] parameter = '' if len(message) > 1: parameter = message[1] else: return logging.info(command + ' - ' + parameter + ' by ' + self.mumble.users[text.actor]['name']) if command == var.config.get('command', 'play_file') and parameter: music_folder = var.config.get('bot', 'music_folder') # sanitize "../" and so on path = os.path.abspath(os.path.join(music_folder, parameter)) if path.startswith(music_folder): if os.path.isfile(path): filename = path.replace(music_folder, '') var.playlist.append(["file", filename]) else: # try to do a partial match matches = [ file for file in util.get_recursive_filelist_sorted(music_folder) if parameter.lower() in file.lower() ] if len(matches) == 0: self.mumble.users[text.actor].send_message( var.config.get('strings', 'no_file')) elif len(matches) == 1: var.playlist.append(["file", matches[0]]) else: msg = var.config.get('strings', 'multiple_matches') + '<br />' msg += '<br />'.join(matches) self.mumble.users[text.actor].send_message(msg) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'bad_file')) elif command == var.config.get('command', 'play_url') and parameter: var.playlist.append(["url", parameter]) elif command == var.config.get('command', 'play_radio') and parameter: if var.config.has_option('radio', parameter): parameter = var.config.get('radio', parameter) var.playlist.append(["radio", parameter]) elif command == var.config.get('command', 'help'): self.send_msg_channel(var.config.get('strings', 'help')) elif command == var.config.get('command', 'stop'): self.stop() elif command == var.config.get('command', 'kill'): if self.is_admin(text.actor): self.stop() self.exit = True else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'not_admin')) elif command == var.config.get('command', 'stop_and_getout'): self.stop() if self.channel: self.mumble.channels.find_by_name(self.channel).move_in() elif command == var.config.get('command', 'joinme'): self.mumble.users.myself.move_in( self.mumble.users[text.actor]['channel_id']) elif command == var.config.get('command', 'volume'): if parameter is not None and parameter.isdigit( ) and 0 <= int(parameter) <= 100: self.volume = float(float(parameter) / 100) self.send_msg_channel( var.config.get('strings', 'change_volume') % (int(self.volume * 100), self.mumble.users[text.actor]['name'])) else: self.send_msg_channel( var.config.get('strings', 'current_volume') % int(self.volume * 100)) elif command == var.config.get('command', 'current_music'): if var.current_music: source = var.current_music[0] if source == "radio": reply = "[radio] {title} sur {url}".format( title=media.get_radio_title(var.current_music[1]), url=var.current_music[2]) elif source == "url": reply = "[url] {title} (<a href=\"{url}\">{url}</a>)".format( title=var.current_music[2], url=var.current_music[1]) elif source == "file": reply = "[file] {title}".format( title=var.current_music[2]) else: reply = "(?)[{}] {} {}".format( var.current_music[0], var.current_music[1], var.current_music[2], ) else: reply = var.config.get('strings', 'not_playing') self.mumble.users[text.actor].send_message(reply) elif command == var.config.get('command', 'next'): if var.playlist: var.current_music = [ var.playlist[0][0], var.playlist[0][1], None, None ] var.playlist.pop(0) self.launch_next() else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'queue_empty')) self.stop() elif command == var.config.get('command', 'list'): folder_path = var.config.get('bot', 'music_folder') files = util.get_recursive_filelist_sorted(folder_path) if files: self.mumble.users[text.actor].send_message( '<br>'.join(files)) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'no_file')) elif command == var.config.get('command', 'queue'): if len(var.playlist) == 0: msg = var.config.get('strings', 'queue_empty') else: msg = var.config.get('strings', 'queue_contents') + '<br />' for (type, path) in var.playlist: msg += '({}) {}<br />'.format(type, path) self.send_msg_channel(msg) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'bad_command'))
def message_received(self, text): message = text.message.strip() user = self.mumble.users[text.actor]['name'] if message[0] == '!': message = message[1:].split(' ', 1) if len(message) > 0: command = message[0] parameter = '' if len(message) > 1: parameter = message[1] else: return logging.info(command + ' - ' + parameter + ' by ' + user) if command == var.config.get('command', 'joinme'): self.mumble.users.myself.move_in( self.mumble.users[text.actor]['channel_id']) return if not self.is_admin(user) and not var.config.getboolean( 'bot', 'allow_other_channel_message' ) and self.mumble.users[text.actor][ 'channel_id'] != self.mumble.users.myself['channel_id']: self.mumble.users[text.actor].send_message( var.config.get('strings', 'not_in_my_channel')) return if not self.is_admin(user) and not var.config.getboolean( 'bot', 'allow_private_message') and text.session: self.mumble.users[text.actor].send_message( var.config.get('strings', 'pm_not_allowed')) return if command == var.config.get('command', 'play_file') and parameter: music_folder = var.config.get('bot', 'music_folder') # sanitize "../" and so on path = os.path.abspath(os.path.join(music_folder, parameter)) if path.startswith(music_folder): if os.path.isfile(path): filename = path.replace(music_folder, '') var.playlist.append(["file", filename, user]) else: # try to do a partial match matches = [ file for file in util.get_recursive_filelist_sorted(music_folder) if parameter.lower() in file.lower() ] if len(matches) == 0: self.mumble.users[text.actor].send_message( var.config.get('strings', 'no_file')) elif len(matches) == 1: var.playlist.append(["file", matches[0], user]) else: msg = var.config.get('strings', 'multiple_matches') + '<br />' msg += '<br />'.join(matches) self.mumble.users[text.actor].send_message(msg) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'bad_file')) self.async_download_next() elif command == var.config.get('command', 'play_url') and parameter: var.playlist.append(["url", parameter, user]) self.async_download_next() elif command == var.config.get('command', 'play_playlist') and parameter: offset = 1 try: offset = int(parameter.split(" ")[-1]) except ValueError: pass var.playlist.append([ "playlist", parameter, user, var.config.getint('bot', 'max_track_playlist'), offset ]) self.async_download_next() elif command == var.config.get('command', 'play_radio') and parameter: if var.config.has_option('radio', parameter): parameter = var.config.get('radio', parameter) var.playlist.append(["radio", parameter, user]) self.async_download_next() elif command == var.config.get('command', 'help'): self.send_msg_channel(var.config.get('strings', 'help')) elif command == var.config.get('command', 'stop'): self.stop() elif command == var.config.get('command', 'kill'): if self.is_admin(user): self.stop() self.exit = True else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'not_admin')) elif command == var.config.get('command', 'update'): if not self.is_admin(user): self.mumble.users[text.actor].send_message( "Starting the update") tp = sp.check_output([ var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl' ]).decode() msg = "" if "Requirement already up-to-date" in tp: msg += "Youtube-dl is up-to-date" else: msg += "Update done : " + tp.split( 'Successfully installed')[1] if 'Your branch is up-to-date' in sp.check_output( ['/usr/bin/env', 'git', 'status']).decode(): msg += "<br /> Botamusique is up-to-date" else: msg += "<br /> Botamusique have available update" self.mumble.users[text.actor].send_message(msg) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'not_admin')) elif command == var.config.get('command', 'stop_and_getout'): self.stop() if self.channel: self.mumble.channels.find_by_name(self.channel).move_in() elif command == var.config.get('command', 'volume'): if parameter is not None and parameter.isdigit( ) and 0 <= int(parameter) <= 100: self.volume = float(float(parameter) / 100) self.send_msg_channel( var.config.get('strings', 'change_volume') % (int(self.volume * 100), self.mumble.users[text.actor]['name'])) var.db.set('bot', 'volume', str(self.volume)) else: self.send_msg_channel( var.config.get('strings', 'current_volume') % int(self.volume * 100)) elif command == var.config.get('command', 'current_music'): if var.current_music: source = var.current_music["type"] if source == "radio": reply = "[radio] {title} on {url} by {user}".format( title=media.get_radio_title( var.current_music["path"]), url=var.current_music["title"], user=var.current_music["user"]) elif source == "url": reply = "[url] {title} (<a href=\"{url}\">{url}</a>) by {user}".format( title=var.current_music["title"], url=var.current_music["path"], user=var.current_music["user"]) elif source == "file": reply = "[file] {title} by {user}".format( title=var.current_music["title"], user=var.current_music["user"]) elif source == "playlist": reply = "[playlist] {title} (from the playlist <a href=\"{url}\">{playlist}</a> by {user}".format( title=var.current_music["title"], url=var.current_music["path"], playlist=var.current_music["playlist_title"], user=var.current_music["user"]) else: reply = "(?)[{}] {} {} by {}".format( var.current_music["type"], var.current_music["path"], var.current_music["title"], var.current_music["user"]) else: reply = var.config.get('strings', 'not_playing') self.mumble.users[text.actor].send_message(reply) elif command == var.config.get('command', 'next'): if self.get_next(): self.launch_next() self.async_download_next() else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'queue_empty')) self.stop() elif command == var.config.get('command', 'list'): folder_path = var.config.get('bot', 'music_folder') files = util.get_recursive_filelist_sorted(folder_path) if files: self.mumble.users[text.actor].send_message( '<br>'.join(files)) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'no_file')) elif command == var.config.get('command', 'queue'): if len(var.playlist) == 0: msg = var.config.get('strings', 'queue_empty') else: msg = var.config.get('strings', 'queue_contents') + '<br />' for (music_type, path, user) in var.playlist: msg += '({}) {}<br />'.format(music_type, path) self.send_msg_channel(msg) elif command == var.config.get('command', 'repeat'): var.playlist.append([ var.current_music["type"], var.current_music["path"], var.current_music["user"] ]) else: self.mumble.users[text.actor].send_message( var.config.get('strings', 'bad_command'))
def message_received(self, text): message = text.message if message[0] == '!': message = message[1:].split(' ', 1) if len(message) > 0: command = message[0] parameter = '' if len(message) > 1: parameter = message[1] else: return logging.info(command + ' - ' + parameter + ' by ' + self.mumble.users[text.actor]['name']) if command == self.config.get('command', 'play_file') and parameter: path = self.config.get('bot', 'music_folder') + parameter if "/" in parameter: self.mumble.users[text.actor].send_message( self.config.get('strings', 'bad_file')) elif os.path.isfile(path): var.playlist.append(["file", path]) else: self.mumble.users[text.actor].send_message( self.config.get('strings', 'bad_file')) elif command == self.config.get('command', 'play_url') and parameter: var.playlist.append(["url", parameter]) elif command == self.config.get('command', 'play_radio') and parameter: if self.config.has_option('radio', parameter): parameter = self.config.get('radio', parameter) var.playlist.append(["radio", parameter]) elif command == self.config.get('command', 'help'): self.send_msg_channel(self.config.get('strings', 'help')) elif command == self.config.get('command', 'stop'): self.stop() elif command == self.config.get('command', 'kill'): if self.is_admin(text.actor): self.stop() self.exit = True else: self.mumble.users[text.actor].send_message( self.config.get('strings', 'not_admin')) elif command == self.config.get('command', 'stop_and_getout'): self.stop() if self.channel: self.mumble.channels.find_by_name(self.channel).move_in() elif command == self.config.get('command', 'joinme'): self.mumble.users.myself.move_in( self.mumble.users[text.actor]['channel_id']) elif command == self.config.get('command', 'volume'): if parameter is not None and parameter.isdigit( ) and 0 <= int(parameter) <= 100: self.volume = float(float(parameter) / 100) self.send_msg_channel( self.config.get('strings', 'change_volume') % (int(self.volume * 100), self.mumble.users[text.actor]['name'])) else: self.send_msg_channel( self.config.get('strings', 'current_volume') % int(self.volume * 100)) elif command == self.config.get('command', 'current_music'): if var.current_music is not None: if var.current_music[0] == "radio": self.send_msg_channel( media.get_radio_title(var.current_music[1]) + " sur " + var.current_music[2]) else: self.send_msg_channel(var.current_music[2] + "<br />" + var.current_music[1]) else: self.mumble.users[text.actor].send_message( self.config.get('strings', 'not_playing')) elif command == self.config.get('command', 'next'): if var.playlist: var.current_music = var.playlist[0] var.playlist.pop(0) self.launch_next() else: self.mumble.users[text.actor].send_message( self.config.get('strings', 'empty_playlist')) self.stop() else: self.mumble.users[text.actor].send_message( self.config.get('strings', 'bad_command'))