Exemple #1
0
    def cmd_sbnow(self, data):
        all_data = data.message.strip().split()
        if len(all_data) < 2:
            return

        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']
        to_play = all_data[1].strip()
        audio_clip = sbu.find_file(to_play)
        if not audio_clip:
            gs.gui_service.quick_gui(
                f"The sound clip '{to_play}' does not exist.",
                text_type='header',
                box_align='left')
            gs.aud_interface.clear_dni()
            return
        track_obj = TrackInfo(
            uri=
            f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
            alt_uri=
            f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
            name=to_play,
            sender=sender,
            duration=None,
            track_type=TrackType.FILE,
            quiet=False)
        gs.aud_interface.enqueue_track(track_obj=track_obj,
                                       to_front=False,
                                       quiet=True)
        gs.aud_interface.play(audio_lib=AudioLibrary.FFMPEG, override=True)
Exemple #2
0
    def cmd_sbdownload(self, data):
        data_stripped = BeautifulSoup(data.message.strip(),
                                      features='html.parser').get_text()
        all_data = data_stripped.split()

        if len(all_data) >= 3:
            if "youtube.com" in data_stripped or "youtu.be" in data_stripped:
                if sbu.find_file(all_data[2].strip()):
                    gs.gui_service.quick_gui(
                        f"A sound clip with the name {all_data[2].strip()} already exists!",
                        text_type='header',
                        box_align='left')
                    return
                if len(all_data) == 4:
                    time_range = all_data[3].strip().split('-')
                    if time_range:
                        sbu.download_clip(
                            all_data[1],
                            all_data[2].strip(),
                            time_range=time_range,
                            ffmpeg_path=gs.cfg[C_MEDIA_SETTINGS]
                            [P_MEDIA_FFMPEG_PATH],
                            proxy=gs.cfg[C_MEDIA_SETTINGS][P_MEDIA_PROXY_URL])
                        gs.gui_service.quick_gui(
                            f"Downloaded sound clip as : {all_data[2].strip()}[{time_range[0]}-{time_range[1]}]",
                            text_type='header',
                            box_align='left')
                    else:
                        gs.gui_service.quick_gui(
                            f"Incorrect Formatting! Format: {get_command_token()}sbdownload 'youtube_link' 'file_name' 'XXh:XXm:XXs-XXh:XXm:XXs",
                            text_type='header',
                            box_align='left')
                else:
                    if "youtube.com" in data_stripped or "youtu.be" in all_data[
                            1]:
                        sbu.download_clip(
                            all_data[1],
                            all_data[2].strip(),
                            ffmpeg_path=gs.cfg[C_MEDIA_SETTINGS]
                            [P_MEDIA_FFMPEG_PATH],
                            proxy=gs.cfg[C_MEDIA_SETTINGS][P_MEDIA_PROXY_URL])
                        gs.gui_service.quick_gui(
                            f"Downloaded sound clip as : {all_data[2].strip()}",
                            text_type='header',
                            box_align='left')
                    else:
                        gs.gui_service.quick_gui(
                            f"Incorrect Formatting! Format: {get_command_token()}sbdownload 'youtube_link' 'file_name' 'XXh:XXm:XXs-XXh:XXm:XXs",
                            text_type='header',
                            box_align='left')
            else:
                gs.gui_service.quick_gui(
                    f"The given link was not identified as a youtube link!",
                    text_type='header',
                    box_align='left')
        else:
            gs.gui_service.quick_gui(
                f"Incorrect Formatting! Format: {get_command_token()}sbdownload 'youtube_link' 'file_name' 'XXh:XXm:XXs-XXh:XXm:XXs'(optional)",
                text_type='header',
                box_align='left')
Exemple #3
0
    def clbk_user_connected(self, user):
        # Return if playing audio clips on user join is disabled.
        if not self.metadata.getboolean(
                C_PLUGIN_SET, P_PLAY_AUDIO_CLIP_ON_USER_JOIN, fallback=False):
            return

        if gs.aud_interface.check_dni(self.plugin_name, quiet=True):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        to_play = None
        # If playing the same clip on user join is enabled, load the generic clip name.
        # Otherwise, load the clip name set to the user.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_SAME_CLIP_ON_USER_JOIN,
                                    fallback=True):
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]
        else:
            to_play = st_settings.user_connections.get(user[0]['name'])

        # If to_play doesn't exist, that means the user is not on the user_connections.csv file.
        # use the generic clip when the user isn't on the list.
        if not to_play:
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]

        # If the clip is only allowed to play when other users are in the channel
        # and no users are present, clear DNI and return.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_CLIP_ONLY_IF_USERS_IN_CHANNEL,
                                    fallback=True):
            if len(get_users_in_my_channel()) <= 1:
                gs.aud_interface.clear_dni()
                return

        # Find and load the clip, then play it.
        audio_clip = find_file(to_play)
        if not path.exists(
                f"{dir_utils.get_perm_med_dir()}/{sb_plugin_name}/{audio_clip}"
        ):
            gs.aud_interface.clear_dni()
            gs.gui_service.quick_gui(
                f"The audio clip: {to_play} could not be found.",
                text_type='header',
                box_align='left')
            return
        track_obj = TrackInfo(
            uri=f'{dir_utils.get_perm_med_dir()}/{sb_plugin_name}/{audio_clip}',
            name=to_play,
            sender=get_bot_name(),
            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=True)
Exemple #4
0
    def cmd_sbdownload(self, data):
        data_stripped = BeautifulSoup(data.message.strip(),
                                      features='html.parser').get_text()
        all_data = data_stripped.split()

        if len(all_data) == 3:
            if "youtube.com" in data_stripped or "youtu.be" in data_stripped:
                if sbu.find_file(all_data[2].strip):
                    gs.gui_service.quick_gui(
                        f"A sound clip with the name {all_data[2].strip()} already exists!",
                        text_type='header',
                        box_align='left')
                    return
                sbu.download_clip(
                    all_data[1],
                    all_data[2].strip(),
                    proxy=gs.cfg[C_MEDIA_SETTINGS][P_MEDIA_PROXY_URL])
                gs.gui_service.quick_gui(
                    f"Downloaded sound clip as : {all_data[2].strip()}",
                    text_type='header',
                    box_align='left')
            else:
                gs.gui_service.quick_gui(
                    f"The given link was not identified as a youtube link!",
                    text_type='header',
                    box_align='left')
        else:
            gs.gui_service.quick_gui(
                f"Incorrect Formatting! Format: {get_command_token()}sbdownload 'youtube_link' 'file_name'",
                text_type='header',
                box_align='left')
Exemple #5
0
 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')
Exemple #6
0
 def cmd_setdefaultloginsound(self, data):
     all_data = data.message.strip().split(' ', 1)
     data_actor = gs.mumble_inst.users[data.actor]
     if len(all_data) != 2:
         log(ERROR,
             CMD_INVALID_SET_USER_DEFAULT_CONNECTION,
             origin=L_COMMAND,
             error_type=CMD_PROCESS_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(CMD_INVALID_SET_USER_DEFAULT_CONNECTION,
                                  text_type='header',
                                  box_align='left',
                                  user=data_actor['name'])
         return
     audio_clip_name = all_data[1]
     if not find_file(audio_clip_name):
         log(ERROR,
             f"{audio_clip_name} is not one of the available files in the sound board permanent directory.",
             origin=L_COMMAND,
             error_type=CMD_PROCESS_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(
             f"{audio_clip_name} is not one of the available files in the sound board permanent directory.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
         return
     self.metadata[C_PLUGIN_SET][
         P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN] = audio_clip_name
     try:
         with open(
                 f'{dir_utils.get_core_plugin_dir()}/{self.plugin_name}/metadata.ini',
                 'w') as metadata_file:
             self.metadata.write(metadata_file)
         self.metadata = PluginUtilityService.process_metadata(
             f'plugins/core/{self.plugin_name}')
         log(INFO,
             f"Updated the default user connection sound and saved the {self.plugin_name} metadata to the metadata.ini file.",
             origin=L_COMMAND,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(
             f"Updated the default user connection sound and saved the {self.plugin_name} metadata to the metadata.ini file.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
     except IOError:
         log(ERROR,
             f"There was an error saving the {self.plugin_name} metadata to the metadata.ini file.",
             origin=L_COMMAND,
             error_type=CMD_PROCESS_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(
             f"There was an error saving the {self.plugin_name} metadata to the metadata.ini file.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
         return
Exemple #7
0
 def cmd_setdefaultconnectionsound(self, data):
     all_data = data.message.strip().split(' ', 1)
     data_actor = gs.mumble_inst.users[data.actor]
     if len(all_data) != 2:
         gs.gui_service.quick_gui(
             f"Incorrect Formatting!"
             f"<br>Format: {get_command_token()}setdefaultconnectionsound 'audio_clip_name'",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
         return
     audio_clip_name = all_data[1]
     if not find_file(audio_clip_name):
         gs.gui_service.quick_gui(
             f"{audio_clip_name} is not one of the available files in the sound board permanent directory.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
         return
     self.metadata[C_PLUGIN_SET][
         P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN] = audio_clip_name
     try:
         with open(
                 f'{dir_utils.get_main_dir()}/plugins/extensions/{self.plugin_name}/metadata.ini',
                 'w') as metadata_file:
             self.metadata.write(metadata_file)
         self.metadata = PluginUtilityService.process_metadata(
             f'plugins/extensions/{self.plugin_name}')
         gs.gui_service.quick_gui(
             f"Updated the default user connection sound and saved the {self.plugin_name} metadata to the metadata.ini file.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
     except IOError:
         gs.gui_service.quick_gui(
             f"There was an error saving the {self.plugin_name} metadata to the metadata.ini file.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])
         return
Exemple #8
0
 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))
Exemple #9
0
    def clbk_user_connected(self, user):
        # Display the welcome message to the user if any.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_USE_WELCOME_MSG,
                                    fallback=False):
            if len(self.metadata[C_PLUGIN_SET][P_WELCOME_MSG]) > 0:
                gs.gui_service.quick_gui(
                    f"{self.metadata[C_PLUGIN_SET][P_WELCOME_MSG]}",
                    text_type='header',
                    box_align='left',
                    user=user[0]['name'])

        # Return if the user that connected is the bot (self-detection).
        if len(get_users_in_my_channel()) == 1:
            return

        # Return if playing audio clips on user join is disabled.
        if not self.metadata.getboolean(
                C_PLUGIN_SET, P_PLAY_AUDIO_CLIP_ON_USER_JOIN, fallback=False):
            return

        if gs.aud_interface.check_dni(self.plugin_name, quiet=True):
            gs.aud_interface.set_dni(
                self.plugin_name, self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
        else:
            return

        to_play = None
        # If playing the same clip on user join is enabled, load the generic clip name.
        # Otherwise, load the clip name set to the user.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_SAME_CLIP_ON_USER_JOIN,
                                    fallback=True):
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]
        else:
            to_play = st_settings.user_connections.get(user[0]['name'])

        # If to_play doesn't exist, that means the user is not on the user_connections.csv file.
        # use the built-in clip when the user isn't on the list.
        if not to_play:
            to_play = self.metadata[C_PLUGIN_SET][
                P_GENERIC_CLIP_TO_PLAY_ON_USER_JOIN]

        # If the clip is only allowed to play when other users are in the channel
        # and no users are present, clear DNI and return.
        if self.metadata.getboolean(C_PLUGIN_SET,
                                    P_PLAY_CLIP_ONLY_IF_USERS_IN_CHANNEL,
                                    fallback=True):
            if len(get_users_in_my_channel()) <= 1:
                gs.aud_interface.clear_dni()
                return

        # Find and load the clip, then play it.
        audio_clip = find_file(to_play)
        if not audio_clip:
            if not self.metadata.getboolean(
                    C_PLUGIN_SET, P_USE_BUILT_IN_CLIP, fallback=True):
                gs.aud_interface.clear_dni()
                log(ERROR,
                    f"The audio clip: {to_play} for the user connection sound could not be found.",
                    origin=L_COMMAND,
                    error_type=CMD_PROCESS_ERR,
                    print_mode=PrintMode.VERBOSE_PRINT.value)
                gs.gui_service.quick_gui(
                    f"The audio clip: {to_play} for the user connection sound could not be found.",
                    text_type='header',
                    box_align='left')
                return
            track_obj = TrackInfo(
                uri=
                f'{dir_utils.get_core_plugin_dir()}/server_tools/resources/default_user_sound.wav',
                alt_uri=
                f'{dir_utils.get_core_plugin_dir()}/server_tools/resources/default_user_sound.wav',
                name='default_user_sound.wav',
                sender=get_bot_name(),
                duration=None,
                track_type=TrackType.FILE,
                quiet=True)
        else:
            # If the plugin is set to use sound board clips, retrieve the clip from the sound board media directory.
            if self.metadata.getboolean(C_PLUGIN_SET,
                                        P_USE_SOUNDBOARD_CLIPS,
                                        fallback=True):
                track_obj = TrackInfo(
                    uri=
                    f'{dir_utils.get_perm_med_dir()}/sound_board/{audio_clip}',
                    alt_uri=
                    f'{dir_utils.get_perm_med_dir()}/sound_board/{audio_clip}',
                    name=to_play,
                    sender=get_bot_name(),
                    duration=None,
                    track_type=TrackType.FILE,
                    quiet=True)
            else:
                # Otherwise, retrieve the clip from the server tools plugin media directory.
                track_obj = TrackInfo(
                    uri=
                    f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
                    alt_uri=
                    f'{dir_utils.get_perm_med_dir()}/{self.plugin_name}/{audio_clip}',
                    name=to_play,
                    sender=get_bot_name(),
                    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=True)