Ejemplo n.º 1
0
        except ValueError:
            await context.edit("`An error occurred during the conversion.`")
            remove(target_file_path)
            return
        await context.delete()
        remove("result.png")
        remove(target_file_path)
        message = string_1 + "` and `" + string_2
        if log:
            await context.client.send_message(
                log_chatid, "Captions `" + message + "` added to an image.")


command_help.update({
    "caption":
    "Parameter: -caption <text>,<text> <image>\
    \nUsage: Adds two lines of captions to an image."
})


@register(outgoing=True, pattern="^-ocr(?: |$)(.*)")
@diagnostics
async def ocr(context):
    """ Extracts texts from images. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        if context.fwd_from:
            return
        reply = await context.get_reply_message()
        await context.edit("`Processing image, please wait . . .`")
        if reply:
Ejemplo n.º 2
0
@register(outgoing=True, pattern="^-help(?: |$)(.*)")
@diagnostics
async def help(context):
    """ The help command,"""
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        args = context.pattern_match.group(1)
        if args:
            if args in command_help:
                await context.edit(str(command_help[args]))
            else:
                await context.edit(
                    "`Invalid argument, please check module list.`")
        else:
            result = "**Commands loaded from current modules: \n**"
            for i in sorted(command_help, reverse=False):
                result += "`" + str(i)
                result += "`, "
            await context.edit(
                result[:-2] +
                "\n**Do \"-help <command>\" to view help for a specific command.**"
            )


command_help.update({
    "help":
    "Parameter: -help <command>\
    \nUsage: Shows a list of commands or help string of a single command."
})
Ejemplo n.º 3
0
@register(outgoing=True, pattern="^-sysinfo$")
@diagnostics
async def sysinfo(context):
    """ Fetches system info using neofetch. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        result = await execute("neofetch --stdout")
        if result == "/bin/sh: neofetch: command not found":
            await context.edit("`Neofetch does not exist on this system.`")
            return
        await context.edit("`" + result + "`")


command_help.update({
    "sysinfo":
    "Parameter: -sysinfo\
    \nUsage: Retrieve system information via neofetch."
})


@register(outgoing=True, pattern="^-fortune$")
@diagnostics
async def fortune(context):
    """ Reads a fortune cookie. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        result = await execute("fortune")
        if result == "/bin/sh: fortune: command not found":
            await context.edit("`No fortune cookies on this system.`")
            return
        await context.edit(result)
Ejemplo n.º 4
0
            await context.edit("`Invalid argument.`")
            return
        latency = 0.03
        cursor = "█"
        old_text = ''
        await context.edit(cursor)
        await sleep(latency)
        for character in message:
            old_text = old_text + "" + character
            typing_text = old_text + "" + cursor
            await context.edit(typing_text)
            await sleep(latency)
            await context.edit(old_text)
            await sleep(latency)
command_help.update({
    "animate": "Parameter: -animate <text>\
    \nUsage: Animated text via edit."
})


@register(outgoing=True, pattern="^-mock(?: |$)(.*)")
@diagnostics
async def mock(context):
    """ Mock people with weird caps. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@", "!"):
        reply = await context.get_reply_message()
        message = context.pattern_match.group(1)
        if message:
            pass
        elif reply:
            message = reply.text
        else:
Ejemplo n.º 5
0
            if msgs:
                await context.client.delete_messages(chat, msgs)
            notification = await send_notify(context, count)

            if log:
                await context.client.send_message(
                    log_chatid, "Deleted " + str(count) + " messages.")
            await sleep(0.5)
            await notification.delete()
    except TypeError:
        await context.edit("`Please reply to a message.`")


command_help.update({
    "prune":
    "Parameter: -prune\
    \nUsage: Deletes everything starting from the message you replied to."
})


@register(outgoing=True, pattern="^-selfprune")
@diagnostics
async def selfprune(context):
    """ Prune self message. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        try:
            message = context.text
            count = int(message[11:])
            i = 1
Ejemplo n.º 6
0
            else:
                user_id = message.forward.sender.id
                if message.forward.sender.username:
                    target = "@" + message.forward.sender.username
                else:
                    target = "*" + message.forward.sender.first_name + "*"
            await context.edit("**Username:** {} \n**UserID:** `{}`".format(
                target, user_id))
        else:
            await context.edit("`Unable to get the target message.`")


command_help.update({
    "userid":
    "Parameter: -userid\
    \nUsage: Query the userid of the sender of the message you replied to."
})


@register(outgoing=True, pattern="^-chatid$")
@diagnostics
async def chatid(context):
    """ Queries the chatid of the chat you are in. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        await context.edit("ChatID: `" + str(context.chat_id) + "`")


command_help.update({
    "chatid":
Ejemplo n.º 7
0
                        remove("output.log")
                        return
                    await context.edit(f">>> {expression}\n" f"{evaluation}")

        except Exception as err:
            await context.edit(f">>> {expression}\n" f"`{err}`")

        if log:
            await context.client.send_message(
                log_chatid,
                f"Evaluated `{expression}` in the python interpreter.")


command_help.update({
    "evaluate":
    "Parameter: -evaluate <expression>>\
    \nUsage: Evaluate an expression in the python interpreter."
})


@register(outgoing=True, pattern="^-sh(?: |$)(.*)")
@diagnostics
async def sh(context):
    """ For calling a binary from the shell. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        user = getuser()
        command = context.pattern_match.group(1)
        uid = geteuid()
        hostname = node()
        if context.is_channel and not context.is_group:
Ejemplo n.º 8
0
        return

    await context.edit('`Found update(s), pulling it in . . .`')

    try:
        upstream_remote.pull(active_branch)
        await execute("pip install -r requirements.txt --upgrade")
        await execute("pip install -r requirements.txt")
        if log:
            await context.client.send_message(
                log_chatid, "Jarvis have been updated."
            )
        await context.edit(
            '`Update successful, Jarvis is restarting.`'
            )
        await context.client.disconnect()
    except GitCommandError:
        upstream_remote.git.reset('--hard')
        if log:
            await context.client.send_message(
                log_chatid, "Jarvis failed to update."
            )
        await context.edit(
            '`Updated with errors, Jarvis is restarting.`'
            )
        await context.client.disconnect()
command_help.update({
    "update": "Parameter: -update <boolean>\
    \nUsage: Checks for updates from remote origin, and apply updates to Jarvis."
})
Ejemplo n.º 9
0
        await context.edit(result)
        if log:
            result = f"Translated `{message}` from {source_lang} to {trans_lang}."
            if len(result) > 4096:
                await context.edit("`Output exceeded limit, attaching file.`")
                await attach_log(context, result)
                return
            await context.client.send_message(
                log_chatid,
                result,
            )


command_help.update({
    "translate":
    "Parameter: -translate <text>\
    \nUsage: Translate the target message into English."
})


@register(outgoing=True, pattern=r"^-tts(?: |$)([\s\S]*)")
@diagnostics
async def tts(context):
    """ Send TTS stuff as voice message. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        text = await context.get_reply_message()
        message = context.pattern_match.group(1)
        if message:
            pass
        elif text:
Ejemplo n.º 10
0
                                                                 "!"):
        result = context.pattern_match.group(1)
        try:
            await bot(UpdateUsernameRequest(result))
        except UsernameOccupiedError:
            await context.edit("`Username is taken.`")
            return
        except UsernameInvalidError:
            await context.edit("`Invalid username.`")
            return
        await context.edit("`Username have been updated.`")


command_help.update({
    "username":
    "******"
})


@register(outgoing=True, pattern="^-name")
@diagnostics
async def name(context):
    """ Updates your display name. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        new = context.text[6:]
        if " " not in new:
            first = new
            last = ""
        else:
Ejemplo n.º 11
0
                            await context.edit(
                                f"Sticker has been added to [this](t.me/addstickers/{pack_name}) alternative pack.",
                                parse_mode='md')
                            return
                    await upload_sticker(animated, bot, message, context, file,
                                         conversation)
                    await conversation.get_response()
                    await conversation.send_message(emoji)
                    await bot.send_read_acknowledge(conversation.chat_id)
                    await conversation.get_response()
                    await conversation.send_message('/done')
                    await conversation.get_response()
                    await bot.send_read_acknowledge(conversation.chat_id)
            else:
                await context.edit("Pack does not exist, creating . . .")
                async with bot.conversation('Stickers') as conversation:
                    await add_sticker(conversation, command, pack_title,
                                      pack_name, bot, animated, message,
                                      context, file, emoji)

            await context.edit(
                f"Sticker has been added to [this](t.me/addstickers/{pack_name}) pack.",
                parse_mode='md')


command_help.update({
    "sticker":
    "Parameter: -sticker <emoji>\
    \nUsage: Collects image/sticker as sticker, specify emoji to set custom emoji."
})
Ejemplo n.º 12
0
        if photo:
            try:
                EditPhotoRequest(context.chat_id, await bot.upload_file(photo))
                await context.edit("`Group image updated.`")

            except PhotoCropSizeSmallError:
                await context.edit(
                    "`Image dimensions smaller than minimum requirements.`")
            except ImageProcessFailedError:
                await context.edit("`Failed to process image.`")


command_help.update({
    "group_image":
    "Parameter: -group_image <image>\
    \nUsage: Changes the group's pfp to the attachment."
})


@register(outgoing=True, pattern="^-admins$")
@diagnostics
async def admins(context):
    """ Lists admins of the group chat. """
    if not context.text[0].isalpha() and context.text[0] not in ("/", "#", "@",
                                                                 "!"):
        if not context.is_group:
            await context.edit("Current chat is not a group.")
            return
        info = await context.client.get_entity(context.chat_id)
        title = info.title if info.title else "this chat"
Ejemplo n.º 13
0
            reason = str(message[5:])
        except:
            reason = ''
        if not reason:
            reason = 'rest'
        await context.edit("Entering afk status.")
        if log:
            await context.client.send_message(
                log_chatid, "User is afk, begin message logging.")
        await db_afk(reason)
        raise StopPropagation


command_help.update({
    "afk":
    "Parameter: -afk <text>\
    \nUsage: Sets yourself to afk and enables message logging and auto response, a message cancels the status."
})


@register(outgoing=True)
@diagnostics
async def back(context):
    global count_msg
    if not redis_check():
        return
    afk_query = await is_afk()
    if afk_query is True:
        await not_afk()
        if log:
            await context.client.send_message(