Esempio n. 1
0
def refresh_plugins():
    from JJMumbleBot.lib.helpers.bot_service_helper import BotServiceHelper
    from JJMumbleBot.lib import database
    dprint("Refreshing all plugins...")
    log(INFO, f"{META_NAME} is refreshing all plugins....")
    global_settings.gui_service.quick_gui(
        f"{get_bot_name()} is refreshing all plugins.",
        text_type='header',
        box_align='left',
        ignore_whisper=True)
    for plugin in global_settings.bot_plugins.values():
        plugin.quit()
    global_settings.bot_plugins.clear()
    if global_settings.safe_mode:
        BotServiceHelper.initialize_plugins_safe()
    else:
        BotServiceHelper.initialize_plugins()
    database.init_database()
    dprint("All plugins refreshed.")
    global_settings.gui_service.quick_gui(
        f"{get_bot_name()} has refreshed all plugins.",
        text_type='header',
        box_align='left',
        ignore_whisper=True)
    log(INFO, f"{META_NAME} has refreshed all plugins.")
Esempio n. 2
0
 def __init__(self):
     # Initialize bot services.
     global_settings.bot_service = self
     # Initialize user settings.
     BotServiceHelper.initialize_settings()
     # Initialize logging services.
     initialize_logging()
     log(INFO, "###########################")
     log(INFO, "Initializing JJMumbleBot...")
     # Check and classify system arguments.
     import JJMumbleBot.core.cla_classifier as cla
     cla.classify()
     # Initialize up-time tracking.
     runtime_helper.start_time = datetime.now()
     # Set maximum multi-command limit.
     runtime_settings.multi_cmd_limit = int(
         global_settings.cfg[C_MAIN_SETTINGS][P_CMD_MULTI_LIM])
     # Initialize command queue limit.
     global_settings.cmd_queue = QueueHandler(runtime_settings.cmd_hist_lim)
     # Initialize command history tracking.
     global_settings.cmd_history = CMDQueue(runtime_settings.cmd_hist_lim)
     # Initialize bot database.
     global_settings.mumble_db = init_database()
     # Initialize major directories.
     dir_utils.make_directory(
         global_settings.cfg[C_MEDIA_DIR][P_TEMP_MED_DIR])
     dir_utils.make_directory(
         f'{global_settings.cfg[C_MEDIA_DIR][P_TEMP_MED_DIR]}/internal/images'
     )
     dir_utils.make_directory(
         f'{global_settings.cfg[C_MEDIA_DIR][P_TEMP_MED_DIR]}/internal/audio'
     )
     log(INFO, "Initialized temporary directories.")
     # Initialize PGUI system.
     global_settings.gui_service = PseudoGUI()
     log(INFO, "Initialized PGUI.")
     # Initialize plugins.
     if global_settings.safe_mode:
         BotServiceHelper.initialize_plugins_safe()
         runtime_settings.tick_rate = 0.2
         log(INFO, "Initialized plugins with safe mode.")
     else:
         BotServiceHelper.initialize_plugins()
         log(INFO, "Initialized all plugins.")
     log(INFO, "###########################")
     # Retrieve mumble client data from configs.
     mumble_login_data = BotServiceHelper.retrieve_mumble_data()
     BotService.initialize_mumble(mumble_login_data)
     # Start runtime loop.
     BotService.loop()
Esempio n. 3
0
    def __init__(self):
        # Initialize bot services.
        global_settings.bot_service = self
        # Initialize user settings.
        BotServiceHelper.initialize_settings()
        # Initialize logging services.
        initialize_logging()

        log(INFO,
            "######### Initializing JJMumbleBot #########",
            origin=L_STARTUP)
        rprint("######### Initializing JJMumbleBot #########",
               origin=L_STARTUP)
        # Initialize up-time tracking.
        runtime_settings.start_time = datetime.now()
        # Set maximum multi-command limit.
        runtime_settings.multi_cmd_limit = int(
            global_settings.cfg[C_MAIN_SETTINGS][P_CMD_MULTI_LIM])
        # Initialize command queue limit.
        global_settings.cmd_queue = QueueHandler(
            [], maxlen=runtime_settings.cmd_queue_lim)
        # Initialize command history tracking.
        global_settings.cmd_history = CMDQueue(runtime_settings.cmd_hist_lim)
        log(INFO,
            "######### Initializing Internal Database #########",
            origin=L_DATABASE)
        rprint("######### Initializing Internal Database #########",
               origin=L_DATABASE)
        # Back up internal database.
        if global_settings.cfg.getboolean(C_MAIN_SETTINGS,
                                          P_DB_BACKUP,
                                          fallback=False):
            db_backup = BotServiceHelper.backup_database()
            if db_backup:
                log(INFO,
                    f"Created internal database backup @ {db_backup}",
                    origin=L_DATABASE)
                rprint(f"Created internal database backup @ {db_backup}",
                       origin=L_DATABASE)
        # Initialize internal database.
        global_settings.mumble_db = init_database()
        log(INFO,
            "######### Initialized Internal Database #########",
            origin=L_DATABASE)
        rprint("######### Initialized Internal Database #########",
               origin=L_DATABASE)
        # Initialize major directories.
        dir_utils.make_directory(
            global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR])
        dir_utils.make_directory(
            f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/images'
        )
        dir_utils.make_directory(
            f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/audio'
        )
        log(INFO, "Initialized Temporary Directories.", origin=L_STARTUP)
        rprint("Initialized Temporary Directories.", origin=L_STARTUP)
        # Initialize PGUI system.
        global_settings.gui_service = PseudoGUI()
        log(INFO, "Initialized PGUI.", origin=L_STARTUP)
        rprint("Initialized PGUI.", origin=L_STARTUP)
        # Initialize VLC interface.
        global_settings.vlc_interface = VLCInterface()
        # Initialize plugins.
        if global_settings.safe_mode:
            BotServiceHelper.initialize_plugins_safe()
            runtime_settings.tick_rate = 0.2
            log(INFO, "Initialized plugins with safe mode.", origin=L_STARTUP)
            rprint("Initialized plugins with safe mode.", origin=L_STARTUP)
        else:
            BotServiceHelper.initialize_plugins()
            log(INFO, "Initialized all plugins.", origin=L_STARTUP)
            rprint("Initialized all plugins.", origin=L_STARTUP)
        log(INFO,
            "######### Initializing Mumble Client #########",
            origin=L_STARTUP)
        rprint("######### Initializing Mumble Client #########",
               origin=L_STARTUP)
        # Retrieve mumble client data from configs.
        mumble_login_data = BotServiceHelper.retrieve_mumble_data()
        BotService.initialize_mumble(mumble_login_data)
        log(INFO,
            "######### Initialized Mumble Client #########",
            origin=L_STARTUP)
        rprint("######### Initialized Mumble Client #########",
               origin=L_STARTUP)
        # Initialize web interface
        if global_settings.cfg.getboolean(
                C_WEB_SETTINGS,
                P_WEB_ENABLE) and global_settings.safe_mode is False:
            log(INFO,
                "######### Initializing Web Interface #########",
                origin=L_WEB_INTERFACE)
            rprint("######### Initializing Web Interface #########",
                   origin=L_WEB_INTERFACE)
            from JJMumbleBot.web import web_helper
            web_helper.initialize_web()
            log(INFO,
                "######### Initialized Web Interface #########",
                origin=L_WEB_INTERFACE)
            rprint("######### Initialized Web Interface #########",
                   origin=L_WEB_INTERFACE)
        # Start runtime loop.
        BotService.loop()
Esempio n. 4
0
    def __init__(self, serv_ip, serv_port, serv_pass):
        # Initialize bot services.
        global_settings.bot_service = self
        global_settings.clbk_service = CallbackService()
        # Initialize user settings.
        BotServiceHelper.initialize_settings()

        # Initialize logging services.
        initialize_logging()

        log(INFO, "######### Initializing JJMumbleBot",
            origin=L_STARTUP, print_mode=PrintMode.REG_PRINT.value)
        # Initialize up-time tracking.
        runtime_settings.start_time = datetime.now()
        # Set maximum multi-command limit.
        runtime_settings.multi_cmd_limit = int(global_settings.cfg[C_MAIN_SETTINGS][P_CMD_MULTI_LIM])
        # Initialize command queue limit.
        global_settings.cmd_queue = QueueHandler([], maxlen=runtime_settings.cmd_queue_lim)
        # Initialize command history tracking.
        global_settings.cmd_history = CMDQueue(runtime_settings.cmd_hist_lim)
        log(INFO, "######### Initializing Internal Database",
            origin=L_DATABASE, print_mode=PrintMode.REG_PRINT.value)
        # Back up internal database.
        if global_settings.cfg.getboolean(C_MAIN_SETTINGS, P_DB_BACKUP, fallback=False):
            db_backup = BotServiceHelper.backup_database()
            if db_backup:
                log(INFO, f"Created internal database backup @ {db_backup}",
                    origin=L_DATABASE, print_mode=PrintMode.REG_PRINT.value)
        # Initialize internal database.
        global_settings.mumble_db = init_database()
        log(INFO, "######### Initialized Internal Database",
            origin=L_DATABASE, print_mode=PrintMode.VERBOSE_PRINT.value)
        # Initialize major directories.
        if global_settings.cfg.get(C_MEDIA_SETTINGS, P_TEMP_MED_DIR, fallback=None):
            dir_utils.make_directory(global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR])
        else:
            dir_utils.make_directory(f'{dir_utils.get_main_dir()}/cfg/temporary_media_directory')
            global_settings.cfg[C_MEDIA_SETTINGS][
                P_TEMP_MED_DIR] = f'{dir_utils.get_main_dir()}/cfg/temporary_media_directory'
        if global_settings.cfg.get(C_MEDIA_SETTINGS, P_PERM_MEDIA_DIR, fallback=None):
            dir_utils.make_directory(global_settings.cfg[C_MEDIA_SETTINGS][P_PERM_MEDIA_DIR])
        else:
            dir_utils.make_directory(f'{dir_utils.get_main_dir()}/cfg/permanent_media_directory')
            global_settings.cfg[C_MEDIA_SETTINGS][
                P_PERM_MEDIA_DIR] = f'{dir_utils.get_main_dir()}/cfg/permanent_media_directory'
        dir_utils.make_directory(f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/images')
        dir_utils.make_directory(f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/audio')
        log(INFO, "######### Initialized Temporary Directories",
            origin=L_STARTUP, print_mode=PrintMode.VERBOSE_PRINT.value)
        # Initialize PGUI system.
        global_settings.gui_service = PseudoGUI()
        log(INFO, "######### Initialized PGUI",
            origin=L_STARTUP, print_mode=PrintMode.VERBOSE_PRINT.value)
        # Initialize VLC interface.
        global_settings.aud_interface = AudioLibraryInterface()
        # Initialize plugins.
        if global_settings.safe_mode:
            BotServiceHelper.initialize_plugins_safe()
            runtime_settings.tick_rate = 0.2
            log(INFO, "Initialized plugins with safe mode.",
                origin=L_STARTUP, print_mode=PrintMode.VERBOSE_PRINT.value)
        else:
            BotServiceHelper.initialize_plugins()
        log(INFO, "######### Initializing Mumble Client",
            origin=L_STARTUP, print_mode=PrintMode.VERBOSE_PRINT.value)
        # Retrieve mumble client data from configs.
        mumble_login_data = BotServiceHelper.retrieve_mumble_data(serv_ip, serv_port, serv_pass)
        self.initialize_mumble(mumble_login_data)
        log(INFO, "######### Initialized Mumble Client",
            origin=L_STARTUP, print_mode=PrintMode.VERBOSE_PRINT.value)
        # Start runtime loop.
        BotService.loop()
Esempio n. 5
0
    def __init__(self, serv_ip, serv_port, serv_pass):
        # Initialize bot services.
        global_settings.bot_service = self
        global_settings.clbk_service = CallbackService()
        # Initialize user settings.
        BotServiceHelper.initialize_settings()

        # Initialize logging directory if unavailable.
        if global_settings.cfg.get(C_LOGGING, P_LOG_DIR, fallback=None):
            dir_utils.make_directory(global_settings.cfg[C_LOGGING][P_LOG_DIR])
        else:
            dir_utils.make_directory(f'{dir_utils.get_main_dir()}/cfg/logs')
            global_settings.cfg[C_LOGGING][P_LOG_DIR] = f'{dir_utils.get_main_dir()}/cfg/logs'

        # Initialize logging services.
        initialize_logging()

        log(INFO, "######### Initializing JJMumbleBot #########", origin=L_STARTUP)
        rprint("######### Initializing JJMumbleBot #########", origin=L_STARTUP)
        # Initialize up-time tracking.
        runtime_settings.start_time = datetime.now()
        # Set maximum multi-command limit.
        runtime_settings.multi_cmd_limit = int(global_settings.cfg[C_MAIN_SETTINGS][P_CMD_MULTI_LIM])
        # Initialize command queue limit.
        global_settings.cmd_queue = QueueHandler([], maxlen=runtime_settings.cmd_queue_lim)
        # Initialize command history tracking.
        global_settings.cmd_history = CMDQueue(runtime_settings.cmd_hist_lim)
        log(INFO, "######### Initializing Internal Database #########", origin=L_DATABASE)
        rprint("######### Initializing Internal Database #########", origin=L_DATABASE)
        # Back up internal database.
        if global_settings.cfg.getboolean(C_MAIN_SETTINGS, P_DB_BACKUP, fallback=False):
            db_backup = BotServiceHelper.backup_database()
            if db_backup:
                log(INFO, f"Created internal database backup @ {db_backup}", origin=L_DATABASE)
                rprint(f"Created internal database backup @ {db_backup}", origin=L_DATABASE)
        # Initialize internal database.
        global_settings.mumble_db = init_database()
        log(INFO, "######### Initialized Internal Database #########", origin=L_DATABASE)
        rprint("######### Initialized Internal Database #########", origin=L_DATABASE)
        # Initialize major directories.
        if global_settings.cfg.get(C_MEDIA_SETTINGS, P_TEMP_MED_DIR, fallback=None):
            dir_utils.make_directory(global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR])
        else:
            dir_utils.make_directory(f'{dir_utils.get_main_dir()}/cfg/temporary_media_directory')
            global_settings.cfg[C_MEDIA_SETTINGS][
                P_TEMP_MED_DIR] = f'{dir_utils.get_main_dir()}/cfg/temporary_media_directory'
        if global_settings.cfg.get(C_MEDIA_SETTINGS, P_PERM_MEDIA_DIR, fallback=None):
            dir_utils.make_directory(global_settings.cfg[C_MEDIA_SETTINGS][P_PERM_MEDIA_DIR])
        else:
            dir_utils.make_directory(f'{dir_utils.get_main_dir()}/cfg/permanent_media_directory')
            global_settings.cfg[C_MEDIA_SETTINGS][
                P_PERM_MEDIA_DIR] = f'{dir_utils.get_main_dir()}/cfg/permanent_media_directory'
        dir_utils.make_directory(f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/images')
        dir_utils.make_directory(f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/audio')
        log(INFO, "######### Initialized Temporary Directories #########", origin=L_STARTUP)
        rprint("######### Initialized Temporary Directories #########", origin=L_STARTUP)
        # Initialize PGUI system.
        global_settings.gui_service = PseudoGUI()
        log(INFO, "######### Initialized PGUI #########", origin=L_STARTUP)
        rprint("######### Initialized PGUI #########", origin=L_STARTUP)
        # Initialize VLC interface.
        global_settings.aud_interface = AudioLibraryInterface()
        # Initialize plugins.
        if global_settings.safe_mode:
            BotServiceHelper.initialize_plugins_safe()
            runtime_settings.tick_rate = 0.2
            log(INFO, "Initialized plugins with safe mode.", origin=L_STARTUP)
            rprint("Initialized plugins with safe mode.", origin=L_STARTUP)
        else:
            BotServiceHelper.initialize_plugins()
        log(INFO, "######### Initializing Mumble Client #########", origin=L_STARTUP)
        rprint("######### Initializing Mumble Client #########", origin=L_STARTUP)
        # Retrieve mumble client data from configs.
        mumble_login_data = BotServiceHelper.retrieve_mumble_data(serv_ip, serv_port, serv_pass)
        self.initialize_mumble(mumble_login_data)
        log(INFO, "######### Initialized Mumble Client #########", origin=L_STARTUP)
        rprint("######### Initialized Mumble Client #########", origin=L_STARTUP)
        # Initialize web interface
        if global_settings.cfg.getboolean(C_WEB_SETTINGS, P_WEB_ENABLE, fallback=False) and global_settings.safe_mode is False:
            log(INFO, "######### Initializing Web Interface #########", origin=L_WEB_INTERFACE)
            rprint("######### Initializing Web Interface #########", origin=L_WEB_INTERFACE)
            from JJMumbleBot.lib.database import InsertDB
            from JJMumbleBot.lib.utils.database_management_utils import get_memory_db
            from JJMumbleBot.lib.privileges import Privileges
            if InsertDB.insert_new_user(db_conn=get_memory_db(),
                                        username=global_settings.cfg[C_CONNECTION_SETTINGS][P_USER_ID]):
                InsertDB.insert_new_permission(db_conn=get_memory_db(),
                                               username=global_settings.cfg[C_CONNECTION_SETTINGS][P_USER_ID],
                                               permission_level=int(Privileges.SUPERUSER.value))
            from JJMumbleBot.web import web_helper
            web_helper.initialize_web()
            log(INFO, "######### Initialized Web Interface #########", origin=L_WEB_INTERFACE)
            rprint("######### Initialized Web Interface #########", origin=L_WEB_INTERFACE)
        # Start runtime loop.
        BotService.loop()