Beispiel #1
0
def vkGetMessages():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if (vkapi.check_server_key == False):
        return 'secret_key_is_wrong'
    if data['type'] == 'confirmation':
        return config.SERVER_COMFIRMATION_KEY
    elif data['type'] == 'message_new':
        vkapi.create_answer(data['object'], config.VK_API_KEY)
        write_json(data, fileName="vkmessage")
        # write_json(data['object'], fileName="vkmessage")
        return 'ok'
Beispiel #2
0
def vkGetPosts():
    data = json.loads(request.data)
    if 'type' not in data.keys():
        return 'not vk'
    if (vkapi.check_server_key == False):
        return 'secret_key_is_wrong'
    if data['type'] == 'confirmation':
        return config.SERVER_COMFIRMATION_KEY
    else:
        write_json(data['object'], fileName="postFile")
        result = create_sendler_form(data['object'])
        result.Attachments = GetAttachments(data['object'])
        url = config.CSHARP_API_URL + "sendler/vkpost"
        headers = {
            'Content-type': 'application/json',  # Определение типа данных
            'Accept': 'text/plain',
            'Content-Encoding': 'utf-8'
        }
        if ((result is not None) and result != 400):
            write_json(data=result.__dict__, fileName="postresult")
            # write_json(data=jsons.dump(result.__dict__), fileName="postresult")
            response = opers.ExecuteActions(url=url,
                                            reqstType="POST",
                                            sending_body=jsons.dump(
                                                result.__dict__),
                                            headers=headers)
            if ("status_code" in response):
                send_error_message_to_developer(response)
            else:
                write_json(data=response, fileName="responseSendler")
                ApplySending(data=response, teleBot=teleBot, vkBot=vkapi.api)
            return 'ok'
            # if (response == "REQUEST_ERROR")
    return 'ok'
Beispiel #3
0
def onIncommingMessages(message):
    command = opers.get_command(message.text)
    write_json(data=message.chat.__dict__, fileName="telemessage")
    if (message.text in config.LOCAL_COMMANDS):
        text = "на тебе фото"
        imgUrl = "https://sun9-11.userapi.com/c840329/v840329318/cdeb/dHft4lHtLao.jpg"
        teleBot.send_message(message.chat.id, f'{text}\n{imgUrl}')
    elif ((command is not None) and command != 404):
        client.ChatId = str(message.chat.id)
        url = GetUrlBotApiInfo(command)
        response_result = opers.ExecuteActions(url)
        if (response_result == "REQUEST_ERROR"):
            server_error(message)
            send_error_message_to_developer(response_result)
        else:
            if ("status_code" in response_result):
                server_error(message)
            else:
                if ("stepCode" in response_result):
                    write_json(response_result)
                    if ("actionList" in response_result):
                        key_board = types.InlineKeyboardMarkup()
                        for item in response_result['actionList']:
                            keyAction = types.InlineKeyboardButton(
                                text=item['name'], callback_data=item['code'])
                            key_board.add(keyAction)
                        teleBot.send_message(message.from_user.id,
                                             text=response_result['stepName'],
                                             reply_markup=key_board)
                    else:
                        teleBot.send_message(message.from_user.id,
                                             text=response_result['stepName'])
                elif ("sectionCode" in response_result):
                    pass
                else:
                    send_error_message_to_developer(response_result)
    else:
        command_is_unknown(message)
Beispiel #4
0
def index():
    print(TOKEN)
    r = request.get_json()
    write_json(r)
    # если бот вызван в inlineрежиме
    if 'inline_query' in r:
        id = r['inline_query']['id']
        query = r['inline_query']['query']
        chat_id = r['inline_query']['from']['id']
        result = search(query)
        if result:
            admin = is_admin(chat_id)
            send_inline_results(id, admin, result)
        return jsonify(r)

    elif 'callback_query' in r:
        callback_data = r['callback_query']['data'].split('__')
        callback_from_chat_id = r['callback_query']['from']['id']
        first_name = r['callback_query']['from']['first_name']
        callback_message = r['callback_query'].get('message')
        if callback_message:
            callback_message_id = r['callback_query']['message']['message_id']
            callback_message_text = r['callback_query']['message']['text']

        if callback_data[0] == 'delete':
            if is_admin(callback_from_chat_id):
                delete = delete_contact(callback_data[1])
                text = 'Удалено!' if delete else 'ID не найден.'
                send_Message(callback_from_chat_id, text=text)

        return jsonify(r)

    elif 'message' in r:
        chat_id = r['message']['chat']['id']
        first_name = r['message']['from']['first_name']
        message = r['message'].get('text')
        via_bot = r['message'].get('via_bot')

        access = check_user(first_name, chat_id)
        if not access:
            return jsonify(r)

        if message:
            if message == '/exit':
                CONTACTS.pop(chat_id, None)
                send_Message(chat_id, text='OK!')
                return jsonify(r)

            if chat_id in CONTACTS:
                if CONTACTS[chat_id] == 'adress':
                    create_contact(message)
                    CONTACTS.pop(chat_id, None)
                    send_Message(chat_id, text='Сохранено!')
                    return jsonify(r)

            if re.search(r'add', message):
                # Добавление пользователя.
                if is_admin(chat_id):
                    add_user(message)

            elif message == 'Аварии ШПД':
                send_event(chat_id, input='input.txt')

            elif message == 'Аварии КТВ':
                send_event(chat_id, input='input_ktv.txt')

            elif message == 'Аварии ИБП':
                send_event(chat_id, input='input_ups.txt')

            elif message == 'Аварии RX':
                send_event(chat_id, input='input_rx.txt')

            elif message == 'Добавить контакт':
                if is_admin(chat_id):
                    CONTACTS[chat_id] = 'adress'
                    send_Message(
                        chat_id,
                        text=
                        'Ввежите данные по следующему шаблону:\n*Адрес дома* _пробел_ *контактные данные*\nЕсли не хотите добавлять данные нажмите /exit'
                    )
                else:
                    send_Message(chat_id,
                                 text='У вас нет доступа к добавлению!')

            else:
                if via_bot:
                    return jsonify(r)

                text = '*МТС-ШПД-БОТ*\nДля получения информации по авариям воспользуйтесь соответствующими клавишами.\nСписок аварий обновляется раз в *10 минут*.\nДля поиска контактов начните вводить сообщение:\n*@MTS_SHPD_Bot* _Адрес который ищите_'
                send_Message(chat_id, text=text, kb=1)

    return jsonify(r)
Beispiel #5
0
def Sendler():
    data = json.loads(request.data)
    write_json(data, fileName="post")