P
P
pruha192018-12-06 12:50:41
Python
pruha19, 2018-12-06 12:50:41

Why is the bot flooding?

I wrote a bot on the callback api, and it duplicates and floods with messages. Code below, return "ok" entered!

from flask import *
import time
import vk
from cleverapi import CleverApi
session = vk.Session()
api = vk.API(session, v="5.8")
admin = "296223969"
token = "token"
app = Flask(__name__)

@app.route('/', methods = ['POST'])
def hello_world():
    r = request.data
    data = json.loads(r)
    if 'type' not in data:
        return "non vk request"
    if data['type'] == 'confirmation':
        return 'my code'
    elif data['type'] == 'message_new':
        if "geo" in data['object']:
            lat = data['object']['geo']['coordinates']['latitude']
            lon = data['object']['geo']['coordinates']['longitude']
            api.messages.send(access_token = token, user_id = data["object"]["from_id"], message = "Жду тебя через 5 секунд по координатам: Широта: "+str(lat)+", Долгота: "+str(lon))
            time.sleep(5)
            api.messages.send(access_token = token, user_id = data["object"]["from_id"], message = "Тряси свой телефон прямо сейчас!")
            apii = CleverApi("token")
            apii.bump(lat, lon)
            apii = CleverApi("token")
            apii.bump(lat, lon)
            apii = CleverApi("token")
            apii.bump(lat, lon)
            apii = CleverApi("token")
            apii.bump(lat, lon)
            time.sleep(5)
            api.messages.send(access_token = token, user_id = data["object"]["from_id"], message = "У тебя получилось бампнуться? Напиши ДА или НЕТ")
        if "text" in data["object"]:
            texxt = data["object"]["text"]
            errorid = data["object"]["from_id"]
        if texxt == "ДА":
            api.messages.send(access_token = token, user_id = data["object"]["from_id"], message = "Супер!")
        if texxt =="НЕТ":
            api.messages.send(access_token = token, user_id = data["object"]["from_id"], message = "Это плохо :с, я отправил это админу.")
            api.messages.send(access_token = token, user_id = admin, message = "У этого бампера не получился бамп: @id"+str(errorid))
    elif data['type'] == 'wall_repost':
        api.messages.send(access_token = token, user_id = data["object"]["from_id"], message ="Спасибо за репост! :р")
    elif data["type"] == "group_join":
        api.messages.send(access_token = token, user_id = data["object"]["user_id"], message ="Спасибо за то что вступил и поддерживаешь проект! с; ")
    return "ok"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maqstein, 2019-01-14
@pruha19

The problem really can be that the callback server does not receive ok. In such cases, it is better to use exception handling (try,except) and insert a finally block into which to push the response ok

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question