コード例 #1
0
ファイル: core_commands.py プロジェクト: DuckBoss/JJMumbleBot
 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)
コード例 #2
0
    def message_received(text):
        all_commands = runtime_utils.parse_message(text)
        if all_commands is None:
            return
        # Iterate through all commands provided and generate commands.
        for i, item in enumerate(all_commands):
            # Generate command with parameters
            new_text = deepcopy(text)
            new_text.message = item
            try:
                new_command = Command(item[1:].split()[0], new_text)
            except IndexError:
                continue
            all_aliases = aliases.get_all_aliases()
            all_alias_names = [x[0] for x in all_aliases]
            if len(all_aliases) != 0:
                if new_command.command in all_alias_names:
                    alias_item_index = all_alias_names.index(
                        new_command.command)
                    alias_commands = [
                        msg.strip()
                        for msg in all_aliases[alias_item_index][1].split('|')
                    ]
                    if len(alias_commands) > runtime_settings.multi_cmd_limit:
                        rprint(
                            f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        log(WARNING, f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        return
                    for x, sub_item in enumerate(alias_commands):
                        sub_text = deepcopy(text)
                        if len(item[1:].split()) > 1:
                            sub_text.message = f"{sub_item} {item[1:].split(' ', 1)[1]}"
                        else:
                            sub_text.message = sub_item
                        try:
                            sub_command = Command(sub_item[1:].split()[0],
                                                  sub_text)
                        except IndexError:
                            continue
                        global_settings.cmd_queue.insert(sub_command)
                else:
                    # Insert command into the command queue
                    global_settings.cmd_queue.insert(new_command)
            else:
                global_settings.cmd_queue.insert(new_command)

        # Process commands if the queue is not empty
        while not global_settings.cmd_queue.is_empty():
            # Process commands in the queue
            BotService.process_command_queue(global_settings.cmd_queue.pop())
            sleep(runtime_settings.tick_rate)
コード例 #3
0
ファイル: bot_service.py プロジェクト: yquemener/JJMumbleBot
    def message_received(text, remote_cmd=False):
        all_commands = runtime_utils.parse_message(text)
        if all_commands is None:
            return
        # Iterate through all commands provided and generate commands.
        for i, item in enumerate(all_commands):
            # Generate command with parameters
            if not remote_cmd:
                new_text = deepcopy(text)
            else:
                new_text = RemoteTextMessage(
                    channel_id=global_settings.mumble_inst.users.
                    myself['channel_id'],
                    session=global_settings.mumble_inst.users.
                    myself['session'],
                    message=text.message,
                    actor=global_settings.mumble_inst.users.myself['session'])
            new_text.message = item
            try:
                new_command = Command(item[1:].split()[0], new_text)
            except IndexError:
                continue
            all_aliases = aliases.get_all_aliases()
            all_alias_names = [x[0] for x in all_aliases]
            if len(all_aliases) != 0:
                if new_command.command in all_alias_names:
                    alias_item_index = all_alias_names.index(
                        new_command.command)
                    alias_commands = [
                        msg.strip()
                        for msg in all_aliases[alias_item_index][1].split('|')
                    ]
                    if len(alias_commands) > runtime_settings.multi_cmd_limit:
                        rprint(
                            f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        log(WARNING, f"The multi-command limit was reached! "
                            f"The multi-command limit is {runtime_settings.multi_cmd_limit} "
                            f"commands per line.",
                            origin=L_COMMAND)
                        return
                    for x, sub_item in enumerate(alias_commands):
                        if not remote_cmd:
                            sub_text = deepcopy(text)
                        else:
                            sub_text = RemoteTextMessage(
                                channel_id=global_settings.mumble_inst.users.
                                myself['channel_id'],
                                session=global_settings.mumble_inst.users.
                                myself['session'],
                                message=text.message,
                                actor=global_settings.mumble_inst.users.
                                myself['session'])
                        if len(item.split()) > 1:
                            sub_text.message = f"{sub_item} {item.split(' ', 1)[1]}"
                        else:
                            sub_text.message = sub_item
                        try:
                            com_parse = sub_item.split()[0]
                            if com_parse[0] != '(' and com_parse[-1] != ')':
                                return
                            sub_command = Command(com_parse[1:][:-1], sub_text)
                        except IndexError:
                            continue
                        global_settings.cmd_queue.insert_item(sub_command)
                else:
                    # Insert command into the command queue
                    global_settings.cmd_queue.insert_item(new_command)
            else:
                global_settings.cmd_queue.insert_item(new_command)

        # Process commands if the queue is not empty
        while not global_settings.cmd_queue.is_empty():
            # Process commands in the queue
            BotService.process_command_queue(
                global_settings.cmd_queue.pop_item())
            sleep(runtime_settings.tick_rate)
コード例 #4
0
    def process(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        command = message_parse[0]

        if command == "sleep":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            sleep_time = float(text.message[1:].split(' ', 1)[1].strip())
            RS.tick_rate = sleep_time
            sleep(sleep_time)
            RS.tick_rate = float(GS.cfg[C_MAIN_SETTINGS][P_CMD_TICK_RATE])

        elif command == "version":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            GS.gui_service.quick_gui(
                f"{rutils.get_bot_name()} is on version {rutils.get_version()}",
                text_type='header',
                box_align='left')

        elif command == "about":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            GS.gui_service.quick_gui(
                f"{rutils.get_about()}<br>{rutils.get_bot_name()} is on version {rutils.get_version()}",
                text_type='header',
                box_align='left')

        elif command == "uptime":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            GS.gui_service.quick_gui(
                rutils.check_up_time(),
                text_type='header',
                box_align='left',
                ignore_whisper=True,
                user=GS.mumble_inst.users[text.actor]['name'])

        elif command == "exit":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            dprint("Stopping all threads...")
            rutils.exit_bot()
            log(INFO, "JJ Mumble Bot is being shut down.")
            log(INFO, "######################################")

        elif command == "reboot":
            import os
            import sys
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            rutils.exit_bot()
            log(INFO, "JJ Mumble Bot is being rebooted.", origin=L_STARTUP)
            os.execv(sys.executable, ['python3'] + sys.argv)  # nosec

        elif command == "safereboot":
            import os
            import sys
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            rutils.exit_bot()
            log(INFO,
                "JJ Mumble Bot is being rebooted in safe mode.",
                origin=L_STARTUP)
            os.execv(sys.executable,
                     ['python3'] + sys.argv + ['-safe'])  # nosec

        elif command == "refresh":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            rutils.refresh_plugins()

        elif command == "help":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            message = text.message.strip()
            message_parse = message[1:].split(' ', 2)
            if len(message_parse) < 2:
                return
            plugin_name = message_parse[1]

            plugin_help_data = PluginUtilityService.process_help(
                db_cursor=get_memory_db().cursor(), plugin_name=plugin_name)
            if plugin_help_data:
                GS.gui_service.open_box()
                all_help_lines = [
                    msg.strip() for msg in plugin_help_data.split('<br>')
                ]
                content = GS.gui_service.make_content(
                    f'<font color="red">##### </font>'
                    f'<b>{rutils.get_bot_name()} Help Commands - [{plugin_name}]</b>'
                    f'<font color="red"> #####</font>')
                GS.gui_service.append_row(content)
                content = GS.gui_service.make_content(
                    f'Plugin Version: {self.metadata[C_PLUGIN_INFO][P_PLUGIN_VERS]}<br>',
                    text_color='cyan')
                GS.gui_service.append_row(content)
                for i, item in enumerate(all_help_lines):
                    item_parts = item.split(':', 1)
                    if len(item_parts) > 1:
                        content = GS.gui_service.make_content(
                            f'<font color="yellow">{item_parts[0]}</font>:{item_parts[1]}',
                            text_type='header',
                            text_align="left")
                    else:
                        content = GS.gui_service.make_content(
                            f'{item}', text_type='header', text_align="left")
                    GS.gui_service.append_row(content)
                GS.gui_service.close_box()
                GS.gui_service.display_box(channel=rutils.get_my_channel())
                dprint(
                    f"Displayed help screen for {plugin_name} in the channel.")
                log(INFO,
                    f"Displayed help screen for {plugin_name} in the channel.",
                    origin=L_COMMAND)

        elif command == "alias":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            message = text.message.strip()
            message_parse = message[1:].split(' ', 2)
            if len(message_parse) < 2:
                return
            alias_name = message_parse[1]

            if aliases.add_to_aliases(alias_name, message_parse[2]):
                GS.gui_service.quick_gui(
                    f"Registered new alias: [{alias_name}] - [{message_parse[2]}]",
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GS.mumble_inst.users[text.actor]['name'])
            elif aliases.set_alias(alias_name, message_parse[2]):
                GS.gui_service.quick_gui(
                    f"Registered alias: [{alias_name}] - [{message_parse[2]}]",
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GS.mumble_inst.users[text.actor]['name'])

        elif command == "aliases":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            aliases_list = aliases.get_all_aliases()
            if len(aliases_list) == 0:
                cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Registered Aliases: None</font>"
            else:
                cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Registered Aliases:</font>"
                for i, alias in enumerate(aliases_list):
                    cur_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_text,
                            text_type='header',
                            box_align='left',
                            text_align='left',
                            ignore_whisper=True,
                            user=GS.mumble_inst.users[text.actor]['name'])
                        cur_text = ""
            GS.gui_service.quick_gui(
                cur_text,
                text_type='header',
                box_align='left',
                text_align='left',
                ignore_whisper=True,
                user=GS.mumble_inst.users[text.actor]['name'])

        elif command == "removealias":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            message = text.message.strip()
            message_parse = message[1:].split(' ', 2)
            if len(message_parse) < 2:
                return
            alias_name = message_parse[1]
            if aliases.remove_from_aliases(alias_name):
                GS.gui_service.quick_gui(
                    f'Removed [{alias_name}] from registered aliases.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GS.mumble_inst.users[text.actor]['name'])
            else:
                GS.gui_service.quick_gui(
                    f'Could not remove [{alias_name}] from registered aliases.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GS.mumble_inst.users[text.actor]['name'])

        elif command == "clearaliases":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            if aliases.clear_aliases():
                GS.gui_service.quick_gui(
                    'Cleared all registered aliases.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GS.mumble_inst.users[text.actor]['name'])
            else:
                GS.gui_service.quick_gui(
                    'The registered aliases could not be cleared.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GS.mumble_inst.users[text.actor]['name'])

        elif command == "clearhistory":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            GS.cmd_history.queue_storage.clear()
            GS.gui_service.quick_gui(
                f'<font color="{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}">Cleared command history.</font>',
                text_type='header',
                box_align='left',
                text_align='left',
                ignore_whisper=True,
                user=GS.mumble_inst.users[text.actor]['name'])

        elif command == "history":
            if not privileges.plugin_privilege_checker(text, command,
                                                       self.plugin_name):
                return
            cur_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Command History:</font>"
            for i, item in enumerate(GS.cmd_history.queue_storage):
                cur_text += f"<br><font color={GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}>[{i}]</font> - {item}"
                if i % 50 == 0 and i != 0:
                    GS.gui_service.quick_gui(
                        cur_text,
                        text_type='header',
                        box_align='left',
                        text_align='left',
                        ignore_whisper=True,
                        user=GS.mumble_inst.users[text.actor]['name'])
                    cur_text = ""
            GS.gui_service.quick_gui(
                cur_text,
                text_type='header',
                box_align='left',
                text_align='left',
                ignore_whisper=True,
                user=GS.mumble_inst.users[text.actor]['name'])