Beispiel #1
0
    def process_core_commands(self, command, text):
        if command == "alias":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            message = text.message.strip()
            message_parse = message[1:].split(' ', 2)
            alias_name = message_parse[1]

            if alias_name in aliases.aliases.keys():
                aliases.set_alias(alias_name, message_parse[2])
                debug_print(f"Registered alias: [{alias_name}] - [{message_parse[2]}]")
                GM.gui.quick_gui(
                    f"Registered alias: [{alias_name}] - [{message_parse[2]}]",
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GM.mumble.users[text.actor]['name'])
            else:
                aliases.add_to_aliases(alias_name, message_parse[2])
                debug_print(f"Registered new alias: [{alias_name}] - [{message_parse[2]}]")
                GM.gui.quick_gui(
                    f"Registered alias: [{alias_name}] - [{message_parse[2]}]",
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GM.mumble.users[text.actor]['name'])
            return

        elif command == "aliases":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Registered Aliases:</font>"
            for i, alias in enumerate(aliases.aliases):
                cur_text += f"<br><font color={GM.cfg['PGUI_Settings']['IndexTextColor']}>[{alias}]</font> - " \
                            f"[{BeautifulSoup(aliases.aliases[alias], 'html.parser').get_text()}] "
                if i % 50 == 0 and i != 0:
                    GM.gui.quick_gui(
                        cur_text,
                        text_type='header',
                        box_align='left',
                        text_align='left',
                        ignore_whisper=True,
                        user=GM.mumble.users[text.actor]['name']
                        )
                    cur_text = ""
            GM.gui.quick_gui(
                cur_text,
                text_type='header',
                box_align='left',
                text_align='left',
                ignore_whisper=True,
                user=GM.mumble.users[text.actor]['name']
                )
            return

        elif command == "removealias":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            message = text.message.strip()
            message_parse = message[1:].split(' ', 2)
            alias_name = message_parse[1]
            if aliases.remove_from_aliases(alias_name):
                debug_print(f'Removed [{alias_name}] from registered aliases.')
                GM.gui.quick_gui(
                    f'Removed [{alias_name}] from registered aliases.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GM.mumble.users[text.actor]['name']
                )
            else:
                debug_print(f'Could not remove [{alias_name}] from registered aliases.')
                GM.gui.quick_gui(
                    f'Could not remove [{alias_name}] from registered aliases.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GM.mumble.users[text.actor]['name']
                )
            return

        elif command == "clearaliases":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if aliases.clear_aliases():
                debug_print('Cleared all registered aliases.')
                GM.gui.quick_gui(
                    'Cleared all registered aliases.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GM.mumble.users[text.actor]['name']
                )
            else:
                debug_print('The registered aliases could not be cleared.')
                GM.gui.quick_gui(
                    'The registered aliases could not be cleared.',
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True,
                    user=GM.mumble.users[text.actor]['name']
                )
            return

        elif command == "refresh":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            self.refresh_plugins()
            return

        elif command == "sleep":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            sleep_time = float(text.message[1:].split(' ', 1)[1].strip())
            self.tick_rate = sleep_time
            time.sleep(sleep_time)
            self.tick_rate = float(GM.cfg['Main_Settings']['CommandTickRate'])
            return

        elif command == "exit":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            debug_print("Stopping all threads...")
            self.exit()
            GM.logger.info("JJ Mumble Bot is being shut down.")
            GM.logger.info("######################################")
            return

        elif command == "status":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(
                f"{utils.get_bot_name()} is {self.status()}.",
                text_type='header',
                box_align='left'
            )
            return

        elif command == "version":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(
                f"{utils.get_bot_name()} is on version {utils.get_version()}",
                text_type='header',
                box_align='left'
            )
            return

        elif command == "system_test":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            self.plugin_callback_test()
            debug_print("A system self-test was run.")
            GM.logger.info("A system self-test was run.")
            return

        elif command == "about":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(
                f"{utils.get_about()}<br>{utils.get_bot_name()} is on version {utils.get_version()}",
                text_type='header',
                box_align='left'
            )
            return

        elif command == "history":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Command History:</font>"
            for i, item in enumerate(GM.cmd_history.queue_storage):
                cur_text += f"<br><font color={GM.cfg['PGUI_Settings']['IndexTextColor']}>[{i}]</font> - {item}"
                if i % 50 == 0 and i != 0:
                    GM.gui.quick_gui(
                        cur_text,
                        text_type='header',
                        box_align='left',
                        text_align='left',
                        ignore_whisper=True,
                        user=GM.mumble.users[text.actor]['name']
                    )
                    cur_text = ""
            GM.gui.quick_gui(
                cur_text,
                text_type='header',
                box_align='left',
                text_align='left',
                ignore_whisper=True,
                user=GM.mumble.users[text.actor]['name']
            )

        elif command == "uptime":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(
                check_time(),
                text_type='header',
                box_align='left',
                ignore_whisper=True,
                user=GM.mumble.users[text.actor]['name']
            )
            return

        elif command == "reboot":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            self.exit()
            GM.logger.info("JJ Mumble Bot is being rebooted.")
            os.execv(sys.executable, ['python3'] + sys.argv)
            return
Beispiel #2
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        command = message_parse[0]

        if command == "help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip() for msg in self.help_data.split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold(f"{utils.get_bot_name()} General Help Commands")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print("Displayed general help screen in the channel.")
            GM.logger.info("Displayed general help screen in the channel.")
            return

        elif command == "bot_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip() for msg in self.bot_plugins.get(
                    "bot_commands").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Bot_Commands Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("bot_commands").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print(
                "Displayed bot commands plugin help screen in the channel.")
            GM.logger.info(
                "Displayed bot commands plugin help screen in the channel.")
            return

        elif command == "whisper_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip()
                for msg in self.bot_plugins.get("whisper").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Whisper Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("whisper").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print("Displayed whisper plugin help screen in the channel.")
            GM.logger.info(
                "Displayed whisper plugin help screen in the channel.")
            return

        elif command == "sound_board_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip() for msg in self.bot_plugins.get(
                    "sound_board").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Sound_Board Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("sound_board").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print(
                "Displayed sound_board plugin help screen in the channel.")
            GM.logger.info(
                "Displayed sound_board plugin help screen in the channel.")
            return

        elif command == "youtube_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip()
                for msg in self.bot_plugins.get("youtube").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Youtube Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("youtube").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print("Displayed youtube plugin help screen in the channel.")
            GM.logger.info(
                "Displayed youtube plugin help screen in the channel.")
            return

        elif command == "images_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip()
                for msg in self.bot_plugins.get("images").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Images Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("images").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print("Displayed images plugin help screen in the channel.")
            GM.logger.info(
                "Displayed images plugin help screen in the channel.")
            return

        elif command == "uptime_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip()
                for msg in self.bot_plugins.get("uptime").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Uptime Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("uptime").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print("Displayed uptime plugin help screen in the channel.")
            GM.logger.info(
                "Displayed uptime plugin help screen in the channel.")
            return

        elif command == "randomizer_help":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.open_box()
            all_help_lines = [
                msg.strip() for msg in self.bot_plugins.get(
                    "randomizer").help().split('<br>')
            ]
            content = GM.gui.make_content(
                f'<font color="red">#####</font> '
                f'{GUIHelper.bold("Randomizer Plugin Help")} '
                f'<font color="red">#####</font>')
            GM.gui.append_row(content)
            content = GM.gui.make_content(
                f'Plugin Version: {self.bot_plugins.get("randomizer").get_plugin_version()}<br>',
                text_color='cyan')
            GM.gui.append_row(content)

            for i, item in enumerate(all_help_lines):
                content = GM.gui.make_content(f'{item}',
                                              'header',
                                              text_color='yellow',
                                              text_align="left")
                GM.gui.append_row(content)
            GM.gui.close_box()
            GM.gui.display_box(channel=utils.get_my_channel())

            reg_print(
                "Displayed randomizer plugin help screen in the channel.")
            GM.logger.info(
                "Displayed randomizer plugin help screen in the channel.")
            return
Beispiel #3
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        all_messages = message[1:].split()
        command = message_parse[0]

        if command == "echo":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            parameter = message_parse[1]
            GM.gui.quick_gui(parameter,
                             text_type='header',
                             box_align='left',
                             ignore_whisper=True)
            GM.logger.info(f"Echo:[{parameter}]")
            return

        elif command == "log":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            debug_print(f"Manually Logged: [{message_parse[1]}]")
            GM.logger.info(f"Manually Logged: [{message_parse[1]}]")
            return

        elif command == "spam_test":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            for i in range(10):
                GM.gui.quick_gui("This is a spam test message...",
                                 text_type='header',
                                 box_align='left',
                                 ignore_whisper=True)
            GM.logger.info(
                f"A spam_test was conducted by: {GM.mumble.users[text.actor]['name']}."
            )
            return

        elif command == "msg":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(message[1:].split(' ', 2)[2],
                             text_type='header',
                             box_align='left',
                             user=all_messages[1],
                             ignore_whisper=True)
            GM.logger.info(
                f"Msg:[{all_messages[1]}]->[{message[1:].split(' ', 2)[2]}]")
            return

        elif command == "move":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            parameter = message_parse[1]
            channel_name = parameter
            if channel_name == "default" or channel_name == "Default":
                channel_name = utils.get_default_channel()
            channel_search = utils.get_channel(channel_name)
            if channel_search is None:
                return
            else:
                channel_search.move_in()
                GM.gui.quick_gui(
                    f"{utils.get_bot_name()} was moved by {GM.mumble.users[text.actor]['name']}",
                    text_type='header',
                    box_align='left',
                    ignore_whisper=True)
                GM.logger.info(
                    f"Moved to channel: {channel_name} by {GM.mumble.users[text.actor]['name']}"
                )
            return

        elif command == "make":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            parameter = message_parse[1]
            channel_name = parameter
            utils.make_channel(utils.get_my_channel(), channel_name)
            GM.logger.info(
                f"Made a channel: {channel_name} by {GM.mumble.users[text.actor]['name']}"
            )
            return

        elif command == "leave":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            utils.leave()
            GM.logger.info("Returned to default channel.")
            return

        elif command == "joinme":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(
                f"Joining user: {GM.mumble.users[text.actor]['name']}",
                text_type='header',
                box_align='left',
                ignore_whisper=True)

            GM.mumble.channels[GM.mumble.users[text.actor]
                               ['channel_id']].move_in()
            GM.logger.info(
                f"Joined user: {GM.mumble.users[text.actor]['name']}")
            return

        elif command == "privileges":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            GM.gui.quick_gui(f"{pv.get_all_privileges()}",
                             text_type='header',
                             box_align='left',
                             text_align='left',
                             user=GM.mumble.users[text.actor]['name'],
                             ignore_whisper=True)
            return

        elif command == "setprivileges":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                username = all_messages[1]
                level = int(all_messages[2])
                result = pv.set_privileges(username, level,
                                           GM.mumble.users[text.actor])
                if result:
                    GM.gui.quick_gui(
                        f"User: {username} privileges have been modified.",
                        text_type='header',
                        box_align='left',
                        user=GM.mumble.users[text.actor]['name'],
                        ignore_whisper=True)
                    GM.logger.info(f"Modified user privileges for: {username}")
            except Exception:
                reg_print(
                    "Incorrect format! Format: !setprivileges 'username' 'level'"
                )
                GM.gui.quick_gui(
                    "Incorrect format! Format: !setprivileges 'username' 'level'",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "addprivileges":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                username = all_messages[1]
                level = int(all_messages[2])
                result = pv.add_to_privileges(username, level)
                if result:
                    GM.gui.quick_gui(
                        f"Added a new user: {username} to the user privileges.",
                        text_type='header',
                        box_align='left',
                        user=GM.mumble.users[text.actor]['name'],
                        ignore_whisper=True)
                    GM.logger.info(
                        f"Added a new user: {username} to the user privileges."
                    )
            except Exception:
                reg_print(
                    "Incorrect format! Format: !addprivileges 'username' 'level'"
                )
                GM.gui.quick_gui(
                    "Incorrect format! Format: !addprivileges 'username' 'level'",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "blacklist":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                parameter = all_messages[1]
                reason = "No reason provided."
                print(len(message[1:].split()))
                if len(message[1:].split()) >= 3:
                    reason = message[1:].split(' ', 2)[2]
                result = pv.add_to_blacklist(parameter,
                                             GM.mumble.users[text.actor])
                if result:
                    GM.gui.quick_gui(
                        f"User: {parameter} added to the blacklist.<br>Reason: {reason}",
                        text_type='header',
                        box_align='left',
                        text_align='left')
                    GM.logger.info(
                        f"Blacklisted user: {parameter} <br>Reason: {reason}")
            except IndexError:
                GM.gui.quick_gui(pv.get_blacklist(),
                                 text_type='header',
                                 box_align='left',
                                 text_align='left')
            return

        elif command == "whitelist":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                parameter = message_parse[1]
                result = pv.remove_from_blacklist(parameter)
                if result:
                    GM.gui.quick_gui(
                        f"User: {parameter} removed from the blacklist.",
                        text_type='header',
                        box_align='left')
                    GM.logger.info(
                        f"User: {parameter} removed from the blacklist.")
            except IndexError:
                GM.gui.quick_gui("Command format: !whitelist username",
                                 text_type='header',
                                 box_align='left')
                return
            return
Beispiel #4
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        all_messages = message[1:].split()
        command = message_parse[0]
        if command == "sbstop":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if SBH.audio_thread is not None:
                SBM.stop_audio()
                GM.gui.quick_gui("Stopping sound board audio thread...",
                                 text_type='header',
                                 box_align='left')
                return
            return

        elif command == "sblist":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            file_counter = 0
            gather_list = []
            internal_list = []
            for file_item in os.listdir(utils.get_permanent_media_dir() +
                                        "sound_board/"):
                if file_item.endswith(".wav"):
                    gather_list.append(f"{file_item}")
                    file_counter += 1

            gather_list.sort(key=str.lower)
            for i, item in enumerate(gather_list):
                internal_list.append(
                    f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{i}]</font> - [{item}]"
                )

            cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Sound Board Files:</font>"
            if len(internal_list) == 0:
                cur_text += "<br>There are no local sound board files available."
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'])
                GM.logger.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:
                    GM.gui.quick_gui(cur_text,
                                     text_type='header',
                                     box_align='left',
                                     text_align='left',
                                     user=GM.mumble.users[text.actor]['name'])
                    cur_text = ""
            if cur_text != "":
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left',
                                 text_align='left',
                                 user=GM.mumble.users[text.actor]['name'])
            GM.logger.info("Displayed a list of all local sound board files.")
            return

        elif command == "sblist_echo":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            file_counter = 0
            gather_list = []
            internal_list = []

            for file_item in os.listdir(utils.get_permanent_media_dir() +
                                        "sound_board/"):
                if file_item.endswith(".wav"):
                    gather_list.append(f"{file_item}")
                    file_counter += 1

            gather_list.sort(key=str.lower)
            for i, item in enumerate(gather_list):
                internal_list.append(
                    f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{i}]</font> - [{item}]"
                )

            cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Sound Board Files:</font>"
            if len(internal_list) == 0:
                cur_text += "<br>There are no local sound board files available."
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left')
                GM.logger.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:
                    GM.gui.quick_gui(cur_text,
                                     text_type='header',
                                     box_align='center',
                                     text_align='left')
                    cur_text = ""
            if cur_text != "":
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='center',
                                 text_align='left')
            GM.logger.info("Displayed a list of all local sound board files.")
            return

        elif command == "sbreplay":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.is_playing:
                GM.gui.quick_gui(
                    "The youtube audio plugin is currently live. "
                    "Use !stop before using the sound board plugin.",
                    text_type='header',
                    box_align='left')
                return
            if SBH.current_song is not None:
                self.youtube_plugin.clear_audio_plugin()
                SBM.play_audio()
            else:
                GM.gui.quick_gui(
                    "There is no sound board track available to replay.",
                    text_type='header',
                    box_align='left')
                return
            return

        elif command == "sbv":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                vol = float(message[1:].split(' ', 1)[1])
            except IndexError:
                GM.gui.quick_gui(f"Current sound board volume: {SBH.volume}",
                                 text_type='header',
                                 box_align='left')
                return
            if vol > 1:
                GM.gui.quick_gui("Invalid sound_board volume Input: [0-1]",
                                 text_type='header',
                                 box_align='left')
                return
            if vol < 0:
                GM.gui.quick_gui("Invalid sound_board volume Input: [0-1]",
                                 text_type='header',
                                 box_align='left')
                return
            SBH.volume = vol
            GM.gui.quick_gui(f"Set sound_board volume to {SBH.volume}",
                             text_type='header',
                             box_align='left')
            return

        elif command == "sbdownload":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            all_messages_stripped = BeautifulSoup(
                message_parse[1], features='html.parser').get_text()
            split_msgs = all_messages_stripped.split()
            stripped_url = split_msgs[0]
            if len(all_messages) >= 3:
                if "youtube.com" in stripped_url or "youtu.be" in stripped_url:
                    SBM.download_clip(stripped_url, split_msgs[1].strip())
                    GM.gui.quick_gui(
                        f"Downloaded sound clip as : {split_msgs[1].strip()}.wav",
                        text_type='header',
                        box_align='left')
                    return
                return
            return

        elif command == "sbdelete":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if len(all_messages) == 2:
                if ".wav" in all_messages[1].strip():
                    utils.remove_file(
                        all_messages[1].strip(),
                        utils.get_permanent_media_dir() + "sound_board/")
                    GM.gui.quick_gui(
                        f"Deleted sound clip : {all_messages[1].strip()}",
                        text_type='header',
                        box_align='left')

        elif command == "sb":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            parameter = message_parse[1]

            if self.youtube_plugin.clear_audio_plugin() is False:
                GM.gui.quick_gui(
                    "The youtube audio plugin is currently live. "
                    "Use !stop before using the sound board plugin.",
                    text_type='header',
                    box_align='left')
                return

            if not os.path.isfile(utils.get_permanent_media_dir() +
                                  f"sound_board/{parameter}.wav"):
                GM.gui.quick_gui("The sound clip does not exist.",
                                 text_type='header',
                                 box_align='left')
                return False
            SBH.current_song = parameter
            SBM.play_audio()
Beispiel #5
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        command = message_parse[0]

        if command == "coinflip":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 2)
            if result == 1:
                result = "Heads"
            else:
                result = "Tails"
            GM.gui.quick_gui(
                f"<font color='cyan'>Coin Flip Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "d4roll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 4)
            GM.gui.quick_gui(
                f"<font color='cyan'>D4 Roll Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "d6roll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 6)
            GM.gui.quick_gui(
                f"<font color='cyan'>D6 Roll Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "d8roll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 8)
            GM.gui.quick_gui(
                f"<font color='cyan'>D8 Roll Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "d10roll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 10)
            GM.gui.quick_gui(
                f"<font color='cyan'>D10 Roll Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "d12roll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 12)
            GM.gui.quick_gui(
                f"<font color='cyan'>D12 Roll Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "d20roll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            random.seed(int.from_bytes(os.urandom(8), byteorder="big"))
            result = random.randint(1, 20)
            GM.gui.quick_gui(
                f"<font color='cyan'>D20 Roll Result:</font> <font color='yellow'>{result}</font>",
                text_type='header',
                box_align='left')
            return
        elif command == "customroll":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                all_messages = message[1:].split()
                number_of_dice = int(all_messages[1])
                number_of_faces = int(all_messages[2])
                if number_of_dice > 20:
                    GM.gui.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>"
                GM.gui.quick_gui(ret_text,
                                 text_type='header',
                                 box_align='left')
                return
            except Exception:
                GM.gui.quick_gui(
                    "Incorrect paramaters! Format: !customroll 'number_of_dice' 'dice_faces'",
                    text_type='header',
                    box_align='left')
                return
Beispiel #6
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        all_messages = message[1:].split()
        command = message_parse[0]

        if command == "song":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.current_song_info is not None:
                GM.gui.quick_gui_img(f"{utils.get_temporary_img_dir()}",
                                     f"{YH.current_song_info['img_id']}",
                                     caption=f"Now playing: {YH.current_song_info['main_title']}",
                                     format=True,
                                     img_size=32768)
                GM.logger.info("Displayed current song in the youtube plugin.")
            else:
                GM.gui.quick_gui(
                    f"{utils.get_bot_name()} is not playing anything right now.",
                    text_type='header',
                    box_align='left')
            return

        elif command == "autoplay":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.autoplay:
                YH.autoplay = False;
                GM.gui.quick_gui(
                    "Autoplay has been disabled.",
                    text_type='header',
                    box_align='left')
                GM.logger.info("Autoplay has been disabled in the youtube plugin.")
            else:
                YH.autoplay = True
                GM.gui.quick_gui(
                    "Autoplay has been enabled.",
                    text_type='header',
                    box_align='left')
                GM.logger.info("Autoplay has been enabled in the youtube plugin.")
            return

        elif command == "shuffle":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.music_thread is not None:
                if not YH.queue_instance.is_empty():
                    YH.queue_instance.shuffle()
                    YM.download_next()
                    GM.gui.quick_gui(
                        "The youtube queue has been shuffled.",
                        text_type='header',
                        box_align='left')
                    GM.logger.info("The youtube audio queue was shuffled.")
                    return

        elif command == "next":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            YM.next()
            return

        elif command == "remove":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.music_thread is not None:
                if YH.queue_instance.is_empty():
                    GM.gui.quick_gui(
                        "The youtube queue is empty, so I can't remove tracks.",
                        text_type='header',
                        box_align='left')
                    return
                rem_val = int(message[1:].split(' ', 1)[1])
                if rem_val > YH.queue_instance.size() - 1 or rem_val < 0:
                    GM.gui.quick_gui(
                        f"You can't remove tracks beyond the length of the current queue.",
                        text_type='header',
                        box_align='left')
                    return
                removed_item = YH.queue_instance.remove(rem_val)
                GM.gui.quick_gui(
                    f"Removed track: [{rem_val}]-{removed_item['main_title']} from the queue.",
                    text_type='header',
                    box_align='left')
                GM.logger.info(f"Removed track #{rem_val} from the youtube audio queue.")
                return

        elif command == "skipto":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            skip_val = int(message[1:].split(' ', 1)[1])
            YM.skipto(skip_val)
            GM.logger.info(f"The youtube audio queue skipped to track #{skip_val}.")
            return

        elif command == "stop":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.music_thread is not None:
                GM.gui.quick_gui(
                    "Stopping youtube audio thread.",
                    text_type='header',
                    box_align='left')
                YH.queue_instance.clear()
                YM.stop_audio()
                utils.clear_directory(utils.get_temporary_img_dir())
                YH.queue_instance = qh.QueueHandler(YH.max_queue_size)
                GM.logger.info("The youtube audio thread was stopped.")
                return
            return

        elif command == "clear":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            reg_print("Clearing youtube queue.")
            YM.clear_queue()
            GM.gui.quick_gui(
                "Cleared youtube queue.",
                text_type='header',
                box_align='left')
            GM.logger.info("The youtube queue was cleared.")
            return

        elif command == "max_duration":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                new_max = int(message[1:].split(' ', 1)[1])
                YM.set_max_track_duration(new_max)
                GM.gui.quick_gui(
                    f"Set youtube track max duration to {YH.max_track_duration}",
                    text_type='header',
                    box_align='left')
                GM.logger.info(f"The youtube track max duration was set to {YH.max_track_duration}.")
            except IndexError:
                GM.gui.quick_gui(
                    f"Current youtube track max duration: {YH.max_track_duration}",
                    text_type='header',
                    box_align='left')
                return

        elif command == "volume":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                vol = float(message[1:].split(' ', 1)[1])
            except IndexError:
                GM.gui.quick_gui(
                    f"Current youtube volume: {YH.volume}",
                    text_type='header',
                    box_align='left')
                return

            if vol > 1:
                GM.gui.quick_gui(
                    "Invalid Volume Input: [0-1]",
                    text_type='header',
                    box_align='left')
                return
            if vol < 0:
                GM.gui.quick_gui(
                    "Invalid Volume Input: [0-1]",
                    text_type='header',
                    box_align='left')
                return
            YH.volume = vol
            GM.gui.quick_gui(
                f"Set volume to {YH.volume}",
                text_type='header',
                box_align='left')
            GM.logger.info(f"The youtube audio volume was changed to {YH.volume}.")
            return

        elif command == "youtube":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                search_term = message_parse[1]
            except IndexError:
                return

            YH.all_searches = YM.get_search_results(search_term)
            search_results = YM.get_choices(YH.all_searches)
            GM.gui.quick_gui(
                f"{search_results}\nWhich one would you like to play?",
                text_type='header',
                box_align='left',
                text_align='left')
            GM.logger.info("Displayed youtube search results.")
            YH.can_play = True
            return

        elif command == "queue":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            queue_results = YM.get_queue()
            if queue_results is not None:
                cur_text = ""
                for i, item in enumerate(queue_results):
                    cur_text += f"{item}"
                    if i % 50 == 0 and i != 0:
                        GM.gui.quick_gui(
                            f"{cur_text}",
                            text_type='header',
                            box_align='left',
                            text_align='left')
                        cur_text = ""
                if cur_text != "":
                    GM.gui.quick_gui(
                        f"{cur_text}",
                        text_type='header',
                        box_align='left',
                        text_align='left')
                GM.logger.info("Displayed current youtube queue.")
                return
            else:
                GM.gui.quick_gui(
                    "The youtube queue is empty.",
                    text_type='header',
                    box_align='left')
            return

        elif command == "playlist":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if len(message_parse) == 2:
                stripped_url = BeautifulSoup(message_parse[1], features='html.parser').get_text()
                if "youtube.com" in stripped_url or "youtu.be" in stripped_url:
                    if YH.queue_instance.is_full():
                        GM.gui.quick_gui(
                            "The youtube queue is full!",
                            text_type='header',
                            box_align='left')
                        return
                    all_song_data = YM.download_playlist(stripped_url)
                    if all_song_data is None:
                        return

                    self.sound_board_plugin.clear_audio_thread()
                    for i, song_data in enumerate(all_song_data):
                        YH.queue_instance.insert(song_data)

                    GM.gui.quick_gui(
                        f"Playlist generated: {stripped_url}",
                        text_type='header',
                        box_align='left')
                    GM.logger.info(f"Generated playlist: {stripped_url}")
                    if not YH.is_playing:
                        YM.download_next()
                        YM.play_audio()
                    return
            else:
                GM.gui.quick_gui(
                    "The given link was not identified as a youtube video link!",
                    text_type='header',
                    box_align='left')
                return

        elif command == "linkfront":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if len(message_parse) == 2:
                stripped_url = BeautifulSoup(message_parse[1], features='html.parser').get_text()
                if "youtube.com" in stripped_url or "youtu.be" in stripped_url:
                    if YH.queue_instance.is_full():
                        GM.gui.quick_gui(
                            "The youtube queue is full!",
                            text_type='header',
                            box_align='left')
                        return
                    song_data = YM.download_song_name(stripped_url)
                    if song_data is None:
                        GM.gui.quick_gui(
                            "ERROR: The chosen stream was either too long or a live stream.",
                            text_type='header',
                            box_align='left')
                        return
                    song_data['main_url'] = stripped_url

                    self.sound_board_plugin.clear_audio_thread()
                    YH.queue_instance.insert_priority(song_data)

                    GM.gui.quick_gui(
                        f"Added to front of queue: {stripped_url}",
                        text_type='header',
                        box_align='left')
                    GM.logger.info("Direct link added to the front of the youtube queue.")
                    if not YH.is_playing:
                        YM.download_next()
                        YM.play_audio()
                    return
                else:
                    GM.gui.quick_gui(
                        "The given link was not identified as a youtube video link!",
                        text_type='header',
                        box_align='left')
                    return

        elif command == "link":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if len(message_parse) == 2:
                stripped_url = BeautifulSoup(message_parse[1], features='html.parser').get_text()
                if "youtube.com" in stripped_url or "youtu.be" in stripped_url:
                    if YH.queue_instance.is_full():
                        GM.gui.quick_gui(
                            "The youtube queue is full!",
                            text_type='header',
                            box_align='left')
                        return
                    song_data = YM.download_song_name(stripped_url)
                    if song_data is None:
                        GM.gui.quick_gui(
                            "ERROR: The chosen stream was either too long or a live stream.",
                            text_type='header',
                            box_align='left')
                        return
                    song_data['main_url'] = stripped_url

                    self.sound_board_plugin.clear_audio_thread()
                    YH.queue_instance.insert(song_data)

                    GM.gui.quick_gui(
                        f"Added to queue: {stripped_url}",
                        text_type='header',
                        box_align='left')
                    GM.logger.info("Direct link added to youtube queue.")
                    if not YH.is_playing:
                        YM.download_next()
                        YM.play_audio()
                    return
                else:
                    GM.gui.quick_gui(
                        "The given link was not identified as a youtube video link!",
                        text_type='header',
                        box_align='left')
                    return

        elif command == "play":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.can_play:
                if YH.queue_instance.is_full():
                    GM.gui.quick_gui(
                        "The youtube queue is full!",
                        text_type='header',
                        box_align='left')
                    return
                self.sound_board_plugin.clear_audio_thread()

                if len(all_messages) == 1:
                    song_data = YM.download_song_name(
                        "https://www.youtube.com" + YH.all_searches[0]['href'])
                    if song_data is None:
                        GM.gui.quick_gui(
                            f"The chosen video is too long. The maximum video length is {(YH.max_track_duration/60)} minutes",
                            text_type='header',
                            box_align='left')
                        return
                    song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[0]['href']
                    GM.gui.quick_gui(
                        f"Automatically chosen: {YH.all_searches[0]['title']}",
                        text_type='header',
                        box_align='left')
                    YH.can_play = False
                    YH.queue_instance.insert(song_data)
                    if not YH.is_playing:
                        YM.download_next()
                        YM.play_audio()
                elif len(all_messages) == 2:
                    if 9 >= int(all_messages[1]) >= 0:
                        song_data = YM.download_song_name(
                            "https://www.youtube.com" + YH.all_searches[int(all_messages[1])]['href'])
                        if song_data is None:
                            utils.echo(utils.get_my_channel(),
                                       f"The chosen video is too long. The maximum video length is {(YH.max_track_duration/60)} minutes")
                            return
                        song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[int(all_messages[1])]['href']
                        GM.gui.quick_gui(
                            f"You've chosen: {YH.all_searches[int(all_messages[1])]['title']}",
                            text_type='header',
                            box_align='left')
                        YH.can_play = False
                    else:
                        GM.gui.quick_gui(
                            "Invalid choice! Valid Range [0-9]",
                            text_type='header',
                            box_align='left')
                        YH.can_play = False
                        return
                    YH.queue_instance.insert(song_data)
                    if not YH.is_playing:
                        YM.download_next()
                        YM.play_audio()
                elif len(all_messages) == 3:
                    if 9 >= int(all_messages[1]) >= 0:
                        song_data = YM.download_song_name(
                            "https://www.youtube.com" + YH.all_searches[int(all_messages[1])]['href'])
                        if song_data is None:
                            GM.gui.quick_gui(
                                f"The chosen video is too long. The maximum video length is {(YH.max_track_duration/60)} minutes",
                                text_type='header',
                                box_align='left')
                            return
                        song_data['main_url'] = "https://www.youtube.com" + YH.all_searches[int(all_messages[1])]['href']
                        GM.gui.quick_gui(
                            f"You've chosen: {YH.all_searches[int(all_messages[1])]['title']}",
                            text_type='header',
                            box_align='left')
                        YH.can_play = False
                    else:
                        GM.gui.quick_gui(
                            "Invalid choice! Valid Range [0-9]",
                            text_type='header',
                            box_align='left')
                        YH.can_play = False
                        return
                    count = int(all_messages[2])
                    for i in range(count):
                        YH.queue_instance.insert(song_data)
                    if not YH.is_playing:
                        YM.download_next()
                        YM.play_audio()
            return

        elif command == "replay":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if YH.music_thread is not None:
                if YH.current_song is not None and YH.current_song_info is not None:
                    YH.queue_instance.insert_priority(YH.current_song_info)
                    YM.stop_audio()
                    YM.download_next()
                    YM.play_audio()
            else:
                GM.gui.quick_gui(
                    "There is no track available to replay.",
                    text_type='header',
                    box_align='left')
                return
            return
Beispiel #7
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        command = message_parse[0]

        if command == "post":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            img_url = message_parse[1]
            # Download image
            img_url = ''.join(
                BeautifulSoup(img_url, 'html.parser').findAll(text=True))
            IH.download_image_stream(img_url)
            # Format image
            time.sleep(1)
            img_ext = img_url.rsplit('.', 1)[1]
            formatted_string = IH.format_image("image", img_ext,
                                               utils.get_temporary_img_dir())
            reg_print("Posting an image to the mumble channel chat.")
            # Display image with PGUI system
            GM.gui.quick_gui_img(
                f"{utils.get_temporary_img_dir()}",
                formatted_string,
                bgcolor=GM.cfg['Plugin_Settings']['Images_FrameColor'],
                cellspacing=GM.cfg['Plugin_Settings']['Images_FrameSize'],
                format=False)
            GM.logger.info(
                f"Posted an image to the mumble channel chat from: {message_parse[1]}."
            )
            return

        elif command == "img":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            parameter = message_parse[1]
            if not os.path.isfile(utils.get_permanent_media_dir() +
                                  f"images/{parameter}.jpg"):
                GM.gui.quick_gui("The image does not exist.",
                                 text_type='header',
                                 box_align='left')
                return False
            # Format image
            img_data = parameter.rsplit('.', 1)
            formatted_string = IH.format_image(
                img_data[0], "jpg",
                utils.get_permanent_media_dir() + "images/")
            reg_print("Posting an image to the mumble channel chat.")
            # Display image with PGUI system
            GM.gui.quick_gui_img(
                f"{utils.get_permanent_media_dir()}images/",
                formatted_string,
                bgcolor=GM.cfg['Plugin_Settings']['Images_FrameColor'],
                cellspacing=GM.cfg['Plugin_Settings']['Images_FrameSize'],
                format=False)
            GM.logger.info(
                "Posted an image to the mumble channel chat from local files.")
            return

        elif command == "imglist":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            file_counter = 0
            gather_list = []
            internal_list = []

            for file_item in os.listdir(utils.get_permanent_media_dir() +
                                        "images/"):
                if file_item.endswith(".jpg"):
                    gather_list.append(f"{file_item}")
                    file_counter += 1

            gather_list.sort(key=str.lower)
            for i, item in enumerate(gather_list):
                internal_list.append(
                    f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{i}]</font> - [{item}]"
                )

            cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Image Files:</font>"
            if len(internal_list) == 0:
                cur_text += "<br>There are no local image files available."
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'])
                GM.logger.info("Displayed a list of all local image files.")
                return

            for i, item in enumerate(internal_list):
                cur_text += item
                if i % 50 == 0 and i != 0:
                    GM.gui.quick_gui(cur_text,
                                     text_type='header',
                                     box_align='left',
                                     text_align='left',
                                     user=GM.mumble.users[text.actor]['name'])
                    cur_text = ""
            if cur_text != "":
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left',
                                 text_align='left',
                                 user=GM.mumble.users[text.actor]['name'])
            GM.logger.info("Displayed a list of all local image files.")
            return

        elif command == "imglist_echo":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            file_counter = 0
            gather_list = []
            internal_list = []

            for file_item in os.listdir(utils.get_permanent_media_dir() +
                                        "images/"):
                if file_item.endswith(".jpg"):
                    gather_list.append(f"{file_item}")
                    file_counter += 1

            gather_list.sort(key=str.lower)
            for i, item in enumerate(gather_list):
                internal_list.append(
                    f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{i}]</font> - [{item}]"
                )

            cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Image Files:</font>"
            if len(internal_list) == 0:
                cur_text += "<br>There are no local image files available."
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left')
                GM.logger.info("Displayed a list of all local image files.")
                return

            for i, item in enumerate(internal_list):
                cur_text += item
                if i % 50 == 0 and i != 0:
                    GM.gui.quick_gui(cur_text,
                                     text_type='header',
                                     box_align='left',
                                     text_align='left')
                    cur_text = ""
            if cur_text != "":
                GM.gui.quick_gui(cur_text,
                                 text_type='header',
                                 box_align='left',
                                 text_align='left')
            GM.logger.info("Displayed a list of all local image files.")
            return
Beispiel #8
0
    def process_command(self, text):
        message = text.message.strip()
        message_parse = message[1:].split(' ', 1)
        command = message_parse[0]

        if command == "getwhisper":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            if GM.whisper_target is None:
                GM.gui.quick_gui("There is no whisper target set",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                return
            if GM.whisper_target["type"] == 0:
                ch = GM.mumble.channels[GM.whisper_target['id']]['name']
                GM.gui.quick_gui(f"Current whisper channel: {ch}",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                return
            elif GM.whisper_target["type"] == 1:
                us = ""
                for user in GM.mumble.users:
                    if GM.mumble.users[user]['session'] == GM.whisper_target[
                            'id']:
                        us = GM.mumble.users[user]['name']
                GM.gui.quick_gui(f"Current whisper user: {us}",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                return
            elif GM.whisper_target["type"] == 2:
                users = ""
                counter = 0
                for i, user in enumerate(GM.mumble.users):
                    if GM.mumble.users[user]['session'] in GM.whisper_target[
                            'id']:
                        users += f"<br>[{counter}] - {GM.mumble.users[user]['name']}"
                        counter += 1
                GM.gui.quick_gui(f"Current whisper users: {users}",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                return

        elif command == "setwhisperuser":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                parameter = message_parse[1]
                if parameter == GM.cfg['Connection_Settings']['UserID']:
                    GM.logger.info("I can't set the whisper target to myself!")
                    GM.gui.quick_gui(
                        "I can't set the whisper target to myself!",
                        text_type='header',
                        box_align='left',
                        user=GM.mumble.users[text.actor]['name'],
                        ignore_whisper=True)
                    return
                utils.set_whisper_user(parameter)

                GM.gui.quick_gui(f"Set whisper to User: {parameter}",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                GM.logger.info(f"Set whisper to User: {parameter}.")
            except IndexError:
                GM.gui.quick_gui(
                    "Invalid whisper command!<br>Command format: !setwhisperuser username",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "removewhisperuser":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                username = message_parse[1]
                if GM.whisper_target is not None:
                    if not isinstance(GM.whisper_target['id'], list):
                        GM.gui.quick_gui(
                            "<br>The current whisper mode is set to single user/channel."
                            "<br>You can only remove a user from a multi-user whisper mode."
                            "<br>Did you mean to use the 'clearwhisper' command?",
                            text_type='header',
                            box_align='left',
                            user=GM.mumble.users[text.actor]['name'],
                            ignore_whisper=True)
                        return
                else:
                    return

                user_id = None
                for user in GM.mumble.users:
                    if GM.mumble.users[user]['name'] == username:
                        user_id = GM.mumble.users[user]['session']
                if user_id is not None:
                    if user_id in GM.whisper_target['id']:
                        GM.whisper_target['id'].remove(user_id)
                    else:
                        GM.gui.quick_gui(
                            f"Could not find user: {username} in the whisper targets!",
                            text_type='header',
                            box_align='left',
                            user=GM.mumble.users[text.actor]['name'],
                            ignore_whisper=True)
                        return
                else:
                    GM.gui.quick_gui(
                        f"Could not find user: {username} in the whisper targets!",
                        text_type='header',
                        box_align='left',
                        user=GM.mumble.users[text.actor]['name'],
                        ignore_whisper=True)
                    return
                if len(GM.whisper_target['id']) < 1:
                    utils.clear_whisper()
                else:
                    utils.set_whisper_multi_user(GM.whisper_target['id'])

                GM.gui.quick_gui(
                    f"Removed user: {username} from the whisper targets!",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                GM.logger.info(
                    f"Removed user: {username} from the whisper targets!")
            except IndexError:
                GM.gui.quick_gui(
                    "Invalid whisper command!<br>Command format: !removewhisperuser username",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "addwhisperuser":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                username = message_parse[1]
                if username == GM.cfg['Connection_Settings']['UserID']:
                    GM.logger.info(
                        "I can't add myself to the whisper targets!")
                    GM.gui.quick_gui(
                        "I can't add myself to the whisper targets!",
                        text_type='header',
                        box_align='left',
                        user=GM.mumble.users[text.actor]['name'],
                        ignore_whisper=True)
                    return
                if GM.whisper_target is not None:
                    if not isinstance(GM.whisper_target['id'], list):
                        GM.gui.quick_gui(
                            "<br>The current whisper mode is set to single user.<br>Use the 'setwhisperusers' command for multi-user whispers.",
                            text_type='header',
                            box_align='left',
                            user=GM.mumble.users[text.actor]['name'],
                            ignore_whisper=True)
                        return
                else:
                    return
                for user in GM.mumble.users:
                    if GM.mumble.users[user]['name'] == username:
                        if GM.mumble.users[user][
                                'session'] in GM.whisper_target['id']:
                            GM.gui.quick_gui(
                                "<br>This user is already one of the whisper targets!",
                                text_type='header',
                                box_align='left',
                                user=GM.mumble.users[text.actor]['name'],
                                ignore_whisper=True)
                            return

                GM.whisper_target['id'].append(username)
                utils.set_whisper_multi_user(GM.whisper_target['id'])

                GM.gui.quick_gui(
                    f"Added new user: {username} to the whisper targets!",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                GM.logger.info(
                    f"Added new user: {username} to the whisper targets!")
            except IndexError:
                GM.gui.quick_gui(
                    "Invalid whisper command!<br>Command format: !addwhisperuser username",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "setwhisperusers":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                parameter = message_parse[1]

                users_list = [
                    user.strip() for user in parameter.split(',') if
                    not user.strip() == GM.cfg['Connection_Settings']['UserID']
                ]
                if len(users_list) < 2:
                    GM.gui.quick_gui(
                        "Use the 'setwhisperuser' command for a single user!",
                        text_type='header',
                        box_align='left',
                        user=GM.mumble.users[text.actor]['name'],
                        ignore_whisper=True)
                    return

                utils.set_whisper_multi_user(users_list)

                GM.gui.quick_gui(f"Added whisper to multiple users!",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                GM.logger.info(f"Added whisper to multiple users!")
            except IndexError:
                GM.gui.quick_gui(
                    "Invalid whisper command!<br>Command format: !setwhisperusers username0,username1,...",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "setwhisperme":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            parameter = GM.mumble.users[text.actor]['name']
            if parameter == GM.cfg['Connection_Settings']['UserID']:
                GM.logger.info("I can't set the whisper target to myself!")
                return

            utils.set_whisper_user(parameter)

            GM.gui.quick_gui(f"Set whisper to user: {parameter}",
                             text_type='header',
                             box_align='left',
                             user=GM.mumble.users[text.actor]['name'],
                             ignore_whisper=True)
            GM.logger.info(f"Set whisper to user: {parameter}.")
            return

        elif command == "setwhisperchannel":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            try:
                parameter = message_parse[1]
                utils.set_whisper_channel(parameter)

                GM.gui.quick_gui(f"Set whisper to channel: {parameter}",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                GM.logger.info(f"Set whisper to channel: {parameter}.")
            except IndexError:
                GM.gui.quick_gui(
                    "Command format: !setwhisperchannel channel_name",
                    text_type='header',
                    box_align='left',
                    user=GM.mumble.users[text.actor]['name'],
                    ignore_whisper=True)
                return
            return

        elif command == "clearwhisper":
            if not pv.plugin_privilege_checker(text, command, self.priv_path):
                return
            utils.clear_whisper()
            if GM.whisper_target is None:
                GM.gui.quick_gui(f"Cleared current whisper",
                                 text_type='header',
                                 box_align='left',
                                 user=GM.mumble.users[text.actor]['name'],
                                 ignore_whisper=True)
                return
            GM.gui.quick_gui("Unable to remove current whisper!",
                             text_type='header',
                             box_align='left',
                             user=GM.mumble.users[text.actor]['name'],
                             ignore_whisper=True)
            return