Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if data["type"] == "message_new":
- object = data["object"]
- id = object["peer_id"]
- msgID = object["id"]
- body = object["text"]
- fromID = object["from_id"]
- attachments = object["attachments"
- elif body.lower() == "/sv":
- photoURL = attachments[0]['photo']['sizes'][4]['url']
- addTime = object['date']
- response = requests.get(photoURL, stream=True)
- with open('img.jpg', 'wb') as out_file:
- shutil.copyfileobj(response.raw, out_file)
- del response
- uploadUrl = vkUser.method("photos.getChatUploadServer",
- {
- "chat_id":id
- })
- url = uploadUrl['upload_url']
- files = {'file': open('img.jpg', 'rb')}
- r = requests.post(url, files=files)
- t = r.json()
- vk.method("messages.send",
- {
- "peer_id": id,
- "random_id": random.randint(1, 2147483647),
- "message": t['response']
- })
- vkUser.method("messages.setChatPhoto",{"file":t['response']})
- else:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement