def telegram():
    data = json.loads(request.data)
    if data.get("message"):
        messageHandler.create_answer(data["message"],
                                     config['app']['tg']['token'], 1)
        return "ok"
    return "nothing"
예제 #2
0
def go_to_start(user_id, send=True):
    survey = Survey(user_id)
    survey.cleanup()
    survey = Survey(user_id)
    question = survey.step_question()
    if send:
        create_answer(user_id, question)
    return question, survey.user
예제 #3
0
파일: Bot.py 프로젝트: tanya124/MyBot
def processing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        messageHandler.create_answer(data['object'], token)
        return 'ok'
def vk():
    data = json.loads(request.data)
    if "type" not in data.keys():
        return "not vk"
    if data["type"] == "confirmation":
        return config['confirmation_token']
    elif data["type"] == "message_new":
        messageHandler.create_answer(data["object"], config['token'], 0)
        return "ok"
    return "nothing"
예제 #5
0
def processing():
    #Распаковываем json из пришедшего GET-запроса
    data = json.loads(request.data)
    #Вконтакте в своих запросах всегда отправляет поле типа
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        messageHandler.create_answer(data['object'], token)
        return 'ok'
예제 #6
0
def process(user_id, points=0, send=True):
    survey = Survey(user_id)
    survey.change_points(points)
    try:
        text = survey.step_question()
    except EndOfTest:
        text = str(survey.results())  # TODO: nice results
        survey.cleanup()
    if send:
        create_answer(user_id, text)
    return text, survey.user
예제 #7
0
def next(vk_id, body):
    if vk_id not in settings.admin_ids:
        return None, None

    if not body.startswith("ответ "):
        return None, None

    spl = body.split()
    data = vkapi.get_last_msg(spl[1])
    mh.create_answer(data, settings.token)

    return "Выполнено", None
예제 #8
0
def bot():
    resp = request.json
    if 'type' not in resp.keys():
        return abort(400)
    if resp['type'] == 'confirmation':
        return confirmation_string
    elif resp['type'] == 'message_new':
        print(resp)
        messageHandler.create_answer(peer_id=resp['object']['peer_id'],
                                     message=resp['object']['text'].lower())
        return 'ok'
    else:
        return abort(400)
예제 #9
0
def processing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'this is not vk data'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        print(data['object']['user_id'])
        print(data)
        user_id = data['object']['user_id']
        # отправляем сообщение
        messageHandler.create_answer(data['object'], token)
        return 'ok'
예제 #10
0
def processing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        messageHandler.create_answer(
            data['object'],
            token)  #тут все данные по объекту передаем в Handler
        return 'ok'
    elif data['type'] == 'group_join':
        messageHandler.welcome_new_user(data['object'], token)
        return 'ok'
예제 #11
0
def processing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        messageHandler.create_answer(data['object'])
        try:
            requests.post('https://ocheredsut.ru/api/1/conversations/messages',
                          json=data['object'])
        except Exception as e:
            print('Failed')
        return 'ok'
예제 #12
0
def processing():
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        if data["group_id"] == group_id:
            return confirmation_token
    elif data['type'] == 'message_new':
        if data["group_id"]== group_id:
            messageHandler.create_answer(data['object'], token)
            return 'ok'


    #######################################################################################################################################################
    return 'ok'
예제 #13
0
def processing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        data_forward = data
        data = data.get('object')
        while (data.get('fwd_messages', "") != ""):
            data = data.get('fwd_messages')
            data = dict(data[0])
        if (data.get('attachments', "") != ""):
            return 'ok'
        messageHandler.create_answer(data_forward['object'], token)
    return 'ok'
예제 #14
0
def processing():

     #Распаковываем json из пришедшего POST-запроса
     data = json.loads(request.data)
     #Вконтакте в своих запросах всегда отправляет поле типа
     if 'type' not in data.keys():
         print('return not vk')
         return 'not vk'
     if data['type'] == 'confirmation':
         return confirmation_token
     elif data['type'] == 'message_new':


         messageHandler.create_answer(data['object'], token)
         # Сообщение о том, что обработка прошла успешно
         return 'ok'
예제 #15
0
def processing():
    #Распаковываем json из пришедшего GET-запроса
    data = json.loads(request.data)
    #Вконтакте в своих запросах всегда отправляет поле типа
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        # session = vk.Session()
        # api = vk.API(session, v=5.0)
        # user_id = data['object']['user_id']
        # api.messages.send(access_token=token, user_id=str(user_id), message='Привет, я новый бот!')
        messageHandler.create_answer(data['object'], token)
        # Сообщение о том, что обработка прошла успешно
        return 'ok'
예제 #16
0
def processing():
    #Распаковываем json из пришедшего POST-запроса
    data = json.loads(request.data)
    #Вконтакте в своих запросах всегда отправляет поле типа
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        session = vk.Session()
        api = vk.API(session, v=5.0)
        user_id = data['object']['user_id']
        #api.messages.send(access_token=token, user_id=str(user_id),
        #message='Псс, ведутся работы с Callback_api, дизрегард зет, вам пока ответит \
        #какой-нибудь кожаный ублюдок')
        messageHandler.create_answer(data['object'], token)
        return 'ok'
예제 #17
0
def proccessing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if data['type'] == 'confirmation':
        return confirmation_token
    elif data['type'] == 'message_new':
        # получаем информацию из чёрного списка
        mas = get_info('black')
        user_id = data['object']['from_id']
        # если пользователь в чёрном списке-игнорим
        if in_blacklist(str(user_id), mas):
            return 'ok'
        # иначе отвечаем
        else:
            messageHandler.create_answer(data['object'], token)
            return 'ok'
예제 #18
0
def go_back(user_id, send=True):
    survey = Survey(user_id)
    question = survey.step_question(backward=True)
    if send:
        log = create_answer(user_id, question)
        if log == 'error':
            throttle_dict[user_id] = get_unixtime()
    return question, survey.user
예제 #19
0
def telegram():
    data = json.loads(request.data)
    if data.get("message"):
        #        if data["message"]["chat"]["id"] == 661793395:
        #            return "nothing"
        step = push_database(data["message"])
        step = messageHandler.create_answer(data["message"],
                                            config['app']['tg']['token'], step)
        update_user_step(step=step, user_id=str(data["message"]["chat"]["id"]))
        return "ok"
    return "nothing"
예제 #20
0
def process(user_id, points=0, send=True):
    artist = None
    survey = Survey(user_id)
    survey.change_points(points)
    try:
        text = survey.step_question()                       # next question
        path_to_img = ''
    except EndOfTest:
        create_answer(user_id, "Результат обрабатывается... ждите.")
        text = ""
        artist = Artist(user_id, survey.results())          # wait 4 seconds, hard computing
        path_to_img = artist.get_path_to_img()
        survey.cleanup()

    if send:
        log = create_answer(user_id, text, path_to_img)
        if log == 'error':
            throttle_dict[user_id] = get_unixtime()
        if artist is not None:
            artist.__del__()
    return text, survey.user
예제 #21
0
파일: app.py 프로젝트: tamkovich/Finagram
def telegram():
    data = json.loads(request.data)
    if data.get("message"):
        branch_name, status = push_database(data["message"])
        branch_name, status = messageHandler.create_answer(
            data["message"],
            config['app']['tg']['token'],
            branch_name,
            str(status),
        )
        update_user_state(branch=branch_name,
                          status=status,
                          user_id=data["message"]["chat"]["id"])
        return "ok"
    return "nothing"
예제 #22
0
def processing():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'

    if 'secret' not in data.keys():
        return 'not enough'

    if data['secret'] != settings.secret:
        return 'go home'

    if data['type'] == 'confirmation':
        return settings.confirmation_token

    if data['type'] == 'message_new':
        try:
            res = messageHandler.create_answer(data['object'], settings.token)
            if res != "good":
                vkapi.notify_admins(res)
            return 'ok'
        except Exception as e:
            vkapi.notify_admins('Бот упал...')
            vkapi.notify_admins(str(e))
            raise e
예제 #23
0
def echo(message):
    messageHandler.create_answer(bot, message)
예제 #24
0
def callback_echo(call):
    call.message.text = call.data
    messageHandler.create_answer(bot, call.message)
예제 #25
0
def go_back(user_id, send=True):
    survey = Survey(user_id)
    question = survey.step_question(backward=True)
    if send:
        create_answer(user_id, question)
    return question, survey.user
예제 #26
0
def test():
    meme = {'from_id': 163563035, 'peer_id': 163563035, 'text':'20.06-01.07', 'attachments': []}
    messageHandler.create_answer(meme)