Skip to content

Commit

Permalink
add /type command
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Mar 7, 2020
1 parent ea4863e commit e9ca4b6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"DELAY_BETWEEN_EDITS": {
"description": "delay between edits, should be an integer",
"required": false
},
"TYPE_CMD_TRIGGER": {
"description": "TYPE command trigger",
"required": false
}
},
"addons": [],
Expand Down
3 changes: 3 additions & 0 deletions termbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
SIG_KILL_CMD_TRIGGER = Config.SIG_KILL_CMD_TRIGGER
CHANGE_DIRECTORY_CTD = Config.CHANGE_DIRECTORY_CTD
DELAY_BETWEEN_EDITS = Config.DELAY_BETWEEN_EDITS
TYPE_CMD_TRIGGER = Config.TYPE_CMD_TRIGGER

HELP_STICKER = "CAADAgAD6AkAAowucAABsFGHedLEzeUWBA"
PROCESS_RUNNING = "processing ..."
TERMINATE_HELP_GNIRTS = "reply to a <u>command reply</u> to terminate 😡😳😳 it"
SIG_KILL_HELP_GNIRTS = "reply to a <u>command reply</u> to kill 😡 it"
TYPE_HELP_GNIRTS = "reply to a <u>command reply</u> to pass additional <s>required</s> input"
NO_CMD_RUNNING = "No command is running in that message."
33 changes: 23 additions & 10 deletions termbot/plugins/exec_c_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
DELAY_BETWEEN_EDITS,
EXEC_CMD_TRIGGER,
MAX_MESSAGE_LENGTH,
NO_CMD_RUNNING,
PROCESS_RUNNING,
SIG_KILL_CMD_TRIGGER,
SIG_KILL_HELP_GNIRTS,
TERMINATE_CMD_TRIGGER,
TERMINATE_HELP_GNIRTS,
TMP_DOWNLOAD_DIRECTORY
TMP_DOWNLOAD_DIRECTORY,
TYPE_CMD_TRIGGER,
TYPE_HELP_GNIRTS
)


Expand All @@ -45,11 +48,7 @@
aktifperintah = {}
# a variable to store the current working directory
inikerjasaatdirektori = os.path.abspath(
os.path.dirname(
os.path.abspath(
CHANGE_DIRECTORY_CTD
)
)
CHANGE_DIRECTORY_CTD
)
logger.info(inikerjasaatdirektori)

Expand All @@ -72,7 +71,7 @@ async def execution_cmd_t(client, message):
editor = MessageEditor(status_message, cmd)
editor.update_process(process)

aktifperintah[hash_msg(message)] = process
aktifperintah[hash_msg(status_message)] = process
await editor.redraw(True)
await asyncio.gather(
read_stream(
Expand All @@ -87,7 +86,7 @@ async def execution_cmd_t(client, message):
)
)
await editor.cmd_ended(await process.wait())
del aktifperintah[hash_msg(message)]
del aktifperintah[hash_msg(status_message)]


@Client.on_message(Filters.command([TERMINATE_CMD_TRIGGER]) & Filters.chat(AUTH_USERS))
Expand All @@ -103,7 +102,7 @@ async def terminate_cmd_t(client, message):
else:
await message.reply_to_message.edit("Terminated!")
else:
await message.reply_text("No command is running in that message.", quote=True)
await message.reply_text(NO_CMD_RUNNING, quote=True)


@Client.on_message(Filters.command([SIG_KILL_CMD_TRIGGER]) & Filters.chat(AUTH_USERS))
Expand All @@ -119,7 +118,21 @@ async def kill_cmd_t(client, message):
else:
await message.reply_to_message.edit("Killed!")
else:
await message.reply_text("No command is running in that message.", quote=True)
await message.reply_text(NO_CMD_RUNNING, quote=True)


@Client.on_message(Filters.command([TYPE_CMD_TRIGGER]) & Filters.chat(AUTH_USERS))
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)


# Friendly Telegram (telegram userbot)
Expand Down
2 changes: 2 additions & 0 deletions termbot/sample_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Config(object):
CHANGE_DIRECTORY_CTD = os.environ.get("CHANGE_DIRECTORY_CTD", ".")
#
DELAY_BETWEEN_EDITS = int(os.environ.get("DELAY_BETWEEN_EDITS", "2"))
# TYPE command trigger
TYPE_CMD_TRIGGER = os.environ.get("TYPE_CMD_TRIGGER", "type")


class Production(Config):
Expand Down

0 comments on commit e9ca4b6

Please sign in to comment.