예제 #1
0
def update_list() -> list:
    modules_list = []
    for module, isRunning in LOAD_MODULES.items():
        if not module == basename(__file__)[:-3]:  # exclude this module
            if module in USER_MODULES:
                if module in MODULE_INFO.keys():
                    # Append [Name of module, filename of module, running] -> []
                    modules_list.append([
                        MODULE_INFO.get(module,
                                        {}).get("name", msgRep.UNKNOWN),
                        module, isRunning
                    ])
                else:
                    modules_list.append([module, module, isRunning])
            else:
                if module in MODULE_INFO.keys():
                    modules_list.append([
                        MODULE_INFO.get(module,
                                        {}).get("name", msgRep.UNKNOWN),
                        module, isRunning
                    ])
                else:
                    modules_list.append([module, module, isRunning])

    global MODULES_LISTED

    if MODULES_LISTED:
        MODULES_LISTED = {}  # reset dict

    num = 0

    for module in [modules[1] for modules in sorted(modules_list)]:
        num += 1
        MODULES_LISTED[str(num)] = module
    return sorted(modules_list)
예제 #2
0
def module_info(name_of_module: str, module: str) -> str:
    if module in getLoadModules().keys():
        package_name, moduletype, installation_date = (msgRep.UNKNOWN,)*3
        size = 0
        if module in getModuleInfo().keys():
            authors = getModuleInfo().get(module, {}).get("authors", msgRep.UNKNOWN)
            version = getModuleInfo().get(module, {}).get("version", 0)
        elif module in MODULE_INFO.keys():
            log.info(f"MODULE_INFO is obsolete, please use register_module_info() instead (in module '{module}')")
            authors = MODULE_INFO.get(module, {}).get("authors", msgRep.UNKNOWN)
            version = MODULE_INFO.get(module, {}).get("version", 0)
        if not authors:
            authors = msgRep.UNKNOWN
        if not version:
            version = 0
        package_name = module
        module += ".py"
        syspath = join(".", "userbot", "modules")
        userpath = join(".", "userbot", "modules_user")
        if exists(join(syspath, module)):
            moduletype = msgRep.SYSTEM
            size = sizeStrMaker(getsize(join(syspath, module)))
            if OS and OS.lower().startswith("win"):
                installation_date = getctime(join(syspath, module))
            elif OS and OS.lower().startswith("darwin"):
                installation_date = stat(join(syspath, module)).st_birthtime
            else:
                installation_date = stat(join(syspath, module)).st_ctime
        elif exists(join(userpath, module)):
            moduletype = msgRep.USER
            size = sizeStrMaker(getsize(join(userpath, module)))
            if OS and OS.lower().startswith("win"):
                installation_date = getctime(join(userpath, module))
            elif OS and OS.lower().startswith("darwin"):
                installation_date = stat(join(userpath, module)).st_birthtime
            else:
                installation_date = stat(join(userpath, module)).st_ctime
        result = f"{msgRep.PKG_NAME}: {package_name}\n"
        result += f"{msgRep.MODULE_TYPE}: {moduletype}\n"
        result += f"{msgRep.AUTHORS}: {authors}\n"
        result += f"{msgRep.VERSION}: {version}\n"
        result += f"{msgRep.SIZE}: {size}\n"
        result += f"{msgRep.INSTALL_DATE}: {ctime(installation_date)}"
        return msgRep.NAME_MODULE.format(name_of_module) + "\n\n" + result
    else:
        raise IndexError
예제 #3
0
def module_info(name_of_module: str, module: str) -> str:
    if module in LOAD_MODULES:
        package_name, moduletype, installation_date = (msgRep.UNKNOWN, ) * 3
        size = 0
        version = MODULE_INFO.get(module, {}).get("version", 0)
        package_name = module
        module += ".py"
        if OS and OS.lower().startswith("win"):
            syspath = ".\\userbot\\modules\\"
            userpath = ".\\userbot\\modules_user\\"
        else:
            syspath = "./userbot/modules/"
            userpath = "./userbot/modules_user/"
        if exists(syspath + module):
            moduletype = msgRep.SYSTEM
            size = sizeStrMaker(getsize(syspath + module))
            if OS and OS.lower().startswith("win"):
                installation_date = getctime(syspath + module)
            elif OS and OS.lower().startswith("darwin"):
                installation_date = stat(syspath + module).st_birthtime
            else:
                installation_date = stat(syspath + module).st_ctime
        elif exists(userpath + module):
            moduletype = msgRep.USER
            size = sizeStrMaker(getsize(userpath + module))
            if OS and OS.lower().startswith("win"):
                installation_date = getctime(userpath + module)
            elif OS and OS.lower().startswith("darwin"):
                installation_date = stat(userpath + module).st_birthtime
            else:
                installation_date = stat(userpath + module).st_ctime
        result = f"{msgRep.PKG_NAME}: {package_name}\n"
        result += f"{msgRep.MODULE_TYPE}: {moduletype}\n"
        result += f"{msgRep.VERSION}: {version}\n"
        result += f"{msgRep.SIZE}: {size}\n"
        result += f"{msgRep.INSTALL_DATE}: {ctime(installation_date)}"
        return msgRep.NAME_MODULE.format(name_of_module) + "\n\n" + result
    else:
        raise IndexError
예제 #4
0
            await event.edit(msgRep.SPD_FAIL_SEND_RESULT)
    else:
        # Convert speed to Mbit/s
        down_in_mbits = round(result["download"] / 10**6, 2)
        up_in_mbits = round(result["upload"] / 10**6, 2)
        # Convert speed to MB/s (real speed?)
        down_in_mb = round(result["download"] / ((10**6) * 8), 2)
        up_in_mb = round(result["upload"] / ((10**6) * 8), 2)
        time = parse(result["timestamp"])
        ping = result["ping"]
        isp = result["client"]["isp"]
        host = result["server"]["sponsor"]
        host_cc = result["server"]["cc"]

        text = "<b>Speedtest by Ookla</b>\n\n"
        text += f"<b>{msgRep.SPD_TIME}</b>: <code>{time.strftime('%B %d, %Y')} - {time.strftime('%H:%M:%S')} {time.tzname()}</code>\n"
        text += f"<b>{msgRep.SPD_DOWNLOAD}</b>: <code>{down_in_mbits}</code> {msgRep.SPD_MEGABITS} (<code>{down_in_mb}</code> {msgRep.SPD_MEGABYTES})\n"
        text += f"<b>{msgRep.SPD_UPLOAD}</b>: <code>{up_in_mbits}</code> {msgRep.SPD_MEGABITS} (<code>{up_in_mb}</code> {msgRep.SPD_MEGABYTES})\n"
        text += f"<b>{msgRep.SPD_PING}</b>: <code>{ping}</code> ms\n"
        text += f"<b>{msgRep.SPD_ISP}</b>: {isp}\n"
        text += f"<b>{msgRep.SPD_HOSTED_BY}</b>: {host} ({host_cc})\n"
        await event.edit(text, parse_mode="html")

    return


MODULE_DESC.update({basename(__file__)[:-3]: descRep.WEBTOOLS_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.WEBTOOLS_USAGE})
MODULE_INFO.update(
    {basename(__file__)[:-3]: module_info(name="Web Tools", version=VERSION)})
예제 #5
0
        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(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))
        args = [EXECUTABLE, "-m", "userbot"]
        os.execle(sys.executable, *args, os.environ)
        await msg.client.disconnect()
        return
    else:
        await msg.edit(msgRep.INVALID_ARG)
        return


MODULE_DESC.update({basename(__file__)[:-3]: descRep.PACKAGE_MANAGER_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.PACKAGE_MANAGER_USAGE})
MODULE_INFO.update({
    basename(__file__)[:-3]:
    module_info(name="Package Manager", version=VERSION)
})
예제 #6
0
        reason = message
    gbantext = '/gkick ' + user + ' ' + reason
    for i in GBAN_BOT_IDS:
        async with tgclient.conversation(i) as conv:
            await conv.send_message(gbantext)
            x = None
            try:
                x = await conv.get_response()
            except Timeout:
                log.warning("@" + i + " took too much to respond, likely it is offline!\n")
            if x:
                response += i + ': ' + x.text.replace("**", "").replace("`", "").replace("tg://user?id=", "") + '\n\n'
            else:
                response += i + " took too much time to respond, likely it is offline!\n"
    await request.edit("`" + response + "`")
    return

DESC = "nunos-private-repo modules are not for human consumption! This is the global bans module, which will redirect the gban command to group management bots (based on Marie), gbanning people on multiple bots at the same time."
USAGE = "`.gban` <optional: user identifier> \
        \nUsage: Globally bans a user in the specified Marie based bots. \
        \n\n`.ungban` <optional: user identifier> \
        \nUsage: Globally unbans a user in the specified Marie based bots. \
        \n\n`.gkick` <optional: user identifier> \
        \nUsage: Globally kicks a user in the specified Marie based bots. \
        **ALERT**: This module is not suitable for human consumption! Please refrain from using it unless you know what you are doing!"


MODULE_DESC.update({basename(__file__)[:-3]: DESC})
MODULE_DICT.update({basename(__file__)[:-3]: USAGE})
MODULE_INFO.update({basename(__file__)[:-3]: module_info(name="Global Bans Utility", version=VERSION)})
            scale = 512 / size2
            size1new = size1 * scale
            size2new = 512
        size1new = math.floor(size1new)
        size2new = math.floor(size2new)
        sizenew = (size1new, size2new)
        image = image.resize(sizenew)
    else:
        image.thumbnail(maxsize)

    return image


DESC = "Sticker Management Module - Allows you to clone or add existing stickers"

USG = "`.clone`\
    \nUsage: Reply .kang to a sticker or an image to add it to your userbot pack.\
    \n\n`.clone [emoji('s)]`\
    \nUsage: Works just like .clone but uses the emoji you picked.\
    \n\n`.clone [number]`\
    \nUsage: Add's the sticker/image to the specified pack but uses 🤔 as emoji.\
    \n\n`.clone [emoji('s)] [number]`\
    \nUsage: Add's the sticker/image to the specified pack and uses the emoji('s) you picked."

MODULE_DESC.update({basename(__file__)[:-3]: DESC})
MODULE_DICT.update({basename(__file__)[:-3]: USG})
MODULE_INFO.update({
    basename(__file__)[:-3]:
    module_info(name='Sticker Manager', version='1.0.0-debug')
})
예제 #8
0
            text += f"{msgRep.RESULT}: {is_banned}\n"
            if offenses:
                text += f"{msgRep.OFFENSES}: `{offenses}`\n"
            if time_banned:
                text += f"{msgRep.BANNED_SINCE}: `{time_banned.strftime('%b %d, %Y')} - {time_banned.time()} {time_banned.tzname()}`"
    except ChatAdminRequiredError:
        await event.edit(msgRep.NO_ADMIN)
        return
    except Exception as e:
        log.warning(e)
        await event.edit(msgRep.CAS_CHECK_FAIL)
        return

    try:
        if cas_count > 35:  # limit list up to 35 users
            await casSendAsFile(event, text)
        else:
            await event.edit(text)
    except MessageTooLongError:
        await casSendAsFile(event, text)

    return


MODULE_DESC.update({basename(__file__)[:-3]: descRep.CAS_INTERFACE_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.CAS_INTERFACE_USAGE})
MODULE_INFO.update({
    basename(__file__)[:-3]:
    module_info(name="CAS Interface", version=VERSION)
})
예제 #9
0
파일: misc.py 프로젝트: soulr344/HyperUBot
@ehandler.on(pattern=r"^\.rand(?: |$)(.*)", outgoing=True)
async def randomizer(msg):
    limit1 = 0
    limit2 = 0
    arguments = msg.text.split(" ")
    if len(arguments) != 3:
        await msg.edit(msgRep.RAND_INVLD_ARGS)
        return
    try:
        limit1 = int(arguments[1])
    except ValueError:
        await msg.edit(msgRep.FRST_LIMIT_INVALID)
        return
    try:
        limit2 = int(arguments[2])
    except ValueError:
        await msg.edit(msgRep.SCND_LIMIT_INVALID)
        return
    if limit1 > limit2:
        temp = limit1
        limit1 = limit2
        limit2 = temp
    rand_num = random.randint(limit1, limit2)
    await msg.edit(msgRep.RAND_NUM_GEN.format(limit1, limit2, rand_num))
    return

MODULE_DESC.update({basename(__file__)[:-3]: descRep.MISC_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.MISC_USAGE})
MODULE_INFO.update({basename(__file__)[:-3]: module_info(name="Miscellaneous", version=VERSION)})
예제 #10
0
        caption += f"- {msgRep.ROOT_RIGHTS} {root_rights}\n\n"
    else:
        caption += f"- {msgRep.SEND_MESSAGES} {send_messages}\n"
        caption += f"- {msgRep.SEND_MEDIA} {send_media}\n"
        caption += f"- {msgRep.SEND_GIFS_STICKERS} {send_stickers_gifs}\n"
        caption += f"- {msgRep.SEND_POLLS} {send_polls}\n"
        caption += f"- {msgRep.EMBED_LINKS} {embed_links}\n"
        caption += f"- {msgRep.INVITE_USERS} {invite_users}\n"
        caption += f"- {msgRep.PIN_MESSAGES} {pin_messages}\n"
        caption += f"- {msgRep.CHANGE_GROUP_INFO} {change_info}\n\n"
        if not am_i_admeme and not member_is_self:
            caption += f"{warning} <i>{msgRep.WARN_ADMIN_PRIV}</i>\n\n"
    if is_admin and promoted_by is not None:
        caption += f"{msgRep.PROMOTED_BY}: {promoted_by}\n"
    if added_by is not None:
        caption += f"{msgRep.ADDED_BY}: {added_by}\n"
    if (not banned and not not_member) and join_date is not None:
        caption += f"{msgRep.JOIN_DATE}: <code>{join_date.strftime('%b %d, %Y')} - {join_date.time()} {join_date.tzinfo}</code>\n"

    await event.edit(caption, parse_mode="html")

    return


MODULE_DESC.update({basename(__file__)[:-3]: descRep.MEMBERINFO_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.MEMBERINFO_USAGE})
MODULE_INFO.update({
    basename(__file__)[:-3]:
    module_info(name="Member Info", version=VERSION)
})
예제 #11
0
    except Exception as e:
        log.error(e, exc_info=True)
        await event.edit(f"`{msgRep.BASH_SEND_FILE_FAILED}`")

    remove(temp_file)
    return


@ehandler.on(pattern=r"^\.shell(?: |$)(.*)", outgoing=True)
async def bash(command):
    full_cmd_str = command.pattern_match.group(1)
    commandArray = command.text.split(" ")
    del (commandArray[0])
    cmd_output = shell_runner(commandArray)
    if cmd_output is None:
        cmd_output = msgRep.BASH_ERROR
    output = "$ " + full_cmd_str + "\n\n" + cmd_output
    try:
        await command.edit("`" + output + "`")
    except MessageTooLongError:
        log.info(
            "Shell output is too large. Trying to upload output as a file...")
        await outputAsFile(command, output)
    return


MODULE_DESC.update({basename(__file__)[:-3]: descRep.TERMINAL_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.TERMINAL_USAGE})
MODULE_INFO.update(
    {basename(__file__)[:-3]: module_info(name="Terminal", version=VERSION)})
예제 #12
0
        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 = 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)
        args = [EXECUTABLE, "-m", "userbot"]
        await event.edit(msgRep.RBT_CPLT)
        os.execle(sys.executable, *args, os.environ)
        await event.client.disconnect()
        return
    else:
        await event.edit(msgRep.INVALID_FILE)
        return

MODULE_DESC.update({basename(__file__)[:-3]: descRep.SIDELOADER_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.SIDELOADER_USAGE})
MODULE_INFO.update({basename(__file__)[:-3]: module_info(name="Sideloader", version=VERSION)})
예제 #13
0
    deleted_accounts, rem_del_accounts = (0,)*2
    await event.edit(msgRep.TRY_DEL_ACCOUNTS)
    async for member in event.client.iter_participants(chat.id):
        if member.deleted:
            deleted_accounts += 1
            if chat.creator or (chat.admin_rights and chat.admin_rights.ban_users):
                try:
                    await event.client.kick_participant(chat.id, member.id)
                    await sleep(0.2)
                    rem_del_accounts += 1
                except:
                    pass

    if deleted_accounts > 0 and not rem_del_accounts:
        await event.edit(msgRep.DEL_ACCS_COUNT.format(deleted_accounts))
    elif rem_del_accounts > 0 and rem_del_accounts <= deleted_accounts:
        await event.edit(msgRep.REM_DEL_ACCS_COUNT.format(rem_del_accounts, deleted_accounts))
        if LOGGING:
            await event_log(event, "DELACCS", chat_title=chat.title,
                            chat_link=chat.username if hasattr(chat, "username") else None, chat_id=chat.id)
    else:
        await event.edit(msgRep.NO_DEL_ACCOUNTS)

    return


MODULE_DESC.update({basename(__file__)[:-3]: descRep.ADMIN_DESC})
MODULE_DICT.update({basename(__file__)[:-3]: usageRep.ADMIN_USAGE})
MODULE_INFO.update({basename(__file__)[:-3]: module_info(name="Admininstration", version=VERSION)})