diff --git a/vk_messages.py b/vk_messages.py
index f7bf859..e2d561b 100644
--- a/vk_messages.py
+++ b/vk_messages.py
@@ -2,6 +2,7 @@ import vk
import time
import requests
import wget
+import os
class VkPolling:
@@ -72,30 +73,42 @@ def attachment_handler(m, user, bot, chat_id):
bot.send_message(chat_id, data, parse_mode='HTML',
disable_notification=check_notification(m)).wait()
- if doc['doc']['ext'] == 'pdf' or doc['doc']['ext'] == 'zip':
+ elif doc['doc']['ext'] == 'pdf' or doc['doc']['ext'] == 'zip':
link = doc['doc']['url']
data = add_reply_info(m, user["first_name"], user["last_name"], ) + 'Документ'.format(
link)
bot.send_message(chat_id, data, parse_mode='HTML',
disable_notification=check_notification(m)).wait()
- if doc['doc']['ext'] == 'jpg' or doc['doc']['ext'] == 'png':
+ elif doc['doc']['ext'] == 'jpg' or doc['doc']['ext'] == 'png':
link = doc['doc']['url']
data = add_reply_info(m, user["first_name"], user["last_name"], ) + 'Документ'
- bot.send_message(chat_id, data, parse_mode='HTML',
- disable_notification=check_notification(m)).wait()
+ notification = bot.send_message(chat_id, data, parse_mode='HTML',
+ disable_notification=check_notification(m)).wait()
uploading = bot.send_chat_action(chat_id, 'upload_document')
- bot.send_document(chat_id, link).wait()
+ bot.send_document(chat_id, link, reply_to_message_id=notification.message_id,
+ disable_notification=check_notification(m)).wait()
uploading.wait()
- if doc['doc']['ext'] == 'doc' or doc['doc']['ext'] == 'docx' or doc['doc']['ext'] == 'rar' or \
- doc['doc']['ext'] == 'ogg':
- data = add_reply_info(m, user["first_name"], user["last_name"], ) + 'Документ'
+ elif doc['doc']['ext'] == 'ogg':
+ link = doc['doc']['url']
+ data = add_reply_info(m, user["first_name"], user["last_name"], ) + \
+ 'Аудио'.format(link)
bot.send_message(chat_id, data, parse_mode='HTML',
disable_notification=check_notification(m)).wait()
+
+ elif doc['doc']['ext'] == 'doc' or doc['doc']['ext'] == 'docx':
+ data = add_reply_info(m, user["first_name"], user["last_name"], ) + 'Документ'
+ notification = bot.send_message(chat_id, data, parse_mode='HTML',
+ disable_notification=check_notification(m)).wait()
uploading = bot.send_chat_action(chat_id, 'upload_document')
- bot.send_document(chat_id, wget.download(requests.get(doc['doc']['url']).url)).wait()
+ file = wget.download(requests.get(doc['doc']['url']).url)
+ bot.send_document(chat_id, open(file, 'rb'),
+ reply_to_message_id=notification.message_id,
+ disable_notification=check_notification(m)).wait()
uploading.wait()
+ file.close()
+ os.remove(file)
else:
link = doc['doc']['url']
@@ -117,7 +130,8 @@ def add_reply_info(m, first_name, last_name):
if 'chat_id' in m:
# TODO: Handle forwared messages
return '{} {} @ {}:\n{}\n'.format(m['uid'], m['chat_id'], first_name,
- last_name, m['title'], m['body'].replace('
', '\n'))
+ last_name, m['title'],
+ m['body'].replace('
', '\n'))
else:
return '{} {}:\n{}\n'.format(m['uid'], first_name, last_name,
m['body'].replace('
', '\n'))