Skip to content

Commit

Permalink
Added parse_mode command line keys
Browse files Browse the repository at this point in the history
  • Loading branch information
anightshade authored and iw4p committed Nov 6, 2020
1 parent d2efb2a commit 9366843
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -68,6 +68,7 @@ tgsend accepts these arguments:
| ------ | ------ |
| --name / -n | A Name you choose while tglogin-ing and use for specify the current user you work on it |
| --username / -u | Target username that you want to send file, type `me` if you want to get it on your `saved messages` |
| --format { text, markdown, html }| How to parse message body. Default is `text`|
| --silent | Disable audible notification |
| --stdin | Read message text from stdin |

Expand Down
11 changes: 9 additions & 2 deletions telegramcloud/tgsend.py
Expand Up @@ -43,9 +43,16 @@ async def main():

if len(message) == 0:
print ("No text specified. Can't send empty message")
exit (1)
sys.exit (1)

await client.send_message(entity=target_chat, message=message, silent=args.silent)
if args.parse_mode == "text":
parse_mode = None
if args.parse_mode == "markdown":
parse_mode = "md"
if args.parse_mode == "html":
parse_mode = "html"

await client.send_message(entity=target_chat, message=message, silent=args.silent, parse_mode=parse_mode)


def cli():
Expand Down
2 changes: 2 additions & 0 deletions telegramcloud/utils/args.py
Expand Up @@ -32,6 +32,8 @@ def tgsend_args():
parser.add_argument("message", help="Message to send", nargs="*")
parser.add_argument("--name", "-n", help = "Unique profile name you've set at the first run", required = True)
parser.add_argument("--username", "-u", help = "Recipient username or chat id", required = True)
parser.add_argument("--format", default="text", dest="parse_mode", choices=["text", "markdown", "html"],
help="Parse mode for message body. Choose from 'text', 'markdown', or 'html'. Default is 'text'")
parser.add_argument("--stdin", help="Read message text from stdin", action="store_true")
parser.add_argument("--silent", help="Send silently, user will receive notification without sound", required=False, action="store_true")
args = parser.parse_args()
Expand Down

0 comments on commit 9366843

Please sign in to comment.