Example #1
0
async def execution_cmd_t(client, message):
    # send a message, use it to update the progress when required
    status_message = await message.reply_text(PROCESS_RUNNING, quote=True)
    # get the message from the triggered command
    cmd = message.text.split(" ", maxsplit=1)[1]

    process = await asyncio.create_subprocess_shell(
        cmd,
        stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
        cwd=inikerjasaatdirektori
    )

    editor = MessageEditor(status_message, cmd)
    editor.update_process(process)

    aktifperintah[hash_msg(status_message)] = editor
    await editor.redraw(True)
    await asyncio.gather(
        read_stream(
            editor.update_stdout,
            process.stdout,
            DELAY_BETWEEN_EDITS
        ),
        read_stream(
            editor.update_stderr,
            process.stderr,
            DELAY_BETWEEN_EDITS
        )
    )
    await editor.cmd_ended(await process.wait())
    del aktifperintah[hash_msg(status_message)]
Example #2
0
async def type_cmd_t(client, message):
    if message.reply_to_message is None:
        await message.reply_text(TYPE_HELP_GNIRTS, quote=True)
        return
    if hash_msg(message.reply_to_message) in aktifperintah:
        running_proc = aktifperintah[hash_msg(message.reply_to_message)]
        # get the message from the triggered command
        additional_input = message.text.split(" ", maxsplit=1)[1]
        running_proc.stdin.write(additional_input.encode("UTF-8") + b"\n")
    else:
        await message.reply_text(NO_CMD_RUNNING, quote=True)
Example #3
0
async def terminate_cmd_t(client, message):
    if message.reply_to_message is None:
        await message.reply_text(TERMINATE_HELP_GNIRTS, quote=True)
        return
    if hash_msg(message.reply_to_message) in aktifperintah:
        try:
            aktifperintah[hash_msg(message.reply_to_message)].terminate()
        except Exception:
            await message.reply_text("Could not Terminate!", quote=True)
        else:
            await message.reply_to_message.edit("Terminated!")
    else:
        await message.reply_text(NO_CMD_RUNNING, quote=True)
Example #4
0
async def kill_cmd_t(client, message):
    if message.reply_to_message is None:
        await message.reply_text(SIG_KILL_HELP_GNIRTS, quote=True)
        return
    if hash_msg(message.reply_to_message) in aktifperintah:
        try:
            aktifperintah[hash_msg(message.reply_to_message)].kill()
        except Exception:
            await message.reply_text("Could not kill!", quote=True)
        else:
            await message.reply_to_message.edit("Killed!")
    else:
        await message.reply_text(NO_CMD_RUNNING, quote=True)
Example #5
0
async def terminate_cmd_t(client, message):
    if message.reply_to_message is None:
        await message.reply_text(TYPE_HELP_GNIRTS, quote=True)
        return
    if hash_msg(message.reply_to_message) in aktifperintah:
        # get the input from the triggered command
        passed_ip = message.text.split(" ", maxsplit=1)[1]
        #
        current_message_editor = aktifperintah[hash_msg(
            message.reply_to_message)]
        process = current_message_editor.process
        process.stdin.write(passed_ip.encode("UTF-8") + b"\r\n")
        # https://stackoverflow.com/a/163556/4723940
        # process.stdin.close()
        # await process.communicate()
        #
    else:
        await message.reply_text(NO_CMD_RUNNING, quote=True)