Ejemplo n.º 1
0
 def upload_file(self, path):
     up = VkUpload(self.config.api)
     filename = os.path.basename(path)
     new_uploaded_file = up.document(doc=path, title=filename)
     return new_uploaded_file['doc']['owner_id'], new_uploaded_file['doc'][
         'id']
Ejemplo n.º 2
0
        try:
            for event in longpoll.listen():
                if event.type == VkBotEventType.MESSAGE_NEW:
                    # print(event.obj)
                    user_id = event.obj.message['from_id']
                    if len(event.obj.message['fwd_messages']):
                        attachments = event.obj.message['fwd_messages'][0]['attachments']
                    else:
                        attachments = event.obj.message['attachments']
                    if 0 < len(attachments) < 3:
                        for a in attachments:
                            if a['type'] == 'photo':
                                sizes = a['photo']['sizes']
                                for s in sizes:
                                    if s['type'] == 'x':
                                        pic = s['url']
                                        break
                                item = [pic, user_id]
                                q.put(item)
                    elif event.obj.message['text'] == '/log':
                        logfile = upload.document(log.get_file_path(), title=log.get_file_path(),
                                                  message_peer_id=user_id)['doc']
                        doc = "doc" + str(logfile['owner_id']) + "_" + str(logfile['id'])
                        vk.messages.send(user_id=user_id, random_id=get_random_id(), attachment=doc)
                    else:
                        vk.messages.send(user_id=user_id, random_id=get_random_id(),
                                         message=msg_dict[msgid.msg_need_2_photos.value])
        except Exception as e:
            log.log("Error: " + str(e))
            time.sleep(10)