Exemplo n.º 1
0
 def quit(self):
     if gs.aud_interface.check_dni_is_mine(self.plugin_name):
         gs.aud_interface.stop()
         gs.audio_dni = None
     self.is_running = False
     dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/{self.plugin_name}')
     log(INFO, f"Exiting {self.plugin_name} plugin...", origin=L_SHUTDOWN, print_mode=PrintMode.REG_PRINT.value)
Exemplo n.º 2
0
 def cmd_aliases(self, data):
     aliases_list = aliases.get_all_aliases()
     if len(aliases_list) == 0:
         cur_alias_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Registered Aliases: None</font>"
     else:
         cur_alias_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Registered Aliases:</font>"
         for i, alias in enumerate(aliases_list):
             cur_alias_text += f"<br><font color={GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}>[{alias[0]}]</font> - " \
                               f"[{BeautifulSoup(alias[1], 'html.parser').get_text()}] "
             if i % 50 == 0 and i != 0:
                 GS.gui_service.quick_gui(
                     cur_alias_text,
                     text_type='header',
                     box_align='left',
                     text_align='left',
                     ignore_whisper=True,
                     user=GS.mumble_inst.users[data.actor]['name'])
                 cur_alias_text = ""
     GS.gui_service.quick_gui(cur_alias_text,
                              text_type='header',
                              box_align='left',
                              text_align='left',
                              ignore_whisper=True,
                              user=GS.mumble_inst.users[data.actor]['name'])
     log(INFO,
         "Displayed all registered aliases.",
         origin=L_COMMAND,
         print_mode=PrintMode.VERBOSE_PRINT.value)
Exemplo n.º 3
0
def ban_user(receiver, reason='N/A'):
    user = get_user(receiver)
    if user:
        log(INFO,
            f"Banning user:[{user['name']}]->[{reason}]", origin=L_COMMAND,
            print_mode=PrintMode.VERBOSE_PRINT.value)
        user.ban(reason=reason)
Exemplo n.º 4
0
    def cmd_setcomment(self, data):
        from JJMumbleBot.lib.utils.dir_utils import get_main_dir
        all_data = data.message.strip().split(' ', 1)
        if len(all_data) != 2:
            log(ERROR,
                CMD_INVALID_SET_COMMENT,
                origin=L_COMMAND,
                error_type=CMD_INVALID_ERR,
                print_mode=PrintMode.VERBOSE_PRINT.value)
            GS.gui_service.quick_gui(
                CMD_INVALID_SET_COMMENT,
                text_type='header',
                box_align='left',
                ignore_whisper=True,
                user=GS.mumble_inst.users[data.actor]['name'])
            return
        new_comment = all_data[1]
        # Set the new comment.
        GS.mumble_inst.users.myself.comment(
            f'{new_comment}<br><br>[{META_NAME}({META_VERSION})] - {rutils.get_bot_name()}<br>{rutils.get_about()}'
        )
        # Write the new comment into the config file.
        GS.cfg.set(C_CONNECTION_SETTINGS, P_USER_COMMENT, new_comment)
        with open(f'{get_main_dir()}/cfg/config.ini', mode='w') as cfg_file:
            GS.cfg.write(cfg_file)

        GS.gui_service.quick_gui(f"Changed the bot's user comment.",
                                 text_type='header',
                                 box_align='left',
                                 ignore_whisper=True,
                                 user=GS.mumble_inst.users[data.actor]['name'])
        log(INFO,
            f"Changed the bot's user comment to: {new_comment}.",
            origin=L_COMMAND,
            print_mode=PrintMode.VERBOSE_PRINT.value)
Exemplo n.º 5
0
 def cmd_getpermission(self, data):
     all_data = data.message.strip().split(' ', 1)
     if len(all_data) != 2:
         log(ERROR,
             CMD_INVALID_GET_CMD_PERMISSION,
             origin=L_COMMAND,
             error_type=CMD_INVALID_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         GS.gui_service.quick_gui(
             CMD_INVALID_GET_CMD_PERMISSION,
             text_type='header',
             text_align='left',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
         return
     cmd_name = all_data[1].strip()
     cmd_data = get_command_privileges(cmd_name)
     if cmd_data:
         GS.gui_service.quick_gui(
             f"Command: {cmd_data['name']}<br>"
             f"Permission Level:{Privileges(int(cmd_data['level'])).name} ({cmd_data['level']})",
             text_type='header',
             text_align='left',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
     else:
         GS.gui_service.quick_gui(
             f"Error retrieving command information for: {cmd_name}",
             text_type='header',
             text_align='left',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
Exemplo n.º 6
0
def on_reset():
    # Clear the thumbnails since the queue is cleared.
    dir_utils.clear_directory(f'{dir_utils.get_temp_med_dir()}/{settings.plugin_name}')
    log(INFO, "Cleared the thumbnails in the temporary media folder when resetting audio interface.", origin=L_GENERAL,
        print_mode=PrintMode.VERBOSE_PRINT.value)
    settings.can_play = False
    settings.search_results = None
Exemplo n.º 7
0
 def cmd_img(self, data):
     all_data = data.message.strip().split()
     parameters = all_data[1].rsplit(".", 1)
     try:
         if not os.path.isfile(
                 f"{dir_utils.get_perm_med_dir()}/images/{parameters[0]}.{parameters[1]}"
         ):
             gs.gui_service.quick_gui("The image does not exist.",
                                      text_type='header',
                                      box_align='left')
             return False
     except IndexError:
         return False
     # Format image
     formatted_string = IH.format_image(
         parameters[0], parameters[1],
         f"{dir_utils.get_perm_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_perm_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,
         "Posted an image to the mumble channel chat from local files.")
Exemplo n.º 8
0
 def insert_new_plugins_help(db_conn,
                             plugin_name,
                             help_text,
                             ignore_file_save=False) -> bool:
     table_query = f"""
         INSERT INTO plugins_help(plugin_id, help_text)
         VALUES (
         (SELECT plugins.plugin_id FROM plugins WHERE plugins.name = ? LIMIT 1),
         ?
         );
     """
     try:
         db_conn.cursor().execute(table_query, (plugin_name, help_text))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(
                 f"Inserted new plugin help data into the database: {plugin_name}",
                 origin=L_DATABASE)
             log(INFO,
                 f"Inserted new plugin help data into the database: {plugin_name}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         if 'UNIQUE' not in str(err):
             dprint(err)
         return False
Exemplo n.º 9
0
 def insert_new_alias(db_conn,
                      alias_name,
                      commands,
                      ignore_file_save=False) -> bool:
     table_query = f"""
             INSERT INTO aliases(name, alias)
             VALUES (
             ?,
             ?
             );
         """
     try:
         db_conn.cursor().execute(table_query, (alias_name, commands))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(f"Inserted new alias into the database: {alias_name}",
                    origin=L_DATABASE)
             log(INFO,
                 f"Inserted new alias into the database: {alias_name}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         if 'UNIQUE' not in str(err):
             dprint(err)
         return False
Exemplo n.º 10
0
 def cmd_my_echo_command(self, data):
     text_to_echo = data.message.strip().split(' ', 1)[1]
     global_settings.gui_service.quick_gui(text_to_echo,
                                           text_type='header',
                                           box_align='left',
                                           ignore_whisper=True)
     log(INFO, f"Echo:[{text_to_echo}]", origin=L_GENERAL)
Exemplo n.º 11
0
 def insert_new_command(db_conn,
                        plugin_name,
                        command_name,
                        permission_level,
                        ignore_file_save=False) -> bool:
     table_query = f"""
         INSERT INTO commands(plugin_id, name, level)
         VALUES (
         (SELECT plugins.plugin_id FROM plugins WHERE plugins.name = ? LIMIT 1),
         ?,
         ?
         );
     """
     try:
         db_conn.cursor().execute(
             table_query, (plugin_name, command_name, permission_level))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(
                 f"Inserted new command into the database: {plugin_name}-{command_name}-{permission_level}",
                 origin=L_DATABASE)
             log(INFO,
                 f"Inserted new command into the database: {plugin_name}-{command_name}-{permission_level}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         if 'UNIQUE' not in str(err):
             dprint(err)
         return False
Exemplo n.º 12
0
 def cmd_replay(self, data):
     if gs.aud_interface.check_dni_active():
         gs.aud_interface.replay()
         log(INFO,
             INFO_AUDIO_REPLAYED,
             origin=L_COMMAND,
             print_mode=PrintMode.VERBOSE_PRINT.value)
Exemplo n.º 13
0
 def cmd_shuffle(self, data):
     if gs.aud_interface.check_dni_active():
         gs.aud_interface.shuffle()
         log(INFO,
             INFO_AUDIO_SHUFFLED,
             origin=L_COMMAND,
             print_mode=PrintMode.VERBOSE_PRINT.value)
Exemplo n.º 14
0
 def cmd_ytsearch(self, data):
     all_data = data.message.strip().split(' ', 1)
     try:
         search_term = all_data[1]
     except IndexError:
         log(ERROR,
             CMD_INVALID_YTSEARCH,
             origin=L_COMMAND,
             error_type=CMD_INVALID_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(CMD_INVALID_YTSEARCH,
                                  text_type='header',
                                  box_align='left')
         return
     gs.gui_service.quick_gui(
         f"Searching for '{search_term}'... please wait a moment.",
         text_type='header',
         box_align='left')
     search_results = md_utility.get_search_results(
         search_term,
         int(self.metadata[C_PLUGIN_SETTINGS][P_YT_MAX_SEARCH_LEN]))
     log(INFO, "Displayed youtube search results.", origin=L_COMMAND)
     results_text = f"<font color='{gs.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Search Results:</font><br>"
     for i, item in enumerate(search_results):
         results_text += item["formatted_title"]
     gs.gui_service.quick_gui(results_text,
                              text_type='header',
                              text_align='left',
                              box_align='left')
     md_settings.can_play = True
Exemplo n.º 15
0
def format_image_html(img_ext, byte_arr, quiet=False, src_only=False):
    if img_ext == "jpg":
        img_ext = "JPEG"
    elif img_ext == "jpeg":
        img_ext = "JPEG"
    elif img_ext == "png":
        img_ext = "PNG"

    raw_base = encode_b64(byte_arr)
    encoded = []
    i = 0

    begin = i * 72
    end = i * 72
    mid_raw_base = mid(raw_base, begin, 72)
    encoded.append(quote(mid_raw_base, safe=''))
    i += 1
    while end < len(raw_base):
        begin = i * 72
        end = i * 72
        mid_raw_base = mid(raw_base, begin, 72)
        encoded.append(quote(mid_raw_base, safe=''))
        i += 1
    if not quiet:
        log(INFO,
            INFO_IMG_HTML_FORMATTED,
            origin=L_GENERAL,
            print_mode=PrintMode.VERBOSE_PRINT.value)
    if src_only:
        return f"data:image/{img_ext};base64,{''.join(encoded)}"
    return f"<img src='data:image/{img_ext};base64,{''.join(encoded)}' />"
Exemplo n.º 16
0
 def insert_new_permission_level(db_conn,
                                 level_id: int,
                                 level_type: str,
                                 ignore_file_save=False) -> bool:
     table_query = f"""
         INSERT INTO permission_levels(level_id, level_type)
         VALUES (
         ?, 
         ?
         );
     """
     try:
         db_conn.cursor().execute(table_query, (level_id, level_type))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(
                 f"Inserted new permission level into the database: {level_id}-{level_type}",
                 origin=L_DATABASE)
             log(INFO,
                 f"Inserted new permission level into the database: {level_id}-{level_type}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         dprint(err)
         return False
Exemplo n.º 17
0
 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.")
Exemplo n.º 18
0
 def insert_new_permission(db_conn,
                           username: str,
                           permission_level: int,
                           ignore_file_save=False) -> bool:
     table_query = f"""
         INSERT INTO permissions(user_id, level)
         VALUES (
         (SELECT users.user_id FROM users WHERE users.name = ? LIMIT 1), 
         (SELECT permission_levels.level_id FROM permission_levels WHERE permission_levels.level_id = ? LIMIT 1)
         );
     """
     try:
         db_conn.cursor().execute(table_query, (username, permission_level))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(
                 f"Inserted new permission into the database: {username}-{permission_level}",
                 origin=L_DATABASE)
             log(INFO,
                 f"Inserted new permission into the database: {username}-{permission_level}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         dprint(err)
         return False
Exemplo n.º 19
0
def get_video_info(video_url):
    # Update the audio interface status with the media mrl, duration, and video title.
    try:
        ydl_opts = {
            'quiet': True,
            'format': 'bestaudio/best',
            'noplaylist': True,
            'skip_download': True,
            'proxy': gs.cfg[C_MEDIA_SETTINGS][P_MEDIA_PROXY_URL]
        }
        if runtime_settings.use_logging:
            ydl_opts['logger'] = gs.log_service
        if len(gs.cfg[C_MEDIA_SETTINGS][P_MEDIA_COOKIE_FILE]) > 0:
            ydl_opts['cookiefile'] = gs.cfg[C_MEDIA_SETTINGS][P_MEDIA_COOKIE_FILE]

        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.cache.remove()
            info_dict = ydl.extract_info(video_url, download=False)

            prep_struct = {
                'std_url': video_url,
                'main_url': info_dict['url'],
                'main_title': info_dict['title'],
                'main_id': info_dict['id'],
                'duration': info_dict['duration']
            }
            return prep_struct
    except youtube_dl.utils.DownloadError as e:
        log(ERROR, f"Encountered a youtube_dl download error while retrieving the video information for {video_url}.\n{e}",
            origin=L_GENERAL, print_mode=PrintMode.VERBOSE_PRINT.value)
        return None
Exemplo n.º 20
0
 def update_user_privileges(db_conn,
                            user_name,
                            level,
                            ignore_file_save=False) -> bool:
     update_privileges_query = f"""
         UPDATE permissions
         SET level = ?
         WHERE user_id = (SELECT users.user_id FROM users WHERE users.name = ? LIMIT 1)
         AND ? = (SELECT permission_levels.level_id FROM permission_levels WHERE permission_levels.level_id = ?);
     """
     try:
         db_conn.cursor().execute(update_privileges_query,
                                  (level, user_name, level, level))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(
                 f"Updated user permission in the database: {user_name}-{level}",
                 origin=L_DATABASE)
             log(INFO,
                 f"Updated user permission in the database: {user_name}-{level}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         dprint(err)
         return False
Exemplo n.º 21
0
 def cmd_duckaudio(self, data):
     gs.vlc_interface.audio_utilities.toggle_ducking()
     gs.gui_service.quick_gui(
         f"{'Enabled' if gs.vlc_interface.audio_utilities.can_duck() else 'Disabled'} audio volume ducking.",
         text_type='header',
         box_align='left')
     log(INFO, f"Audio ducking was {'enabled' if gs.vlc_interface.audio_utilities.can_duck() else 'disabled'}.", origin=L_COMMAND)
Exemplo n.º 22
0
 def update_plugin_help(db_conn,
                        plugin_name,
                        plugin_help_text,
                        ignore_file_save=False) -> bool:
     update_help_query = f"""
         UPDATE plugins_help
         SET help_text = ?
         WHERE plugin_id = (SELECT plugins.plugin_id from plugins WHERE plugins.name = ? );
     """
     try:
         db_conn.cursor().execute(update_help_query,
                                  (plugin_help_text, plugin_name))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(
                 f"Updated plugin help text in the database: {plugin_name}",
                 origin=L_DATABASE)
             log(INFO,
                 f"Updated plugin help text in the database: {plugin_name}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         dprint(err)
         return False
Exemplo n.º 23
0
    def cmd_pguistresstest(self, data):
        all_data = data.message.strip().split(' ', 1)
        if len(all_data) < 2:
            num_of_lines = 5
        else:
            num_of_lines = int(all_data[1])

        import random
        bg_colors = [
            "Blue", "Cyan", "Magenta", "Red", "Yellow", "Green", "Lime",
            "Black", "Snow", "Violet", "Salmon", "Purple", "Pink", "Navy",
            "MintCream", "Maroon", "Gray", "Indigo", "Coral", "Ivory", "Gold",
            "DodgerBlue", "CadetBlue", "Brown", "Beige", "Aquamarine"
        ]
        GS.gui_service.open_box()

        for x in range(num_of_lines):
            content = GS.gui_service.make_content(
                f'<font color="{random.choice(bg_colors)}">[{x}] - PGUI STRESS TEST</font>',
                text_type='header',
                text_align="left",
                bgcolor=random.choice(bg_colors))
            GS.gui_service.append_row(content)
            random.seed(x)

        GS.gui_service.close_box()
        GS.gui_service.display_box(channel=rutils.get_my_channel())
        log(INFO,
            f"Conducted PGUI stress test in the channel.",
            origin=L_COMMAND,
            print_mode=PrintMode.VERBOSE_PRINT.value)
Exemplo n.º 24
0
 def update_alias(db_conn,
                  alias_name,
                  commands,
                  ignore_file_save=False) -> bool:
     update_alias_query = f"""
         UPDATE aliases
         SET alias = ?
         WHERE name = ?;
     """
     try:
         db_conn.cursor().execute(update_alias_query,
                                  (commands, alias_name))
         save_memory_db(db_conn)
         if not ignore_file_save:
             save_memory_db_to_file()
         if db_conn.cursor().rowcount == -1:
             dprint(f"Updated alias in the database: {alias_name}",
                    origin=L_DATABASE)
             log(INFO,
                 f"Updated alias in the database: {alias_name}",
                 origin=L_DATABASE)
             return True
         return False
     except Error as err:
         dprint(err)
         return False
Exemplo n.º 25
0
 def cmd_restartplugin(self, data):
     all_data = data.message.strip().split(' ', 1)
     if len(all_data) != 2:
         log(ERROR,
             CMD_INVALID_RESTART_PLUGIN,
             origin=L_COMMAND,
             error_type=CMD_INVALID_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         GS.gui_service.quick_gui(
             CMD_INVALID_RESTART_PLUGIN,
             text_type='header',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
         return
     if cutils.restart_plugin(all_data[1]):
         GS.gui_service.quick_gui(
             f"Successfully restarted plugin: {all_data[1]}",
             text_type='header',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
         return
     GS.gui_service.quick_gui(
         f"The plugin: {all_data[1]} could not be restarted.",
         text_type='header',
         box_align='left',
         ignore_whisper=True,
         user=GS.mumble_inst.users[data.actor]['name'])
Exemplo n.º 26
0
 def cmd_customroll(self, data):
     all_data = data.message.strip().split()
     try:
         number_of_dice = int(all_data[1])
         number_of_faces = int(all_data[2])
         if number_of_dice > 20:
             gs.gui_service.quick_gui("Too many dice! Dice Limit: 20",
                                      text_type='header',
                                      box_align='left')
             return
         ret_text = "<br><font color='red'>Custom Dice Roll:</font>"
         for i in range(number_of_dice):
             random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
             result = random.randint(1, number_of_faces)
             ret_text += f"<br><font color='cyan'>[Dice {i}]-</font> <font color='yellow'>Rolled {result}</font>"
         gs.gui_service.quick_gui(ret_text,
                                  text_type='header',
                                  box_align='left')
         return
     except IndexError:
         log(ERROR,
             CMD_INVALID_CUSTOM_ROLL,
             origin=L_COMMAND,
             error_type=CMD_INVALID_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL,
                                  text_type='header',
                                  box_align='left')
         return
Exemplo n.º 27
0
 def cmd_removealias(self, data):
     all_data = data.message.strip().split(' ', 2)
     if len(all_data) != 2:
         log(ERROR,
             CMD_INVALID_REMOVE_ALIAS,
             origin=L_COMMAND,
             error_type=CMD_INVALID_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         GS.gui_service.quick_gui(
             CMD_INVALID_REMOVE_ALIAS,
             text_type='header',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
         return
     alias_name = all_data[1]
     if aliases.remove_from_aliases(alias_name):
         GS.gui_service.quick_gui(
             f'Removed <font color={GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}>[{alias_name}]</font> from registered aliases.',
             text_type='header',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
     else:
         GS.gui_service.quick_gui(
             f'Could not remove <font color={GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}>[{alias_name}]</font> from registered aliases.',
             text_type='header',
             box_align='left',
             ignore_whisper=True,
             user=GS.mumble_inst.users[data.actor]['name'])
Exemplo n.º 28
0
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)
Exemplo n.º 29
0
def set_plugin_metadata(plugin_name: str, metadata) -> bool:
    if path.exists(f"{dir_utils.get_main_dir()}/plugins/core/{plugin_name}"):
        plugin_path = f"{dir_utils.get_main_dir()}/plugins/core/{plugin_name}"
    elif path.exists(f"{dir_utils.get_main_dir()}/plugins/extensions/{plugin_name}"):
        plugin_path = f"{dir_utils.get_main_dir()}/plugins/extensions/{plugin_name}"
    else:
        return False

    if "DEFAULT" in metadata:
        del metadata["DEFAULT"]

    cfg = configparser.ConfigParser()
    for key, values in metadata.items():
        cfg[key] = {}
        for item, value in values.items():
            cfg[key][item] = value
    try:
        with open(f"{plugin_path}/metadata.ini", 'w') as f:
            cfg.write(f)
        for plugin in global_settings.bot_plugins.values():
            if plugin.plugin_name == plugin_name:
                if plugin_name == "web_server":
                    global_settings.web_cfg = configparser.ConfigParser()
                    global_settings.web_cfg.read(f'{plugin_path}/metadata.ini')
                    plugin.metadata = global_settings.web_cfg
                else:
                    plugin.metadata = configparser.ConfigParser()
                    plugin.metadata.read(f'{plugin_path}/metadata.ini')
                if force_restart_plugin(plugin_name):
                    return True
        return False
    except IOError as e:
        log(ERROR, f"Encountered an error while updating {plugin_name} metadata file: {e}",
            origin=L_GENERAL, error_type=GEN_PROCESS_ERR, print_mode=PrintMode.VERBOSE_PRINT.value)
        return False
Exemplo n.º 30
0
 def cmd_clearloginsound(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_CLEAR_USER_CONNECTION,
             origin=L_COMMAND,
             error_type=CMD_PROCESS_ERR,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(CMD_INVALID_CLEAR_USER_CONNECTION,
                                  text_type='header',
                                  box_align='left',
                                  user=data_actor['name'])
         return
     username = all_data[1]
     if st_settings.user_connections.get(username):
         del st_settings.user_connections[username]
         st_utility.save_user_connections()
         log(INFO,
             f"Removed {username} from the user_connections.csv file.",
             origin=L_COMMAND,
             print_mode=PrintMode.VERBOSE_PRINT.value)
         gs.gui_service.quick_gui(
             f"Removed {username} from the user_connections.csv file.",
             text_type='header',
             box_align='left',
             user=data_actor['name'])