コード例 #1
0
ファイル: image_helper.py プロジェクト: DuckBoss/JJMumbleBot
def download_image_stream_to_dir(img_url,
                                 dir_name,
                                 img_name='_image',
                                 force_jpg=True):
    dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    img_ext = img_url.rsplit('.', 1)[1]
    with open(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/{img_name}.{img_ext}",
            'wb') as img_file:
        resp = requests.get(img_url, stream=True)
        for block in resp.iter_content(1024):
            if not block:
                break
            img_file.write(block)
    if img_ext == 'png' and force_jpg:
        log(WARNING,
            WARN_IMG_INCORRECT_FORMAT,
            origin=L_GENERAL,
            error_type=WARN_FIXED_IMG_FORMAT,
            print_mode=PrintMode.VERBOSE_PRINT.value)
        img_fix = Image.open(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/{img_name}.{img_ext}")
        img_fix.convert('RGB').save(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/{img_name}.jpg")
        dir_utils.remove_file(f"{img_name}.png",
                              f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    log(INFO,
        INFO_IMG_DOWNLOADED,
        origin=L_GENERAL,
        print_mode=PrintMode.VERBOSE_PRINT.value)
コード例 #2
0
ファイル: sound_board.py プロジェクト: mwalbeck/JJMumbleBot
 def cmd_sbdelete(self, data):
     all_data = data.message.strip().split()
     if len(all_data) == 2:
         audio_clip = sbu.find_file(all_data[1].strip())
         if audio_clip:
             dir_utils.remove_file(audio_clip, f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/")
             gs.gui_service.quick_gui(f"Deleted sound clip : {audio_clip}", text_type='header',
                                      box_align='left')
コード例 #3
0
def delete_ini(plugin_name) -> bool:
    if path.exists(
            f'{dir_utils.get_plugin_data_dir()}/{plugin_name}/{plugin_name}.ini'
    ):
        dir_utils.remove_file(
            f'{plugin_name}.ini',
            f'{dir_utils.get_plugin_data_dir()}/{plugin_name}/')
        return True
    return False
コード例 #4
0
 def cmd_ttsdelete(self, data):
     all_data = data.message.strip().split(' ', 1)
     if ".wav" in all_data[1].strip():
         dir_utils.remove_file(
             all_data[1].strip(),
             f"{dir_utils.get_perm_med_dir()}/{self.plugin_name}/")
         gs.gui_service.quick_gui(
             f"Deleted text-to-speech clip : {all_data[1].strip()}",
             text_type='header',
             box_align='left')
         return
     return
コード例 #5
0
ファイル: image_helper.py プロジェクト: yquemener/JJMumbleBot
def download_image_stream_to_dir(img_url, dir_name):
    dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    img_ext = img_url.rsplit('.', 1)[1]
    with open(f"{dir_utils.get_temp_med_dir()}/{dir_name}/_image.{img_ext}",
              'wb') as img_file:
        resp = requests.get(img_url, stream=True)
        for block in resp.iter_content(1024):
            if not block:
                break
            img_file.write(block)
    if img_ext == 'png':
        dprint(f"Fixing image to force jpg conversion: {img_url}")
        img_fix = Image.open(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/_image.{img_ext}")
        img_fix.convert('RGB').save(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/_image.jpg")
        dir_utils.remove_file("_image.png",
                              f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    dprint(f"Downloaded image from: {img_url}")
コード例 #6
0
def next_track():
    if GS.audio_inst is not None:
        if YoutubeHelper.queue_instance.is_empty():
            GS.gui_service.quick_gui(
                "The youtube queue is empty, so I can't go to the next song.",
                text_type='header',
                box_align='left')
            return
        GS.gui_service.quick_gui(
            "Going to next available track.",
            text_type='header',
            box_align='left')
        GS.log_service.info("The youtube audio queue moved to the next available track.")
        try:
            dir_utils.remove_file(f"{YoutubeHelper.current_song_info['img_id']}.jpg", f'{dir_utils.get_temp_med_dir()}/youtube')
        except FileNotFoundError:
            pass
        stop_audio()
        GS.audio_dni = (True, YoutubeHelper.yt_metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        download_next()
        play_audio()
        return
    return
コード例 #7
0
ファイル: image_helper.py プロジェクト: yquemener/JJMumbleBot
def download_image_requests_to_dir(img_url, dir_name):
    dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    img_ext = img_url.rsplit('.', 1)[1]
    s = requests.Session()
    r = s.get(img_url)
    if r.status_code == 200:
        with open(
                f"{dir_utils.get_temp_med_dir()}/{dir_name}/_image.{img_ext}",
                'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)
        dprint(f"Downloaded image from: {img_url}")
    else:
        dprint(f"{r.status_code} Error! - {img_url}")
    if img_ext == 'png':
        dprint(f"Fixing image to force jpg conversion: {img_url}")
        img_fix = Image.open(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/_image.{img_ext}")
        img_fix.convert('RGB').save(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/_image.jpg")
        dir_utils.remove_file("_image.png",
                              f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    dprint(f"Downloaded image from: {img_url}")
コード例 #8
0
ファイル: images.py プロジェクト: yquemener/JJMumbleBot
 def cmd_post(self, data):
     all_data = data.message.strip().split()
     img_url = all_data[1]
     # Download image
     img_url = ''.join(
         BeautifulSoup(img_url, 'html.parser').findAll(text=True))
     IH.download_image_stream(img_url)
     # Format image
     time.sleep(1)
     img_ext = img_url.rsplit('.', 1)[1]
     formatted_string = IH.format_image(
         "_image", img_ext, f'{dir_utils.get_temp_med_dir()}/images')
     rprint("Posting an image to the mumble channel chat.")
     # Display image with PGUI system
     gs.gui_service.quick_gui_img(
         f"{dir_utils.get_temp_med_dir()}/images",
         formatted_string,
         bgcolor=self.metadata[C_PLUGIN_SETTINGS][P_FRAME_COL],
         cellspacing=self.metadata[C_PLUGIN_SETTINGS][P_FRAME_SIZE],
         format_img=False)
     log(INFO,
         f"Posted an image to the mumble channel chat from: {img_url}.")
     dir_utils.remove_file("_image.jpg",
                           f'{dir_utils.get_temp_med_dir()}/images')
コード例 #9
0
ファイル: image_helper.py プロジェクト: DuckBoss/JJMumbleBot
def download_image_requests_to_dir(img_url,
                                   dir_name,
                                   img_name='_image',
                                   force_jpg=True):
    dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/{dir_name}')
    img_ext = img_url.rsplit('.', 1)[1]
    s = requests.Session()
    r = s.get(img_url)
    if r.status_code == 200:
        with open(
                f"{dir_utils.get_temp_med_dir()}/{dir_name}/{img_name}.{img_ext}",
                'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)
        log(INFO,
            INFO_IMG_DOWNLOADED,
            origin=L_GENERAL,
            print_mode=PrintMode.VERBOSE_PRINT.value)
    else:
        log(ERROR,
            f"ERROR: Encountered a Requests Module error while trying to download an image - {r.status_code} - {img_url}",
            origin=L_GENERAL,
            error_type=GEN_PROCESS_ERR,
            print_mode=PrintMode.VERBOSE_PRINT.value)
    if img_ext == 'png' and force_jpg:
        log(WARNING,
            WARN_IMG_INCORRECT_FORMAT,
            origin=L_GENERAL,
            error_type=WARN_FIXED_IMG_FORMAT,
            print_mode=PrintMode.VERBOSE_PRINT.value)
        img_fix = Image.open(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/{img_name}.{img_ext}")
        img_fix.convert('RGB').save(
            f"{dir_utils.get_temp_med_dir()}/{dir_name}/{img_name}.jpg")
        dir_utils.remove_file(f"{img_name}.png",
                              f'{dir_utils.get_temp_med_dir()}/{dir_name}')
コード例 #10
0
def play_audio():
    GS.audio_dni = (True, YoutubeHelper.yt_metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
    GS.mumble_inst.sound_output.clear_buffer()
    time.sleep(0.1)

    YoutubeHelper.current_song_info = YoutubeHelper.queue_instance.pop()
    if YoutubeHelper.current_song_info is None:
        stop_audio()
        return
    if YoutubeHelper.current_song_info['img_id'] is None:
        return
    YoutubeHelper.current_song = YoutubeHelper.current_song_info.get('main_url')

    stripped_url = BeautifulSoup(YoutubeHelper.current_song, features='html.parser').get_text()
    uri = stripped_url
    dprint(uri)
    dprint(YoutubeHelper.current_song)

    command = YoutubeHelper.yt_metadata[C_PLUGIN_SETTINGS][P_YT_VLC_DIR]

    thr = None
    if not YoutubeHelper.queue_instance.is_empty():
        thr = threading.Thread(target=download_next)
        thr.start()

    if GS.audio_inst:
        GS.audio_inst.terminate()
        GS.audio_inst.kill()
        GS.audio_inst = None

    if GS.audio_inst is None:
        use_stereo = GS.cfg.getboolean(C_MAIN_SETTINGS, P_AUD_STEREO)
        dprint(f"USE STEREO: {use_stereo}")
        if use_stereo:
            GS.audio_inst = sp.Popen(
                [command, uri] + ['-I', 'dummy', f'{"--quiet" if YoutubeHelper.yt_metadata.getboolean(C_PLUGIN_SETTINGS, P_YT_VLC_QUIET, fallback=True) else ""}',
                                  '--one-instance', f'{"--no-repeat" if YoutubeHelper.loop_song is False else "--repeat"}', '--sout',
                                  '#transcode{acodec=s16le, channels=2, '
                                  'samplerate=48000, ab=192, threads=8}:std{access=file, '
                                  'mux=wav, dst=-}',
                                  'vlc://quit'],
                stdout=sp.PIPE, bufsize=1024)
        else:
            GS.audio_inst = sp.Popen(
                [command, uri] + ['-I', 'dummy', f'{"--quiet" if YoutubeHelper.yt_metadata.getboolean(C_PLUGIN_SETTINGS, P_YT_VLC_QUIET, fallback=True) else ""}',
                                  '--one-instance', f'{"--no-repeat" if YoutubeHelper.loop_song is False else "--repeat"}', '--sout',
                                  '#transcode{acodec=s16le, channels=2, '
                                  'samplerate=24000, ab=192, threads=8}:std{access=file, '
                                  'mux=wav, dst=-}',
                                  'vlc://quit'],
                stdout=sp.PIPE, bufsize=1024)
    # YoutubeHelper.music_thread.wait()
    YoutubeHelper.is_playing = True
    runtime_utils.unmute()
    try:
        GS.gui_service.quick_gui_img(f"{dir_utils.get_temp_med_dir()}/youtube",
                                     f"{YoutubeHelper.current_song_info['img_id']}",
                                     caption=f"Now playing: {YoutubeHelper.current_song_info['main_title']}",
                                     format_img=True,
                                     img_size=32768)
    except FileNotFoundError:
        GS.gui_service.quick_gui(f"Thumbnail Image Unavailable<br>Now playing: {YoutubeHelper.current_song_info['img_id']}",
                                text_type='header',
                                box_align='left')

    while not YoutubeHelper.exit_flag and GS.mumble_inst.isAlive():
        while GS.mumble_inst.sound_output.get_buffer_size() > 0.5 and not YoutubeHelper.exit_flag:
            time.sleep(0.01)
        if GS.audio_inst:
            raw_music = GS.audio_inst.stdout.read(1024)
            if raw_music and GS.audio_inst and YoutubeHelper.is_playing:
                GS.mumble_inst.sound_output.add_sound(audioop.mul(raw_music, 2, YoutubeHelper.volume))
            else:
                if not YoutubeHelper.autoplay:
                    YoutubeHelper.is_playing = False
                    if thr:
                        thr.join()
                    try:
                        dir_utils.remove_file(f"{YoutubeHelper.current_song_info['img_id']}.jpg",
                                              f'{dir_utils.get_temp_med_dir()}/youtube')
                        if YoutubeHelper.queue_instance.size() < 1:
                            dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/youtube')
                    except (FileNotFoundError, TypeError):
                        pass
                    download_next()
                    return
                YoutubeHelper.is_playing = False
                if thr:
                    thr.join()
                try:
                    dir_utils.remove_file(f"{YoutubeHelper.current_song_info['img_id']}.jpg",
                                          f'{dir_utils.get_temp_med_dir()}/youtube')
                    if YoutubeHelper.queue_instance.size() < 1:
                        dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/youtube')
                except (FileNotFoundError, TypeError):
                    pass
                download_next()
                play_audio()
                return
        else:
            return
    return
コード例 #11
0
    def process(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        command = message_parse[0]

        if command == "ttsstop":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            if tts_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
                ttsu.stop_audio()
                GS.gui_service.quick_gui(
                    "Stopping text to speech audio thread...",
                    text_type='header',
                    box_align='left')
                return

        elif command == "ttsv":
            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 text to speech volume: {tts_settings.volume}",
                    text_type='header',
                    box_align='left')
                return
            if vol > 1:
                GS.gui_service.quick_gui(
                    "Invalid text to speech volume Input: [0-1]",
                    text_type='header',
                    box_align='left')
                return
            if vol < 0:
                GS.gui_service.quick_gui(
                    "Invalid text to speech volume Input: [0-1]",
                    text_type='header',
                    box_align='left')
                return
            tts_settings.volume = vol
            GS.gui_service.quick_gui(
                f"Set text to speech volume to {tts_settings.volume}",
                text_type='header',
                box_align='left')

        elif command == "ttslist":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            internal_list = []
            gather_list = ttsu.prepare_tts_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 TTS Files:</font>"
            if len(internal_list) == 0:
                cur_text += "<br>There are no local text to speech files available."
                GS.gui_service.quick_gui(
                    cur_text,
                    text_type='header',
                    box_align='left',
                    user=GS.mumble_inst.users[text.actor]['name'])
                GS.log_service.info(
                    "Displayed a list of all local text to speech 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 text to speech files.",
                origin=L_COMMAND)

        elif command == "ttslist_echo":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            internal_list = []
            gather_list = ttsu.prepare_tts_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 TTS Files:</font>"
            if len(internal_list) == 0:
                cur_text += "<br>There are no local text to speech files available."
                GS.gui_service.quick_gui(cur_text,
                                         text_type='header',
                                         box_align='left')
                log(INFO,
                    "Displayed a list of all local text to speech files.",
                    origin=L_COMMAND)
                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 text to speech board files.",
                origin=L_COMMAND)

        elif command == "ttsvoices":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            if len(tts_settings.voice_list) == 0:
                cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Available Voices:</font> None"
                GS.gui_service.quick_gui(cur_text,
                                         text_type='header',
                                         box_align='left')
                log(INFO,
                    "Displayed a list of all available text to speech voices.",
                    origin=L_COMMAND)
                return
            cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Available Voices:</font>"
            for i, voice_name in enumerate(tts_settings.voice_list):
                cur_text += f"[{i}] - {voice_name}<br>"
            GS.gui_service.quick_gui(cur_text,
                                     text_type='header',
                                     box_align='left')
            log(INFO,
                "Displayed a list of all available text to speech voices.",
                origin=L_COMMAND)

        elif command == "ttsdownload":
            from JJMumbleBot.plugins.extensions.text_to_speech.resources.strings import P_VLC_DIR

            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            all_messages = message[1:].split(' ', 3)
            if ttsu.download_clip(all_messages[1].strip(),
                                  all_messages[2].strip(),
                                  all_messages[3].strip()):
                GS.gui_service.quick_gui(
                    f"Downloaded text to speech clip as : {all_messages[1].strip()}.oga",
                    text_type='header',
                    box_align='left')
                return

        elif command == "ttsdelete":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            all_messages = message[1:].split()
            if len(all_messages) == 2:
                if ".oga" in all_messages[1].strip():
                    dir_utils.remove_file(
                        all_messages[1].strip(),
                        f"{dir_utils.get_perm_med_dir()}/text_to_speech/")
                    GS.gui_service.quick_gui(
                        f"Deleted text to speech clip : {all_messages[1].strip()}",
                        text_type='header',
                        box_align='left')
                    return
                return

        elif command == "ttsplay":
            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
            parameter = message_parse[1].strip()
            if not os.path.isfile(
                    f"{dir_utils.get_perm_med_dir()}/text_to_speech/{parameter}.oga"
            ):
                GS.gui_service.quick_gui(
                    "The text to speech clip does not exist.",
                    text_type='header',
                    box_align='left')
                return False
            tts_settings.current_track = parameter
            ttsu.play_audio()

        elif command == "ttsplayquiet":
            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]:
                    return
            parameter = message_parse[1].strip()
            if not os.path.isfile(
                    f"{dir_utils.get_perm_med_dir()}/text_to_speech/{parameter}.oga"
            ):
                return False
            tts_settings.current_track = parameter
            ttsu.play_audio()

        elif command == "tts":
            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
            all_messages = message[1:].split(' ', 2)
            if all_messages[1].strip() in tts_settings.voice_list:
                all_messages = message[1:].split(' ', 2)
            else:
                all_messages = message[1:].split(' ', 1)

            if len(all_messages) == 2:
                if len(all_messages[1]) > int(
                        self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]):
                    GS.gui_service.quick_gui(
                        f"The text to speech message exceeded the character limit:"
                        f" [{self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]}].",
                        text_type='header',
                        box_align='left',
                        user=GS.mumble_inst.users[text.actor]['name'])
                    return
                if ttsu.download_clip(
                        "_temp",
                        self.metadata[C_PLUGIN_SETTINGS][P_TTS_DEF_VOICE],
                        all_messages[1].strip(),
                        directory=f'{dir_utils.get_temp_med_dir()}'):
                    tts_settings.current_track = "_temp"
                    ttsu.play_audio(mode=0)
                    return
            elif len(all_messages) == 3:
                if len(all_messages[1]) > int(
                        self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]):
                    GS.gui_service.quick_gui(
                        f"The text to speech message exceeded the character limit:"
                        f" [{self.metadata[C_PLUGIN_SETTINGS][P_TTS_MSG_CHR_LIM]}].",
                        text_type='header',
                        box_align='left',
                        user=GS.mumble_inst.users[text.actor]['name'])
                    return
                if ttsu.download_clip(
                        "_temp",
                        all_messages[1].strip(),
                        all_messages[2].strip(),
                        directory=f'{dir_utils.get_temp_med_dir()}'):
                    tts_settings.current_track = "_temp"
                    ttsu.play_audio(mode=0)
                    return
            GS.gui_service.quick_gui(
                f"Incorrect Format:<br>!tts 'voice_name' 'message'<br>OR<br>!tts 'message'",
                text_type='header',
                box_align='left',
                user=GS.mumble_inst.users[text.actor]['name'])
コード例 #12
0
    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')
コード例 #13
0
ファイル: __main__.py プロジェクト: DuckBoss/JJMumbleBot
    if args.safe_mode:
        global_settings.safe_mode = True
    elif args.verbose_mode:
        global_settings.verbose_mode = True
    if global_settings.verbose_mode and global_settings.quiet_mode:
        raise SysArgError(
            "It looks like both verbose mode and quiet mode are enabled.\n"
            "Only one or the other can be used!")

    if not path.exists(f'{dir_utils.get_main_dir()}/cfg/'):
        dir_utils.make_directory(f'{dir_utils.get_main_dir()}/cfg/')

    if args.force_defaults:
        dir_utils.clear_directory(f'{dir_utils.get_main_dir()}/cfg/')
    if args.regenerate_database:
        dir_utils.remove_file('jjmumblebot.db',
                              f'{dir_utils.get_main_dir()}/cfg/')

    if not path.exists(f'{dir_utils.get_main_dir()}/cfg/config.ini'):
        copy(f'{dir_utils.get_main_dir()}/templates/config_template.ini',
             f'{dir_utils.get_main_dir()}/cfg/config.ini')
    if not path.exists(f'{dir_utils.get_main_dir()}/cfg/custom_aliases.csv'):
        copy(f'{dir_utils.get_main_dir()}/templates/aliases_template.csv',
             f'{dir_utils.get_main_dir()}/cfg/custom_aliases.csv')
    if not path.exists(
            f'{dir_utils.get_main_dir()}/cfg/custom_permissions.csv'):
        copy(f'{dir_utils.get_main_dir()}/templates/permissions_template.csv',
             f'{dir_utils.get_main_dir()}/cfg/custom_permissions.csv')
    if not path.exists(
            f'{dir_utils.get_main_dir()}/cfg/custom_user_privileges.csv'):
        copy(
            f'{dir_utils.get_main_dir()}/templates/user_privileges_template.csv',