G
G
gggggooooooooooood2018-09-28 05:21:34
Python
gggggooooooooooood, 2018-09-28 05:21:34

How to make the bot react only to the commands of a certain person?

import vk_api
import time
import codecs


vk = vk_api.VkApi(login = 'log', password='pass')
vk.auth()
while True:
        messages = vk.method('messages.getConversations', {'offset': 0, "count": 20, 'filter': 'unread'})
        if messages["count"] >= 1:
            id = messages['items'][0]['last_message']["from_id"]
            body = messages["items"][0]['last_message']['text']
            if body.lower() == "!crush":
                for i in range(10):
                    file = open('f.txt')
                    f = file.read()
                    vk.method('messages.send', {'peer_id': id, 'message': f})
                    file.close()
            elif body.lower() == "...":
                vk.method('messages.send', {'peer_id': id, 'message': "..."})
            else:
                vk.method('messages.send', {'peer_id': id, 'message': "text"})
            time.sleep(1)

Here's the actual code. It responds to commands, but "text" loops, that is, if you write something left, the bot will spam until it is overtaken by captcha.
The bot, even if he is given a command in a conversation, starts to write in PM, obviously this is because of the id, but I don’t know how to fix it, because I did it 2 days ago, so I’m generally a cormorant, please help in detail. Ideally, the bot should: respond to the commands of a certain person in a conversation, start spamming on command and stop on command, and also accept the id of the user who needs to be spammed in PM, this is also only from the 1st person. Thanks if anyone can help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question