Ejemplo n.º 1
0
def _update_menu():
    has_git = BotUtils.is_git_installed()
    BotUtils.clear_screen()
    while True:
        print(f"{constants.INTRO}\n")
        print("Update: (require admin privileges)")
        print("1. Update Bot")
        print("2. Update Requirements")
        print("0. Go back")
        choice = BotUtils.user_choice()
        if choice == "1":
            if not has_git:
                log.error("\nWARNING: Git not found. This means that it's either not "
                          "installed or not in the PATH environment variable.\n"
                          "Git is needed to update the Bot!\n")
            else:
                _update()
                if constants.INTERACTIVE_MODE:
                    BotUtils.wait_return()
        elif choice == "2":
            _update_requirements()
            if constants.INTERACTIVE_MODE:
                BotUtils.wait_return()
        elif choice == "0":
            break
        BotUtils.clear_screen()
Ejemplo n.º 2
0
def _update_requirements():
    interpreter = sys.executable
    if interpreter is None:
        raise RuntimeError("Python interpreter not found.")

    if pip is None:
        raise RuntimeError("Unable to update.\n"
                           "Pip module is missing.\n"
                           "Please make sure to install Python with pip module.")

    arguments = []
    f = open("requirements/requirements.txt")
    file_contents = f.readlines()
    for line in file_contents:
        foo = line.strip('\n')
        arguments.append(foo)

    BotUtils.clear_screen()
    for module in arguments:
        if module != "pip":
            print(f"\n\n==> Updating: {module}")
            command = interpreter, "-m", "pip", "install", "-U", module
            code = subprocess.call(command)
            if code != 0:
                BotUtils.clear_screen()
                return log.error(f"\nAn error occurred trying to update: {module}\n")

    log.info("PIP should be manually upgraded: python -m pip install --upgrade pip\n")
    log.info("\nAll requirements are up tp date.\n")
Ejemplo n.º 3
0
def _insert_token():
    BotUtils.clear_screen()
    tokenFile = open(constants.TOKEN_FILENAME, encoding="utf-8", mode="w")
    print("Please insert your BOT TOKEN bellow:")
    token = BotUtils.read_token()
    tokenFile.write(token)
    tokenFile.close()
    return token
Ejemplo n.º 4
0
        async def on_ready():
            author = bot.get_user(constants.AUTHOR_ID)
            bot.owner = (await bot.application_info()).owner
            bot.owner_id = bot.owner.id
            bot.settings["author_id"] = author.id
            bot.settings["author_avatar_url"] = str(author.avatar_url)
            bot.settings["author"] = f"{author.name}#{author.discriminator}"
            full_db_name = bot.settings["full_db_name"]

            conn = await BotUtils.check_database_connection(bot)
            if conn is None:
                msg = "Cannot Create Database Connection." \
                      f"Check if the server is up and try again ({full_db_name})."
                bot.log.error(msg)
                await bot.logout()
                # await bot.loop.exception()
                return

            bot.log.debug("Setting Initial SQL Tables...")
            await UtilsEvents.set_initial_sql_tables(bot)

            bot.log.debug("Setting Default Initial configs...")
            await UtilsEvents.insert_default_initial_configs(bot)

            bot.log.debug("Setting Other Sql configs...")
            await UtilsEvents.set_others_sql_configs(bot)

            bot.log.debug("Setting BackGround tasks...")
            await UtilsEvents.run_bg_tasks(bot)

            BotUtils.clear_screen()

            # executing all sql files inside dir data/sql
            if bot.settings["ExecuteSqlFilesOnBoot"].lower() == "yes":
                await BotUtils.execute_all_sql_files(self)

            bot_stats = BotUtils.get_bot_stats(bot)
            servers = bot_stats["servers"]
            users = bot_stats["users"]
            channels = bot_stats["channels"]

            conn_msg = f"====> {bot.user} IS ONLINE AND CONNECTED TO DISCORD <===="
            print(f"{constants.INTRO}")
            print("Python v{}.{}.{}".format(*os.sys.version_info[:3]))
            print(f"Discord API v{discord.__version__}")
            print(f"{full_db_name}")
            print("--------------------")
            print(f"{bot.user} (id:{bot.user.id})")
            print(f"Servers: {servers}")
            print(f"Users: {users}")
            print(f"Channels: {channels}")
            print("--------------------")
            print(f"{bot.uptime.strftime('%c')}")
            bot.log.info(conn_msg)
Ejemplo n.º 5
0
def main():
    if constants.IS_WINDOWS:
        os.system("TITLE Discord Bot - Launcher")

    BotUtils.clear_screen()
    while True:
        print(f"{constants.INTRO}\n")
        print("1. Start Bot")
        print("2. Updates")
        print("0. Quit")
        choice = BotUtils.user_choice()
        if choice == "1":
            _run(auto_restart=True)
        elif choice == "2":
            _update_menu()
        elif choice == "0":
            break
        BotUtils.clear_screen()