Ejemplo n.º 1
0
async def welcome(message: types.Message):
    button = KeyboardButton(B_REGISTRER)
    button.request_contact = True
    kb = ReplyKeyboardMarkup(resize_keyboard=True).add(button)
    await bot.send_message(message.chat.id, T_HELLO, reply_markup=kb)
    await bot.send_sticker(message.chat.id, 'CAADBAAD8AIAAlI5kwZeZ9hi6NX9qQI')
Ejemplo n.º 2
0
async def main_logic(message: types.Message):

    t0 = time.time()
    if message.text == 'clean':
        with open('data2.json', 'rb') as f:
            await bot.edit_message_media(InputMediaDocument(f), admin_id, 4)
    # with open('data.json', 'rb') as f:
    #     print(f)
    #     await bot.send_document(message.chat.id, f)
    print(message.message_id)
    data = await get_data()
    # print(data)
    print(len(data['users']))
    metka2 = False
    for user in data['users']:
        if user['chatid'] == message.chat.id:
            time_user = []
            try:
                for stroka in message.text.split(':'):
                    time_user.append(int(re.search(r'\d+', stroka).group()))

            except Exception as ex:
                # print(ex)
                pass

            print(time_user)
            if len(time_user) == 1:
                if time_user[0] > 0 and time_user[0] < 120:

                    new_time = datetime.datetime.now() + datetime.timedelta(
                        minutes=time_user[0])

                    metka_time = False
                    for time_us in user['calltime']:
                        if (new_time.time().hour +
                                3) == time_us[0] and new_time.time(
                                ).minute == time_us[1]:
                            await bot.send_message(
                                message.chat.id,
                                'На данное время у Вас уже записан звонок')
                            metka_time = True
                            break
                    if metka_time == False:
                        user['calltime'].append(
                            [new_time.time().hour + 3,
                             new_time.time().minute])
                        await save_data(data)
                        await bot.send_message(
                            message.chat.id,
                            'Вы добавили звонок на {}:{}'.format(
                                str(new_time.time().hour + 3),
                                str(new_time.time().minute)))
                else:
                    await bot.send_message(message.chat.id,
                                           'Укажите время от 1 до 120 минут')
            if len(time_user) == 2:
                if time_user[0] >= 0 and time_user[0] <= 24 and time_user[
                        1] >= 0 and time_user[1] <= 60:

                    metka_time = False
                    for time_us in user['calltime']:
                        if time_user[0] == time_us[0] and time_user[
                                1] == time_us[1]:
                            await bot.send_message(
                                message.chat.id,
                                'На данное время уже запланирован звонок')
                            metka_time = True
                            break
                    if metka_time == False:
                        user['calltime'].append([time_user[0], time_user[1]])
                        await save_data(data)
                        await bot.send_message(
                            message.chat.id,
                            'Вы добавили звонок на {}:{}'.format(
                                str(time_user[0]), str(time_user[1])))
                else:
                    await bot.send_message(
                        message.chat.id,
                        'Вы указали неправильное время. Попробуйте занова.')

            if message.text == B_CLEAN:
                user['calltime'].clear()
                await save_data(data)
                await bot.send_message(message.chat.id,
                                       'Все звонки удачно сброшены.')

            if message.text == B_CALL_NOW:
                client = Client(account_sid, auth_token)
                client.calls.create(url='https://ex.ru',
                                    to=user['phones'],
                                    from_='+12027967603')

            if message.text == B_LIST_CALLS:
                if len(user['calltime']) == 0:
                    await bot.send_message(
                        message.chat.id, 'У Вас нет запланированных звонков')
                else:
                    str_call_list = 'Запланированные звонки:\n'
                    for time_call in user['calltime']:
                        str_call_list += str(time_call[0]) + ':' + str(
                            time_call[1]) + '\n'
                    await bot.send_message(message.chat.id, str_call_list)
            if message.text == B_INFO:
                await bot.send_message(message.chat.id, 'Инфо тут')

            metka2 = True
            break
    if metka2 == False:
        button = KeyboardButton(B_REGISTRER)
        button.request_contact = True
        kb = ReplyKeyboardMarkup(resize_keyboard=True).add(button)
        await bot.send_message(
            message.chat.id,
            'Вы не зарегистрированы, нажмите на кнопку "Регистрация"',
            reply_markup=kb)

    if message.text == 'add':
        for number in range(10000):
            data['users'].append({
                'chatid': number,
                'phones': 8917,
                'state': 0,
                'calltime': []
            })

        with open('data3.json', 'w') as json_file:
            json.dump(data, json_file)
        with open('data3.json', 'rb') as f:
            await bot.edit_message_media(InputMediaDocument(f), admin_id, 4)

    t1 = time.time()
    print('end: ' + str(t1 - t0))