def cmd_sblist(self, data): internal_list = [] data_actor = gs.mumble_inst.users[data.actor] gather_list = sbu.prepare_sb_list() for i, item in enumerate(gather_list): internal_list.append( f"<br><font color='{gs.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}'>[{i}]</font> - [{item}]" ) cur_text = f"<font color='{gs.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Local Sound Board Files:</font>" if len(internal_list) == 0: cur_text += "<br>There are no local sound board files available." gs.gui_service.quick_gui(cur_text, text_type='header', box_align='left', user=data_actor['name']) log(INFO, "Displayed a list of all local sound board files.") return for i, item in enumerate(internal_list): cur_text += item if i % 50 == 0 and i != 0: gs.gui_service.quick_gui(cur_text, text_type='header', box_align='left', text_align='left', user=data_actor['name']) cur_text = "" if cur_text != "": gs.gui_service.quick_gui(cur_text, text_type='header', box_align='left', text_align='left', user=data_actor['name']) log(INFO, "Displayed a list of all local sound board files.")
def cmd_sbrandomquiet(self, data): if gs.aud_interface.check_dni(self.plugin_name): gs.aud_interface.set_dni( self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) else: return sender = gs.mumble_inst.users[data.actor]['name'] gather_list = sbu.prepare_sb_list(include_file_extensions=True) random.seed() random_sfx = random.choice(gather_list) track_obj = TrackInfo( uri= f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{random_sfx}', name=random_sfx, sender=sender, duration=None, track_type=TrackType.FILE, quiet=True) gs.aud_interface.enqueue_track(track_obj=track_obj, to_front=False, quiet=True) gs.aud_interface.play( audio_lib=AudioLibrary.FFMPEG, override=not self.metadata.getboolean( C_PLUGIN_SETTINGS, P_ENABLE_QUEUE, fallback=False))
async def get_soundboard_data(self): if "sound_board" in list(global_settings.bot_plugins): import JJMumbleBot.plugins.extensions.sound_board.utility.sound_board_utility as sbu clips_list = sbu.prepare_sb_list() return ResponseModel(200, "success", {"clips": clips_list}).toDict() return ResponseModel(500, "error", {"error_message": "Encountered an error retrieving sound_board clips."}).toDict()
def cmd_sbrandom(self, data): if gs.vlc_interface.check_dni( self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]): gs.vlc_interface.set_dni( self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) else: return sender = gs.mumble_inst.users[data.actor]['name'] gather_list = sbu.prepare_sb_list() random.seed(datetime.now()) random_sfx = random.choice(gather_list) audio_clip = sbu.find_file(random_sfx) track_obj = TrackInfo( uri= f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}', name=random_sfx, sender=sender, duration=None, track_type=TrackType.FILE, quiet=False) gs.vlc_interface.enqueue_track(track_obj=track_obj, to_front=False) gs.vlc_interface.play(override=self.metadata.getboolean( C_PLUGIN_SETTINGS, P_ENABLE_QUEUE, fallback=False))
def process(self, text): message = text.message.strip() message_parse = message[1:].split(' ', 1) command = message_parse[0] if command == "sbstop": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return if sbu_settings.is_playing and GS.audio_inst is not None: if not GS.audio_dni[0]: GS.audio_dni = ( True, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) else: if GS.audio_dni[1] != self.metadata[C_PLUGIN_INFO][ P_PLUGIN_NAME]: rprint( f'An audio plugin is using the audio thread with no interruption mode enabled. [{GS.audio_dni[1]}]' ) GS.gui_service.quick_gui( "An audio plugin is using the audio thread with no interruption mode enabled.", text_type='header', box_align='left') return sbu.stop_audio() GS.gui_service.quick_gui( "Stopping sound board audio thread...", text_type='header', box_align='left') return elif command == "sbvolume": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return try: vol = float(message[1:].split(' ', 1)[1]) except IndexError: GS.gui_service.quick_gui( f"Current sound board volume: {sbu_settings.volume}", text_type='header', box_align='left') return if vol > 1 or vol < 0: GS.gui_service.quick_gui( "Invalid sound_board volume Input: [0-1]", text_type='header', box_align='left') return sbu_settings.volume = vol log(INFO, f"Set {self.plugin_name} volume to {sbu_settings.volume}", origin=L_COMMAND) GS.gui_service.quick_gui( f"Set {self.plugin_name} volume to {sbu_settings.volume}", text_type='header', box_align='left') elif command == "sblist": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return internal_list = [] gather_list = sbu.prepare_sb_list() for i, item in enumerate(gather_list): internal_list.append( f"<br><font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}'>[{i}]</font> - [{item}]" ) cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Local Sound Board Files:</font>" if len(internal_list) == 0: cur_text += "<br>There are no local sound board files available." GS.gui_service.quick_gui( cur_text, text_type='header', box_align='left', user=GS.mumble_inst.users[text.actor]['name']) log(INFO, "Displayed a list of all local sound board files.") return for i, item in enumerate(internal_list): cur_text += item if i % 50 == 0 and i != 0: GS.gui_service.quick_gui( cur_text, text_type='header', box_align='left', text_align='left', user=GS.mumble_inst.users[text.actor]['name']) cur_text = "" if cur_text != "": GS.gui_service.quick_gui( cur_text, text_type='header', box_align='left', text_align='left', user=GS.mumble_inst.users[text.actor]['name']) log(INFO, "Displayed a list of all local sound board files.") elif command == "sblist_echo": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return internal_list = [] gather_list = sbu.prepare_sb_list() for i, item in enumerate(gather_list): internal_list.append( f"<br><font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}'>[{i}]</font> - [{item}]" ) cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Local Sound Board Files:</font>" if len(internal_list) == 0: cur_text += "<br>There are no local sound board files available." GS.gui_service.quick_gui(cur_text, text_type='header', box_align='left') log(INFO, "Displayed a list of all local sound board files.") return for i, item in enumerate(internal_list): cur_text += item if i % 50 == 0 and i != 0: GS.gui_service.quick_gui(cur_text, text_type='header', box_align='left', text_align='left') cur_text = "" if cur_text != "": GS.gui_service.quick_gui(cur_text, text_type='header', box_align='left', text_align='left') log(INFO, "Displayed a list of all local sound board files.") elif command == "sbdownload": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return all_messages = message[1:].split() all_messages_stripped = BeautifulSoup( message_parse[1], features='html.parser').get_text() split_msgs = all_messages_stripped.split() stripped_url = split_msgs[0] if len(all_messages) >= 3: if "youtube.com" in stripped_url or "youtu.be" in stripped_url: sbu.download_clip(stripped_url, split_msgs[1].strip()) GS.gui_service.quick_gui( f"Downloaded sound clip as : {split_msgs[1].strip()}.wav", text_type='header', box_align='left') return return elif command == "sbdelete": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return all_messages = message[1:].split() if len(all_messages) == 2: if ".wav" in all_messages[1].strip(): dir_utils.remove_file( all_messages[1].strip(), f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/") GS.gui_service.quick_gui( f"Deleted sound clip : {all_messages[1].strip()}", text_type='header', box_align='left') elif command == "sbplaying": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return if GS.audio_dni[1] == self.metadata[C_PLUGIN_INFO][ P_PLUGIN_NAME] and GS.audio_dni[0] is True: track_duration = sbu.get_audio_length( sbu_settings.current_track) rprint( f'{get_bot_name()}({self.plugin_name}) is playing: {sbu_settings.current_track} (duration: {str(timedelta(seconds = round(track_duration))) if track_duration > 0 else "Unavailable"})', origin=L_COMMAND) GS.gui_service.quick_gui( f'{get_bot_name()}({self.plugin_name}) is playing: {sbu_settings.current_track} (duration: {str(timedelta(seconds = round(track_duration))) if track_duration > 0 else "Unavailable"})', text_type='header', box_align='left') elif command == "sbrandom": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return if not GS.audio_dni[0]: GS.audio_dni = (True, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) else: if GS.audio_dni[1] != self.metadata[C_PLUGIN_INFO][ P_PLUGIN_NAME]: rprint( f'An audio plugin is using the audio thread with no interruption mode enabled. [{GS.audio_dni[1]}]' ) GS.gui_service.quick_gui( "An audio plugin is using the audio thread with no interruption mode enabled.", text_type='header', box_align='left') return # print(GS.audio_dni) gather_list = sbu.prepare_sb_list() random.seed(datetime.now()) random_sfx = random.choice(gather_list)[:-4] if not os.path.isfile( f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{random_sfx}.wav" ): GS.gui_service.quick_gui("The sound clip does not exist.", text_type='header', box_align='left') return False sbu_settings.current_track = random_sfx sbu_settings.loop_clip = False sbu.play_audio() elif command == "sb": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return if len(message_parse) < 2: return if not GS.audio_dni[0]: GS.audio_dni = (True, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) else: if GS.audio_dni[1] != self.metadata[C_PLUGIN_INFO][ P_PLUGIN_NAME]: rprint( f'An audio plugin is using the audio thread with no interruption mode enabled. [{GS.audio_dni[1]}]' ) GS.gui_service.quick_gui( "An audio plugin is using the audio thread with no interruption mode enabled.", text_type='header', box_align='left') return # print(GS.audio_dni) parameter = message_parse[1].strip() if not os.path.isfile( f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{parameter}.wav" ): GS.gui_service.quick_gui("The sound clip does not exist.", text_type='header', box_align='left') return False sbu_settings.current_track = parameter sbu_settings.loop_clip = False sbu.play_audio() elif command == "sbloop": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return if len(message_parse) < 2: return if not GS.audio_dni[0]: GS.audio_dni = (True, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]) else: if GS.audio_dni[1] != self.metadata[C_PLUGIN_INFO][ P_PLUGIN_NAME]: rprint( f'An audio plugin is using the audio thread with no interruption mode enabled. [{GS.audio_dni[1]}]' ) GS.gui_service.quick_gui( "An audio plugin is using the audio thread with no interruption mode enabled.", text_type='header', box_align='left') return # print(GS.audio_dni) parameter = message_parse[1].strip() if not os.path.isfile( f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{parameter}.wav" ): GS.gui_service.quick_gui("The sound clip does not exist.", text_type='header', box_align='left') return False sbu_settings.current_track = parameter sbu_settings.loop_clip = True sbu.play_audio() elif command == "sbskip": if not privileges.plugin_privilege_checker(text, command, self.plugin_name): return if len(message_parse) < 2: return if GS.audio_dni[1] == self.metadata[C_PLUGIN_INFO][ P_PLUGIN_NAME] and GS.audio_dni[0] is True: if not sbu_settings.loop_clip: try: seconds_to_skip = int(message_parse[1]) sbu_settings.skip_to = seconds_to_skip sbu.play_audio() except ValueError: return else: GS.gui_service.quick_gui( "The skip feature is currently unavailable when looping clips.", text_type='header', box_align='left')