Skip to content

Commit

Permalink
Command line option to select format for the file caption
Browse files Browse the repository at this point in the history
  • Loading branch information
anightshade authored and iw4p committed Nov 18, 2020
1 parent e9b514f commit f65f5d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion telegramcloud/__main__.py
Expand Up @@ -51,9 +51,17 @@ async def main():

# Upload file to specific target_chat and retrieve the file_id
elif args.mode == 'upload':

if args.parse_mode == "text":
parse_mode = None
if args.parse_mode == "markdown":
parse_mode = "md"
if args.parse_mode == "html":
parse_mode = "html"

if args.path and username:
try:
message = await client.send_file(entity=target_chat, file=args.path, caption=args.caption, progress_callback=upload_callback)
message = await client.send_file(entity=target_chat, file=args.path, caption=args.caption, progress_callback=upload_callback, parse_mode=parse_mode)
print("File id: {}".format(message.file.id))
except:
print("Something went wrong, make sure the directory path is valid.")
Expand Down
2 changes: 2 additions & 0 deletions telegramcloud/utils/args.py
Expand Up @@ -9,6 +9,8 @@ def tgcloud_args():
parser.add_argument("--username", "-u", help = "Set target username for sending file/files to her/him", required = True)
parser.add_argument("--path", "-p", help = "Path of the file/files you want to upload", required = True)
parser.add_argument("--mode", "-m", help="Change mode to upload or download", required=True)
parser.add_argument("--format", default="text", dest="parse_mode", choices=["text", "markdown", "html"],
help="Parse mode for file caption. Choose from 'text', 'markdown', or 'html'. Default is 'text'")
parser.add_argument("--caption", "-c", help = "for upload mode: write caption/text under file, for download mode: download file by its caption or name", default = '', required = False)

args = parser.parse_args()
Expand Down

0 comments on commit f65f5d1

Please sign in to comment.