Exemplo n.º 1
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)
Exemplo n.º 2
0
def main():
    return render_template(
        'index.html',
        server_ip=global_settings.cfg[C_WEB_SETTINGS][P_WEB_IP],
        server_port=int(global_settings.cfg[C_WEB_SETTINGS][P_WEB_PAGE_PORT]),
        socket_port=int(global_settings.cfg[C_WEB_SETTINGS][P_WEB_SOCK_PORT]),
        bot_name=get_bot_name(),
        command_token=global_settings.cfg[C_MAIN_SETTINGS][P_CMD_TOKEN],
        plugins=list(global_settings.bot_plugins))
Exemplo n.º 3
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)
Exemplo n.º 4
0
 async def general_api(self):
     return ResponseModel(
         200, "success",
         {"name": get_bot_name(), "command_token": global_settings.cfg[C_MAIN_SETTINGS][P_CMD_TOKEN]}
     ).toDict()
 #endregion
Exemplo n.º 5
0
 async def get_name(self):
     return ResponseModel(
         200, "success",
         {"name": get_bot_name()}
     ).toDict()