Beispiel #1
0
async def sideload(event):
    OVR_WRT_CAUT = True
    cmd_args = event.pattern_match.group(1).split(" ", 1)
    if cmd_args[0].lower() == "force":
        OVR_WRT_CAUT = False
    if event.reply_to_msg_id:
        msg = await event.get_reply_message()
        file = msg.file
        if not file.name.endswith(".py"):
            await event.edit(msgRep.NOT_PY_FILE)
            return
        dest_path = os.path.join(USER_MODULES_DIR, file.name)
        await event.edit(msgRep.DLOADING)
        if os.path.isfile(dest_path) and OVR_WRT_CAUT:
            log.info(f"Module '{file.name[:-3]}' installed already")
            await event.edit(msgRep.MODULE_EXISTS.format(file.name))
            return
        await event.client.download_media(message=msg, file=dest_path)
        log.info(f"Module '{file.name[:-3]}' has been installed to userpace")
        await event.edit(msgRep.SUCCESS.format(file.name))
        if getConfig("LOGGING"):
            await event_log(event,
                            "SIDELOAD",
                            custom_text=msgRep.LOG.format(file.name))
        log.info("Rebooting userbot...")
        time.sleep(1)
        await event.edit(msgRep.RBT_CPLT)
        setConfig("REBOOT", True)
        await event.client.disconnect()
    else:
        await event.edit(msgRep.INVALID_FILE)
    return
Beispiel #2
0
def _set_autoupdate(commit_id: str) -> bool:
    try:
        setConfig("UPDATE_COMMIT_ID", commit_id)
        setConfig("START_RECOVERY", True)
        return True
    except Exception as e:
        log.error(f"Unable to set reboot reason: {e}")
    return False
Beispiel #3
0
async def restart(power_off):  # Totally not a shutdown kang *sips whiskey*
    cmd_args = power_off.pattern_match.group(1).split(" ", 1)
    if cmd_args[0] == "safemode":
        setConfig("REBOOT_SAFEMODE", True)
    setConfig("REBOOT", True)
    await power_off.edit(msgRep.RESTART)
    time.sleep(1)  # just so we can actually see a message
    if getConfig("LOGGING"):
        await event_log(power_off, "RESTART", custom_text=msgRep.RESTART_LOG)
    await power_off.edit(msgRep.RESTARTED)
    await power_off.client.disconnect()
Beispiel #4
0
def _set_autoupdate(chat_id: int, msg_id: int, new_version: str,
                    commit_id: str) -> bool:
    try:
        _setprop("reboot", True)
        _setprop("rebootchatid", chat_id)
        _setprop("rebootmsgid", msg_id)
        _setprop("rebootmsg", msgRep.UPDATE_SUCESS.format(new_version))
        _setprop("updateversion", new_version)
        _setprop("updatefailedmsg", msgRep.UPDATE_FAIL.format(new_version))
        setConfig("UPDATE_COMMIT_ID", commit_id)
        setConfig("START_RECOVERY", True)
        return True
    except Exception as e:
        log.error(f"Unable to set reboot reason: {e}")
    return False
Beispiel #5
0
async def restart(power_off):  # Totally not a shutdown kang *sips whiskey*
    if isWindows():
        await power_off.edit(msgRep.RESTART_UNSUPPORTED)
        return
    cmd_args = power_off.pattern_match.group(1).split(" ", 1)
    if cmd_args[0] == "safemode":
        setConfig("REBOOT_SAFEMODE", True)
    setConfig("REBOOT", True)
    await power_off.edit(msgRep.RESTART)
    if getConfig("LOGGING"):
        await event_log(power_off, "RESTART", custom_text=msgRep.RESTART_LOG)
    _setprop("reboot", True)
    _setprop("rebootchatid", power_off.chat_id)
    _setprop("rebootmsgid", power_off.message.id)
    _setprop("rebootmsg", msgRep.RESTARTED)
    await power_off.client.disconnect()
    return
Beispiel #6
0
async def universe_checker(msg):
    cmd_args = msg.pattern_match.group(1).split(" ", 1)
    user_modules = getUserModules()
    if cmd_args[0].lower() == "update":
        list_updater()
        write_list()
        repos = UNIVERSE_NAME
        for repo in REPOS_NAMES:
            repos += ", " + repo
        await msg.edit(msgRep.UPDATE_COMPLETE.format(repos))
    elif cmd_args[0].lower() == "list":
        files = msgRep.INSTALLED
        count = 1
        for item in user_modules:
            files += str(count) + ". " + item + "\n"
            count += 1
        if len(user_modules) == 0:
            files += msgRep.NO_MOD_IN_USERSPACE
        count = 1
        if MODULE_LIST is None or len(MODULE_LIST) == 0:
            files += msgRep.EMPTY_LIST
        else:
            mdInstalled = False
            oldName = ""
            for m in MODULE_LIST:
                if not (m["repo"] == oldName):
                    files += msgRep.FILES_IN.format(m["repo"])
                    oldName = m["repo"]
                    count = 1
                size = sizeStrMaker(int(m["size"]))
                mdName = m["name"].split(".py")[0]
                if mdName in user_modules:
                    mdName += "*"
                    mdInstalled = True
                files += msgRep.FILE_DSC.format(count, mdName, m["url"], size)
                count += 1
            if mdInstalled:
                files += msgRep.ALREADY_PRESENT
        if SAFEMODE:
            files += msgRep.BOT_IN_SAFEMODE
        await msg.edit(files, parse_mode='md')
    elif cmd_args[0].lower() == "install":
        if MODULE_LIST is None or len(MODULE_LIST) == 0:
            await msg.edit(msgRep.EMPTY_LIST)
            return
        if len(cmd_args) == 1:
            await msg.edit(msgRep.NO_PKG)
            return
        if SAFEMODE:
            await msg.edit(msgRep.INSTALL_DSBLD_SAFEMODE)
            return
        del (cmd_args[0])
        fileURLs = []
        modules_installed = []
        cmd_args = cmd_args[0].split(" ")
        for i in cmd_args:
            found = False
            if not i.endswith(".py"):
                i += ".py"
            for j in MODULE_LIST:
                if j['name'] == i:
                    fileURLs.append({'filename': i, 'link': j['url']})
                    found = True
                    break
            if not found:
                await msg.edit(msgRep.MOD_NOT_FOUND_INSTALL.format(i))
                return
        for i in fileURLs:
            request = requests.get(i['link'], allow_redirects=True)
            # We remove first, in case exists for updates
            if os.path.exists(os.path.join(USER_MODULES_DIR, i['filename'])):
                os.remove(os.path.join(USER_MODULES_DIR, i['filename']))
            open(os.path.join(USER_MODULES_DIR, i['filename']),
                 'wb').write(request.content)
            modules_installed.append(i['filename'])
            log.info(f"Module '{i['filename'][:-3]}' "
                     f"has been installed to userspace")
        md_installed_string = ""
        for md in modules_installed:
            if md_installed_string == "":
                md_installed_string += md
            else:
                md_installed_string += ", " + md
        log.info("Rebooting userbot...")
        await msg.edit(msgRep.DONE_RBT)
        time.sleep(1)  # just so we can actually see a message
        if LOGGING:
            await event_log(
                msg,
                "MODULE INSTALL",
                custom_text=msgRep.INSTALL_LOG.format(md_installed_string))
        await msg.edit(msgRep.REBOOT_DONE_INS.format(md_installed_string))
        setConfig("REBOOT", True)
        await msg.client.disconnect()
    elif cmd_args[0].lower() == "uninstall":
        if len(user_modules) == 0:
            await msg.edit(msgRep.NO_UNINSTALL_MODULES)
            return
        if len(cmd_args) == 1:
            await msg.edit(msgRep.NO_UN_NAME)
            return
        del (cmd_args[0])
        mods_uninstall = cmd_args[0].split()
        modNames = ""
        for i in mods_uninstall:
            if modNames == "":
                modNames += i
            else:
                modNames += ", " + i
        await msg.edit(msgRep.UNINSTALLING.format(modNames))
        for modName in mods_uninstall:
            if modName not in user_modules:
                await msg.edit(msgRep.NOT_IN_USERSPACE.format(modName))
                return
            os.remove(os.path.join(USER_MODULES_DIR, modName + ".py"))
        log.info(f"Modules '{modNames}' has been uninstalled from userspace")
        log.info("Rebooting userbot...")
        await msg.edit(msgRep.DONE_RBT)
        time.sleep(1)  # just so we can actually see a message
        if LOGGING:
            await event_log(msg,
                            "MODULE UNINSTALL",
                            custom_text=msgRep.UNINSTALL_LOG.format(modNames))
        await msg.edit(msgRep.REBOOT_DONE_UNINS.format(modNames))
        if SAFEMODE:
            setConfig("REBOOT_SAFEMODE", True)
        setConfig("REBOOT", True)
        await msg.client.disconnect()
    else:
        await msg.edit(msgRep.INVALID_ARG)
    return