Ejemplo n.º 1
0
async def start_bot():
	# sys.excepthook = except_hook
	print("----- Checking user and bot... -----")
	await reinitial()
	print("----------- Check done! ------------")
	# Assistant bot
	await setbot.start()
	for setting in ALL_SETTINGS:
		imported_module = importlib.import_module("nana.assistant." + setting)
	# Nana userbot
	await app.start()
	for modul in ALL_MODULES:
		imported_module = importlib.import_module("nana.modules." + modul)
		if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
			imported_module.__MODULE__ = imported_module.__MODULE__
		if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
			if not imported_module.__MODULE__.lower() in HELP_COMMANDS:
				HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
			else:
				raise Exception("Can't have two modules with the same name! Please change one")
		if hasattr(imported_module, "__HELP__") and imported_module.__HELP__:
			HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
	log.info("-----------------------")
	log.info("Userbot modules: " + str(ALL_MODULES))
	log.info("-----------------------")
	log.info("Assistant modules: " + str(ALL_SETTINGS))
	log.info("-----------------------")
	log.info("Bot run successfully!")
	if TEST_DEVELOP:
		log.warning("Test is passed!")
	else:
		await setbot.idle()
Ejemplo n.º 2
0
async def start_bot():
    # sys.excepthook = await except_hook
    print("----- Checking user and bot... -----")
    await reinitial()
    print("----------- Check done! ------------")
    # Assistant bot
    await setbot.start()
    for setting in ALL_SETTINGS:
        imported_module = importlib.import_module("nana.plugins.assistant." +
                                                  setting)
    # Nana userbot
    await app.start()
    for modul in ALL_MODULES:
        imported_module = importlib.import_module("nana.plugins." + modul)
        if hasattr(imported_module,
                   "__MODULE__") and imported_module.__MODULE__:
            imported_module.__MODULE__ = imported_module.__MODULE__
        if hasattr(imported_module,
                   "__MODULE__") and imported_module.__MODULE__:
            if imported_module.__MODULE__.lower() not in HELP_COMMANDS:
                HELP_COMMANDS[
                    imported_module.__MODULE__.lower()] = imported_module
            else:
                raise Exception("Can't have two modules with the same name!")
        if hasattr(imported_module, "__HELP__") and imported_module.__HELP__:
            HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
    userbot_modules = ""
    assistant_modules = ""
    j = 1
    for i in ALL_MODULES:
        if j == 4:
            userbot_modules += "|{:<15}|\n".format(i)
            j = 0
        else:
            userbot_modules += "|{:<15}".format(i)
        j += 1
    j = 1
    for i in ALL_SETTINGS:
        if j == 4:
            assistant_modules += "|{:<15}|\n".format(i)
            j = 0
        else:
            assistant_modules += "|{:<15}".format(i)
        j += 1
    print("+===========================================================+")
    print("|                   Userbot Modules                         |")
    print("+=============+==============+==============+===============+")
    print(userbot_modules)
    print("+=============+=================+===========+===============+\n")
    print("+===========================================================+")
    print("|                   Assistant Modules                       |")
    print("+=============+===============+=============+===============+")
    print(assistant_modules)
    print("+===============+===========+=============+=================+")
    print("Bot run successfully!")
    if TEST_DEVELOP:
        log.warning("Test is passed!")
    else:
        await idle()
Ejemplo n.º 3
0
async def update_button(client, query):
    await query.message.edit_text("Updating, please wait...")
    try:
        repo = Repo()
    except exc.NoSuchPathError as error:
        log.warning(f"Check update failed!\nDirectory {error} is not found!")
        return
    except exc.InvalidGitRepositoryError as error:
        log.warning(
            f"Check update failed!\nDirectory {error} does not seems to be a git repository"
        )
        return
    except exc.GitCommandError as error:
        log.warning(f"Check update failed!\n{error}")
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote('upstream', REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote('upstream')
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}')
    if HEROKU_API is not None:
        import heroku3
        heroku = heroku3.from_key(HEROKU_API)
        heroku_applications = heroku.apps()
        if len(heroku_applications) >= 1:
            heroku_app = heroku_applications[0]
            heroku_git_url = heroku_app.git_url.replace(
                "https://", "https://*****:*****@")
            if "heroku" in repo.remotes:
                remote = repo.remote("heroku")
                remote.set_url(heroku_git_url)
            else:
                remote = repo.create_remote("heroku", heroku_git_url)
            remote.push(refspec="HEAD:refs/heads/master")
        else:
            await query.reply(
                "no heroku application found, but a key given? 😕 ")
    try:
        upstream.pull(brname)
        await query.message.edit_text(
            'Successfully Updated!\nBot is restarting...')
    except exc.GitCommandError:
        repo.git.reset('--hard')
        repo.git.clean('-fd', 'nana/modules/')
        repo.git.clean('-fd', 'nana/assistant/')
        repo.git.clean('-fd', 'nana/helpers/')
        await query.message.edit_text(
            'Successfully Force Updated!\nBot is restarting...')
    await update_changelog(changelog)
    await restart_all()
Ejemplo n.º 4
0
async def update_checker():
    try:
        repo = Repo()
    except NoSuchPathError as error:
        log.warning(f'Check update failed!\nDirectory {error} is not found!')
        return
    except InvalidGitRepositoryError as error:
        log.warning(
            'Check update failed!\nDirectory {} Not a git repository'.format(
                error, ), )
        return
    except GitCommandError as error:
        log.warning(f'Check update failed!\n{error}')
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote('upstream', REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote('upstream')
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}')

    if not changelog:
        log.info(f'Nana is up-to-date with branch {brname}')
        return

    log.warning(f'New UPDATE available for [{brname}]!')

    text = tld('updater_available_text').format(brname)
    text += f'**CHANGELOG:**\n`{changelog}`'
    button = InlineKeyboard(row_width=1)
    button.add(
        InlineKeyboardButton(
            tld('update_now_btn'),
            callback_data='update_now',
        ), )
    await setbot.send_message(
        Owner,
        text,
        reply_markup=button,
        parse_mode='markdown',
    )
Ejemplo n.º 5
0
async def start_bot():
    # sys.excepthook = except_hook
    # print("----- Checking user and bot... -----")
    print("Checking userbot...")
    await reinitial()
    print("Check done, please wait...")
    # print("----------- Check done! ------------")
    # Assistant bot
    # Nana userbot
    await app.start()
    for modul in ALL_MODULES:
        imported_module = importlib.import_module("nana.modules." + modul)
        if hasattr(imported_module,
                   "__MODULE__") and imported_module.__MODULE__:
            imported_module.__MODULE__ = imported_module.__MODULE__
    log.info("-----------------------")
    log.info("Userbot modules: " + str(ALL_MODULES))
    print("Module was loaded: " + ", ".join(ALL_MODULES))
    log.info("-----------------------")
    log.warning("──「 Bot run successfully! 」──")
    if TEST_DEVELOP:
        log.warning("Test is passed!")
    else:
        await app.idle()
Ejemplo n.º 6
0
async def update_checker():
    try:
        repo = Repo()
    except NoSuchPathError as error:
        log.warning(f"Check update failed!\nDirectory {error} is not found!")
        return
    except InvalidGitRepositoryError as error:
        log.warning(
            f"Check update failed!\nDirectory {error} does not seems to be a git repository"
        )
        return
    except GitCommandError as error:
        log.warning(f"Check update failed!\n{error}")
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote("upstream", REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote("upstream")
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f"HEAD..upstream/{brname}")

    if not changelog:
        log.info(f"Nana is up-to-date with branch {brname}")
        return

    log.warning(f"New UPDATE available for [{brname}]!")

    text = tld("updater_available_text").format(brname)
    text += f"**CHANGELOG:**\n`{changelog}`"
    button = InlineKeyboardMarkup([[
        InlineKeyboardButton(tld("update_now_btn"), callback_data="update_now")
    ]])
    await setbot.send_message(Owner,
                              text,
                              reply_markup=button,
                              parse_mode="markdown")
Ejemplo n.º 7
0
async def update_button(client, query):
    await query.message.edit_text("Updating, please wait...")
    try:
        repo = Repo()
    except exc.NoSuchPathError as error:
        log.warning(f"Check update failed!\nDirectory {error} is not found!")
        return
    except exc.InvalidGitRepositoryError as error:
        log.warning(
            f"Check update failed!\nDirectory {error} does not seems to be a git repository"
        )
        return
    except exc.GitCommandError as error:
        log.warning(f"Check update failed!\n{error}")
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote('upstream', REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote('upstream')
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}')

    try:
        upstream.pull(brname)
        await query.message.edit_text(
            'Successfully Updated!\nBot is restarting...')
    except exc.GitCommandError:
        repo.git.reset('--hard')
        repo.git.clean('-fd', 'nana/modules/')
        repo.git.clean('-fd', 'nana/assistant/')
        repo.git.clean('-fd', 'nana/helpers/')
        await query.message.edit_text(
            'Successfully Force Updated!\nBot is restarting...')
    await update_changelog(changelog)
    await restart_all()
Ejemplo n.º 8
0
async def update_button(client, _):
    await client.send_message(Owner, "Updating, please wait...")
    try:
        repo = Repo()
    except NoSuchPathError as error:
        log.warning(f"Check update failed!\nDirectory {error} is not found!")
        return
    except InvalidGitRepositoryError as error:
        log.warning(
            f"Check update failed!\nDirectory {error} does not seems to be a git repository"
        )
        return
    except GitCommandError as error:
        log.warning(f"Check update failed!\n{error}")
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote("upstream", REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote("upstream")
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f"HEAD..upstream/{brname}")
    try:
        upstream.pull(brname)
        await client.send_message(
            Owner, "Successfully Updated!\nBot is restarting...")
    except GitCommandError:
        repo.git.reset("--hard")
        repo.git.clean("-fd", "nana/modules/")
        repo.git.clean("-fd", "nana/assistant/")
        repo.git.clean("-fd", "nana/helpers/")
        await client.send_message(
            Owner, "Successfully Force Updated!\nBot is restarting...")
    await update_changelog(changelog)
    await restart_all()
Ejemplo n.º 9
0
async def update_button(client, query):
    await query.message.delete()
    await client.send_message(Owner, 'Updating, please wait...')
    try:
        repo = Repo()
    except NoSuchPathError as error:
        log.warning(f'Check update failed!\nDirectory {error} is not found!')
        return
    except InvalidGitRepositoryError as error:
        log.warning(
            'Check update failed!\nDirectory {} Not a git repository'.format(
                error, ), )
        return
    except GitCommandError as error:
        log.warning(f'Check update failed!\n{error}')
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote('upstream', REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote('upstream')
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}')
    try:
        upstream.pull(brname)
        await client.send_message(Owner, tld('update_successful'))
    except GitCommandError:
        repo.git.reset('--hard')
        repo.git.clean('-fd', 'nana/modules/')
        repo.git.clean('-fd', 'nana/assistant/')
        repo.git.clean('-fd', 'nana/utils/')
        await client.send_message(Owner, tld('update_successful_force'))
    await update_changelog(changelog)
    await restart_all()
Ejemplo n.º 10
0
async def start_bot():
    # sys.excepthook = await except_hook
    print('----- Checking user and bot... -----')
    await reinitial()
    print('----------- Check done! ------------')
    # Assistant bot
    await setbot.start()
    for setting in ALL_SETTINGS:
        imported_module = importlib.import_module(
            'nana.plugins.assistant.' + setting, )
    # Nana userbot
    await app.start()
    for modul in ALL_MODULES:
        imported_module = importlib.import_module('nana.plugins.' + modul)
        if hasattr(
                imported_module,
                '__MODULE__',
        ) and imported_module.__MODULE__:
            imported_module.__MODULE__ = imported_module.__MODULE__
        if hasattr(
                imported_module,
                '__MODULE__',
        ) and imported_module.__MODULE__:
            if imported_module.__MODULE__.lower() not in HELP_COMMANDS:
                HELP_COMMANDS[
                    imported_module.__MODULE__.lower()] = imported_module
            else:
                raise Exception("Can't have two modules with the same name!", )
        if hasattr(imported_module, '__HELP__') and imported_module.__HELP__:
            HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
    userbot_modules = ''
    assistant_modules = ''
    j = 1
    for i in ALL_MODULES:
        if j == 4:
            userbot_modules += f'|{i:<15}|\n'
            j = 0
        else:
            userbot_modules += f'|{i:<15}'
        j += 1
    j = 1
    for i in ALL_SETTINGS:
        if j == 4:
            assistant_modules += f'|{i:<15}|\n'
            j = 0
        else:
            assistant_modules += f'|{i:<15}'
        j += 1
    print('+===============================================================+')
    print('|                     Userbot Modules                           |')
    print('+=============+===============+================+===============+')
    print(userbot_modules)
    print('+=============+===================+=============+===============+')
    print('+===============================================================+')
    print('|                     Assistant Modules                         |')
    print('+=============+=================+===============+===============+')
    print(assistant_modules)
    print('+===============+=============+===============+=================+')
    print('Logged in User: {}'.format((await app.get_me()).first_name))
    print('Logged in Bot: {}'.format((await setbot.get_me()).first_name))
    if TEST_DEVELOP:
        log.warning('Test is passed!')
    else:
        await idle()
Ejemplo n.º 11
0
async def update_button(client, _):
    await client.send_message(Owner, "Updating, please wait...")
    try:
        repo = Repo()
    except NoSuchPathError as error:
        log.warning(f"Check update failed!\nDirectory {error} is not found!")
        return
    except InvalidGitRepositoryError as error:
        log.warning(
            f"Check update failed!\nDirectory {error} does not seems to be a git repository"
        )
        return
    except GitCommandError as error:
        log.warning(f"Check update failed!\n{error}")
        return

    brname = repo.active_branch.name
    if brname not in OFFICIAL_BRANCH:
        return

    try:
        repo.create_remote("upstream", REPOSITORY)
    except BaseException:
        pass

    upstream = repo.remote("upstream")
    upstream.fetch(brname)
    changelog = await gen_chlog(repo, f"HEAD..upstream/{brname}")
    if HEROKU_API is not None:
        import heroku3

        heroku = heroku3.from_key(HEROKU_API)
        heroku_applications = heroku.apps()
        if len(heroku_applications) >= 1:
            heroku_app = heroku_applications[0]
            heroku_git_url = heroku_app.git_url.replace(
                "https://", "https://*****:*****@"
            )
            if "heroku" in repo.remotes:
                remote = repo.remote("heroku")
                remote.set_url(heroku_git_url)
            else:
                remote = repo.create_remote("heroku", heroku_git_url)
            remote.push(refspec="HEAD:refs/heads/master")
        else:
            await client.send_message(
                Owner, "no heroku application found, but a key given? 😕 "
            )
        await client.send_message(
            Owner, "Build Unsuccess, Check heroku build log for more detail"
        )
        return
    else:
        try:
            os.system("git reset --hard")
            os.system("git pull")
            os.system("pip install -U -r requirements.txt")
            await client.send_message(
                Owner, "Built Successfully, Please Restart Manually in /settings"
            )
            return
        except Exception as e:
            await client.send_message(Owner, f"Build Unsuccess,\nLog:{e}")
            return
    try:
        upstream.pull(brname)
        await client.send_message(Owner, "Successfully Updated!\nBot is restarting...")
    except GitCommandError:
        repo.git.reset("--hard")
        repo.git.clean("-fd", "nana/modules/")
        repo.git.clean("-fd", "nana/assistant/")
        repo.git.clean("-fd", "nana/helpers/")
        await client.send_message(
            Owner, "Successfully Force Updated!\nBot is restarting..."
        )
    await update_changelog(changelog)
    await restart_all()