mirror of
https://github.com/LonamiWebs/Telethon
synced 2025-09-05 00:35:15 +00:00
Added ability to upload and send media, and more fixes
Uploading and sending media are different things. Once you have uploaded a media file, you can send it to many users without uploading it again, since you have a handle to the uploaded file. Other fixes include not showing additional data on error messages and not generating correct code for sending bytes
This commit is contained in:
12
main.py
12
main.py
@@ -61,6 +61,7 @@ if __name__ == '__main__':
|
||||
print('You are now sending messages to "{}". Available commands:'.format(display))
|
||||
print(' !q: Quits the current chat.')
|
||||
print(' !h: prints the latest messages (message History) of the chat.')
|
||||
print(' !p <path>: sends a Photo located at the given path')
|
||||
|
||||
# And start a while loop to chat
|
||||
while True:
|
||||
@@ -80,6 +81,17 @@ if __name__ == '__main__':
|
||||
date = datetime.fromtimestamp(msg.date)
|
||||
print('[{}:{}] {}: {}'.format(date.hour, date.minute, name, msg.message))
|
||||
|
||||
# Send photo
|
||||
elif msg.startswith('!p '):
|
||||
file_path = msg[len('!p '):] # Slice the message to get the path
|
||||
|
||||
print('Uploading {}...'.format(file_path))
|
||||
input_file = client.upload_file(file_path)
|
||||
|
||||
# After we have the handle to the uploaded file, send it to our peer
|
||||
client.send_photo_file(input_file, input_peer)
|
||||
print('Media sent!')
|
||||
|
||||
# Send chat message (if any)
|
||||
elif msg:
|
||||
client.send_message(input_peer, msg, markdown=True, no_web_page=True)
|
||||
|
Reference in New Issue
Block a user