D
D
Dmitry2020-07-22 15:26:15
Python
Dmitry, 2020-07-22 15:26:15

How to clear a message from mentions?

I want to make it so that the bot can respond to mentions. I can’t do it myself, but there is very little information about this on the Internet.

import random
import json
from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import time
from vk_api.utils import get_random_id


ping = 'пау!','понг!','понг','пау'
print("")
print("====================================")
print("")
print("Бот работает!")
print("")
print("====================================")
time.sleep(0.2)

def counter(user):
    file = open("stats.json", "r") # "r" - read , "w" - write
    data = json.loads(file.read())
    data["counter"] += 1
    if user not in data["users"]:
        data["users"].append(user)
    file = open("stats.json", "w")
    file.write(json.dumps(data))
def getCounter():
    file = open("stats.json", "r")  # "r" - read , "w" - write
    data = json.loads(file.read())
    return data["counter"]
def getUsers():
    file = open("stats.json", "r")  # "r" - read , "w" - write
    data = json.loads(file.read())
    return len(data["users"])

def main() -> None:
    vk_session = VkApi(token= 'цензура')
    long_poll = VkBotLongPoll(vk_session, 'хых')
    vk = vk_session.get_api()
    users = vk.users

    for event in long_poll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW:
            time.sleep(0.2)
            peer_id = event.obj['peer_id']
            message = event.obj['text'].lower()
            counter(peer_id)

            if message == 'ку':
                vk.messages.send(
                    peer_id=peer_id,
                    message='Бонжур!',
                    random_id=get_random_id(),
                )
            if message == "пинг" or message == "ping":
                vk.messages.send(peer_id=peer_id, random_id=get_random_id(), message=ping[random.randint(0, len(ping) - 1)],)
            if message == 'сколько сообщений обработано' or message == 'ссо':
                vk.messages.send(
                    peer_id=peer_id,
                    message="Cообщений обработано: " + str(getCounter()) + "\n"
                            "\n"
                            "Цель: 10000 сообщений \n"
                            "Собрано: " + str(getCounter()) +"/10000 сообщений",
                    random_id=get_random_id(),
                )


if __name__ == '__main__':
    main()

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