def dialogs_command(message): if logged(message): session = VkMessage(vk_tokens.get(str(message.chat.id))).session request_user_dialogs(session, message.chat.id) create_markup(message, message.chat.id, 0)
def send_doc(message, userid, group, forward_messages=None): filetype = message.content_type session = VkMessage(vk_tokens.get(str(message.chat.id))).session api = vk.API(session, v=VK_API_VERSION) if filetype == 'document' and 'video' not in message.document.mime_type: file = wget.download( FILE_URL.format(token, bot.get_file(getattr(message, filetype).file_id).wait().file_path)) openedfile = open(file, 'rb') files = {'file': openedfile} fileonserver = ujson.loads(requests.post(api.docs.getUploadServer()['upload_url'], files=files).text) attachment = api.docs.save(file=fileonserver['file'], title=getattr(message, filetype).file_name, tags='') openedfile.close() os.remove(file) elif filetype == 'voice': file = wget.download( FILE_URL.format(token, bot.get_file(getattr(message, filetype).file_id).wait().file_path)) openedfile = open(file, 'rb') files = {'file': openedfile} fileonserver = ujson.loads( requests.post(api.docs.getUploadServer(type='audio_message')['upload_url'], files=files).text) attachment = api.docs.save(file=fileonserver['file'], title='Аудиосообщение', tags='') openedfile.close() os.remove(file) elif filetype == 'document' and 'video' in message.document.mime_type: vk_sender(message, send_video) return else: # filetype == 'audio': file = wget.download( FILE_URL.format(token, bot.get_file(getattr(message, filetype).file_id).wait().file_path)) newfile = file.split('.')[0] + '.aac' os.rename(file, newfile) openedfile = open(newfile, 'rb') files = {'file': openedfile} fileonserver = ujson.loads(requests.post(api.docs.getUploadServer()['upload_url'], files=files).text) attachment = api.docs.save(file=fileonserver['file'], title=audio_title_creator(message, message.audio.performer, message.audio.title), tags='') openedfile.close() os.remove(newfile) if group: if message.caption: api.messages.send(chat_id=userid, message=message.caption, attachment='doc{}_{}'.format(attachment[0]['owner_id'], attachment[0]['did']), forward_messages=forward_messages) else: api.messages.send(chat_id=userid, attachment='doc{}_{}'.format(attachment[0]['owner_id'], attachment[0]['did']), forward_messages=forward_messages) else: if message.caption: api.messages.send(user_id=userid, message=message.caption, attachment='doc{}_{}'.format(attachment[0]['owner_id'], attachment[0]['did']), forward_messages=forward_messages) else: api.messages.send(user_id=userid, attachment='doc{}_{}'.format(attachment[0]['owner_id'], attachment[0]['did']), forward_messages=forward_messages)
def send_text(message, userid, group, forward_messages=None): session = VkMessage(vk_tokens.get(str(message.from_user.id))).session if group: vk.API(session, v=3.0).messages.send(chat_id=userid, message=message.text, forward_messages=forward_messages) else: vk.API(session, v=3.0).messages.send(user_id=userid, message=message.text, forward_messages=forward_messages)